Commit b18039e3 authored by Eric Duminil's avatar Eric Duminil
Browse files

Explicitely set LED on or off instead of toggling

* Night mode is still available when pressing the flash button
* "led 0" or "led 1" should now be used as commands instead of
"night_mode"
parent a224c1fa
......@@ -12,7 +12,7 @@ namespace config {
const uint8_t brightness_amplitude = config::max_brightness - config::min_brightness;
const int kitt_tail = 3; // How many dimmer LEDs follow in K.I.T.T. wheel
const uint16_t poor_air_quality_ppm = 1600; // Above this threshold, LED breathing effect is faster.
bool night_mode = false; //NOTE: Use a class instead? NightMode could then be another state.
bool display_led = true; // Will be set to false during "night mode".
#if !defined(LED_COUNT)
# define LED_COUNT 12
......@@ -78,7 +78,7 @@ namespace led_effects {
}
void showColor(int32_t color) {
config::night_mode = true; // In order to avoid overwriting the desired color next time CO2 is displayed
config::display_led = false; // In order to avoid overwriting the desired color next time CO2 is displayed
pixels.setBrightness(255);
pixels.fill(color);
pixels.show();
......@@ -88,17 +88,21 @@ namespace led_effects {
pixels.begin();
pixels.setBrightness(config::max_brightness);
LEDsOff();
sensor_console::defineCommand("night_mode", toggleNightMode, F("(Toggles night mode on/off)"));
sensor_console::defineIntCommand("led", turnLEDsOnOff, F("0/1 (Turns LEDs on/off)"));
sensor_console::defineIntCommand("color", showColor, F("0xFF0015 (Shows color, specified as RGB, for debugging)"));
}
void toggleNightMode() {
config::night_mode = !config::night_mode;
if (config::night_mode) {
Serial.println(F("NIGHT MODE!"));
LEDsOff();
turnLEDsOnOff(!config::display_led);
}
void turnLEDsOnOff(int32_t display_led) {
config::display_led = display_led;
if (config::display_led) {
Serial.println(F("LEDs are on!"));
} else {
Serial.println(F("DAY MODE!"));
Serial.println(F("Night mode!"));
LEDsOff();
}
}
......@@ -106,7 +110,7 @@ namespace led_effects {
void showWaitingLED(uint32_t color) {
using namespace config;
delay(80);
if (night_mode) {
if (!display_led) {
return;
}
static uint16_t kitt_offset = 0;
......@@ -162,7 +166,7 @@ namespace led_effects {
* Fills the whole ring with green, yellow, orange or black, depending on co2 input and CO2_TICKS.
*/
void displayCO2color(uint16_t co2) {
if (config::night_mode) {
if (!config::display_led) {
return;
}
pixels.setBrightness(config::max_brightness);
......@@ -177,7 +181,7 @@ namespace led_effects {
}
void showRainbowWheel(uint16_t duration_ms) {
if (config::night_mode) {
if (!config::display_led) {
return;
}
static uint16_t wheel_offset = 0;
......@@ -195,7 +199,7 @@ namespace led_effects {
}
void redAlert() {
if (config::night_mode) {
if (!config::display_led) {
onBoardLEDOn();
delay(500);
onBoardLEDOff();
......@@ -218,7 +222,7 @@ namespace led_effects {
* been released or after every LED has been turned off.
*/
bool countdownToZero() {
if (config::night_mode) {
if (!config::display_led) {
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 false;
......
......@@ -22,6 +22,7 @@ namespace led_effects {
void onBoardLEDOff();
void onBoardLEDOn();
void toggleNightMode();
void turnLEDsOnOff(int32_t);
void LEDsOff();
void setupRing();
......
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