From 1440e361ab4940906754966ca67bb6a881eb773e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20K=C3=A4ppler?= <michael_kaeppler@web.de>
Date: Thu, 22 Apr 2021 11:53:08 +0200
Subject: [PATCH] co2_sensor: Start calibration process by state

This removes the superfluous bool `should_calibrate`.
---
 ampel-firmware/co2_sensor.cpp | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/ampel-firmware/co2_sensor.cpp b/ampel-firmware/co2_sensor.cpp
index 1fe9297..cd4058d 100644
--- a/ampel-firmware/co2_sensor.cpp
+++ b/ampel-firmware/co2_sensor.cpp
@@ -48,8 +48,6 @@ namespace sensor {
   state current_state = INITIAL;
   void switchState(state);
 
-  bool should_calibrate = false;
-
   void initialize() {
 #if defined(ESP8266)
     Wire.begin(12, 14);  // ESP8266 - D6, D5;
@@ -140,7 +138,6 @@ namespace sensor {
     scd30.setMeasurementInterval(2); // [s] The change will only take effect after next measurement.
     Serial.println(F("Waiting until the measurements are stable for at least 2 minutes."));
     Serial.println(F("It could take a very long time."));
-    should_calibrate = true;
     switchState(PREPARECALIBRATION);
   }
 
@@ -223,7 +220,7 @@ namespace sensor {
       } else if (co2 < 250) {
         // Sensor should be calibrated.
         switchState(NEEDSCALIBRATION);
-      } else if (should_calibrate) {
+      } else if (current_state == PREPARECALIBRATION) {
         countStableMeasurements();
         if (stable_measurements == config::enough_stable_measurements) {
           calibrateAndRestart();
-- 
GitLab