From afde7940d83e767de0d19ef64c4b25f166a09eac Mon Sep 17 00:00:00 2001 From: cschwinne Date: Fri, 16 Apr 2021 01:01:24 +0200 Subject: [PATCH 1/5] `NUM_STRIPS` no longer required with compile-time strip defaults --- CHANGELOG.md | 5 +++++ wled00/FX_fcn.cpp | 18 +++++++++--------- wled00/cfg.cpp | 1 - wled00/ntp.cpp | 24 ++++++++++++------------ wled00/wled.h | 2 +- wled00/wled_math.h | 26 +++++++++++++++++++------- 6 files changed, 46 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9b4a9e9..59a4bad1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ### Builds after release 0.12.0 +#### Build 2104151 + +- `NUM_STRIPS` no longer required with compile-time strip defaults +- Further optimizations in wled_math.h + #### Build 2104150 - Added ability to add multiple busses as compile time defaults using the esp32_multistrip usermod define syntax diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index c2f8ff47..7d964cb4 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -44,15 +44,10 @@ */ //factory defaults LED setup -//#define NUM_STRIPS 4 //#define PIXEL_COUNTS 30, 30, 30, 30 //#define DATA_PINS 16, 1, 3, 4 //#define DEFAULT_LED_TYPE TYPE_WS2812_RGB -#if (!defined(NUM_STRIPS) || NUM_STRIPS < 1 || NUM_STRIPS > WLED_MAX_BUSSES) - #define NUM_STRIPS 1 -#endif - #ifndef PIXEL_COUNTS #define PIXEL_COUNTS 30 #endif @@ -79,13 +74,18 @@ void WS2812FX::finalizeInit(uint16_t countPixels, bool skipFirst) //if busses failed to load, add default (FS issue...) if (busses.getNumBusses() == 0) { - const uint8_t defDataPins[NUM_STRIPS] = {DATA_PINS}; - const uint16_t defCounts[NUM_STRIPS] = {PIXEL_COUNTS}; + const uint8_t defDataPins[] = {DATA_PINS}; + const uint16_t defCounts[] = {PIXEL_COUNTS}; + const uint8_t defNumBusses = ((sizeof defDataPins) / (sizeof defDataPins[0])); + const uint8_t defNumCounts = ((sizeof defCounts) / (sizeof defCounts[0])); uint16_t prevLen = 0; - for (uint8_t i = 0; i < NUM_STRIPS; i++) { + for (uint8_t i = 0; i < defNumBusses; i++) { uint8_t defPin[] = {defDataPins[i]}; uint16_t start = prevLen; - uint16_t count = (NUM_STRIPS > 1) ? defCounts[i] : _lengthRaw; + uint16_t count = _lengthRaw; + if (defNumBusses > 1 && defNumCounts) { + count = defCounts[(i < defNumCounts) ? i : defNumCounts -1]; + } prevLen += count; BusConfig defCfg = BusConfig(DEFAULT_LED_TYPE, defPin, start, count, COL_ORDER_GRB); busses.add(defCfg); diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 6c33dfd1..fcfecaae 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -461,7 +461,6 @@ void serializeConfig() { Bus *bus = busses.getBus(s); if (!bus || bus->getLength()==0) break; JsonObject ins = hw_led_ins.createNestedObject(); - ins["en"] = true; ins[F("start")] = bus->getStart(); ins[F("len")] = bus->getLength(); JsonArray ins_pin = ins.createNestedArray("pin"); diff --git a/wled00/ntp.cpp b/wled00/ntp.cpp index 00d33623..3a3d8310 100644 --- a/wled00/ntp.cpp +++ b/wled00/ntp.cpp @@ -319,32 +319,32 @@ int getSunriseUTC(int year, int month, int day, float lat, float lon, bool sunse //1. first calculate the day of the year float N1 = 275 * month / 9; float N2 = (month + 9) / 12; - float N3 = (1 + floor((year - 4 * floor(year / 4) + 2) / 3)); + float N3 = (1 + floor_t((year - 4 * floor_t(year / 4) + 2) / 3)); float N = N1 - (N2 * N3) + day - 30; //2. convert the longitude to hour value and calculate an approximate time - float lngHour = lon / 15.0; + float lngHour = lon / 15.0f; float t = N + (((sunset ? 18 : 6) - lngHour) / 24); //3. calculate the Sun's mean anomaly - float M = (0.9856 * t) - 3.289; + float M = (0.9856f * t) - 3.289f; //4. calculate the Sun's true longitude - float L = fmod(M + (1.916 * sin_t(DEG_TO_RAD*M)) + (0.020 * sin_t(2*DEG_TO_RAD*M)) + 282.634, 360.0); + float L = fmod_t(M + (1.916f * sin_t(DEG_TO_RAD*M)) + (0.02f * sin_t(2*DEG_TO_RAD*M)) + 282.634f, 360.0f); //5a. calculate the Sun's right ascension - float RA = fmod(RAD_TO_DEG*atan_t(0.91764 * tan_t(DEG_TO_RAD*L)), 360.0); + float RA = fmod_t(RAD_TO_DEG*atan_t(0.91764f * tan_t(DEG_TO_RAD*L)), 360.0f); //5b. right ascension value needs to be in the same quadrant as L - float Lquadrant = floor( L/90) * 90; - float RAquadrant = floor(RA/90) * 90; + float Lquadrant = floor_t( L/90) * 90; + float RAquadrant = floor_t(RA/90) * 90; RA = RA + (Lquadrant - RAquadrant); //5c. right ascension value needs to be converted into hours - RA /= 15.; + RA /= 15.0f; //6. calculate the Sun's declination - float sinDec = 0.39782 * sin_t(DEG_TO_RAD*L); + float sinDec = 0.39782f * sin_t(DEG_TO_RAD*L); float cosDec = cos_t(asin_t(sinDec)); //7a. calculate the Sun's local hour angle @@ -354,13 +354,13 @@ int getSunriseUTC(int year, int month, int day, float lat, float lon, bool sunse //7b. finish calculating H and convert into hours float H = sunset ? RAD_TO_DEG*acos_t(cosH) : 360 - RAD_TO_DEG*acos_t(cosH); - H /= 15.; + H /= 15.0f; //8. calculate local mean time of rising/setting - float T = H + RA - (0.06571 * t) - 6.622; + float T = H + RA - (0.06571f * t) - 6.622f; //9. adjust back to UTC - float UT = fmod(T - lngHour, 24.0); + float UT = fmod_t(T - lngHour, 24.0f); // return in minutes from midnight return UT*60; diff --git a/wled00/wled.h b/wled00/wled.h index b955ea4d..5294f8cc 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2104150 +#define VERSION 2104151 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG diff --git a/wled00/wled_math.h b/wled00/wled_math.h index 8184dcf2..88d24179 100644 --- a/wled00/wled_math.h +++ b/wled00/wled_math.h @@ -13,7 +13,7 @@ #define modd(x, y) ((x) - (int)((x) / (y)) * (y)) -double cos_t(double x) +float cos_t(float x) { x = modd(x, TWO_PI); char sign = 1; @@ -22,17 +22,17 @@ double cos_t(double x) x -= PI; sign = -1; } - double xx = x * x; + float xx = x * x; return sign * (1 - ((xx) / (2)) + ((xx * xx) / (24)) - ((xx * xx * xx) / (720)) + ((xx * xx * xx * xx) / (40320)) - ((xx * xx * xx * xx * xx) / (3628800)) + ((xx * xx * xx * xx * xx * xx) / (479001600))); } -double sin_t(double x) { +float sin_t(float x) { return cos_t(HALF_PI - x); } -double tan_t(double x) { - double c = cos_t(x); +float tan_t(float x) { + float c = cos_t(x); if (c==0.0) return 0; return sin_t(x) / c; } @@ -63,9 +63,21 @@ float asin_t(float x) { #define B -0.287434475393028 #define C ((HALF_PI/2) - A - B) -double atan_t(double x) { - double xx = x * x; +float atan_t(float x) { + float xx = x * x; return ((A*xx + B)*xx + C)*x; } +float floor_t(float x) { + bool neg = x < 0; + int val = x; + if (neg) val--; + return val; +} + +float fmod_t(float num, float denom) { + int tquot = num / denom; + return num - tquot * denom; +} + #endif \ No newline at end of file From 12de47c923b8ff86e8c029695ae61c85a4d0018f Mon Sep 17 00:00:00 2001 From: Def3nder Date: Fri, 16 Apr 2021 10:22:22 +0200 Subject: [PATCH 2/5] Fix TV-Simmulator Effect flash usage (#1621) * Add alternative TV-Sim version without tv_colors.h ...and safe 18k flash this way * ...remove the define --- wled00/FX.cpp | 131 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 102 insertions(+), 29 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index d64e6f80..c5df495d 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -25,7 +25,6 @@ */ #include "FX.h" -#include "tv_colors.h" #define IBN 5100 #define PALETTE_SOLID_WRAP (paletteBlend == 1 || paletteBlend == 3) @@ -3832,19 +3831,30 @@ uint16_t WS2812FX::mode_blends(void) { return FRAMETIME; } -#ifndef WLED_DISABLE_FX_HIGH_FLASH_USE typedef struct TvSim { uint32_t totalTime = 0; uint32_t fadeTime = 0; uint32_t startTime = 0; uint32_t elapsed = 0; uint32_t pixelNum = 0; + uint16_t sliderValues = 0; + uint32_t sceeneStart = 0; + uint32_t sceeneDuration = 0; + uint16_t sceeneColorHue = 0; + uint8_t sceeneColorSat = 0; + uint8_t sceeneColorBri = 0; + uint8_t actualColorR = 0; + uint8_t actualColorG = 0; + uint8_t actualColorB = 0; uint16_t pr = 0; // Prev R, G, B uint16_t pg = 0; uint16_t pb = 0; } tvSim; -#define numTVPixels (sizeof(tv_colors) / 2) // 2 bytes per Pixel (5/6/5) + +#ifndef WLED_DISABLE_FX_HIGH_FLASH_USE + #include "tv_colors.h" + #define numTVPixels (sizeof(tv_colors) / 2) // 2 bytes per Pixel (5/6/5) #endif /* @@ -3852,45 +3862,109 @@ typedef struct TvSim { Modified and adapted to WLED by Def3nder, based on "Fake TV Light for Engineers" by Phillip Burgess https://learn.adafruit.com/fake-tv-light-for-engineers/arduino-sketch */ uint16_t WS2812FX::mode_tv_simulator(void) { - #ifdef WLED_DISABLE_FX_HIGH_FLASH_USE - return mode_static(); - #else - uint16_t nr, ng, nb, r, g, b, i; - uint8_t hi, lo, r8, g8, b8; + uint16_t nr, ng, nb, r, g, b, i, hue; + uint8_t hi, lo, r8, g8, b8, sat, bri, j; if (!SEGENV.allocateData(sizeof(tvSim))) return mode_static(); //allocation failed TvSim* tvSimulator = reinterpret_cast(SEGENV.data); - // initialize start of the TV-Colors - if (SEGENV.call == 0) { - tvSimulator->pixelNum = ((uint8_t)random(18)) * numTVPixels / 18; // Begin at random movie (18 in total) + uint8_t colorSpeed = map(SEGMENT.speed, 0, UINT8_MAX, 1, 20); + uint8_t colorIntensity = map(SEGMENT.intensity, 0, UINT8_MAX, 10, 30); + + i = SEGMENT.speed << 8 | SEGMENT.intensity; + if (i != tvSimulator->sliderValues) { + tvSimulator->sliderValues = i; + SEGENV.aux1 = 0; } - // Read next 16-bit (5/6/5) color - hi = pgm_read_byte(&tv_colors[tvSimulator->pixelNum * 2 ]); - lo = pgm_read_byte(&tv_colors[tvSimulator->pixelNum * 2 + 1]); + #ifndef WLED_DISABLE_FX_HIGH_FLASH_USE + /* + * this code uses the real color data from tv_colos.h + */ - // Expand to 24-bit (8/8/8) - r8 = (hi & 0xF8) | (hi >> 5); - g8 = ((hi << 5) & 0xff) | ((lo & 0xE0) >> 3) | ((hi & 0x06) >> 1); - b8 = ((lo << 3) & 0xff) | ((lo & 0x1F) >> 2); + // initialize start of the TV-Colors + if (SEGENV.aux1 == 0) { + tvSimulator->pixelNum = ((uint8_t)random8(18)) * numTVPixels / 18; // Begin at random movie (18 in total) + SEGENV.aux1 = 1; + } + + // Read next 16-bit (5/6/5) color + hi = pgm_read_byte(&tv_colors[tvSimulator->pixelNum * 2 ]); + lo = pgm_read_byte(&tv_colors[tvSimulator->pixelNum * 2 + 1]); + + // Expand to 24-bit (8/8/8) + r8 = (hi & 0xF8) | (hi >> 5); + g8 = ((hi << 5) & 0xff) | ((lo & 0xE0) >> 3) | ((hi & 0x06) >> 1); + b8 = ((lo << 3) & 0xff) | ((lo & 0x1F) >> 2); - // Apply gamma correction, further expand to 16/16/16 - nr = (uint8_t)gamma8(r8) * 257; // New R/G/B - ng = (uint8_t)gamma8(g8) * 257; - nb = (uint8_t)gamma8(b8) * 257; + // Apply gamma correction, further expand to 16/16/16 + nr = (uint8_t)gamma8(r8) * 257; // New R/G/B + ng = (uint8_t)gamma8(g8) * 257; + nb = (uint8_t)gamma8(b8) * 257; + #else + /* + * this code calculates the color to be used and save 18k of flash memory + */ + + // create a new sceene + if (((millis() - tvSimulator->sceeneStart) >= tvSimulator->sceeneDuration) || SEGENV.aux1 == 0) { + tvSimulator->sceeneStart = millis(); // remember the start of the new sceene + tvSimulator->sceeneDuration = random16(60* 250* colorSpeed, 60* 750 * colorSpeed); // duration of a "movie sceene" which has similar colors (5 to 15 minutes with max speed slider) + tvSimulator->sceeneColorHue = random16( 0, 768); // random start color-tone for the sceene + tvSimulator->sceeneColorSat = random8 ( 100, 130 + colorIntensity); // random start color-saturation for the sceene + tvSimulator->sceeneColorBri = random8 ( 200, 240); // random start color-brightness for the sceene + SEGENV.aux1 = 1; + SEGENV.aux0 = 0; + } + + // slightly change the color-tone in this sceene + if ( SEGENV.aux0 == 0) { + // hue change in both directions + j = random8(4 * colorIntensity); + hue = (random8() < 128) ? ((j < tvSimulator->sceeneColorHue) ? tvSimulator->sceeneColorHue - j : 767 - tvSimulator->sceeneColorHue - j) : // negative + ((j + tvSimulator->sceeneColorHue) < 767 ? tvSimulator->sceeneColorHue + j : tvSimulator->sceeneColorHue + j - 767) ; // positive + + // saturation + j = random8(2 * colorIntensity); + sat = (tvSimulator->sceeneColorSat - j) < 0 ? 0 : tvSimulator->sceeneColorSat - j; + + // brightness + j = random8(100); + bri = (tvSimulator->sceeneColorBri - j) < 0 ? 0 : tvSimulator->sceeneColorBri - j; + + // calculate R,G,B from HSV + // Source: https://blog.adafruit.com/2012/03/14/constant-brightness-hsb-to-rgb-algorithm/ + { // just to create a local scope for the variables + uint8_t temp[5], n = (hue >> 8) % 3; + uint8_t x = ((((hue & 255) * sat) >> 8) * bri) >> 8; + uint8_t s = ( (256 - sat) * bri) >> 8; + temp[0] = temp[3] = s; + temp[1] = temp[4] = x + s; + temp[2] = bri - x; + tvSimulator->actualColorR = temp[n + 2]; + tvSimulator->actualColorG = temp[n + 1]; + tvSimulator->actualColorB = temp[n ]; + } + } + // Apply gamma correction, further expand to 16/16/16 + nr = (uint8_t)gamma8(tvSimulator->actualColorR) * 257; // New R/G/B + ng = (uint8_t)gamma8(tvSimulator->actualColorG) * 257; + nb = (uint8_t)gamma8(tvSimulator->actualColorB) * 257; + #endif if (SEGENV.aux0 == 0) { // initialize next iteration SEGENV.aux0 = 1; - // increase color-index for next loop - tvSimulator->pixelNum++; - if (tvSimulator->pixelNum >= numTVPixels) tvSimulator->pixelNum = 0; + #ifndef WLED_DISABLE_FX_HIGH_FLASH_USE + // increase color-index for next loop + tvSimulator->pixelNum++; + if (tvSimulator->pixelNum >= numTVPixels) tvSimulator->pixelNum = 0; + #endif // randomize total duration and fade duration for the actual color - tvSimulator->totalTime = random(250, 2500); // Semi-random pixel-to-pixel time - tvSimulator->fadeTime = random(0, tvSimulator->totalTime); // Pixel-to-pixel transition time - if (random(10) < 3) tvSimulator->fadeTime = 0; // Force scene cut 30% of time + tvSimulator->totalTime = random16(250, 2500); // Semi-random pixel-to-pixel time + tvSimulator->fadeTime = random16(0, tvSimulator->totalTime); // Pixel-to-pixel transition time + if (random8(10) < 3) tvSimulator->fadeTime = 0; // Force scene cut 30% of time tvSimulator->startTime = millis(); } // end of initialization @@ -3923,7 +3997,6 @@ uint16_t WS2812FX::mode_tv_simulator(void) { } return FRAMETIME; - #endif } /* From 13e5c695c3bb96af05420ca4348c1f8314f3eccd Mon Sep 17 00:00:00 2001 From: Eric Severance Date: Sun, 18 Apr 2021 10:14:12 -0700 Subject: [PATCH 3/5] Initialize PixelSettings for TM1814 strips (#1847) * Better handling for TM1814 strips * Call SetPixelSettings after Begin as described on the NeoPixelBus wiki * Use NeoTm1814Settings::MaxCurrent constant --- wled00/bus_wrapper.h | 49 ++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/wled00/bus_wrapper.h b/wled00/bus_wrapper.h index c96896c3..bd3da14d 100644 --- a/wled00/bus_wrapper.h +++ b/wled00/bus_wrapper.h @@ -28,7 +28,7 @@ #define I_8266_U1_400_3 10 #define I_8266_DM_400_3 11 #define I_8266_BB_400_3 12 -//TM1418 (RGBW) +//TM1814 (RGBW) #define I_8266_U0_TM1_4 13 #define I_8266_U1_TM1_4 14 #define I_8266_DM_TM1_4 15 @@ -68,7 +68,7 @@ #define I_32_R7_400_3 44 #define I_32_I0_400_3 45 #define I_32_I1_400_3 46 -//TM1418 (RGBW) +//TM1814 (RGBW) #define I_32_R0_TM1_4 47 #define I_32_R1_TM1_4 48 #define I_32_R2_TM1_4 49 @@ -115,7 +115,7 @@ #define B_8266_U1_400_3 NeoPixelBrightnessBus //3 chan, esp8266, gpio2 #define B_8266_DM_400_3 NeoPixelBrightnessBus //3 chan, esp8266, gpio3 #define B_8266_BB_400_3 NeoPixelBrightnessBus //3 chan, esp8266, bb (any pin) -//TM1418 (RGBW) +//TM1814 (RGBW) #define B_8266_U0_TM1_4 NeoPixelBrightnessBus #define B_8266_U1_TM1_4 NeoPixelBrightnessBus #define B_8266_DM_TM1_4 NeoPixelBrightnessBus @@ -157,7 +157,7 @@ #define B_32_R7_400_3 NeoPixelBrightnessBus #define B_32_I0_400_3 NeoPixelBrightnessBus #define B_32_I1_400_3 NeoPixelBrightnessBus -//TM1418 (RGBW) +//TM1814 (RGBW) #define B_32_R0_TM1_4 NeoPixelBrightnessBus #define B_32_R1_TM1_4 NeoPixelBrightnessBus #define B_32_R2_TM1_4 NeoPixelBrightnessBus @@ -191,6 +191,15 @@ //handles pointer type conversion for all possible bus types class PolyBus { public: + // Begin & initialize the PixelSettings for TM1814 strips. + template + static void beginTM1814(void* busPtr) { + T tm1814_strip = static_cast(busPtr); + tm1814_strip->Begin(); + // Max current for each LED (38.0 mA). + const uint16_t max = NeoTm1814Settings::MaxCurrent; + tm1814_strip->SetPixelSettings(NeoTm1814Settings(/*R*/max, /*G*/max, /*B*/max, /*W*/max)); + } static void begin(void* busPtr, uint8_t busType, uint8_t* pins) { switch (busType) { case I_NONE: break; @@ -207,10 +216,10 @@ class PolyBus { case I_8266_U1_400_3: (static_cast(busPtr))->Begin(); break; case I_8266_DM_400_3: (static_cast(busPtr))->Begin(); break; case I_8266_BB_400_3: (static_cast(busPtr))->Begin(); break; - case I_8266_U0_TM1_4: (static_cast(busPtr))->Begin(); break; - case I_8266_U1_TM1_4: (static_cast(busPtr))->Begin(); break; - case I_8266_DM_TM1_4: (static_cast(busPtr))->Begin(); break; - case I_8266_BB_TM1_4: (static_cast(busPtr))->Begin(); break; + case I_8266_U0_TM1_4: beginTM1814(busPtr); break; + case I_8266_U1_TM1_4: beginTM1814(busPtr); break; + case I_8266_DM_TM1_4: beginTM1814(busPtr); break; + case I_8266_BB_TM1_4: beginTM1814(busPtr); break; case I_HS_DOT_3: (static_cast(busPtr))->Begin(); break; case I_HS_LPD_3: (static_cast(busPtr))->Begin(); break; case I_HS_WS1_3: (static_cast(busPtr))->Begin(); break; @@ -247,16 +256,16 @@ class PolyBus { case I_32_R7_400_3: (static_cast(busPtr))->Begin(); break; case I_32_I0_400_3: (static_cast(busPtr))->Begin(); break; case I_32_I1_400_3: (static_cast(busPtr))->Begin(); break; - case I_32_R0_TM1_4: (static_cast(busPtr))->Begin(); break; - case I_32_R1_TM1_4: (static_cast(busPtr))->Begin(); break; - case I_32_R2_TM1_4: (static_cast(busPtr))->Begin(); break; - case I_32_R3_TM1_4: (static_cast(busPtr))->Begin(); break; - case I_32_R4_TM1_4: (static_cast(busPtr))->Begin(); break; - case I_32_R5_TM1_4: (static_cast(busPtr))->Begin(); break; - case I_32_R6_TM1_4: (static_cast(busPtr))->Begin(); break; - case I_32_R7_TM1_4: (static_cast(busPtr))->Begin(); break; - case I_32_I0_TM1_4: (static_cast(busPtr))->Begin(); break; - case I_32_I1_TM1_4: (static_cast(busPtr))->Begin(); break; + case I_32_R0_TM1_4: beginTM1814(busPtr); break; + case I_32_R1_TM1_4: beginTM1814(busPtr); break; + case I_32_R2_TM1_4: beginTM1814(busPtr); break; + case I_32_R3_TM1_4: beginTM1814(busPtr); break; + case I_32_R4_TM1_4: beginTM1814(busPtr); break; + case I_32_R5_TM1_4: beginTM1814(busPtr); break; + case I_32_R6_TM1_4: beginTM1814(busPtr); break; + case I_32_R7_TM1_4: beginTM1814(busPtr); break; + case I_32_I0_TM1_4: beginTM1814(busPtr); break; + case I_32_I1_TM1_4: beginTM1814(busPtr); break; // ESP32 can (and should, to avoid inadvertantly driving the chip select signal) specify the pins used for SPI, but only in begin() case I_HS_DOT_3: (static_cast(busPtr))->Begin(pins[1], -1, pins[0], -1); break; case I_HS_LPD_3: (static_cast(busPtr))->Begin(pins[1], -1, pins[0], -1); break; @@ -860,6 +869,8 @@ class PolyBus { return I_8266_U0_NEO_4 + offset; case TYPE_WS2811_400KHZ: return I_8266_U0_400_3 + offset; + case TYPE_TM1814: + return I_8266_U0_TM1_4 + offset; } #else //ESP32 uint8_t offset = num; //RMT bus # == bus index in BusManager @@ -872,6 +883,8 @@ class PolyBus { return I_32_R0_NEO_4 + offset; case TYPE_WS2811_400KHZ: return I_32_R0_400_3 + offset; + case TYPE_TM1814: + return I_32_R0_TM1_4 + offset; } #endif } From eb99271120b52356699546f08a9c57fffddd4ab4 Mon Sep 17 00:00:00 2001 From: Eric Severance Date: Tue, 20 Apr 2021 12:36:52 -0700 Subject: [PATCH 4/5] Use 22.5 for the TM1814 max current (#1905) * Configure TM1814 max current * Use 22.5 mA as this seems to be a common value for the LEDs --- wled00/bus_wrapper.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/wled00/bus_wrapper.h b/wled00/bus_wrapper.h index bd3da14d..e5e5db54 100644 --- a/wled00/bus_wrapper.h +++ b/wled00/bus_wrapper.h @@ -196,9 +196,8 @@ class PolyBus { static void beginTM1814(void* busPtr) { T tm1814_strip = static_cast(busPtr); tm1814_strip->Begin(); - // Max current for each LED (38.0 mA). - const uint16_t max = NeoTm1814Settings::MaxCurrent; - tm1814_strip->SetPixelSettings(NeoTm1814Settings(/*R*/max, /*G*/max, /*B*/max, /*W*/max)); + // Max current for each LED (22.5 mA). + tm1814_strip->SetPixelSettings(NeoTm1814Settings(/*R*/225, /*G*/225, /*B*/225, /*W*/225)); } static void begin(void* busPtr, uint8_t busType, uint8_t* pins) { switch (busType) { From 7f6a554e1b36d5d11e3e331ec0903dd23cc2749f Mon Sep 17 00:00:00 2001 From: cschwinne Date: Wed, 21 Apr 2021 17:21:55 +0200 Subject: [PATCH 5/5] Small adjustments --- CHANGELOG.md | 6 ++++++ wled00/FX.cpp | 2 +- wled00/json.cpp | 14 ++++++++++++-- wled00/wled.h | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59a4bad1..6172e26d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ### Builds after release 0.12.0 +#### Build 2104210 + +- Added `tb` to JSON state, allowing setting the timebase (set tb=0 to start e.g. wipe effect from the beginning). Receive only. +- Slightly raised Solid mode refresh rate to work with LEDs (TM1814) that require refresh rates of at least 2fps +- Added sunrise and sunset calculation to the backup JSON time source + #### Build 2104151 - `NUM_STRIPS` no longer required with compile-time strip defaults diff --git a/wled00/FX.cpp b/wled00/FX.cpp index d64e6f80..0e60f9e9 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -35,7 +35,7 @@ */ uint16_t WS2812FX::mode_static(void) { fill(SEGCOLOR(0)); - return (SEGMENT.getOption(SEG_OPTION_TRANSITIONAL)) ? FRAMETIME : 500; //update faster if in transition + return (SEGMENT.getOption(SEG_OPTION_TRANSITIONAL)) ? FRAMETIME : 380; //update faster if in transition } diff --git a/wled00/json.cpp b/wled00/json.cpp index 1ff090c2..ffb2714c 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -182,6 +182,9 @@ bool deserializeState(JsonObject root) jsonTransitionOnce = true; } strip.setTransition(transitionDelayTemp); + + tr = root[F("tb")] | -1; + if (tr >= 0) strip.timebase = ((uint32_t)tr) - millis(); int cy = root[F("pl")] | -2; if (cy > -2) presetCyclingEnabled = (cy >= 0); @@ -203,9 +206,16 @@ bool deserializeState(JsonObject root) receiveNotifications = udpn["recv"] | receiveNotifications; bool noNotification = udpn[F("nn")]; //send no notification just for this request - unsigned long timein = root[F("time")] | UINT32_MAX; + unsigned long timein = root[F("time")] | UINT32_MAX; //backup time source if NTP not synced if (timein != UINT32_MAX) { - if (millis() - ntpLastSyncTime > 50000000L) setTime(timein); + time_t prev = now(); + if (millis() - ntpLastSyncTime > 50000000L) { + setTime(timein); + if (abs(now() - prev) > 60L) { + updateLocalTime(); + calculateSunriseAndSunset(); + } + } if (presetsModifiedTime == 0) presetsModifiedTime = timein; } diff --git a/wled00/wled.h b/wled00/wled.h index 5294f8cc..8391e425 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2104151 +#define VERSION 2104210 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG