From e82da5401ed9ee28a7450d7ba1493c6ebb091b6c Mon Sep 17 00:00:00 2001 From: samuelbles07 Date: Mon, 9 Jun 2025 02:13:32 +0700 Subject: [PATCH] Add new flag for command request Such as led bar test and co2 calibration test --- examples/OneOpenAir/OneOpenAir.ino | 15 ++++++--------- src/AgConfigure.cpp | 16 ++++++++++++---- src/AgConfigure.h | 2 ++ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/examples/OneOpenAir/OneOpenAir.ino b/examples/OneOpenAir/OneOpenAir.ino index a39df2d..9c656fb 100644 --- a/examples/OneOpenAir/OneOpenAir.ino +++ b/examples/OneOpenAir/OneOpenAir.ino @@ -370,6 +370,12 @@ void loop() { /** factory reset handle */ factoryConfigReset(); + + if (configuration.isCommandRequested()) { + // Each state machine already has an independent request command check + stateMachine.executeCo2Calibration(); + stateMachine.executeLedBarTest(); + } } static void co2Update(void) { @@ -1082,10 +1088,6 @@ static void configUpdateHandle() { return; } - if (configuration.isCo2CalibrationRequested()) { - stateMachine.executeCo2Calibration(); - } - String mqttUri = configuration.getMqttBrokerUri(); if (mqttClient.isCurrentUri(mqttUri) == false) { mqttClient.end(); @@ -1157,11 +1159,6 @@ static void configUpdateHandle() { if (configuration.isDisplayBrightnessChanged()) { oledDisplay.setBrightness(configuration.getDisplayBrightness()); } - - stateMachine.executeLedBarTest(); - } - else if(ag->isOpenAir()) { - stateMachine.executeLedBarTest(); } // Update display and led bar notification based on updated configuration diff --git a/src/AgConfigure.cpp b/src/AgConfigure.cpp index 9cb2f08..bec2455 100644 --- a/src/AgConfigure.cpp +++ b/src/AgConfigure.cpp @@ -955,16 +955,18 @@ bool Configuration::parse(String data, bool isLocal) { changed = true; } + if (ledBarTestRequested || co2CalibrationRequested) { + commandRequested = true; + updated = true; + } + if (changed) { updated = true; saveConfig(); printConfig(); _callback(); - } else { - if (ledBarTestRequested || co2CalibrationRequested) { - updated = true; - } } + return true; } @@ -1164,6 +1166,12 @@ bool Configuration::isUpdated(void) { return updated; } +bool Configuration::isCommandRequested(void) { + bool oldState = this->commandRequested; + this->commandRequested = false; + return oldState; +} + String Configuration::jsonTypeInvalidMessage(String name, String type) { return "'" + name + "' type is invalid, expecting '" + type + "'"; } diff --git a/src/AgConfigure.h b/src/AgConfigure.h index c6cc016..6c1fb59 100644 --- a/src/AgConfigure.h +++ b/src/AgConfigure.h @@ -28,6 +28,7 @@ private: bool co2CalibrationRequested; bool ledBarTestRequested; bool updated; + bool commandRequested = false; String failedMessage; bool _noxLearnOffsetChanged; bool _tvocLearningOffsetChanged; @@ -93,6 +94,7 @@ public: void reset(void); String getModel(void); bool isUpdated(void); + bool isCommandRequested(void); String getFailedMesage(void); void setPostToAirGradient(bool enable); bool noxLearnOffsetChanged(void);