diff --git a/ampel-firmware/led_effects.cpp b/ampel-firmware/led_effects.cpp index 4d0d59958aa06b05c54e7b86b406a4e03ea73750..8137f0f4d55e06432778c437da310b96bfa3ebfd 100644 --- a/ampel-firmware/led_effects.cpp +++ b/ampel-firmware/led_effects.cpp @@ -1,6 +1,7 @@ #include "led_effects.h" #include "config.h" +#include "web_config.h" #include "sensor_console.h" // Adafruit NeoPixel (Arduino library for controlling single-wire-based LED pixels and strip) @@ -12,13 +13,6 @@ * Configuration * *****************************************************************/ namespace config { - const uint8_t max_brightness = MAX_BRIGHTNESS; -#if defined(MIN_BRIGHTNESS) - const uint8_t min_brightness = MIN_BRIGHTNESS; -#else - const uint8_t min_brightness = MAX_BRIGHTNESS; -#endif - 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 display_led = true; // Will be set to false during "night mode". @@ -36,10 +30,41 @@ namespace config { // LEDs >= 1600ppm will be pure red (hue angle 0°), LEDs in-between will be yellowish. const uint16_t led_hues[led_count] = { 21845U, 19114U, 16383U, 13653U, 10922U, 8191U, 5461U, 2730U, 0, 0, 0, 0 }; // [hue angle] #elif LED_COUNT == 16 - const uint16_t co2_ticks[led_count + 1] = { 0, 500, 600, 700, 800, 900, 1000, 1100, 1200, - 1300, 1400, 1500, 1600, 1700, 1800, 2000, 2200 }; // [ppm] - const uint16_t led_hues[led_count] = {21845U, 19859U, 17873U, 15887U, 13901U, 11915U, 9929U, 7943U, - 5957U, 3971U, 1985U, 0, 0, 0, 0, 0}; // [hue angle] + const uint16_t co2_ticks[led_count + 1] = { + 0, + 500, + 600, + 700, + 800, + 900, + 1000, + 1100, + 1200, + 1300, + 1400, + 1500, + 1600, + 1700, + 1800, + 2000, + 2200 }; // [ppm] + const uint16_t led_hues[led_count] = { + 21845U, + 19859U, + 17873U, + 15887U, + 13901U, + 11915U, + 9929U, + 7943U, + 5957U, + 3971U, + 1985U, + 0, + 0, + 0, + 0, + 0 }; // [hue angle] #else # error "Only 12 and 16 LEDs rings are currently supported." #endif @@ -95,7 +120,7 @@ namespace led_effects { void setupRing() { pixels.begin(); - pixels.setBrightness(config::max_brightness); + pixels.setBrightness(*config::max_brightness); LEDsOff(); 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)")); @@ -136,7 +161,7 @@ namespace led_effects { // Simulate a moving LED with tail. First LED starts at 0, and moves along a triangular function. The tail follows, with decreasing brightness. // Takes approximately 1s for each direction. void showKITTWheel(uint32_t color, uint16_t duration_s) { - pixels.setBrightness(config::max_brightness); + pixels.setBrightness(*config::max_brightness); for (int i = 0; i < duration_s * config::led_count; ++i) { showWaitingLED(color); } @@ -165,7 +190,8 @@ namespace led_effects { */ void breathe(int16_t co2) { static uint8_t breathing_offset = 0; - uint16_t brightness = config::min_brightness + pixels.sine8(breathing_offset) * config::brightness_amplitude / 255; + uint8_t brightness_amplitude = *config::max_brightness - *config::min_brightness; + uint16_t brightness = *config::min_brightness + pixels.sine8(breathing_offset) * brightness_amplitude / 255; pixels.setBrightness(brightness); pixels.show(); breathing_offset += co2 > config::poor_air_quality_ppm ? 6 : 3; // breathing speed. +3 looks like slow human breathing. @@ -178,13 +204,13 @@ namespace led_effects { if (!config::display_led) { return; } - pixels.setBrightness(config::max_brightness); + pixels.setBrightness(*config::max_brightness); for (int ledId = 0; ledId < config::led_count; ++ledId) { uint8_t brightness = getLedBrightness(co2, ledId); pixels.setPixelColor(ledId, pixels.ColorHSV(config::led_hues[ledId], 255, brightness)); } pixels.show(); - if (config::brightness_amplitude > 0) { + if (*config::max_brightness > *config::min_brightness) { breathe(co2); } } @@ -196,7 +222,7 @@ namespace led_effects { static uint16_t wheel_offset = 0; static uint16_t sine_offset = 0; unsigned long t0 = millis(); - pixels.setBrightness(config::max_brightness); + pixels.setBrightness(*config::max_brightness); while (millis() - t0 < duration_ms) { for (int i = 0; i < config::led_count; i++) { pixels.setPixelColor(i, pixels.ColorHSV(i * 65535 / config::led_count + wheel_offset)); @@ -216,7 +242,7 @@ namespace led_effects { return; } for (int i = 0; i < 10; i++) { - pixels.setBrightness(static_cast<int>(config::max_brightness * (1 - i * 0.1))); + pixels.setBrightness(static_cast<int>(*config::max_brightness * (1 - i * 0.1))); delay(50); pixels.fill(color::red); pixels.show(); diff --git a/ampel-firmware/web_config.cpp b/ampel-firmware/web_config.cpp index dd848bdecf4ff7f43f8cb4ae9f65d1fb539a84f7..b692ac41b2268b7e7f5a21d56f7de039d8341ddc 100644 --- a/ampel-firmware/web_config.cpp +++ b/ampel-firmware/web_config.cpp @@ -272,11 +272,14 @@ namespace web_config { namespace config { // CSV uint16_t *csv_interval = &web_config::csvTimestepParam.value(); - + // Sensor uint16_t *measurement_timestep = &web_config::timestepParam.value(); // [s] Value between 2 and 1800 (range for SCD30 sensor). uint16_t *altitude_above_sea_level = &web_config::altitudeParam.value(); // [m] uint16_t *co2_calibration_level = &web_config::atmosphericCO2Param.value(); // [ppm] bool *auto_calibrate_sensor = &web_config::autoCalibrateParam.value(); // [true / false] float *temperature_offset = &web_config::temperatureOffsetParam.value(); // [K] Sign isn't relevant. -} \ No newline at end of file + + uint8_t *max_brightness = &web_config::maxBrightnessParam.value(); + uint8_t *min_brightness = &web_config::minBrightnessParam.value(); +} diff --git a/ampel-firmware/web_config.h b/ampel-firmware/web_config.h index b74488658e271ea893e9df2d429789a5f5cef6f3..d414af50012cc0dc4e4865262e88eb88e0cf52b8 100644 --- a/ampel-firmware/web_config.h +++ b/ampel-firmware/web_config.h @@ -18,6 +18,10 @@ namespace config { extern uint16_t *co2_calibration_level; // [ppm] extern bool *auto_calibrate_sensor; // [true / false] extern float *temperature_offset; // [K] Sign isn't relevant. + + // LED + extern uint8_t *max_brightness; + extern uint8_t *min_brightness; } namespace web_config {