From 186bf9f9e1643c60db9894a7ea575ee012bba744 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20K=C3=A4ppler?= <michael_kaeppler@web.de>
Date: Fri, 30 Apr 2021 10:21:01 +0200
Subject: [PATCH] co2_sensor: Remove state 'INVALID'

Ongoing investigation showed that the sensor
does report 0 ppm only after startup, i.e.
in 'BOOTUP' state. We check for this condition
in `hasSensprSettled()` already, so there is no
need for this state anymore.
---
 ampel-firmware/co2_sensor.cpp | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/ampel-firmware/co2_sensor.cpp b/ampel-firmware/co2_sensor.cpp
index 637ec0a..a4caca6 100644
--- a/ampel-firmware/co2_sensor.cpp
+++ b/ampel-firmware/co2_sensor.cpp
@@ -33,7 +33,6 @@ namespace sensor {
    * INITIAL -> initial state
    * BOOTUP -> state after initializing the sensor, i.e. after scd.begin()
    * READY -> sensor does output valid information (> 0 ppm) and no other condition takes place
-   * INVALID -> sensor does output invalid CO2 measurements (== 0 ppm)
    * NEEDS_CALIBRATION -> sensor measurements are too low (< 250 ppm)
    * PREPARE_CALIBRATION -> forced calibration was initiated, waiting for stable measurements
    */
@@ -41,7 +40,6 @@ namespace sensor {
     INITIAL,
     BOOTUP,
     READY,
-    INVALID,
     NEEDS_CALIBRATION,
     PREPARE_CALIBRATION_UNSTABLE,
     PREPARE_CALIBRATION_STABLE
@@ -50,7 +48,6 @@ namespace sensor {
       "INITIAL",
       "BOOTUP",
       "READY",
-      "INVALID",
       "NEEDS_CALIBRATION",
       "PREPARE_CALIBRATION_UNSTABLE",
       "PREPARE_CALIBRATION_STABLE" };
@@ -210,12 +207,7 @@ namespace sensor {
       Serial.println(" s.");
       scd30.setMeasurementInterval(config::measurement_timestep); // [s]
     }
-    if (co2 == 0) {
-      // NOTE: Data is available, but it's sometimes erroneous: the sensor outputs
-      // zero ppm but non-zero temperature and non-zero humidity.
-      Serial.println(F("Invalid sensor data - CO2 concentration supposedly 0 ppm"));
-      switchState(INVALID);
-    } else 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
       // leave them before calibration is done.
       bool ready_for_calibration = countStableMeasurements();
@@ -253,9 +245,6 @@ namespace sensor {
     case READY:
       displayCO2OnLedRing();
       break;
-    case INVALID:
-      led_effects::showWaitingLED(color::red);
-      break;
     case NEEDS_CALIBRATION:
       led_effects::showWaitingLED(color::magenta);
       break;
-- 
GitLab