From 91008756b0f5e9b052e4ef39e9375cc8c5de9532 Mon Sep 17 00:00:00 2001 From: SciLor Date: Mon, 21 Nov 2016 09:33:43 +0100 Subject: [PATCH 1/4] Renamed WrapperFastLed to WrapperLedControl --- HyperionRGB/HyperionRGB.ino | 6 +++--- ...rapperFastLed.cpp => WrapperLedControl.cpp} | 18 +++++++++--------- .../{WrapperFastLed.h => WrapperLedControl.h} | 6 +++--- HyperionRGB/WrapperWebconfig.h | 1 - 4 files changed, 15 insertions(+), 16 deletions(-) rename HyperionRGB/{WrapperFastLed.cpp => WrapperLedControl.cpp} (88%) rename HyperionRGB/{WrapperFastLed.h => WrapperLedControl.h} (83%) diff --git a/HyperionRGB/HyperionRGB.ino b/HyperionRGB/HyperionRGB.ino index 6e6a34c..6f7a733 100644 --- a/HyperionRGB/HyperionRGB.ino +++ b/HyperionRGB/HyperionRGB.ino @@ -9,7 +9,7 @@ #include "WrapperWiFi.h" #include "WrapperOTA.h" -#include "WrapperFastLed.h" +#include "WrapperLedControl.h" #include "WrapperUdpLed.h" #include "WrapperJsonServer.h" @@ -23,7 +23,7 @@ LoggerInit loggerInit; WrapperWiFi wifi; WrapperOTA ota; -WrapperFastLed ledStrip; +WrapperLedControl ledStrip; WrapperUdpLed udpLed; WrapperJsonServer jsonServer; @@ -186,7 +186,7 @@ void setup(void) { initConfig(); ota = WrapperOTA(); - ledStrip = WrapperFastLed(); + ledStrip = WrapperLedControl(); statusThread.onRun(statusInfo); statusThread.setInterval(5000); diff --git a/HyperionRGB/WrapperFastLed.cpp b/HyperionRGB/WrapperLedControl.cpp similarity index 88% rename from HyperionRGB/WrapperFastLed.cpp rename to HyperionRGB/WrapperLedControl.cpp index 6c2d846..96b5ae6 100644 --- a/HyperionRGB/WrapperFastLed.cpp +++ b/HyperionRGB/WrapperLedControl.cpp @@ -1,6 +1,6 @@ -#include "WrapperFastLed.h" +#include "WrapperLedControl.h" -void WrapperFastLed::begin() { +void WrapperLedControl::begin() { #ifdef CONFIG_LED_CLOCKLESS_CHIPSET Log.debug("Chipset=%s, dataPin=%i, clockPin=%s, colorOrder=%i, ledCount=%i", "Clockless", CONFIG_LED_DATAPIN, "NONE", CONFIG_LED_COLOR_ORDER, CONFIG_LED_COUNT); #else @@ -18,24 +18,24 @@ void WrapperFastLed::begin() { #endif } -void WrapperFastLed::show(void) { +void WrapperLedControl::show(void) { FastLED.show(); } -void WrapperFastLed::clear(void) { +void WrapperLedControl::clear(void) { FastLED.clear(); } -void WrapperFastLed::fillSolid(CRGB color) { +void WrapperLedControl::fillSolid(CRGB color) { fill_solid(leds, _ledCount, color); show(); } -void WrapperFastLed::fillSolid(byte r, byte g, byte b) { +void WrapperLedControl::fillSolid(byte r, byte g, byte b) { fillSolid(CRGB(r, g, b)); } -void WrapperFastLed::rainbowStep(void) { +void WrapperLedControl::rainbowStep(void) { for (int i=0; i < _ledCount; i++) { leds[i] = wheel((i + _rainbowStepState) % 255); } @@ -48,7 +48,7 @@ void WrapperFastLed::rainbowStep(void) { } } -CRGB WrapperFastLed::wheel(byte wheelPos) { +CRGB WrapperLedControl::wheel(byte wheelPos) { CRGB color = CRGB(); if (wheelPos < 85) { return color.setRGB(wheelPos * 3, 255 - wheelPos * 3, 0); @@ -75,7 +75,7 @@ CRGB WrapperFastLed::wheel(byte wheelPos) { // Default 120, suggested range 50-200. #define SPARKING 120 -void WrapperFastLed::fire2012Step(void) { +void WrapperLedControl::fire2012Step(void) { // Step 1. Cool down every cell a little for( int i = 0; i < _ledCount; i++) { _fire2012Heat[i] = qsub8( _fire2012Heat[i], random8(0, ((COOLING * 10) / _ledCount) + 2)); diff --git a/HyperionRGB/WrapperFastLed.h b/HyperionRGB/WrapperLedControl.h similarity index 83% rename from HyperionRGB/WrapperFastLed.h rename to HyperionRGB/WrapperLedControl.h index 339333a..660fc2b 100644 --- a/HyperionRGB/WrapperFastLed.h +++ b/HyperionRGB/WrapperLedControl.h @@ -1,11 +1,11 @@ -#ifndef WrapperFastLed_h -#define WrapperFastLed_h +#ifndef WrapperLedControl_h +#define WrapperLedControl_h #include "BaseHeader.h" #include -class WrapperFastLed { +class WrapperLedControl { public: void begin(), diff --git a/HyperionRGB/WrapperWebconfig.h b/HyperionRGB/WrapperWebconfig.h index 696c94e..0241e47 100644 --- a/HyperionRGB/WrapperWebconfig.h +++ b/HyperionRGB/WrapperWebconfig.h @@ -3,7 +3,6 @@ #include "BaseHeader.h" #include -#include "WrapperFastLed.h" #include class SelectEntryBase { From 6eb6eb8114e243057d0cba87392790fe5d17931e Mon Sep 17 00:00:00 2001 From: SciLor Date: Mon, 21 Nov 2016 10:05:30 +0100 Subject: [PATCH 2/4] Added PWM LEDs --- HyperionRGB/ConfigStatic.h.example | 8 ++++++-- HyperionRGB/WrapperLedControl.cpp | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/HyperionRGB/ConfigStatic.h.example b/HyperionRGB/ConfigStatic.h.example index cf104cb..27fecba 100644 --- a/HyperionRGB/ConfigStatic.h.example +++ b/HyperionRGB/ConfigStatic.h.example @@ -20,9 +20,13 @@ #define CONFIG_LED_SPI_CHIPSET WS2801 //Comment out for clockless //#define CONFIG_LED_CLOCKLESS_CHIPSET WS2812B //Comment in for clockless //#define FASTLED_ALLOW_INTERRUPTS 0 //Comment in if clockless stripe (ex. WS2812B) is flickering +//#define CONFIG_LED_PWM 1 //Comment in if PWM Stripe -#define CONFIG_LED_DATAPIN D1 -#define CONFIG_LED_CLOCKPIN D2 //Comment out for clockless +#define CONFIG_LED_DATAPIN D1 //Comment out for PWM +#define CONFIG_LED_CLOCKPIN D2 //Comment out for clockless / PWM +//#define CONFIG_LED_PWM_RED D1 //Comment in for PWM +//#define CONFIG_LED_PWM_GREEN D2 //Comment in for PWM +//#define CONFIG_LED_PWM_BLUE D3 //Comment in for PWM //Pin order, see FastLED doc. NodeMCU should work with FASTLED_ESP8266_RAW_PIN_ORDER #define FASTLED_ESP8266_RAW_PIN_ORDER diff --git a/HyperionRGB/WrapperLedControl.cpp b/HyperionRGB/WrapperLedControl.cpp index 96b5ae6..37917cc 100644 --- a/HyperionRGB/WrapperLedControl.cpp +++ b/HyperionRGB/WrapperLedControl.cpp @@ -3,6 +3,11 @@ void WrapperLedControl::begin() { #ifdef CONFIG_LED_CLOCKLESS_CHIPSET Log.debug("Chipset=%s, dataPin=%i, clockPin=%s, colorOrder=%i, ledCount=%i", "Clockless", CONFIG_LED_DATAPIN, "NONE", CONFIG_LED_COLOR_ORDER, CONFIG_LED_COUNT); + #elif defined CONFIG_LED_PWM + Log.debug("Chipset=%s, redPin=%i, greenPin=%i, bluePin=%i, ledCount=%i", "PWM", CONFIG_LED_PWM_RED, CONFIG_LED_PWM_GREEN, CONFIG_LED_PWM_BLUE, CONFIG_LED_COUNT); + #if CONFIG_LED_COUNT != 1 + #error "PWM only supports LED count set to one (even if you have multiple LEDs on your strip, they will all show the same color)" + #endif #else Log.debug("Chipset=%i, dataPin=%i, clockPin=%i, colorOrder=%i, ledCount=%i", CONFIG_LED_SPI_CHIPSET, CONFIG_LED_DATAPIN, CONFIG_LED_CLOCKPIN, CONFIG_LED_COLOR_ORDER, CONFIG_LED_COUNT); #endif @@ -13,17 +18,29 @@ void WrapperLedControl::begin() { #ifdef CONFIG_LED_CLOCKLESS_CHIPSET FastLED.addLeds(leds, _ledCount); + #elif defined CONFIG_LED_PWM + //Nothing to to #else FastLED.addLeds(leds, _ledCount); #endif } void WrapperLedControl::show(void) { - FastLED.show(); + #if defined CONFIG_LED_PWM + analogWrite(CONFIG_LED_PWM_RED, leds[0].red); + analogWrite(CONFIG_LED_PWM_GREEN, leds[0].green); + analogWrite(CONFIG_LED_PWM_BLUE, leds[0].blue); + #else + FastLED.show(); + #endif } void WrapperLedControl::clear(void) { - FastLED.clear(); + #if defined CONFIG_LED_PWM + leds[0] = CRGB::Black; + #else + FastLED.clear(); + #endif } void WrapperLedControl::fillSolid(CRGB color) { From c73e04899fb3f3bdec7dcb9987d04b72f714197e Mon Sep 17 00:00:00 2001 From: SciLor Date: Mon, 21 Nov 2016 10:08:33 +0100 Subject: [PATCH 3/4] Fix Fire2012 crash on ledcount < 8 --- HyperionRGB/WrapperLedControl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HyperionRGB/WrapperLedControl.cpp b/HyperionRGB/WrapperLedControl.cpp index 37917cc..0350687 100644 --- a/HyperionRGB/WrapperLedControl.cpp +++ b/HyperionRGB/WrapperLedControl.cpp @@ -105,7 +105,7 @@ void WrapperLedControl::fire2012Step(void) { // Step 3. Randomly ignite new 'sparks' of _fire2012Heat near the bottom if( random8() < SPARKING ) { - int y = random8(7); + int y = random8(min(7, _ledCount - 1)); _fire2012Heat[y] = qadd8(_fire2012Heat[y], random8(160,255)); } From 0591659795e55147533d7244de082ae5b2ab642c Mon Sep 17 00:00:00 2001 From: SciLor Date: Wed, 23 Nov 2016 19:20:18 +0100 Subject: [PATCH 4/4] Map maximum to PWMRANGE, so the maximum brightness of the PWM LEDs is used --- HyperionRGB/WrapperLedControl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/HyperionRGB/WrapperLedControl.cpp b/HyperionRGB/WrapperLedControl.cpp index 0350687..8f88884 100644 --- a/HyperionRGB/WrapperLedControl.cpp +++ b/HyperionRGB/WrapperLedControl.cpp @@ -27,9 +27,9 @@ void WrapperLedControl::begin() { void WrapperLedControl::show(void) { #if defined CONFIG_LED_PWM - analogWrite(CONFIG_LED_PWM_RED, leds[0].red); - analogWrite(CONFIG_LED_PWM_GREEN, leds[0].green); - analogWrite(CONFIG_LED_PWM_BLUE, leds[0].blue); + analogWrite(CONFIG_LED_PWM_RED, map(leds[0].red, 0, 255, 0, PWMRANGE)); + analogWrite(CONFIG_LED_PWM_GREEN, map(leds[0].green, 0, 255, 0, PWMRANGE)); + analogWrite(CONFIG_LED_PWM_BLUE, map(leds[0].blue, 0, 255, 0, PWMRANGE)); #else FastLED.show(); #endif