co2_sensor: wait for acclimatization after startup
The SCD30 sensor has a response time of 20 s to reach 67 % of its final reading. The first measurement can thus be unreliable, if the environment changed shortly prior to startup. Set measurement interval to the shortest possible value (2 s) and wait then, until the measurements have stabilized. Show a blue led effect in the meanwhile.
-
-
Feel free to write complete names in variables, even if they become long.
_boot
or_startup
could possibly be used instead of_accl
. -
+-20% seems like a lot. Before calibration, +-30ppm is required, which is close to 5%.
-
if (boolean) return true else false;
can simply be replaced byreturn boolean;
-
(100 * delta / config::max_deviation_during_accl) < co2
seems correct, but I'd expectdelta < co2 * max_deviation / 100
to be more readable. Is it to avoid overflow? -
The recursive call
switchStateForCurrentPPM();
could be removed, couldn't it? current_state cannot be BOOTUP anymore, so letting the code run after the first if would be like calling switchStateForCurrentPPM(); again.
-
-
Author Owner
Feel free to write complete names in variables, even if they become long. _boot or _startup could possibly be used instead of _accl.
You're right. I will fix this.
+-20% seems like a lot. Before calibration, +-30ppm is required, which is close to 5%.
While I understand the necessity for calibration, having perfectly stable measurements was not the goal here. Otherwise it may be that in a constantly changing environment the sensor will never start working. But feel free to propose another value. 5%, however, is too low IMHO.
if (boolean) return true else false; can simply be replaced by return boolean;
Sure, thanks.
(100 * delta / config::max_deviation_during_accl) < co2 seems correct, but I'd expect delta < co2 * max_deviation / 100 to be more readable. Is it to avoid overflow?
I don't really know why I wrote it that complicated. Your suggestion is clearly superior, but overflow could occur in both variants, uh oh... So we have to cast
co2
touint32_t
, right?The recursive call switchStateForCurrentPPM(); could be removed, couldn't it? current_state cannot be BOOTUP anymore, so letting the code run after the
Yes, that was a non-intentional leftover... Will remove it.
-
max_deviation could be defined as uint32_t, and delta could be compared to
max_deviation * co2 / 100
. That should do, right?20% is probably fine for startup, okay. I'll check if it's possible to avoid duplicate code between countStableMeasurements hasSensorSettled. Possibly by passing the delta as argument.