Skip to content

Commit ff083da

Browse files
committed
Merge branch 'master' of https://github.com/Aircoookie/WLED
2 parents 7f6a554 + eb99271 commit ff083da

File tree

2 files changed

+133
-48
lines changed

2 files changed

+133
-48
lines changed

wled00/FX.cpp

+103-30
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
*/
2626

2727
#include "FX.h"
28-
#include "tv_colors.h"
2928

3029
#define IBN 5100
3130
#define PALETTE_SOLID_WRAP (paletteBlend == 1 || paletteBlend == 3)
@@ -3832,65 +3831,140 @@ uint16_t WS2812FX::mode_blends(void) {
38323831
return FRAMETIME;
38333832
}
38343833

3835-
#ifndef WLED_DISABLE_FX_HIGH_FLASH_USE
38363834
typedef struct TvSim {
38373835
uint32_t totalTime = 0;
38383836
uint32_t fadeTime = 0;
38393837
uint32_t startTime = 0;
38403838
uint32_t elapsed = 0;
38413839
uint32_t pixelNum = 0;
3840+
uint16_t sliderValues = 0;
3841+
uint32_t sceeneStart = 0;
3842+
uint32_t sceeneDuration = 0;
3843+
uint16_t sceeneColorHue = 0;
3844+
uint8_t sceeneColorSat = 0;
3845+
uint8_t sceeneColorBri = 0;
3846+
uint8_t actualColorR = 0;
3847+
uint8_t actualColorG = 0;
3848+
uint8_t actualColorB = 0;
38423849
uint16_t pr = 0; // Prev R, G, B
38433850
uint16_t pg = 0;
38443851
uint16_t pb = 0;
38453852
} tvSim;
38463853

3847-
#define numTVPixels (sizeof(tv_colors) / 2) // 2 bytes per Pixel (5/6/5)
3854+
3855+
#ifndef WLED_DISABLE_FX_HIGH_FLASH_USE
3856+
#include "tv_colors.h"
3857+
#define numTVPixels (sizeof(tv_colors) / 2) // 2 bytes per Pixel (5/6/5)
38483858
#endif
38493859

