Commit f5afb399 authored by Eric Duminil's avatar Eric Duminil
Browse files

co2_sensor: slight refactor

parent 842a541f
......@@ -126,8 +126,7 @@ namespace sensor {
return (co2 > 0 && delta < ((uint32_t) co2 * config::max_deviation_during_bootup / 100));
}
bool countStableMeasurements() {
// Returns true, if a sufficient number of stable measurements has been observed.
bool enoughStableMeasurements() {
static int16_t previous_co2 = 0;
if (co2 > (previous_co2 - config::max_deviation_during_calibration)
&& co2 < (previous_co2 + config::max_deviation_during_calibration)) {
......@@ -207,11 +206,11 @@ namespace sensor {
}
scd30.setMeasurementInterval(config::measurement_timestep); // [s]
}
// Check for pre-calibration states first, because we do not want to
// leave them before calibration is done.
if ((current_state == PREPARE_CALIBRATION_UNSTABLE) || (current_state == PREPARE_CALIBRATION_STABLE)) {
// Check for pre-calibration states first, because we do not want to
// leave them before calibration is done.
bool ready_for_calibration = countStableMeasurements();
if (ready_for_calibration) {
if (enoughStableMeasurements()) {
calibrate();
}
} else if (co2 < 250) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment