From f5afb399eb5f8091c3ae820bc622cffb1218b53c Mon Sep 17 00:00:00 2001
From: Eric Duminil <eric.duminil@gmail.com>
Date: Sun, 6 Jun 2021 22:13:32 +0200
Subject: [PATCH] co2_sensor: slight refactor

---
 ampel-firmware/co2_sensor.cpp | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/ampel-firmware/co2_sensor.cpp b/ampel-firmware/co2_sensor.cpp
index 069e746..1eb76fc 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) {
-- 
GitLab