Skip to content

Commit 81945a3

Browse files
committed
SGP41 add method to pause and resume task handle
1 parent 3d26a54 commit 81945a3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Sgp41/Sgp41.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ void Sgp41::handle(void) {
131131
}
132132

133133
#else
134+
135+
void Sgp41::pauseHandle() {
136+
onPause = true;
137+
Serial.println("Pausing SGP41 handler task");
138+
// Set latest value to invalid
139+
tvocRaw = utils::getInvalidVOC();
140+
tvoc = utils::getInvalidVOC();
141+
noxRaw = utils::getInvalidNOx();
142+
nox = utils::getInvalidNOx();
143+
}
144+
145+
void Sgp41::resumeHandle() {
146+
onPause = false;
147+
Serial.println("Resume SGP41 handler task");
148+
}
149+
134150
/**
135151
* @brief Handle the sensor conditioning and run time udpate value, This method
136152
* must not call, it's called on private task
@@ -152,6 +168,11 @@ void Sgp41::_handle(void) {
152168
uint16_t srawVoc, srawNox;
153169
for (;;) {
154170
vTaskDelay(pdMS_TO_TICKS(1000));
171+
172+
if (onPause) {
173+
continue;
174+
}
175+
155176
if (getRawSignal(srawVoc, srawNox)) {
156177
tvocRaw = srawVoc;
157178
noxRaw = srawNox;

src/Sgp41/Sgp41.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class Sgp41 {
1818
bool begin(TwoWire &wire, Stream &stream);
1919
void handle(void);
2020
#else
21+
/* pause _handle task to read sensor */
22+
void pauseHandle();
23+
/* resume _handle task to read sensor */
24+
void resumeHandle();
2125
void _handle(void);
2226
#endif
2327
void end(void);
@@ -32,6 +36,7 @@ class Sgp41 {
3236
int getTvocLearningOffset(void);
3337

3438
private:
39+
bool onPause = false;
3540
bool onConditioning = true;
3641
bool ready = false;
3742
bool _isBegin = false;

0 commit comments

Comments
 (0)