38503860
/*
38513861
TV Simulator
38523862
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
38533863
*/
38543864
uint16_t WS2812FX::mode_tv_simulator(void) {
3855-
#ifdef WLED_DISABLE_FX_HIGH_FLASH_USE
3856-
return mode_static();
3857-
#else
3858-
uint16_t nr, ng, nb, r, g, b, i;
3859-
uint8_t hi, lo, r8, g8, b8;
3865+
uint16_t nr, ng, nb, r, g, b, i, hue;
3866+
uint8_t hi, lo, r8, g8, b8, sat, bri, j;
38603867

38613868
if (!SEGENV.allocateData(sizeof(tvSim))) return mode_static(); //allocation failed
38623869
TvSim* tvSimulator = reinterpret_cast<TvSim*>(SEGENV.data);
38633870

3864-
// initialize start of the TV-Colors
3865-
if (SEGENV.call == 0) {
3866-
tvSimulator->pixelNum = ((uint8_t)random(18)) * numTVPixels / 18; // Begin at random movie (18 in total)
3867-
}
3871+
uint8_t colorSpeed = map(SEGMENT.speed, 0, UINT8_MAX, 1, 20);
3872+
uint8_t colorIntensity = map(SEGMENT.intensity, 0, UINT8_MAX, 10, 30);
38683873

3869-
// Read next 16-bit (5/6/5) color
3870-
hi = pgm_read_byte(&tv_colors[tvSimulator->pixelNum * 2 ]);
3871-
lo = pgm_read_byte(&tv_colors[tvSimulator->pixelNum * 2 + 1]);
3874+
i = SEGMENT.speed << 8 | SEGMENT.intensity;
3875+
if (i != tvSimulator->sliderValues) {
3876+
tvSimulator->sliderValues = i;
3877+
SEGENV.aux1 = 0;
3878+
}
38723879

3873-
// Expand to 24-bit (8/8/8)
3874-
r8 = (hi & 0xF8) | (hi >> 5);
3875-
g8 = ((hi << 5) & 0xff) | ((lo & 0xE0) >> 3) | ((hi & 0x06) >> 1);
3876-
b8 = ((lo << 3) & 0xff) | ((lo & 0x1F) >> 2);
3880+
#ifndef WLED_DISABLE_FX_HIGH_FLASH_USE
3881+
/*
3882+
* this code uses the real color data from tv_colos.h
3883+
*/
38773884

3878-
// Apply gamma correction, further expand to 16/16/16
3879-
nr = (uint8_t)gamma8(r8) * 257; // New R/G/B
3880-
ng = (uint8_t)gamma8(g8) * 257;
3881-
nb = (uint8_t)gamma8(b8) * 257;
3885+
// initialize start of the TV-Colors
3886+
if (SEGENV.aux1 == 0) {
3887+
tvSimulator->pixelNum = ((uint8_t)random8(18)) * numTVPixels / 18; // Begin at random movie (18 in total)
3888+
SEGENV.aux1 = 1;
3889+
}
3890+
3891+
// Read next 16-bit (5/6/5) color
3892+
hi = pgm_read_byte(&tv_colors[tvSimulator->pixelNum * 2 ]);
3893+
lo = pgm_read_byte(&tv_colors[tvSimulator->pixelNum * 2 + 1]);
3894+
3895+
// Expand to 24-bit (8/8/8)
3896+
r8 = (hi & 0xF8) | (hi >> 5);
3897+
g8 = ((hi << 5) & 0xff) | ((lo & 0xE0) >> 3) | ((hi & 0x06) >> 1);
3898+
b8 = ((lo << 3) & 0xff) | ((lo & 0x1F) >> 2);
3899+
3900+
// Apply gamma correction, further expand to 16/16/16
3901+
nr = (uint8_t)gamma8(r8) * 257; // New R/G/B
3902+
ng = (uint8_t)gamma8(g8) * 257;
3903+
nb = (uint8_t)gamma8(b8) * 257;
3904+
#else
3905+
/*
3906+
* this code calculates the color to be used and save 18k of flash memory
3907+
*/
3908+
3909+
// create a new sceene
3910+
if (((millis() - tvSimulator->sceeneStart) >= tvSimulator->sceeneDuration) || SEGENV.aux1 == 0) {
3911+
tvSimulator->sceeneStart = millis(); // remember the start of the new sceene
3912+
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)
3913+
tvSimulator->sceeneColorHue = random16( 0, 768); // random start color-tone for the sceene
3914+
tvSimulator->sceeneColorSat = random8 ( 100, 130 + colorIntensity); // random start color-saturation for the sceene
3915+
tvSimulator->sceeneColorBri = random8 ( 200, 240); // random start color-brightness for the sceene
3916+
SEGENV.aux1 = 1;
3917+
SEGENV.aux0 = 0;
3918+
}
3919+
3920+
// slightly change the color-tone in this sceene
3921+
if ( SEGENV.aux0 == 0) {
3922+
// hue change in both directions
3923+
j = random8(4 * colorIntensity);
3924+
hue = (random8() < 128) ? ((j < tvSimulator->sceeneColorHue) ? tvSimulator->sceeneColorHue - j : 767 - tvSimulator->sceeneColorHue - j) : // negative
3925+
((j + tvSimulator->sceeneColorHue) < 767 ? tvSimulator->sceeneColorHue + j : tvSimulator->sceeneColorHue + j - 767) ; // positive
3926+
3927+
// saturation
3928+
j = random8(2 * colorIntensity);
3929+
sat = (tvSimulator->sceeneColorSat - j) < 0 ? 0 : tvSimulator->sceeneColorSat - j;
3930+
3931+
// brightness
3932+
j = random8(100);
3933+
bri = (tvSimulator->sceeneColorBri - j) < 0 ? 0 : tvSimulator->sceeneColorBri - j;
3934+
3935+
// calculate R,G,B from HSV
3936+
// Source: https://blog.adafruit.com/2012/03/14/constant-brightness-hsb-to-rgb-algorithm/
3937+
{ // just to create a local scope for the variables
3938+
uint8_t temp[5], n = (hue >> 8) % 3;
3939+
uint8_t x = ((((hue & 255) * sat) >> 8) * bri) >> 8;
3940+
uint8_t s = ( (256 - sat) * bri) >> 8;
3941+
temp[0] = temp[3] = s;
3942+
temp[1] = temp[4] = x + s;
3943+
temp[2] = bri - x;
3944+
tvSimulator->actualColorR = temp[n + 2];
3945+
tvSimulator->actualColorG = temp[n + 1];
3946+
tvSimulator->actualColorB = temp[n ];
3947+
}
3948+
}
3949+
// Apply gamma correction, further expand to 16/16/16
3950+
nr = (uint8_t)gamma8(tvSimulator->actualColorR) * 257; // New R/G/B
3951+
ng = (uint8_t)gamma8(tvSimulator->actualColorG) * 257;
3952+
nb = (uint8_t)gamma8(tvSimulator->actualColorB) * 257;
3953+
#endif
38823954

