Commits (3)
  • Käppler's avatar
    led_effects: Clarify blocking nature of countdown · 2b62a103
    Käppler authored
    * The 'int' return signature and the comment
    'Returns the number of remaining leds' sounds like the
    function would return its current countdown state.
    However, it only returns the number of remaining
    leds after the button was released. Thus change
    the type to 'bool' and return 'true' after a
    successful countdown
    
    * Do not use 1 as return value for night mode,
    because it is ambigous. Return 'false' instead.
    2b62a103
  • Käppler's avatar
    co2_sensor: Move 'state' enum to header file · a06d0c56
    Käppler authored
    This allows to access the current state from
    another code files.
    a06d0c56
  • Käppler's avatar
    Do not check flash button during calibration · 509121d1
    Käppler authored
    It does not make sense to toggle night mode
    or start another round of countdown during
    calibration.
    
    Closes #4.
    509121d1
...@@ -141,7 +141,12 @@ void loop() { ...@@ -141,7 +141,12 @@ void loop() {
keepServicesAlive(); keepServicesAlive();
// Short press for night mode, Long press for calibration. // Short press for night mode, Long press for calibration.
// Inactive during calibration.
if (!(sensor::current_state == sensor::PREPARE_CALIBRATION_STABLE ||
sensor::current_state == sensor::PREPARE_CALIBRATION_UNSTABLE))
{
checkFlashButton(); checkFlashButton();
}
checkSerialInput(); checkSerialInput();
...@@ -189,7 +194,7 @@ void checkFlashButton() { ...@@ -189,7 +194,7 @@ void checkFlashButton() {
led_effects::toggleNightMode(); led_effects::toggleNightMode();
} else { } else {
Serial.println(F("Flash has been pressed for a long time. Keep it pressed for calibration.")); 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(); sensor::startCalibrationProcess();
} }
} }
......
...@@ -30,28 +30,6 @@ namespace sensor { ...@@ -30,28 +30,6 @@ namespace sensor {
char timestamp[23]; char timestamp[23];
int16_t stable_measurements = 0; 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",
"NEEDS_CALIBRATION",
"PREPARE_CALIBRATION_UNSTABLE",
"PREPARE_CALIBRATION_STABLE" };
state current_state = BOOTUP; state current_state = BOOTUP;
void switchState(state); void switchState(state);
......
...@@ -24,6 +24,31 @@ namespace sensor { ...@@ -24,6 +24,31 @@ namespace sensor {
extern float humidity; extern float humidity;
extern char timestamp[]; 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
};
const char *state_names[] = {
"BOOTUP",
"READY",
"NEEDS_CALIBRATION",
"PREPARE_CALIBRATION_UNSTABLE",
"PREPARE_CALIBRATION_STABLE" };
extern state current_state;
void initialize(); void initialize();
bool processData(); bool processData();
void startCalibrationProcess(); void startCalibrationProcess();
......
...@@ -211,14 +211,17 @@ namespace led_effects { ...@@ -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. * Displays a complete blue circle, and starts removing LEDs one by one.
* Can be used for calibration, e.g. when countdown is 0. Does not work in night mode. * 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) { if (config::night_mode) {
Serial.println(F("Night mode. Not doing anything.")); 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. 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.fill(color::blue);
pixels.show(); pixels.show();
...@@ -229,6 +232,6 @@ namespace led_effects { ...@@ -229,6 +232,6 @@ namespace led_effects {
Serial.println(countdown); Serial.println(countdown);
delay(500); delay(500);
} }
return countdown; return true;
} }
} }
...@@ -26,7 +26,7 @@ namespace led_effects { ...@@ -26,7 +26,7 @@ namespace led_effects {
void setupRing(); void setupRing();
void redAlert(); void redAlert();
int countdownToZero(); bool countdownToZero();
void showWaitingLED(uint32_t color); void showWaitingLED(uint32_t color);
void showKITTWheel(uint32_t color, uint16_t duration_s = 2); void showKITTWheel(uint32_t color, uint16_t duration_s = 2);
void showRainbowWheel(uint16_t duration_ms = 1000); void showRainbowWheel(uint16_t duration_ms = 1000);
......