diff --git a/src/Sgp41/Sgp41.cpp b/src/Sgp41/Sgp41.cpp index 3f957a1..2a0d34d 100644 --- a/src/Sgp41/Sgp41.cpp +++ b/src/Sgp41/Sgp41.cpp @@ -131,6 +131,22 @@ void Sgp41::handle(void) { } #else + +void Sgp41::pauseHandle() { + onPause = true; + Serial.println("Pausing SGP41 handler task"); + // Set latest value to invalid + tvocRaw = utils::getInvalidVOC(); + tvoc = utils::getInvalidVOC(); + noxRaw = utils::getInvalidNOx(); + nox = utils::getInvalidNOx(); +} + +void Sgp41::resumeHandle() { + onPause = false; + Serial.println("Resume SGP41 handler task"); +} + /** * @brief Handle the sensor conditioning and run time udpate value, This method * must not call, it's called on private task @@ -152,6 +168,11 @@ void Sgp41::_handle(void) { uint16_t srawVoc, srawNox; for (;;) { vTaskDelay(pdMS_TO_TICKS(1000)); + + if (onPause) { + continue; + } + if (getRawSignal(srawVoc, srawNox)) { tvocRaw = srawVoc; noxRaw = srawNox; diff --git a/src/Sgp41/Sgp41.h b/src/Sgp41/Sgp41.h index 381af7f..b8275e6 100644 --- a/src/Sgp41/Sgp41.h +++ b/src/Sgp41/Sgp41.h @@ -18,6 +18,10 @@ public: bool begin(TwoWire &wire, Stream &stream); void handle(void); #else + /* pause _handle task to read sensor */ + void pauseHandle(); + /* resume _handle task to read sensor */ + void resumeHandle(); void _handle(void); #endif void end(void); @@ -32,6 +36,7 @@ public: int getTvocLearningOffset(void); private: + bool onPause = false; bool onConditioning = true; bool ready = false; bool _isBegin = false;