38833955
if (SEGENV.aux0 == 0) { // initialize next iteration
38843956
SEGENV.aux0 = 1;
38853957

3886-
// increase color-index for next loop
3887-
tvSimulator->pixelNum++;
3888-
if (tvSimulator->pixelNum >= numTVPixels) tvSimulator->pixelNum = 0;
3958+
#ifndef WLED_DISABLE_FX_HIGH_FLASH_USE
3959+
// increase color-index for next loop
3960+
tvSimulator->pixelNum++;
3961+
if (tvSimulator->pixelNum >= numTVPixels) tvSimulator->pixelNum = 0;
3962+
#endif
38893963

38903964
// randomize total duration and fade duration for the actual color
3891-
tvSimulator->totalTime = random(250, 2500); // Semi-random pixel-to-pixel time
3892-
tvSimulator->fadeTime = random(0, tvSimulator->totalTime); // Pixel-to-pixel transition time
3893-
if (random(10) < 3) tvSimulator->fadeTime = 0; // Force scene cut 30% of time
3965+
tvSimulator->totalTime = random16(250, 2500); // Semi-random pixel-to-pixel time
3966+
tvSimulator->fadeTime = random16(0, tvSimulator->totalTime); // Pixel-to-pixel transition time
3967+
if (random8(10) < 3) tvSimulator->fadeTime = 0; // Force scene cut 30% of time
38943968

38953969
tvSimulator->startTime = millis();
38963970
} // end of initialization
@@ -3923,7 +3997,6 @@ uint16_t WS2812FX::mode_tv_simulator(void) {
39233997
}
39243998

39253999
return FRAMETIME;
3926-
#endif
39274000
}
39284001

