From 221730160b6af6784a8618031a5bfe36f08864b8 Mon Sep 17 00:00:00 2001 From: Phat Nguyen Date: Wed, 1 May 2024 21:02:57 +0700 Subject: [PATCH 1/2] fix led bar button test not work on power up --- examples/OneOpenAir/OneOpenAir.ino | 2 +- src/AgStateMachine.cpp | 34 +++++++++++++++++++----------- src/AgStateMachine.h | 2 ++ src/App/AppDef.h | 1 + 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/examples/OneOpenAir/OneOpenAir.ino b/examples/OneOpenAir/OneOpenAir.ino index 3bb6fc8..6c1f9be 100644 --- a/examples/OneOpenAir/OneOpenAir.ino +++ b/examples/OneOpenAir/OneOpenAir.ino @@ -162,7 +162,7 @@ void setup() { bool connectToWifi = false; if (ag->isOne()) { if (ledBarButtonTest) { - stateMachine.executeLedBarTest(); + stateMachine.executeLedBarPowerUpTest(); } else { ledBarEnabledUpdate(); connectToWifi = true; diff --git a/src/AgStateMachine.cpp b/src/AgStateMachine.cpp index 5efb6f7..0fccf78 100644 --- a/src/AgStateMachine.cpp +++ b/src/AgStateMachine.cpp @@ -302,20 +302,24 @@ void StateMachine::co2Calibration(void) { void StateMachine::ledBarTest(void) { if (config.isLedBarTestRequested()) { - if (config.getCountry() == "TH") { - uint32_t tstart = millis(); - logInfo("Start run LED test for 2 min"); - while (1) { - ledBarRunTest(); - uint32_t ms = (uint32_t)(millis() - tstart); - if (ms >= (60 * 1000 * 2)) { - logInfo("LED test after 2 min finish"); - break; - } - } - } else { + ledBarPowerUpTest(); + } +} + +void StateMachine::ledBarPowerUpTest(void) { + if (config.getCountry() == "TH") { + uint32_t tstart = millis(); + logInfo("Start run LED test for 2 min"); + while (1) { ledBarRunTest(); + uint32_t ms = (uint32_t)(millis() - tstart); + if (ms >= (60 * 1000 * 2)) { + logInfo("LED test after 2 min finish"); + break; + } } + } else { + ledBarRunTest(); } } @@ -706,6 +710,8 @@ void StateMachine::handleLeds(AgStateMachineState state) { case AgStateMachineLedBarTest: ledBarTest(); break; + case AgStateMachineLedBarPowerUpTest: + ledBarPowerUpTest(); default: break; } @@ -759,3 +765,7 @@ void StateMachine::executeCo2Calibration(void) { void StateMachine::executeLedBarTest(void) { handleLeds(AgStateMachineLedBarTest); } + +void StateMachine::executeLedBarPowerUpTest(void) { + handleLeds(AgStateMachineLedBarPowerUpTest); +} diff --git a/src/AgStateMachine.h b/src/AgStateMachine.h index 7299bb3..fa33549 100644 --- a/src/AgStateMachine.h +++ b/src/AgStateMachine.h @@ -28,6 +28,7 @@ private: void pm25handleLeds(void); void co2Calibration(void); void ledBarTest(void); + void ledBarPowerUpTest(void); void ledBarRunTest(void); void runLedTest(char color); @@ -49,6 +50,7 @@ public: AgStateMachineState getLedState(void); void executeCo2Calibration(void); void executeLedBarTest(void); + void executeLedBarPowerUpTest(void); }; #endif /** _AG_STATE_MACHINE_H_ */ diff --git a/src/App/AppDef.h b/src/App/AppDef.h index 7009f92..546ce59 100644 --- a/src/App/AppDef.h +++ b/src/App/AppDef.h @@ -59,6 +59,7 @@ enum AgStateMachineState { /* LED bar testing */ AgStateMachineLedBarTest, + AgStateMachineLedBarPowerUpTest, /** LED: Show working state. * Display: Show dashboard */ From f32d6b1bbea6d4c65ac66783107e332848fd130d Mon Sep 17 00:00:00 2001 From: Phat Nguyen Date: Thu, 2 May 2024 09:10:43 +0700 Subject: [PATCH 2/2] Remove country dependency on LED bar button test --- src/AgStateMachine.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/AgStateMachine.cpp b/src/AgStateMachine.cpp index 0fccf78..0a3665a 100644 --- a/src/AgStateMachine.cpp +++ b/src/AgStateMachine.cpp @@ -302,25 +302,25 @@ void StateMachine::co2Calibration(void) { void StateMachine::ledBarTest(void) { if (config.isLedBarTestRequested()) { - ledBarPowerUpTest(); + if (config.getCountry() == "TH") { + uint32_t tstart = millis(); + logInfo("Start run LED test for 2 min"); + while (1) { + ledBarRunTest(); + uint32_t ms = (uint32_t)(millis() - tstart); + if (ms >= (60 * 1000 * 2)) { + logInfo("LED test after 2 min finish"); + break; + } + } + } else { + ledBarRunTest(); + } } } void StateMachine::ledBarPowerUpTest(void) { - if (config.getCountry() == "TH") { - uint32_t tstart = millis(); - logInfo("Start run LED test for 2 min"); - while (1) { - ledBarRunTest(); - uint32_t ms = (uint32_t)(millis() - tstart); - if (ms >= (60 * 1000 * 2)) { - logInfo("LED test after 2 min finish"); - break; - } - } - } else { - ledBarRunTest(); - } + ledBarRunTest(); } void StateMachine::ledBarRunTest(void) {