From 32fefdbe86450cfe689243c08f20590eb935bfef Mon Sep 17 00:00:00 2001 From: Eric Duminil <eric.duminil@gmail.com> Date: Mon, 21 Dec 2020 12:03:20 +0100 Subject: [PATCH] Removing counter namespace --- led_effects.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/led_effects.cpp b/led_effects.cpp index 71d9b75..6eb91d3 100644 --- a/led_effects.cpp +++ b/led_effects.cpp @@ -34,12 +34,6 @@ const uint16_t CO2_TICKS[NUMPIXELS + 1] = { 0, 500, 600, 700, 800, 900, 1000, 12 const uint16_t LED_HUES[NUMPIXELS] = { 21845, 19114, 16383, 13653, 10922, 8191, 5461, 2730, 0, 0, 0, 0 }; // [hue angle] Adafruit_NeoPixel pixels(NUMPIXELS, NEOPIXELS_PIN, NEO_GRB + NEO_KHZ800); -namespace counter { - uint16_t wheel_offset = 0; - uint16_t kitt_offset = 0; - uint16_t breathing_offset = 0; -} - namespace LedEffects { //On-board LED on D4, aka GPIO02 const int ONBOARD_LED_PIN = 2; @@ -84,13 +78,14 @@ namespace LedEffects { if (config::night_mode) { return; } + static uint16_t kitt_offset = 0; pixels.clear(); for (int j = config::kitt_tail; j >= 0; j--) { - int ledNumber = abs((counter::kitt_offset - j + NUMPIXELS) % (2 * NUMPIXELS) - NUMPIXELS) % NUMPIXELS; // Triangular function + int ledNumber = abs((kitt_offset - j + NUMPIXELS) % (2 * NUMPIXELS) - NUMPIXELS) % NUMPIXELS; // Triangular function pixels.setPixelColor(ledNumber, color * pixels.gamma8(255 - j * 76) / 255); } pixels.show(); - counter::kitt_offset += 1; + kitt_offset++; } // Start K.I.T.T. led effect. Red color as default. @@ -140,12 +135,13 @@ namespace LedEffects { if (config::night_mode) { return; } + static uint16_t wheel_offset = 0; unsigned long t0 = seconds(); pixels.setBrightness(config::max_brightness); while (seconds() < t0 + duration_s) { for (int i = 0; i < NUMPIXELS; i++) { - pixels.setPixelColor(i, pixels.ColorHSV(i * 65535 / NUMPIXELS + counter::wheel_offset)); - counter::wheel_offset += hue_increment; + pixels.setPixelColor(i, pixels.ColorHSV(i * 65535 / NUMPIXELS + wheel_offset)); + wheel_offset += hue_increment; } pixels.show(); delay(10); @@ -170,12 +166,12 @@ namespace LedEffects { void breathe(int16_t co2) { if (!config::night_mode) { + static uint16_t breathing_offset = 0; //TODO: use integer sine pixels.setBrightness( - static_cast<int>(config::average_brightness - + cos(counter::breathing_offset * 0.1) * config::brightness_amplitude)); + static_cast<int>(config::average_brightness + cos(breathing_offset * 0.1) * config::brightness_amplitude)); pixels.show(); - counter::breathing_offset += 1; + breathing_offset++; } delay(co2 > 1600 ? 50 : 100); // faster breathing for higher CO2 values } -- GitLab