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

co2_sensor: slight refactor

parent 842a541f
...@@ -126,8 +126,7 @@ namespace sensor { ...@@ -126,8 +126,7 @@ namespace sensor {
return (co2 > 0 && delta < ((uint32_t) co2 * config::max_deviation_during_bootup / 100)); return (co2 > 0 && delta < ((uint32_t) co2 * config::max_deviation_during_bootup / 100));
} }
bool countStableMeasurements() { bool enoughStableMeasurements() {
// Returns true, if a sufficient number of stable measurements has been observed.
static int16_t previous_co2 = 0; static int16_t previous_co2 = 0;
if (co2 > (previous_co2 - config::max_deviation_during_calibration) if (co2 > (previous_co2 - config::max_deviation_during_calibration)
&& co2 < (previous_co2 + config::max_deviation_during_calibration)) { && co2 < (previous_co2 + config::max_deviation_during_calibration)) {
...@@ -207,11 +206,11 @@ namespace sensor { ...@@ -207,11 +206,11 @@ namespace sensor {
} }
scd30.setMeasurementInterval(config::measurement_timestep); // [s] 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)) { if ((current_state == PREPARE_CALIBRATION_UNSTABLE) || (current_state == PREPARE_CALIBRATION_STABLE)) {
// Check for pre-calibration states first, because we do not want to if (enoughStableMeasurements()) {
// leave them before calibration is done.
bool ready_for_calibration = countStableMeasurements();
if (ready_for_calibration) {
calibrate(); calibrate();
} }
} else if (co2 < 250) { } 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