diff --git a/ampel-firmware/co2_sensor.cpp b/ampel-firmware/co2_sensor.cpp index 069e746b6bd8eb5a31b9586a07610c19c2582c55..1eb76fc9352de9222d5447107502e3131f170683 100644 --- a/ampel-firmware/co2_sensor.cpp +++ b/ampel-firmware/co2_sensor.cpp @@ -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) {