|
@@ -28,9 +28,12 @@
|
|
|
*/
|
|
|
|
|
|
//Define included headers.
|
|
|
+#define NEXTION_SUPPORT
|
|
|
#include <ArduinoBLE.h>
|
|
|
#include <SPI.h>
|
|
|
-
|
|
|
+#ifdef NEXTION_SUPPORT
|
|
|
+#include "EasyNextionLibrary.h"
|
|
|
+#endif
|
|
|
//Define BLE service.
|
|
|
BLEService LambdaService("C664F3C0-81B3-4E7B-A2F6-EA96181A2E71");
|
|
|
BLEUnsignedCharCharacteristic OxygenLevelChar("C83C027E-F105-4E0D-AA8F-801AC553D5C1", BLERead | BLENotify);
|
|
@@ -84,6 +87,8 @@ const float iGain = 0.8; /* Integral
|
|
|
const float dGain = 10; /* Derivative gain. Default = 10*/
|
|
|
int serial_counter = 0;
|
|
|
//Lambda Conversion Lookup Table. (ADC 39-791).
|
|
|
+
|
|
|
+EasyNex myNex(Serial1);
|
|
|
const PROGMEM float Lambda_Conversion[753] {
|
|
|
0.750, 0.751, 0.752, 0.752, 0.753, 0.754, 0.755, 0.755, 0.756, 0.757, 0.758, 0.758, 0.759, 0.760, 0.761, 0.761, 0.762, 0.763, 0.764, 0.764,
|
|
|
0.765, 0.766, 0.766, 0.767, 0.768, 0.769, 0.769, 0.770, 0.771, 0.772, 0.772, 0.773, 0.774, 0.774, 0.775, 0.776, 0.777, 0.777, 0.778, 0.779,
|
|
@@ -338,9 +343,13 @@ void UpdateUI() {
|
|
|
UpdateSerialOutput();
|
|
|
|
|
|
//Output display data.
|
|
|
-
|
|
|
- Serial.print(Lookup_Lambda(adcValue_UA) * AirFuelRatioOctane, 2);
|
|
|
- Serial.print(Lookup_Lambda(adcValue_UA), 2);
|
|
|
+ myNex.writeStr("lambda.txt",(String)(Lookup_Lambda(adcValue_UA) * AirFuelRatioOctane));
|
|
|
+ myNex.writeStr("adca.txt",(String)Lookup_Lambda(adcValue_UA));
|
|
|
+ myNex.writeStr("heaterstatus.txt",(String)HeaterStatus);
|
|
|
+ myNex.writeStr("hardwareid.txt",(String)hardwareId);
|
|
|
+ myNex.writeStr("cj125_status.txt",(String)CJ125_Status);
|
|
|
+ myNex.writeStr("adcr.txt",(String)adcValue_UR);
|
|
|
+ myNex.writeStr("adcb.txt",(String)adcValue_UB);
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -350,7 +359,9 @@ void setup() {
|
|
|
|
|
|
//Set up serial communication.
|
|
|
Serial.begin(9600);
|
|
|
- Serial1.begin(115200);
|
|
|
+#ifdef NEXTION_SUPPORT
|
|
|
+ myNex.begin(115200);
|
|
|
+#endif
|
|
|
//Set up SPI.
|
|
|
SPI.begin(); /* Note, SPI will disable the bult in LED*/
|
|
|
SPI.setClockDivider(SPI_CLOCK_DIV128);
|
|
@@ -375,13 +386,21 @@ void setup() {
|
|
|
}
|
|
|
|
|
|
void loop() {
|
|
|
- Serial.println("TEST");
|
|
|
//Update Analog Values.
|
|
|
UpdateInputs();
|
|
|
|
|
|
//Update front ends.
|
|
|
UpdateBLEOutput();
|
|
|
-
|
|
|
+ if ( (100 / SERIAL_RATE) == serial_counter) {
|
|
|
+
|
|
|
+ //Reset counter.
|
|
|
+ serial_counter = 0;
|
|
|
+
|
|
|
+ //Update frontends.
|
|
|
+ UpdateUI();
|
|
|
+
|
|
|
+ }
|
|
|
+ serial_counter++;
|
|
|
//Turn off heating.
|
|
|
if (adcValue_UB < UBAT_MIN || CJ125_Status != CJ125_DIAG_REG_STATUS_OK) {
|
|
|
|
|
@@ -437,21 +456,13 @@ void loop() {
|
|
|
|
|
|
//Update frontends.
|
|
|
UpdateBLEOutput();
|
|
|
-
|
|
|
+ UpdateUI();
|
|
|
//Increment.
|
|
|
t += 1;
|
|
|
delay(10);
|
|
|
|
|
|
}
|
|
|
- if ( (100 / SERIAL_RATE) == serial_counter) {
|
|
|
-
|
|
|
- //Reset counter.
|
|
|
- serial_counter = 0;
|
|
|
|
|
|
- //Update frontends.
|
|
|
- UpdateUI();
|
|
|
-
|
|
|
- }
|
|
|
//Ramp up phase, +0.4V / s until 100% PWM from 8.5V.
|
|
|
float UHeater = 8.5;
|
|
|
while (UHeater < 13.0 && adcValue_UB > UBAT_MIN && adcValue_UR > adcValue_UR_Optimal) {
|
|
@@ -491,5 +502,5 @@ void loop() {
|
|
|
HeaterStatus = 2;
|
|
|
|
|
|
}
|
|
|
- serial_counter++;
|
|
|
+
|
|
|
}
|