Update BASIC.ino example

This commit is contained in:
Phat Nguyen
2024-06-24 18:34:24 +07:00
parent 57c33e4900
commit dbc63194e6
12 changed files with 1079 additions and 471 deletions

View File

@ -7,11 +7,11 @@
#define SENSOR_CO2_CALIB_COUNTDOWN_MAX 5 /** sec */
#define RGB_COLOR_R 255, 0, 0 /** Red */
#define RGB_COLOR_G 0, 255, 0 /** Green */
#define RGB_COLOR_Y 255, 255, 0 /** Yellow */
#define RGB_COLOR_O 255, 165, 0 /** Organge */
#define RGB_COLOR_P 160, 32, 240 /** Purple */
#define RGB_COLOR_R 255, 0, 0 /** Red */
#define RGB_COLOR_G 0, 255, 0 /** Green */
#define RGB_COLOR_Y 255, 255, 0 /** Yellow */
#define RGB_COLOR_O 255, 165, 0 /** Organge */
#define RGB_COLOR_P 160, 32, 240 /** Purple */
/**
* @brief Animation LED bar with color
@ -228,6 +228,9 @@ void StateMachine::co2Calibration(void) {
String str =
"after " + String(SENSOR_CO2_CALIB_COUNTDOWN_MAX - i) + " sec";
disp.setText("Start CO2 calib", str.c_str(), "");
} else if (ag->isBasic()) {
String str = String(SENSOR_CO2_CALIB_COUNTDOWN_MAX - i) + " sec";
disp.setText("CO2 Calib", "after", str.c_str());
} else {
logInfo("Start CO2 calib after " +
String(SENSOR_CO2_CALIB_COUNTDOWN_MAX - i) + " sec");
@ -238,6 +241,8 @@ void StateMachine::co2Calibration(void) {
if (ag->s8.setBaselineCalibration()) {
if (ag->isOne() || (ag->isPro4_2()) || ag->isPro3_7()) {
disp.setText("Calibration", "success", "");
} else if (ag->isBasic()) {
disp.setText("CO2 Calib", "success", "");
} else {
logInfo("CO2 Calibration: success");
}
@ -264,7 +269,10 @@ void StateMachine::co2Calibration(void) {
} else {
if (ag->isOne() || (ag->isPro4_2()) || ag->isPro3_7()) {
disp.setText("Calibration", "failure!!!", "");
} else {
} else if(ag->isBasic()) {
disp.setText("CO2 calib", "failure!!!", "");
}
else {
logInfo("CO2 Calibration: failure!!!");
}
delay(2000);
@ -279,15 +287,16 @@ void StateMachine::co2Calibration(void) {
if (ag->s8.setAbcPeriod(config.getCO2CalibrationAbcDays() * 24)) {
resultStr = "successful";
}
String fromStr = String(curHour/24) + " days";
if(curHour == 0){
String fromStr = String(curHour / 24) + " days";
if (curHour == 0) {
fromStr = "off";
}
String toStr = String(config.getCO2CalibrationAbcDays()) + " days";
if(config.getCO2CalibrationAbcDays() == 0) {
if (config.getCO2CalibrationAbcDays() == 0) {
toStr = "off";
}
String msg = "Setting S8 from " + fromStr + " to " + toStr + " " + resultStr;
String msg =
"Setting S8 from " + fromStr + " to " + toStr + " " + resultStr;
logInfo(msg);
}
} else {
@ -314,9 +323,7 @@ void StateMachine::ledBarTest(void) {
}
}
void StateMachine::ledBarPowerUpTest(void) {
ledBarRunTest();
}
void StateMachine::ledBarPowerUpTest(void) { ledBarRunTest(); }
void StateMachine::ledBarRunTest(void) {
disp.setText("LED Test", "running", ".....");
@ -398,8 +405,8 @@ StateMachine::~StateMachine() {}
* @param state
*/
void StateMachine::displayHandle(AgStateMachineState state) {
// Ignore handle if not ONE_INDOOR board
if (!(ag->isOne() || (ag->isPro4_2()) || ag->isPro3_7())) {
// Ignore handle if not support display
if (!(ag->isOne() || (ag->isPro4_2()) || ag->isPro3_7() || ag->isBasic())) {
if (state == AgStateMachineCo2Calibration) {
co2Calibration();
}
@ -417,11 +424,17 @@ void StateMachine::displayHandle(AgStateMachineState state) {
case AgStateMachineWiFiManagerMode:
case AgStateMachineWiFiManagerPortalActive: {
if (wifiConnectCountDown >= 0) {
String line1 = String(wifiConnectCountDown) + "s to connect";
String line2 = "to WiFi hotspot:";
String line3 = "\"airgradient-";
String line4 = ag->deviceId() + "\"";
disp.setText(line1, line2, line3, line4);
if (ag->isBasic()) {
String ssid = "\"airgradient-" + ag->deviceId() + "\" " +
String(wifiConnectCountDown) + String("s");
disp.setText("Connect tohotspot:", ssid.c_str(), "");
} else {
String line1 = String(wifiConnectCountDown) + "s to connect";
String line2 = "to WiFi hotspot:";
String line3 = "\"airgradient-";
String line4 = ag->deviceId() + "\"";
disp.setText(line1, line2, line3, line4);
}
wifiConnectCountDown--;
}
break;
@ -435,7 +448,12 @@ void StateMachine::displayHandle(AgStateMachineState state) {
break;
}
case AgStateMachineWiFiOkServerConnecting: {
disp.setText("Connecting to", "Server", "...");
if (ag->isBasic()) {
disp.setText("Connecting", "to", "Server...");
} else {
disp.setText("Connecting to", "Server", "...");
}
break;
}
case AgStateMachineWiFiOkServerConnected: {
@ -451,7 +469,11 @@ void StateMachine::displayHandle(AgStateMachineState state) {
break;
}
case AgStateMachineWiFiOkServerOkSensorConfigFailed: {
disp.setText("Monitor not", "setup on", "dashboard");
if (ag->isBasic()) {
disp.setText("Monitor", "not on", "dashboard");
} else {
disp.setText("Monitor not", "setup on", "dashboard");
}
break;
}
case AgStateMachineWiFiLost: {
@ -502,7 +524,7 @@ void StateMachine::displayHandle(void) { displayHandle(dispState); }
*
*/
void StateMachine::displaySetAddToDashBoard(void) {
if(addToDashBoard == false) {
if (addToDashBoard == false) {
addToDashboardTime = 0;
addToDashBoardToggle = true;
}
@ -527,7 +549,8 @@ void StateMachine::displayWiFiConnectCountDown(int count) {
void StateMachine::ledAnimationInit(void) { ledBarAnimationCount = -1; }
/**
* @brief Handle LED from state, only handle LED if board type is: One Indoor or Open Air
* @brief Handle LED from state, only handle LED if board type is: One Indoor or
* Open Air
*
* @param state
*/