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() {
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();
}
}
......
......@@ -30,28 +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",
"NEEDS_CALIBRATION",
"PREPARE_CALIBRATION_UNSTABLE",
"PREPARE_CALIBRATION_STABLE" };
state current_state = BOOTUP;
void switchState(state);
......
......@@ -24,6 +24,31 @@ 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
};
const char *state_names[] = {
"BOOTUP",
"READY",
"NEEDS_CALIBRATION",
"PREPARE_CALIBRATION_UNSTABLE",
"PREPARE_CALIBRATION_STABLE" };
extern state current_state;
void initialize();
bool processData();
void startCalibrationProcess();
......
......@@ -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;
}
}
......@@ -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);
......