From 0afa64321b13265bbb00b0e2daf2696d2caf998e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20K=C3=A4ppler?= <michael_kaeppler@web.de>
Date: Mon, 7 Jun 2021 11:17:13 +0200
Subject: [PATCH] co2_sensor: Move 'state' enum to header file

This allows to access the current state from
another code files.
---
 ampel-firmware/co2_sensor.cpp | 15 ---------------
 ampel-firmware/co2_sensor.h   | 18 ++++++++++++++++++
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/ampel-firmware/co2_sensor.cpp b/ampel-firmware/co2_sensor.cpp
index 6e0e01e..6fcf2f8 100644
--- a/ampel-firmware/co2_sensor.cpp
+++ b/ampel-firmware/co2_sensor.cpp
@@ -30,21 +30,6 @@ namespace sensor {
   char timestamp[23];
   int16_t stable_measurements = 0;
 
-  /**
-   * Define sensor states
-   * BOOTUP -> initial state, until first >0 ppm values are returned
-   * READY -> sensor does output valid information (> 0 ppm) and no other condition takes place
-   * NEEDS_CALIBRATION -> sensor measurements are too low (< 250 ppm)
-   * PREPARE_CALIBRATION_UNSTABLE -> forced calibration was initiated, last measurements were too far apart
-   * PREPARE_CALIBRATION_STABLE -> forced calibration was initiated, last measurements were close to each others
-   */
-  enum state {
-    BOOTUP,
-    READY,
-    NEEDS_CALIBRATION,
-    PREPARE_CALIBRATION_UNSTABLE,
-    PREPARE_CALIBRATION_STABLE
-  };
   const char *state_names[] = {
       "BOOTUP",
       "READY",
diff --git a/ampel-firmware/co2_sensor.h b/ampel-firmware/co2_sensor.h
index d9eff87..eb2612d 100644
--- a/ampel-firmware/co2_sensor.h
+++ b/ampel-firmware/co2_sensor.h
@@ -24,6 +24,24 @@ namespace sensor {
   extern float humidity;
   extern char timestamp[];
 
+  /**
+   * Define sensor states
+   * BOOTUP -> initial state, until first >0 ppm values are returned
+   * READY -> sensor does output valid information (> 0 ppm) and no other condition takes place
+   * NEEDS_CALIBRATION -> sensor measurements are too low (< 250 ppm)
+   * PREPARE_CALIBRATION_UNSTABLE -> forced calibration was initiated, last measurements were too far apart
+   * PREPARE_CALIBRATION_STABLE -> forced calibration was initiated, last measurements were close to each others
+   */
+  enum state {
+    BOOTUP,
+    READY,
+    NEEDS_CALIBRATION,
+    PREPARE_CALIBRATION_UNSTABLE,
+    PREPARE_CALIBRATION_STABLE
+  };
+
+  extern state current_state;
+
   void initialize();
   bool processData();
   void startCalibrationProcess();
-- 
GitLab