diff --git a/ampel-firmware/ampel-firmware.ino b/ampel-firmware/ampel-firmware.ino index 39f6b0c3b9ede61f313a190e4c292eb6c9bde408..bf673706f3acfa69386ed1c48c0e8e81f70a935f 100644 --- a/ampel-firmware/ampel-firmware.ino +++ b/ampel-firmware/ampel-firmware.ino @@ -141,7 +141,12 @@ void loop() { keepServicesAlive(); // Short press for night mode, Long press for calibration. - checkFlashButton(); + // Inactive during calibration. + if (!(sensor::current_state == sensor::PREPARE_CALIBRATION_STABLE || + sensor::current_state == sensor::PREPARE_CALIBRATION_UNSTABLE)) + { + checkFlashButton(); + } checkSerialInput(); @@ -189,7 +194,7 @@ void checkFlashButton() { led_effects::toggleNightMode(); } else { Serial.println(F("Flash has been pressed for a long time. Keep it pressed for calibration.")); - if (led_effects::countdownToZero() < 0) { + if (led_effects::countdownToZero()) { sensor::startCalibrationProcess(); } } diff --git a/ampel-firmware/co2_sensor.cpp b/ampel-firmware/co2_sensor.cpp index 6e0e01eb6102ccd60586a618fd38d73f726fa213..6fcf2f86863bbf6a726b90fa56aa1f7a1ab4e36b 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 d9eff8724f018e885f260060aaed58678c814092..eb2612ddefc5898c29c89062a5de812dab43bc6e 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(); diff --git a/ampel-firmware/led_effects.cpp b/ampel-firmware/led_effects.cpp index f0b672c9d0c76e1cac6916d94783e85577f387fd..2577161130e5fb500c94a591bc6bc8ac3247fe0e 100644 --- a/ampel-firmware/led_effects.cpp +++ b/ampel-firmware/led_effects.cpp @@ -211,14 +211,17 @@ namespace led_effects { } /** - * Displays a complete blue circle, and starts removing LEDs one by one. Returns the number of remaining LEDs. - * Can be used for calibration, e.g. when countdown is 0. Does not work in night mode. + * Displays a complete blue circle, and starts removing LEDs one by one. + * Does nothing in night mode and returns false then. Returns true if + * the countdown has finished. Can be used for calibration, e.g. when countdown is 0. + * NOTE: This function is blocking and returns only after the button has + * been released. */ - int countdownToZero() { + bool countdownToZero() { if (config::night_mode) { Serial.println(F("Night mode. Not doing anything.")); delay(1000); // Wait for a while, to avoid coming back to this function too many times when button is pressed. - return 1; + return false; } pixels.fill(color::blue); pixels.show(); @@ -229,6 +232,6 @@ namespace led_effects { Serial.println(countdown); delay(500); } - return countdown; + return true; } } diff --git a/ampel-firmware/led_effects.h b/ampel-firmware/led_effects.h index a910d307f7c6294db889e704f745c3777136d19b..8f04d83e751a9de5f2110653d10a794d5494bd36 100644 --- a/ampel-firmware/led_effects.h +++ b/ampel-firmware/led_effects.h @@ -26,7 +26,7 @@ namespace led_effects { void setupRing(); void redAlert(); - int countdownToZero(); + bool countdownToZero(); void showWaitingLED(uint32_t color); void showKITTWheel(uint32_t color, uint16_t duration_s = 2); void showRainbowWheel(uint16_t duration_ms = 1000);