From 048167311dabf87ef502643e7edd4fed5757ee1e Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 9 May 2016 16:08:12 +0200 Subject: [PATCH] Change according new NeoPixelbus library --- examples/Wifinfo/Wifinfo.h | 34 +++++++++++++-------- examples/Wifinfo/Wifinfo.ino | 57 +++++++++++++++++++++++++++++++++--- 2 files changed, 74 insertions(+), 17 deletions(-) diff --git a/examples/Wifinfo/Wifinfo.h b/examples/Wifinfo/Wifinfo.h index 5f1d4bf..6c7d601 100644 --- a/examples/Wifinfo/Wifinfo.h +++ b/examples/Wifinfo/Wifinfo.h @@ -74,14 +74,22 @@ extern "C" { #define BLINK_LED_MS 50 // 50 ms blink #define RGB_LED_PIN 14 #define RED_LED_PIN 12 -// value for RGB color -#define COLOR_RED rgb_brightness, 0, 0 -#define COLOR_ORANGE rgb_brightness, rgb_brightness>>1, 0 -#define COLOR_YELLOW rgb_brightness, rgb_brightness, 0 -#define COLOR_GREEN 0, rgb_brightness, 0 -#define COLOR_CYAN 0, rgb_brightness, rgb_brightness -#define COLOR_BLUE 0, 0, rgb_brightness -#define COLOR_MAGENTA rgb_brightness, 0, rgb_brightness + +// value for HSL color +// see http://www.workwithcolor.com/blue-color-hue-range-01.htm +#define COLOR_RED 0 +#define COLOR_ORANGE 30 +#define COLOR_ORANGE_YELLOW 45 +#define COLOR_YELLOW 60 +#define COLOR_YELLOW_GREEN 90 +#define COLOR_GREEN 120 +#define COLOR_GREEN_CYAN 165 +#define COLOR_CYAN 180 +#define COLOR_CYAN_BLUE 210 +#define COLOR_BLUE 240 +#define COLOR_BLUE_MAGENTA 275 +#define COLOR_MAGENTA 300 +#define COLOR_PINK 350 // GPIO 1 TX on board blue led #ifdef BLU_LED_PIN @@ -95,10 +103,11 @@ extern "C" { #define LedRedON() {digitalWrite(RED_LED_PIN, 1);} #define LedRedOFF() {digitalWrite(RED_LED_PIN, 0);} - // Light off the RGB LED -#define LedRGBOFF() { rgb_led.SetPixelColor(0,0,0,0); rgb_led.Show(); } -#define LedRGBON(x) { rgb_led.SetPixelColor(0,x); rgb_led.Show(); } - +// Light off the RGB LED +#ifndef RGB_LED_PIN +#define LedRGBOFF() {} +#define LedRGBON(x) {} +#endif // sysinfo informations typedef struct { @@ -110,7 +119,6 @@ typedef struct extern ESP8266WebServer server; extern WiFiUDP OTA; extern TInfo tinfo; -extern NeoPixelBus rgb_led ; extern uint8_t rgb_brightness; extern unsigned long seconds; extern _sysinfo sysinfo; diff --git a/examples/Wifinfo/Wifinfo.ino b/examples/Wifinfo/Wifinfo.ino index a84987e..f3ae30a 100644 --- a/examples/Wifinfo/Wifinfo.ino +++ b/examples/Wifinfo/Wifinfo.ino @@ -46,11 +46,15 @@ bool ota_blink; // Teleinfo TInfo tinfo; -// RGB Loed -NeoPixelBus rgb_led = NeoPixelBus(1, RGB_LED_PIN, NEO_RGB | NEO_KHZ800); +// RGB Led +#ifdef RGB_LED_PIN +//NeoPixelBus rgb_led = NeoPixelBus(1, RGB_LED_PIN, NEO_RGB | NEO_KHZ800); +NeoPixelBus rgb_led(1, RGB_LED_PIN); +#endif -// define whole brigtness level for RGBLED -uint8_t rgb_brightness = 127; + +// define whole brigtness level for RGBLED (50%) +uint8_t rgb_brightness = 50; // LED Blink timers Ticker rgb_ticker; Ticker blu_ticker; @@ -143,6 +147,51 @@ void LedOff(int led) LedRGBOFF(); } + +// Light off the RGB LED +#ifdef RGB_LED_PIN +/* ====================================================================== +Function: LedRGBON +Purpose : Light RGB Led with HSB value +Input : Hue (0..255) + Saturation (0..255) + Brightness (0..255) +Output : - +Comments: +====================================================================== */ +void LedRGBON (uint16_t hue) +{ + if (config.config & CFG_RGB_LED) { + // Convert to neoPixel API values + // H (is color from 0..360) should be between 0.0 and 1.0 + // L (is brightness from 0..100) should be between 0.0 and 0.5 + RgbColor target = HslColor( hue / 360.0f, 1.0f, rgb_brightness * 0.005f ); + + // Set RGB Led + rgb_led.SetPixelColor(0, target); + rgb_led.Show(); + } +} + +/* ====================================================================== +Function: LedRGBOFF +Purpose : light off the RGN LED +Input : - +Output : - +Comments: - +====================================================================== */ +//void LedOff(int led) +void LedRGBOFF(void) +{ + if (config.config & CFG_RGB_LED) { + rgb_led.SetPixelColor(0,RgbColor(0)); + rgb_led.Show(); + } +} + +#endif + + /* ====================================================================== Function: ADPSCallback Purpose : called by library when we detected a ADPS on any phased