diff --git a/README.md b/README.md index 157f5a33eada1f65e87fc04e695138251c0aa760..6d9f82ed5b3cbbf8bf123097313e1628b0fcd1d7 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ In Arduino IDE *Serial Monitor* or PlatformIO *Monitor*, type `help` + <kbd>Ente * `lora 300` (Sets LoRaWAN sending interval, in s). * `mqtt 60` (Sets MQTT sending interval, in s). * `night_mode` (Toggles night mode on/off). -* `reset` (Restarts the sensor). +* `reset` (Restarts the ESP). * `reset_scd` (Resets SCD30). * `send_local_ip` (Sends local IP and SSID via MQTT. Can be useful to find sensor). * `set_time 1618829570` (Sets time to the given UNIX time). diff --git a/ampel-firmware/ampel-firmware.ino b/ampel-firmware/ampel-firmware.ino index 39f6b0c3b9ede61f313a190e4c292eb6c9bde408..fa29f4ab76be88be2d1780f0a2df27dd39775fe6 100644 --- a/ampel-firmware/ampel-firmware.ino +++ b/ampel-firmware/ampel-firmware.ino @@ -189,8 +189,10 @@ 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()) { + Serial.println(F("You can now release the button.")); sensor::startCalibrationProcess(); + led_effects::showKITTWheel(color::red, 2); } } led_effects::onBoardLEDOff(); diff --git a/ampel-firmware/co2_sensor.cpp b/ampel-firmware/co2_sensor.cpp index 1eb76fc9352de9222d5447107502e3131f170683..25a7102e19088ae65487234f248fada2ed25fd29 100644 --- a/ampel-firmware/co2_sensor.cpp +++ b/ampel-firmware/co2_sensor.cpp @@ -10,6 +10,7 @@ namespace config { const int8_t max_deviation_during_calibration = 30; // [ppm] const int16_t timestep_during_calibration = 10; // [s] WARNING: Measurements can be unreliable for timesteps shorter than 10s. const int8_t stable_measurements_before_calibration = 120 / timestep_during_calibration; // [-] Stable measurements during at least 2 minutes. + const uint16_t co2_alert_threshold = 2000; // [ppm] Display a flashing led ring, if concentration exceeds this value #ifdef TEMPERATURE_OFFSET // Residual heat from CO2 sensor seems to be high enough to change the temperature reading. How much should it be offset? @@ -227,11 +228,11 @@ namespace sensor { * A short delay is required in order to let background tasks run on the ESP8266. * see https://github.com/esp8266/Arduino/issues/3241#issuecomment-301290392 */ - if (co2 < 2000) { + if (co2 < config::co2_alert_threshold) { led_effects::displayCO2color(co2); delay(100); } else { - // >= 2000: entire ring blinks red + // Display a flashing led ring, if concentration exceeds a specific value led_effects::redAlert(); } } diff --git a/ampel-firmware/led_effects.cpp b/ampel-firmware/led_effects.cpp index f0b672c9d0c76e1cac6916d94783e85577f387fd..84cd7aadbd93d009fea1fd470b71d36ccaa63b57 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 or after every LED has been turned off. */ - 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 countdown < 0; } } 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); diff --git a/ampel-firmware/util.cpp b/ampel-firmware/util.cpp index 5fcb36cb454c42b606fd632e7db9be5faf9108b8..27f23a7e6005f015ca5df979447d6484c0a948c1 100644 --- a/ampel-firmware/util.cpp +++ b/ampel-firmware/util.cpp @@ -85,7 +85,7 @@ Ampel::Ampel() : sensor_console::defineCommand("free", Ampel::showFreeSpace, F("(Displays available heap space)")); sensor_console::defineCommand("reset", []() { ESP.restart(); - }, F("(Restarts the sensor)")); + }, F("(Restarts the ESP)")); } Ampel ampel;