From 59930870fdbe7a39c8bb2d88fd68c57ea21e4c18 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 6 Apr 2020 11:53:55 +0200 Subject: [PATCH] enhanced RGB LED control for M5fire --- include/led.h | 4 ++++ src/hal/m5fire.h | 3 ++- src/led.cpp | 12 +++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/led.h b/include/led.h index 1bc0ccde..6ee08289 100644 --- a/include/led.h +++ b/include/led.h @@ -4,6 +4,10 @@ #include #include "lorawan.h" +#ifndef RGB_LED_COUNT +#define RGB_LED_COUNT 1 +#endif + // value for HSL color // see http://www.workwithcolor.com/blue-color-hue-range-01.htm #define COLOR_RED 0 diff --git a/src/hal/m5fire.h b/src/hal/m5fire.h index ff4e196b..969c05ee 100644 --- a/src/hal/m5fire.h +++ b/src/hal/m5fire.h @@ -38,7 +38,8 @@ //#define BAT_VOLTAGE_DIVIDER 2 // voltage divider 100k/100k on board #define HAS_LED NOT_A_PIN // no on board LED (?) -#define HAS_RGB_LED SmartLed rgb_led(LED_SK6812, 10, GPIO_NUM_15) // LED_SK6812 RGB LED on GPIO15 +#define RGB_LED_COUNT 10 +#define HAS_RGB_LED SmartLed rgb_led(LED_SK6812, RGB_LED_COUNT, GPIO_NUM_15) // LED_SK6812 RGB LED on GPIO15 #define HAS_BUTTON (39) // on board button A // GPS settings diff --git a/src/led.cpp b/src/led.cpp index d7925b4e..64d33d2e 100644 --- a/src/led.cpp +++ b/src/led.cpp @@ -64,8 +64,9 @@ RGBColor rgb_hsl2rgb(float h, float s, float l) { void rgb_set_color(uint16_t hue) { if (hue == COLOR_NONE) { - // Off - rgb_led[0] = Rgb(0, 0, 0); + // set Off + for (int i = 0; i < RGB_LED_COUNT; i++) + rgb_led[i] = Rgb(0, 0, 0); } else { // see http://www.workwithcolor.com/blue-color-hue-range-01.htm // H (is color from 0..360) should be between 0.0 and 1.0 @@ -74,7 +75,8 @@ void rgb_set_color(uint16_t hue) { // cfg.rgblum is between 0 and 100 (percent) RGBColor target = rgb_hsl2rgb(hue / 360.0f, 1.0f, 0.005f * cfg.rgblum); // uint32_t color = target.R<<16 | target.G<<8 | target.B; - rgb_led[0] = Rgb(target.R, target.G, target.B); + for (int i = 0; i < RGB_LED_COUNT; i++) + rgb_led[i] = Rgb(target.R, target.G, target.B); } // Show rgb_led.show(); @@ -211,7 +213,7 @@ void ledLoop(void *parameter) { } // give yield to CPU delay(2); - } // while(1) -}; // ledloop() + } // while(1) +}; // ledloop() #endif // #if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)