39294002
/*

wled00/bus_wrapper.h

+30-18
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define I_8266_U1_400_3 10
2929
#define I_8266_DM_400_3 11
3030
#define I_8266_BB_400_3 12
31-
//TM1418 (RGBW)
31+
//TM1814 (RGBW)
3232
#define I_8266_U0_TM1_4 13
3333
#define I_8266_U1_TM1_4 14
3434
#define I_8266_DM_TM1_4 15
@@ -68,7 +68,7 @@
6868
#define I_32_R7_400_3 44
6969
#define I_32_I0_400_3 45
7070
#define I_32_I1_400_3 46
71-
//TM1418 (RGBW)
71+
//TM1814 (RGBW)
7272
#define I_32_R0_TM1_4 47
7373
#define I_32_R1_TM1_4 48
7474
#define I_32_R2_TM1_4 49
@@ -115,7 +115,7 @@
115115
#define B_8266_U1_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart1400KbpsMethod> //3 chan, esp8266, gpio2
116116
#define B_8266_DM_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Dma400KbpsMethod> //3 chan, esp8266, gpio3
117117
#define B_8266_BB_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266BitBang400KbpsMethod> //3 chan, esp8266, bb (any pin)
118-
//TM1418 (RGBW)
118+
//TM1814 (RGBW)
119119
#define B_8266_U0_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp8266Uart0Tm1814Method>
120120
#define B_8266_U1_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp8266Uart1Tm1814Method>
121121
#define B_8266_DM_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp8266DmaTm1814Method>
@@ -157,7 +157,7 @@
157157
#define B_32_R7_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32Rmt7400KbpsMethod>
158158
#define B_32_I0_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s0400KbpsMethod>
159159
#define B_32_I1_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s1400KbpsMethod>
160-
//TM1418 (RGBW)
160+
//TM1814 (RGBW)
161161
#define B_32_R0_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp32Rmt0Tm1814Method>
162162
#define B_32_R1_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp32Rmt1Tm1814Method>
163163
#define B_32_R2_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp32Rmt2Tm1814Method>
@@ -191,6 +191,14 @@
191191
//handles pointer type conversion for all possible bus types
192192
class PolyBus {
193193
public:
194+
// Begin & initialize the PixelSettings for TM1814 strips.
195+
template <class T>
196+
static void beginTM1814(void* busPtr) {
197+
T tm1814_strip = static_cast<T>(busPtr);
198+
tm1814_strip->Begin();
199+
// Max current for each LED (22.5 mA).
200+
tm1814_strip->SetPixelSettings(NeoTm1814Settings(/*R*/225, /*G*/225, /*B*/225, /*W*/225));
201+
}
194202
static void begin(void* busPtr, uint8_t busType, uint8_t* pins) {
195203
switch (busType) {
196204
case I_NONE: break;
@@ -207,10 +215,10 @@ class PolyBus {
207215
case I_8266_U1_400_3: (static_cast<B_8266_U1_400_3*>(busPtr))->Begin(); break;
208216
case I_8266_DM_400_3: (static_cast<B_8266_DM_400_3*>(busPtr))->Begin(); break;
209217
case I_8266_BB_400_3: (static_cast<B_8266_BB_400_3*>(busPtr))->Begin(); break;
210-
case I_8266_U0_TM1_4: (static_cast<B_8266_U0_TM1_4*>(busPtr))->Begin(); break;
211-
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->Begin(); break;
212-
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->Begin(); break;
213-
case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->Begin(); break;
218+
case I_8266_U0_TM1_4: beginTM1814<B_8266_U0_TM1_4*>(busPtr); break;
219+
case I_8266_U1_TM1_4: beginTM1814<B_8266_U1_TM1_4*>(busPtr); break;
220+
case I_8266_DM_TM1_4: beginTM1814<B_8266_DM_TM1_4*>(busPtr); break;
221+
case I_8266_BB_TM1_4: beginTM1814<B_8266_BB_TM1_4*>(busPtr); break;
214222
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Begin(); break;
215223
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->Begin(); break;
216224
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->Begin(); break;
@@ -247,16 +255,16 @@ class PolyBus {
247255
case I_32_R7_400_3: (static_cast<B_32_R7_400_3*>(busPtr))->Begin(); break;
248256
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->Begin(); break;
249257
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->Begin(); break;
250-
case I_32_R0_TM1_4: (static_cast<B_32_R0_TM1_4*>(busPtr))->Begin(); break;
251-
case I_32_R1_TM1_4: (static_cast<B_32_R1_TM1_4*>(busPtr))->Begin(); break;
252-
case I_32_R2_TM1_4: (static_cast<B_32_R2_TM1_4*>(busPtr))->Begin(); break;
253-
case I_32_R3_TM1_4: (static_cast<B_32_R3_TM1_4*>(busPtr))->Begin(); break;
254-
case I_32_R4_TM1_4: (static_cast<B_32_R4_TM1_4*>(busPtr))->Begin(); break;
255-
case I_32_R5_TM1_4: (static_cast<B_32_R5_TM1_4*>(busPtr))->Begin(); break;
256-
case I_32_R6_TM1_4: (static_cast<B_32_R6_TM1_4*>(busPtr))->Begin(); break;
257-
case I_32_R7_TM1_4: (static_cast<B_32_R7_TM1_4*>(busPtr))->Begin(); break;
258-
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->Begin(); break;
259-
case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->Begin(); break;
258+
case I_32_R0_TM1_4: beginTM1814<B_32_R0_TM1_4*>(busPtr); break;
259+
case I_32_R1_TM1_4: beginTM1814<B_32_R1_TM1_4*>(busPtr); break;
260+
case I_32_R2_TM1_4: beginTM1814<B_32_R2_TM1_4*>(busPtr); break;
261+
case I_32_R3_TM1_4: beginTM1814<B_32_R3_TM1_4*>(busPtr); break;
262+
case I_32_R4_TM1_4: beginTM1814<B_32_R4_TM1_4*>(busPtr); break;
263+
case I_32_R5_TM1_4: beginTM1814<B_32_R5_TM1_4*>(busPtr); break;
264+
case I_32_R6_TM1_4: beginTM1814<B_32_R6_TM1_4*>(busPtr); break;
265+
case I_32_R7_TM1_4: beginTM1814<B_32_R7_TM1_4*>(busPtr); break;
266+
case I_32_I0_TM1_4: beginTM1814<B_32_I0_TM1_4*>(busPtr); break;
267+
case I_32_I1_TM1_4: beginTM1814<B_32_I1_TM1_4*>(busPtr); break;
260268
// ESP32 can (and should, to avoid inadvertantly driving the chip select signal) specify the pins used for SPI, but only in begin()
261269
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Begin(pins[1], -1, pins[0], -1); break;
262270
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->Begin(pins[1], -1, pins[0], -1); break;
@@ -860,6 +868,8 @@ class PolyBus {
860868
return I_8266_U0_NEO_4 + offset;
861869
case TYPE_WS2811_400KHZ:
862870
return I_8266_U0_400_3 + offset;
871+
case TYPE_TM1814:
872+
return I_8266_U0_TM1_4 + offset;
863873
}
864874
#else //ESP32
865875
uint8_t offset = num; //RMT bus # == bus index in BusManager
@@ -872,6 +882,8 @@ class PolyBus {
872882
return I_32_R0_NEO_4 + offset;
873883
case TYPE_WS2811_400KHZ:
874884
return I_32_R0_400_3 + offset;
885+
case TYPE_TM1814:
886+
return I_32_R0_TM1_4 + offset;
875887
}
876888
#endif
877889
}

0 commit comments

Comments
 (0)