mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 20:56:35 +00:00
SDS0X1 take one stable reading every 3 minutes
This commit is contained in:
parent
4a588581d1
commit
87e3dcddb9
@ -31,6 +31,10 @@ TasmotaSerial *NovaSdsSerial;
|
|||||||
|
|
||||||
uint8_t novasds_type = 1;
|
uint8_t novasds_type = 1;
|
||||||
uint8_t novasds_valid = 0;
|
uint8_t novasds_valid = 0;
|
||||||
|
uint8_t novasds_running = 1;
|
||||||
|
uint8_t novasds_read_tick = 30;
|
||||||
|
uint8_t novasds_wakup_tick = 179;
|
||||||
|
uint8_t novasds_ticker = 0;
|
||||||
|
|
||||||
struct sds011data {
|
struct sds011data {
|
||||||
uint16_t pm100;
|
uint16_t pm100;
|
||||||
@ -69,12 +73,35 @@ bool NovaSdsReadData(bool publish)
|
|||||||
|
|
||||||
void NovaSdsSecond() // Every second
|
void NovaSdsSecond() // Every second
|
||||||
{
|
{
|
||||||
if (NovaSdsReadData()) {
|
if (novasds_ticker < novasds_read_tick) {
|
||||||
novasds_valid = 10;
|
// wake up the sensor and wait read ticks to stabalize the sensor
|
||||||
} else {
|
if (!novasds_running) {
|
||||||
if (novasds_valid) {
|
NovaSdsStart();
|
||||||
novasds_valid--;
|
novasds_running = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// drain the serial without publishing data
|
||||||
|
NovaSdsReadData(false);
|
||||||
|
novasds_ticker++;
|
||||||
|
|
||||||
|
} else if (novasds_ticker == novasds_read_tick) {
|
||||||
|
|
||||||
|
// try to take a single stable reading and sleep the sensor
|
||||||
|
if (NovaSdsReadData(true)) {
|
||||||
|
novasds_valid = 1;
|
||||||
|
NovaSdsStop();
|
||||||
|
novasds_running = 0;
|
||||||
|
novasds_ticker++;
|
||||||
|
} else {
|
||||||
|
novasds_valid = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (novasds_ticker >= novasds_wakup_tick) {
|
||||||
|
// reset the counter
|
||||||
|
novasds_ticker = 0;
|
||||||
|
} else {
|
||||||
|
// sensor is sleeping keep waiting
|
||||||
|
novasds_ticker++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user