Commit d4a8e93d authored by Käppler's avatar Käppler Committed by Eric Duminil
Browse files

led_effects: Clarify blocking nature of countdown

* 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.
parent 79e8c6d7
Pipeline #4405 passed with stage
in 2 minutes and 15 seconds
......@@ -189,7 +189,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();
}
}
......
......@@ -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;
}
}
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment