mirror of
https://github.com/wled/WLED.git
synced 2025-04-25 07:17:18 +00:00
Grouping and Spacing
This commit is contained in:
parent
6bc927c535
commit
ae6ba79f1e
305
wled00/FX.cpp
305
wled00/FX.cpp
@ -69,7 +69,7 @@ uint16_t WS2812FX::blink(uint32_t color1, uint32_t color2, bool strobe, bool do_
|
||||
uint32_t color = ((SEGENV.aux0 & 1) == 0) ? color1 : color2;
|
||||
if (color == color1 && do_palette)
|
||||
{
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
|
||||
}
|
||||
} else fill(color);
|
||||
@ -149,18 +149,18 @@ uint16_t WS2812FX::color_wipe(bool rev, bool useRandomColors) {
|
||||
if (rem > 255) rem = 255;
|
||||
|
||||
uint32_t col1 = useRandomColors? color_wheel(SEGENV.aux1) : SEGCOLOR(1);
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++)
|
||||
for (uint16_t i = 0; i < SEGLEN; i++)
|
||||
{
|
||||
uint16_t index = (rev && back)? SEGMENT.stop -1 -i +SEGMENT.start : i;
|
||||
uint16_t index = (rev && back)? SEGLEN -1 -i : i;
|
||||
uint32_t col0 = useRandomColors? color_wheel(SEGENV.aux0) : color_from_palette(index, true, PALETTE_SOLID_WRAP, 0);
|
||||
|
||||
if (i - SEGMENT.start < ledIndex)
|
||||
if (i < ledIndex)
|
||||
{
|
||||
setPixelColor(index, back? col1 : col0);
|
||||
} else
|
||||
{
|
||||
setPixelColor(index, back? col0 : col1);
|
||||
if (i - SEGMENT.start == ledIndex) setPixelColor(index, color_blend(back? col0 : col1, back? col1 : col0, rem));
|
||||
if (i == ledIndex) setPixelColor(index, color_blend(back? col0 : col1, back? col1 : col0, rem));
|
||||
}
|
||||
}
|
||||
return FRAMETIME;
|
||||
@ -253,7 +253,7 @@ uint16_t WS2812FX::mode_dynamic(void) {
|
||||
}
|
||||
|
||||
for (uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(SEGMENT.start + i, color_wheel(SEGENV.data[i]));
|
||||
setPixelColor(i, color_wheel(SEGENV.data[i]));
|
||||
}
|
||||
return FRAMETIME;
|
||||
}
|
||||
@ -272,7 +272,7 @@ uint16_t WS2812FX::mode_breath(void) {
|
||||
}
|
||||
|
||||
uint8_t lum = 30 + var;
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(i, color_blend(SEGCOLOR(1), color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), lum));
|
||||
}
|
||||
|
||||
@ -287,7 +287,7 @@ uint16_t WS2812FX::mode_fade(void) {
|
||||
uint16_t counter = (now * ((SEGMENT.speed >> 3) +10));
|
||||
uint8_t lum = triwave16(counter) >> 8;
|
||||
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(i, color_blend(SEGCOLOR(1), color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), lum));
|
||||
}
|
||||
|
||||
@ -313,14 +313,13 @@ uint16_t WS2812FX::scan(bool dual)
|
||||
|
||||
if (dual) {
|
||||
for (uint16_t j = led_offset; j < led_offset + size; j++) {
|
||||
uint16_t i2 = SEGMENT.stop -1 -j;
|
||||
uint16_t i2 = SEGLEN -1 -j;
|
||||
setPixelColor(i2, color_from_palette(i2, true, PALETTE_SOLID_WRAP, (SEGCOLOR(2))? 2:0));
|
||||
}
|
||||
}
|
||||
|
||||
for (uint16_t j = led_offset; j < led_offset + size; j++) {
|
||||
uint16_t i = SEGMENT.start + j;
|
||||
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
|
||||
setPixelColor(j, color_from_palette(j, true, PALETTE_SOLID_WRAP, 0));
|
||||
}
|
||||
|
||||
return FRAMETIME;
|
||||
@ -366,7 +365,7 @@ uint16_t WS2812FX::mode_rainbow_cycle(void) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
//intensity/29 = 0 (1/16) 1 (1/8) 2 (1/4) 3 (1/2) 4 (1) 5 (2) 6 (4) 7 (8) 8 (16)
|
||||
uint8_t index = (i * (16 << (SEGMENT.intensity /29)) / SEGLEN) + counter;
|
||||
setPixelColor(SEGMENT.start + i, color_wheel(index));
|
||||
setPixelColor(i, color_wheel(index));
|
||||
}
|
||||
|
||||
return FRAMETIME;
|
||||
@ -390,12 +389,12 @@ uint16_t WS2812FX::theater_chase(uint32_t color1, uint32_t color2, bool dopalett
|
||||
if((i % gap) == SEGENV.aux0) {
|
||||
if (dopalette)
|
||||
{
|
||||
setPixelColor(SEGMENT.start + i, color_from_palette(SEGMENT.start + i, true, PALETTE_SOLID_WRAP, 0));
|
||||
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
|
||||
} else {
|
||||
setPixelColor(SEGMENT.start + i, color1);
|
||||
setPixelColor(i, color1);
|
||||
}
|
||||
} else {
|
||||
setPixelColor(SEGMENT.start + i, color2);
|
||||
setPixelColor(i, color2);
|
||||
}
|
||||
}
|
||||
return FRAMETIME;
|
||||
@ -439,7 +438,7 @@ uint16_t WS2812FX::running_base(bool saw) {
|
||||
}
|
||||
}
|
||||
s = sin8(a);
|
||||
setPixelColor(SEGMENT.start + i, color_blend(color_from_palette(SEGMENT.start + i, true, PALETTE_SOLID_WRAP, 0), SEGCOLOR(1), s));
|
||||
setPixelColor(i, color_blend(color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), SEGCOLOR(1), s));
|
||||
}
|
||||
return FRAMETIME;
|
||||
}
|
||||
@ -488,8 +487,7 @@ uint16_t WS2812FX::mode_twinkle(void) {
|
||||
{
|
||||
PRNG16 = (uint16_t)(PRNG16 * 2053) + 13849; // next 'random' number
|
||||
uint32_t p = (uint32_t)SEGLEN * (uint32_t)PRNG16;
|
||||
uint16_t mapped = p >> 16;
|
||||
uint16_t j = SEGMENT.start + mapped;
|
||||
uint16_t j = p >> 16;
|
||||
setPixelColor(j, color_from_palette(j, true, PALETTE_SOLID_WRAP, 0));
|
||||
}
|
||||
|
||||
@ -508,7 +506,7 @@ uint16_t WS2812FX::dissolve(uint32_t color) {
|
||||
if (random8() <= SEGMENT.intensity) {
|
||||
for (uint8_t times = 0; times < 10; times++) //attempt to spawn a new pixel 5 times
|
||||
{
|
||||
uint16_t i = SEGMENT.start + random16(SEGLEN);
|
||||
uint16_t i = random16(SEGLEN);
|
||||
if (SEGENV.aux0) { //dissolve to primary/palette
|
||||
if (getPixelColor(i) == SEGCOLOR(1) || wa) {
|
||||
if (color == SEGCOLOR(0))
|
||||
@ -555,7 +553,7 @@ uint16_t WS2812FX::mode_dissolve_random(void) {
|
||||
* Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/
|
||||
*/
|
||||
uint16_t WS2812FX::mode_sparkle(void) {
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 1));
|
||||
}
|
||||
uint32_t cycleTime = 10 + (255 - SEGMENT.speed)*2;
|
||||
@ -566,7 +564,7 @@ uint16_t WS2812FX::mode_sparkle(void) {
|
||||
SEGENV.step = it;
|
||||
}
|
||||
|
||||
setPixelColor(SEGMENT.start + SEGENV.aux0, SEGCOLOR(0));
|
||||
setPixelColor(SEGENV.aux0, SEGCOLOR(0));
|
||||
return FRAMETIME;
|
||||
}
|
||||
|
||||
@ -576,13 +574,13 @@ uint16_t WS2812FX::mode_sparkle(void) {
|
||||
* Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/
|
||||
*/
|
||||
uint16_t WS2812FX::mode_flash_sparkle(void) {
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
|
||||
}
|
||||
|
||||
if(random8(5) == 0) {
|
||||
SEGENV.aux0 = random16(SEGLEN); // aux0 stores the random led index
|
||||
setPixelColor(SEGMENT.start + SEGENV.aux0, SEGCOLOR(1));
|
||||
setPixelColor(SEGENV.aux0, SEGCOLOR(1));
|
||||
return 20;
|
||||
}
|
||||
return 20 + (uint16_t)(255-SEGMENT.speed);
|
||||
@ -594,13 +592,13 @@ uint16_t WS2812FX::mode_flash_sparkle(void) {
|
||||
* Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/
|
||||
*/
|
||||
uint16_t WS2812FX::mode_hyper_sparkle(void) {
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
|
||||
}
|
||||
|
||||
if(random8(5) < 2) {
|
||||
for(uint16_t i = 0; i < max(1, SEGLEN/3); i++) {
|
||||
setPixelColor(SEGMENT.start + random16(SEGLEN), SEGCOLOR(1));
|
||||
setPixelColor(random16(SEGLEN), SEGCOLOR(1));
|
||||
}
|
||||
return 20;
|
||||
}
|
||||
@ -612,7 +610,7 @@ uint16_t WS2812FX::mode_hyper_sparkle(void) {
|
||||
* Strobe effect with different strobe count and pause, controlled by speed.
|
||||
*/
|
||||
uint16_t WS2812FX::mode_multi_strobe(void) {
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 1));
|
||||
}
|
||||
//blink(SEGCOLOR(0), SEGCOLOR(1), true, true);
|
||||
@ -621,7 +619,7 @@ uint16_t WS2812FX::mode_multi_strobe(void) {
|
||||
uint16_t count = 2 * ((SEGMENT.speed / 10) + 1);
|
||||
if(SEGENV.step < count) {
|
||||
if((SEGENV.step & 1) == 0) {
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(i, SEGCOLOR(0));
|
||||
}
|
||||
delay = 20;
|
||||
@ -637,12 +635,8 @@ uint16_t WS2812FX::mode_multi_strobe(void) {
|
||||
* Android loading circle
|
||||
*/
|
||||
uint16_t WS2812FX::mode_android(void) {
|
||||
if (SEGENV.call == 0)
|
||||
{
|
||||
SEGENV.step = SEGMENT.start;
|
||||
}
|
||||
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 1));
|
||||
}
|
||||
|
||||
@ -666,19 +660,19 @@ uint16_t WS2812FX::mode_android(void) {
|
||||
if (SEGENV.call %3 != 1) SEGENV.aux1--;
|
||||
}
|
||||
|
||||
if (a >= SEGMENT.stop) a = SEGMENT.start;
|
||||
if (a >= SEGLEN) a = 0;
|
||||
|
||||
if (a + SEGENV.aux1 < SEGMENT.stop)
|
||||
if (a + SEGENV.aux1 < SEGLEN)
|
||||
{
|
||||
for(int i = a; i < a+SEGENV.aux1; i++) {
|
||||
setPixelColor(i, SEGCOLOR(0));
|
||||
}
|
||||
} else
|
||||
{
|
||||
for(int i = a; i < SEGMENT.stop; i++) {
|
||||
for(int i = a; i < SEGLEN; i++) {
|
||||
setPixelColor(i, SEGCOLOR(0));
|
||||
}
|
||||
for(int i = SEGMENT.start; i < SEGENV.aux1 - (SEGMENT.stop -a); i++) {
|
||||
for(int i = 0; i < SEGENV.aux1 - (SEGLEN -a); i++) {
|
||||
setPixelColor(i, SEGCOLOR(0));
|
||||
}
|
||||
}
|
||||
@ -699,11 +693,11 @@ uint16_t WS2812FX::chase(uint32_t color1, uint32_t color2, uint32_t color3, bool
|
||||
uint16_t b = (a + 1 + (SEGMENT.intensity * SEGLEN >> 10)) % SEGLEN;
|
||||
uint16_t c = (b + 1 + (SEGMENT.intensity * SEGLEN >> 10)) % SEGLEN;
|
||||
|
||||
if (dopalette) color1 = color_from_palette(SEGMENT.start + a, true, PALETTE_SOLID_WRAP, 1);
|
||||
if (dopalette) color1 = color_from_palette(a, true, PALETTE_SOLID_WRAP, 1);
|
||||
|
||||
setPixelColor(SEGMENT.start + a, color1);
|
||||
setPixelColor(SEGMENT.start + b, color2);
|
||||
setPixelColor(SEGMENT.start + c, color3);
|
||||
setPixelColor(a, color1);
|
||||
setPixelColor(b, color2);
|
||||
setPixelColor(c, color3);
|
||||
|
||||
return FRAMETIME;
|
||||
}
|
||||
@ -764,23 +758,23 @@ uint16_t WS2812FX::mode_colorful(void) {
|
||||
SEGENV.step = it;
|
||||
}
|
||||
|
||||
uint16_t i = SEGMENT.start;
|
||||
for (i; i < SEGMENT.stop -3; i+=4)
|
||||
uint16_t i = 0;
|
||||
for (i; i < SEGLEN -3; i+=4)
|
||||
{
|
||||
setPixelColor(i, cols[SEGENV.aux0]);
|
||||
setPixelColor(i+1, cols[SEGENV.aux0+1]);
|
||||
setPixelColor(i+2, cols[SEGENV.aux0+2]);
|
||||
setPixelColor(i+3, cols[SEGENV.aux0+3]);
|
||||
}
|
||||
if(i < SEGMENT.stop)
|
||||
if(i < SEGLEN)
|
||||
{
|
||||
setPixelColor(i, cols[SEGENV.aux0]);
|
||||
|
||||
if(i+1 < SEGMENT.stop)
|
||||
if(i+1 < SEGLEN)
|
||||
{
|
||||
setPixelColor(i+1, cols[SEGENV.aux0+1]);
|
||||
|
||||
if(i+2 < SEGMENT.stop)
|
||||
if(i+2 < SEGLEN)
|
||||
{
|
||||
setPixelColor(i+2, cols[SEGENV.aux0+2]);
|
||||
}
|
||||
@ -795,10 +789,10 @@ uint16_t WS2812FX::mode_colorful(void) {
|
||||
* Emulates a traffic light.
|
||||
*/
|
||||
uint16_t WS2812FX::mode_traffic_light(void) {
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++)
|
||||
for(uint16_t i=0; i < SEGLEN; i++)
|
||||
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 1));
|
||||
uint32_t mdelay = 500;
|
||||
for (int i = SEGMENT.start; i < SEGMENT.stop-2 ; i+=3)
|
||||
for (int i = 0; i < SEGLEN-2 ; i+=3)
|
||||
{
|
||||
switch (SEGENV.aux0)
|
||||
{
|
||||
@ -839,7 +833,7 @@ uint16_t WS2812FX::mode_chase_rainbow(void) {
|
||||
uint16_t WS2812FX::mode_chase_flash(void) {
|
||||
uint8_t flash_step = SEGENV.call % ((FLASH_COUNT * 2) + 1);
|
||||
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
|
||||
}
|
||||
|
||||
@ -848,8 +842,8 @@ uint16_t WS2812FX::mode_chase_flash(void) {
|
||||
if(flash_step % 2 == 0) {
|
||||
uint16_t n = SEGENV.step;
|
||||
uint16_t m = (SEGENV.step + 1) % SEGLEN;
|
||||
setPixelColor(SEGMENT.start + n, SEGCOLOR(1));
|
||||
setPixelColor(SEGMENT.start + m, SEGCOLOR(1));
|
||||
setPixelColor( n, SEGCOLOR(1));
|
||||
setPixelColor( m, SEGCOLOR(1));
|
||||
delay = 20;
|
||||
} else {
|
||||
delay = 30;
|
||||
@ -868,7 +862,7 @@ uint16_t WS2812FX::mode_chase_flash_random(void) {
|
||||
uint8_t flash_step = SEGENV.call % ((FLASH_COUNT * 2) + 1);
|
||||
|
||||
for(uint16_t i = 0; i < SEGENV.step; i++) {
|
||||
setPixelColor(SEGMENT.start + i, color_wheel(SEGENV.aux0));
|
||||
setPixelColor(i, color_wheel(SEGENV.aux0));
|
||||
}
|
||||
|
||||
uint16_t delay = 1 + ((10 * (uint16_t)(255 - SEGMENT.speed)) / SEGLEN);
|
||||
@ -876,12 +870,12 @@ uint16_t WS2812FX::mode_chase_flash_random(void) {
|
||||
uint16_t n = SEGENV.step;
|
||||
uint16_t m = (SEGENV.step + 1) % SEGLEN;
|
||||
if(flash_step % 2 == 0) {
|
||||
setPixelColor(SEGMENT.start + n, SEGCOLOR(0));
|
||||
setPixelColor(SEGMENT.start + m, SEGCOLOR(0));
|
||||
setPixelColor( n, SEGCOLOR(0));
|
||||
setPixelColor( m, SEGCOLOR(0));
|
||||
delay = 20;
|
||||
} else {
|
||||
setPixelColor(SEGMENT.start + n, color_wheel(SEGENV.aux0));
|
||||
setPixelColor(SEGMENT.start + m, SEGCOLOR(1));
|
||||
setPixelColor( n, color_wheel(SEGENV.aux0));
|
||||
setPixelColor( m, SEGCOLOR(1));
|
||||
delay = 30;
|
||||
}
|
||||
} else {
|
||||
@ -908,13 +902,13 @@ uint16_t WS2812FX::running(uint32_t color1, uint32_t color2) {
|
||||
if((i + SEGENV.aux0) % (pxw*2) < pxw) {
|
||||
if (color1 == SEGCOLOR(0))
|
||||
{
|
||||
setPixelColor(SEGMENT.stop -i -1, color_from_palette(SEGMENT.stop -i -1, true, PALETTE_SOLID_WRAP, 0));
|
||||
setPixelColor(SEGLEN -i -1, color_from_palette(SEGLEN -i -1, true, PALETTE_SOLID_WRAP, 0));
|
||||
} else
|
||||
{
|
||||
setPixelColor(SEGMENT.stop -i -1, color1);
|
||||
setPixelColor(SEGLEN -i -1, color1);
|
||||
}
|
||||
} else {
|
||||
setPixelColor(SEGMENT.stop -i -1, color2);
|
||||
setPixelColor(SEGLEN -i -1, color2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -962,13 +956,17 @@ uint16_t WS2812FX::mode_halloween(void) {
|
||||
* Random colored pixels running.
|
||||
*/
|
||||
uint16_t WS2812FX::mode_running_random(void) {
|
||||
uint32_t cycleTime = 25 + (3 * (uint32_t)(255 - SEGMENT.speed));
|
||||
uint32_t it = now / cycleTime;
|
||||
if (SEGENV.aux1 == it) return FRAMETIME;
|
||||
|
||||
for(uint16_t i=SEGLEN-1; i > 0; i--) {
|
||||
setPixelColor(SEGMENT.start + i, getPixelColor(SEGMENT.start + i - 1));
|
||||
setPixelColor( i, getPixelColor( i - 1));
|
||||
}
|
||||
|
||||
if(SEGENV.step == 0) {
|
||||
SEGENV.aux0 = get_random_wheel_index(SEGENV.aux0);
|
||||
setPixelColor(SEGMENT.start, color_wheel(SEGENV.aux0));
|
||||
setPixelColor(0, color_wheel(SEGENV.aux0));
|
||||
}
|
||||
|
||||
SEGENV.step++;
|
||||
@ -976,7 +974,9 @@ uint16_t WS2812FX::mode_running_random(void) {
|
||||
{
|
||||
SEGENV.step = 0;
|
||||
}
|
||||
return SPEED_FORMULA_L;
|
||||
|
||||
SEGENV.aux1 = it;
|
||||
return FRAMETIME;
|
||||
}
|
||||
|
||||
|
||||
@ -999,7 +999,7 @@ uint16_t WS2812FX::larson_scanner(bool dual) {
|
||||
|
||||
for (uint16_t i = SEGENV.step; i < index; i++) {
|
||||
uint16_t j = (SEGENV.aux0)?i:SEGLEN-1-i;
|
||||
setPixelColor(SEGMENT.start + j, color_from_palette(j, true, PALETTE_SOLID_WRAP, 0));
|
||||
setPixelColor( j, color_from_palette(j, true, PALETTE_SOLID_WRAP, 0));
|
||||
}
|
||||
if (dual) {
|
||||
uint32_t c;
|
||||
@ -1011,7 +1011,7 @@ uint16_t WS2812FX::larson_scanner(bool dual) {
|
||||
|
||||
for (uint16_t i = SEGENV.step; i < index; i++) {
|
||||
uint16_t j = (SEGENV.aux0)?SEGLEN-1-i:i;
|
||||
setPixelColor(SEGMENT.start + j, c);
|
||||
setPixelColor(j, c);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1029,7 +1029,7 @@ uint16_t WS2812FX::mode_comet(void) {
|
||||
|
||||
fade_out(SEGMENT.intensity);
|
||||
|
||||
setPixelColor(SEGMENT.start + index, color_from_palette(index, true, PALETTE_SOLID_WRAP, 0));
|
||||
setPixelColor( index, color_from_palette(index, true, PALETTE_SOLID_WRAP, 0));
|
||||
|
||||
return FRAMETIME;
|
||||
}
|
||||
@ -1044,8 +1044,8 @@ uint16_t WS2812FX::mode_fireworks() {
|
||||
SEGENV.aux0 = UINT16_MAX;
|
||||
SEGENV.aux1 = UINT16_MAX;
|
||||
}
|
||||
bool valid1 = (SEGENV.aux0 < SEGMENT.stop && SEGENV.aux0 >= SEGMENT.start);
|
||||
bool valid2 = (SEGENV.aux1 < SEGMENT.stop && SEGENV.aux1 >= SEGMENT.start);
|
||||
bool valid1 = (SEGENV.aux0 < SEGLEN && SEGENV.aux0 >= 0);
|
||||
bool valid2 = (SEGENV.aux1 < SEGLEN && SEGENV.aux1 >= 0);
|
||||
uint32_t sv1 = 0, sv2 = 0;
|
||||
if (valid1) sv1 = getPixelColor(SEGENV.aux0);
|
||||
if (valid2) sv2 = getPixelColor(SEGENV.aux1);
|
||||
@ -1055,7 +1055,7 @@ uint16_t WS2812FX::mode_fireworks() {
|
||||
|
||||
for(uint16_t i=0; i<max(1, SEGLEN/20); i++) {
|
||||
if(random8(129 - (SEGMENT.intensity >> 1)) == 0) {
|
||||
uint16_t index = SEGMENT.start + random(SEGLEN);
|
||||
uint16_t index = random(SEGLEN);
|
||||
setPixelColor(index, color_from_palette(random8(), false, false, 0));
|
||||
SEGENV.aux1 = SEGENV.aux0;
|
||||
SEGENV.aux0 = index;
|
||||
@ -1072,17 +1072,17 @@ uint16_t WS2812FX::mode_rain()
|
||||
if (SEGENV.step > SPEED_FORMULA_L) {
|
||||
SEGENV.step = 0;
|
||||
//shift all leds right
|
||||
uint32_t ctemp = getPixelColor(SEGMENT.stop -1);
|
||||
for(uint16_t i=SEGMENT.stop -1; i>SEGMENT.start; i--) {
|
||||
uint32_t ctemp = getPixelColor(SEGLEN -1);
|
||||
for(uint16_t i = SEGLEN -1; i > 0; i--) {
|
||||
setPixelColor(i, getPixelColor(i-1));
|
||||
}
|
||||
setPixelColor(SEGMENT.start, ctemp);
|
||||
setPixelColor(0, ctemp);
|
||||
SEGENV.aux0++;
|
||||
SEGENV.aux1++;
|
||||
if (SEGENV.aux0 == 0) SEGENV.aux0 = UINT16_MAX;
|
||||
if (SEGENV.aux1 == 0) SEGENV.aux0 = UINT16_MAX;
|
||||
if (SEGENV.aux0 == SEGMENT.stop) SEGENV.aux0 = SEGMENT.start;
|
||||
if (SEGENV.aux1 == SEGMENT.stop) SEGENV.aux1 = SEGMENT.start;
|
||||
if (SEGENV.aux0 == SEGLEN) SEGENV.aux0 = 0;
|
||||
if (SEGENV.aux1 == SEGLEN) SEGENV.aux1 = 0;
|
||||
}
|
||||
return mode_fireworks();
|
||||
}
|
||||
@ -1092,13 +1092,17 @@ uint16_t WS2812FX::mode_rain()
|
||||
* Fire flicker function
|
||||
*/
|
||||
uint16_t WS2812FX::mode_fire_flicker(void) {
|
||||
uint32_t cycleTime = 40 + (255 - SEGMENT.speed);
|
||||
uint32_t it = now / cycleTime;
|
||||
if (SEGENV.step == it) return FRAMETIME;
|
||||
|
||||
byte w = (SEGCOLOR(0) >> 24) & 0xFF;
|
||||
byte r = (SEGCOLOR(0) >> 16) & 0xFF;
|
||||
byte g = (SEGCOLOR(0) >> 8) & 0xFF;
|
||||
byte b = (SEGCOLOR(0) & 0xFF);
|
||||
byte lum = (SEGMENT.palette == 0) ? max(w, max(r, max(g, b))) : 255;
|
||||
lum /= (((256-SEGMENT.intensity)/16)+1);
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
byte flicker = random8(lum);
|
||||
if (SEGMENT.palette == 0) {
|
||||
setPixelColor(i, max(r - flicker, 0), max(g - flicker, 0), max(b - flicker, 0), max(w - flicker, 0));
|
||||
@ -1106,7 +1110,9 @@ uint16_t WS2812FX::mode_fire_flicker(void) {
|
||||
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0, 255 - flicker));
|
||||
}
|
||||
}
|
||||
return 20 + random((255 - SEGMENT.speed),(2 * (uint16_t)(255 - SEGMENT.speed)));
|
||||
|
||||
SEGENV.step = it;
|
||||
return FRAMETIME;
|
||||
}
|
||||
|
||||
|
||||
@ -1116,7 +1122,7 @@ uint16_t WS2812FX::mode_fire_flicker(void) {
|
||||
uint16_t WS2812FX::gradient_base(bool loading) {
|
||||
uint16_t counter = now * (SEGMENT.speed >> 3) + 1;
|
||||
SEGENV.step = counter * SEGLEN >> 16;
|
||||
if (SEGMENT.speed == 0) SEGENV.step = SEGMENT.start + (SEGLEN >> 1);
|
||||
if (SEGMENT.speed == 0) SEGENV.step = SEGLEN >> 1;
|
||||
if (SEGENV.call == 0) SEGENV.step = 0;
|
||||
float per,val; //0.0 = sec 1.0 = pri
|
||||
float brd = SEGMENT.intensity;
|
||||
@ -1126,7 +1132,7 @@ uint16_t WS2812FX::gradient_base(bool loading) {
|
||||
int p1 = pp-SEGLEN;
|
||||
int p2 = pp+SEGLEN;
|
||||
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++)
|
||||
for(uint16_t i = 0; i < SEGLEN; i++)
|
||||
{
|
||||
if (loading)
|
||||
{
|
||||
@ -1172,8 +1178,8 @@ uint16_t WS2812FX::police_base(uint32_t color1, uint32_t color2)
|
||||
if (idexR > topindex) idexB -= SEGLEN;
|
||||
if (idexB >= SEGLEN) idexB = 0; //otherwise overflow on odd number of LEDs
|
||||
|
||||
setPixelColor(SEGMENT.start + idexR, color1);
|
||||
setPixelColor(SEGMENT.start + idexB, color2);
|
||||
setPixelColor(idexR, color1);
|
||||
setPixelColor(idexB, color2);
|
||||
|
||||
return FRAMETIME;
|
||||
}
|
||||
@ -1228,7 +1234,7 @@ uint16_t WS2812FX::tricolor_chase(uint32_t color1, uint32_t color2) {
|
||||
if(index > width*2/3-1) color = color_from_palette(i, true, PALETTE_SOLID_WRAP, 1);
|
||||
else if(index > width/3-1) color = color2;
|
||||
|
||||
setPixelColor(SEGMENT.stop - i -1, color);
|
||||
setPixelColor(SEGLEN - i -1, color);
|
||||
}
|
||||
|
||||
return FRAMETIME;
|
||||
@ -1262,13 +1268,13 @@ uint16_t WS2812FX::mode_icu(void) {
|
||||
byte pindex = map(dest, 0, SEGLEN/2, 0, 255);
|
||||
uint32_t col = color_from_palette(pindex, false, false, 0);
|
||||
|
||||
setPixelColor(SEGMENT.start + dest, col);
|
||||
setPixelColor(SEGMENT.start + dest + SEGLEN/2, col);
|
||||
setPixelColor( dest, col);
|
||||
setPixelColor( dest + SEGLEN/2, col);
|
||||
|
||||
if(SEGENV.aux0 == dest) { // pause between eye movements
|
||||
if(random8(6) == 0) { // blink once in a while
|
||||
setPixelColor(SEGMENT.start + dest, SEGCOLOR(1));
|
||||
setPixelColor(SEGMENT.start + dest + SEGLEN/2, SEGCOLOR(1));
|
||||
setPixelColor( dest, SEGCOLOR(1));
|
||||
setPixelColor( dest + SEGLEN/2, SEGCOLOR(1));
|
||||
return 200;
|
||||
}
|
||||
SEGENV.aux0 = random16(SEGLEN/2);
|
||||
@ -1283,8 +1289,8 @@ uint16_t WS2812FX::mode_icu(void) {
|
||||
dest--;
|
||||
}
|
||||
|
||||
setPixelColor(SEGMENT.start + dest, col);
|
||||
setPixelColor(SEGMENT.start + dest + SEGLEN/2, col);
|
||||
setPixelColor(dest, col);
|
||||
setPixelColor(dest + SEGLEN/2, col);
|
||||
|
||||
return SPEED_FORMULA_L;
|
||||
}
|
||||
@ -1301,26 +1307,26 @@ uint16_t WS2812FX::mode_tricolor_wipe(void)
|
||||
uint16_t ledIndex = (prog * SEGLEN * 3) >> 16;
|
||||
uint16_t ledOffset = ledIndex;
|
||||
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++)
|
||||
for (uint16_t i = 0; i < SEGLEN; i++)
|
||||
{
|
||||
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 2));
|
||||
}
|
||||
|
||||
if(ledIndex < SEGLEN) { //wipe from 0 to 1
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++)
|
||||
for (uint16_t i = 0; i < SEGLEN; i++)
|
||||
{
|
||||
setPixelColor(i, (i - SEGMENT.start > ledOffset)? SEGCOLOR(0) : SEGCOLOR(1));
|
||||
setPixelColor(i, (i > ledOffset)? SEGCOLOR(0) : SEGCOLOR(1));
|
||||
}
|
||||
} else if (ledIndex < SEGLEN*2) { //wipe from 1 to 2
|
||||
ledOffset = ledIndex - SEGLEN;
|
||||
for (uint16_t i = SEGMENT.start +ledOffset +1; i < SEGMENT.stop; i++)
|
||||
for (uint16_t i = ledOffset +1; i < SEGLEN; i++)
|
||||
{
|
||||
setPixelColor(i, SEGCOLOR(1));
|
||||
}
|
||||
} else //wipe from 2 to 0
|
||||
{
|
||||
ledOffset = ledIndex - SEGLEN*2;
|
||||
for (uint16_t i = SEGMENT.start; i <= SEGMENT.start +ledOffset; i++)
|
||||
for (uint16_t i = 0; i <= ledOffset; i++)
|
||||
{
|
||||
setPixelColor(i, SEGCOLOR(0));
|
||||
}
|
||||
@ -1359,7 +1365,7 @@ uint16_t WS2812FX::mode_tricolor_fade(void)
|
||||
|
||||
byte stp = prog; // % 256
|
||||
uint32_t color = 0;
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
if (stage == 2) {
|
||||
color = color_blend(color_from_palette(i, true, PALETTE_SOLID_WRAP, 2), color2, stp);
|
||||
} else if (stage == 1) {
|
||||
@ -1370,10 +1376,7 @@ uint16_t WS2812FX::mode_tricolor_fade(void)
|
||||
setPixelColor(i, color);
|
||||
}
|
||||
|
||||
SEGENV.step += 4;
|
||||
if(SEGENV.step >= 768) SEGENV.step = 0;
|
||||
|
||||
return 5 + ((uint32_t)(255 - SEGMENT.speed) / 10);
|
||||
return FRAMETIME;
|
||||
}
|
||||
|
||||
|
||||
@ -1383,13 +1386,17 @@ uint16_t WS2812FX::mode_tricolor_fade(void)
|
||||
*/
|
||||
uint16_t WS2812FX::mode_multi_comet(void)
|
||||
{
|
||||
uint32_t cycleTime = 20 + (2 * (uint32_t)(255 - SEGMENT.speed));
|
||||
uint32_t it = now / cycleTime;
|
||||
if (SEGENV.step == it) return FRAMETIME;
|
||||
|
||||
fade_out(SEGMENT.intensity);
|
||||
|
||||
static uint16_t comets[] = {UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX};
|
||||
|
||||
for(uint8_t i=0; i < 8; i++) {
|
||||
if(comets[i] < SEGLEN) {
|
||||
uint16_t index = SEGMENT.start + comets[i];
|
||||
uint16_t index = comets[i];
|
||||
if (SEGCOLOR(2) != 0)
|
||||
{
|
||||
setPixelColor(index, i % 2 ? color_from_palette(index, true, PALETTE_SOLID_WRAP, 0) : SEGCOLOR(2));
|
||||
@ -1404,7 +1411,9 @@ uint16_t WS2812FX::mode_multi_comet(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
return SPEED_FORMULA_L;
|
||||
|
||||
SEGENV.step = it;
|
||||
return FRAMETIME;
|
||||
}
|
||||
|
||||
|
||||
@ -1427,15 +1436,15 @@ uint16_t WS2812FX::mode_random_chase(void)
|
||||
uint32_t it = now / cycleTime;
|
||||
if (SEGENV.step == it) return FRAMETIME;
|
||||
|
||||
for(uint16_t i=SEGMENT.stop -1; i>SEGMENT.start; i--) {
|
||||
for(uint16_t i = SEGLEN -1; i > 0; i--) {
|
||||
setPixelColor(i, getPixelColor(i-1));
|
||||
}
|
||||
uint32_t color = getPixelColor(SEGMENT.start);
|
||||
if (SEGLEN > 1) color = getPixelColor(SEGMENT.start + 1);
|
||||
uint32_t color = getPixelColor(0);
|
||||
if (SEGLEN > 1) color = getPixelColor( 1);
|
||||
uint8_t r = random8(6) != 0 ? (color >> 16 & 0xFF) : random8();
|
||||
uint8_t g = random8(6) != 0 ? (color >> 8 & 0xFF) : random8();
|
||||
uint8_t b = random8(6) != 0 ? (color & 0xFF) : random8();
|
||||
setPixelColor(SEGMENT.start, r, g, b);
|
||||
setPixelColor(0, r, g, b);
|
||||
|
||||
SEGENV.step = it;
|
||||
return FRAMETIME;
|
||||
@ -1495,7 +1504,7 @@ uint16_t WS2812FX::mode_oscillate(void)
|
||||
color = (color == BLACK) ? SEGMENT.colors[j] : color_blend(color, SEGMENT.colors[j], 128);
|
||||
}
|
||||
}
|
||||
setPixelColor(SEGMENT.start + i, color);
|
||||
setPixelColor(i, color);
|
||||
}
|
||||
|
||||
SEGENV.step = it;
|
||||
@ -1505,8 +1514,8 @@ uint16_t WS2812FX::mode_oscillate(void)
|
||||
|
||||
uint16_t WS2812FX::mode_lightning(void)
|
||||
{
|
||||
uint16_t ledstart = SEGMENT.start + random16(SEGLEN); // Determine starting location of flash
|
||||
uint16_t ledlen = random16(SEGMENT.stop -1 -ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1)
|
||||
uint16_t ledstart = random16(SEGLEN); // Determine starting location of flash
|
||||
uint16_t ledlen = random16(SEGLEN -1 -ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1)
|
||||
uint8_t bri = 255/random8(1, 3);
|
||||
|
||||
if (SEGENV.step == 0)
|
||||
@ -1565,7 +1574,7 @@ uint16_t WS2812FX::mode_pride_2015(void)
|
||||
uint16_t brightnesstheta16 = sPseudotime;
|
||||
CRGB fastled_col;
|
||||
|
||||
for( uint16_t i = SEGMENT.start ; i < SEGMENT.stop; i++) {
|
||||
for (uint16_t i = 0 ; i < SEGLEN; i++) {
|
||||
hue16 += hueinc16;
|
||||
uint8_t hue8 = hue16 >> 8;
|
||||
|
||||
@ -1594,7 +1603,7 @@ uint16_t WS2812FX::mode_juggle(void){
|
||||
CRGB fastled_col;
|
||||
byte dothue = 0;
|
||||
for ( byte i = 0; i < 8; i++) {
|
||||
uint16_t index = SEGMENT.start + beatsin88((128 + SEGMENT.speed)*(i + 7), 0, SEGLEN -1);
|
||||
uint16_t index = 0 + beatsin88((128 + SEGMENT.speed)*(i + 7), 0, SEGLEN -1);
|
||||
fastled_col = col_to_crgb(getPixelColor(index));
|
||||
fastled_col |= (SEGMENT.palette==0)?CHSV(dothue, 220, 255):ColorFromPalette(currentPalette, dothue, 255);
|
||||
setPixelColor(index, fastled_col.red, fastled_col.green, fastled_col.blue);
|
||||
@ -1620,7 +1629,7 @@ uint16_t WS2812FX::mode_palette()
|
||||
|
||||
if (noWrap) colorIndex = map(colorIndex, 0, 255, 0, 240); //cut off blend at palette "end"
|
||||
|
||||
setPixelColor(SEGMENT.start + i, color_from_palette(colorIndex, false, true, 255));
|
||||
setPixelColor(i, color_from_palette(colorIndex, false, true, 255));
|
||||
}
|
||||
return FRAMETIME;
|
||||
}
|
||||
@ -1687,7 +1696,7 @@ uint16_t WS2812FX::mode_fire_2012()
|
||||
// Step 4. Map from heat cells to LED colors
|
||||
for (uint16_t j = 0; j < SEGLEN; j++) {
|
||||
CRGB color = ColorFromPalette(currentPalette, min(heat[j],240), 255, LINEARBLEND);
|
||||
setPixelColor(SEGMENT.start + j, color.red, color.green, color.blue);
|
||||
setPixelColor(j, color.red, color.green, color.blue);
|
||||
}
|
||||
return FRAMETIME;
|
||||
}
|
||||
@ -1714,7 +1723,7 @@ uint16_t WS2812FX::mode_colorwaves()
|
||||
uint16_t brightnesstheta16 = sPseudotime;
|
||||
CRGB fastled_col;
|
||||
|
||||
for ( uint16_t i = SEGMENT.start ; i < SEGMENT.stop; i++) {
|
||||
for ( uint16_t i = 0 ; i < SEGLEN; i++) {
|
||||
hue16 += hueinc16;
|
||||
uint8_t hue8 = hue16 >> 8;
|
||||
uint16_t h16_128 = hue16 >> 7;
|
||||
@ -1749,7 +1758,7 @@ uint16_t WS2812FX::mode_bpm()
|
||||
CRGB fastled_col;
|
||||
uint32_t stp = (now / 20) & 0xFF;
|
||||
uint8_t beat = beatsin8(SEGMENT.speed, 64, 255);
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for (uint16_t i = 0; i < SEGLEN; i++) {
|
||||
fastled_col = ColorFromPalette(currentPalette, stp + (i * 2), beat - stp + (i * 10));
|
||||
setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
|
||||
}
|
||||
@ -1761,8 +1770,8 @@ uint16_t WS2812FX::mode_fillnoise8()
|
||||
{
|
||||
if (SEGENV.call == 0) SEGENV.step = random16(12345);
|
||||
CRGB fastled_col;
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
uint8_t index = inoise8(i * SEGLEN, SEGENV.step + i * SEGLEN) % 255;
|
||||
for (uint16_t i = 0; i < SEGLEN; i++) {
|
||||
uint8_t index = inoise8(i * SEGLEN, SEGENV.step + i * SEGLEN);
|
||||
fastled_col = ColorFromPalette(currentPalette, index, 255, LINEARBLEND);
|
||||
setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
|
||||
}
|
||||
@ -1777,7 +1786,7 @@ uint16_t WS2812FX::mode_noise16_1()
|
||||
CRGB fastled_col;
|
||||
SEGENV.step += (1 + SEGMENT.speed/16);
|
||||
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for (uint16_t i = 0; i < SEGLEN; i++) {
|
||||
|
||||
uint16_t shift_x = beatsin8(11); // the x position of the noise field swings @ 17 bpm
|
||||
uint16_t shift_y = SEGENV.step/42; // the y position becomes slowly incremented
|
||||
@ -1805,7 +1814,7 @@ uint16_t WS2812FX::mode_noise16_2()
|
||||
CRGB fastled_col;
|
||||
SEGENV.step += (1 + (SEGMENT.speed >> 1));
|
||||
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for (uint16_t i = 0; i < SEGLEN; i++) {
|
||||
|
||||
uint16_t shift_x = SEGENV.step >> 6; // x as a function of time
|
||||
uint16_t shift_y = SEGENV.step/42;
|
||||
@ -1830,7 +1839,7 @@ uint16_t WS2812FX::mode_noise16_3()
|
||||
CRGB fastled_col;
|
||||
SEGENV.step += (1 + SEGMENT.speed);
|
||||
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for (uint16_t i = 0; i < SEGLEN; i++) {
|
||||
|
||||
uint16_t shift_x = 4223; // no movement along x and y
|
||||
uint16_t shift_y = 1234;
|
||||
@ -1856,8 +1865,8 @@ uint16_t WS2812FX::mode_noise16_4()
|
||||
{
|
||||
CRGB fastled_col;
|
||||
uint32_t stp = (now * SEGMENT.speed) >> 7;
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
int16_t index = inoise16(uint32_t(i - SEGMENT.start) << 12, stp);
|
||||
for (uint16_t i = 0; i < SEGLEN; i++) {
|
||||
int16_t index = inoise16(uint32_t(i) << 12, stp);
|
||||
fastled_col = ColorFromPalette(currentPalette, index);
|
||||
setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
|
||||
}
|
||||
@ -1873,11 +1882,11 @@ uint16_t WS2812FX::mode_colortwinkle()
|
||||
|
||||
CRGB fastled_col, prev;
|
||||
fract8 fadeUpAmount = 8 + (SEGMENT.speed/4), fadeDownAmount = 5 + (SEGMENT.speed/7);
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for (uint16_t i = 0; i < SEGLEN; i++) {
|
||||
fastled_col = col_to_crgb(getPixelColor(i));
|
||||
prev = fastled_col;
|
||||
uint16_t index = (i - SEGMENT.start) >> 3;
|
||||
uint8_t bitNum = (i - SEGMENT.start) & 0x07;
|
||||
uint16_t index = i >> 3;
|
||||
uint8_t bitNum = i & 0x07;
|
||||
bool fadeUp = bitRead(SEGENV.data[index], bitNum);
|
||||
|
||||
if (fadeUp) {
|
||||
@ -1906,11 +1915,11 @@ uint16_t WS2812FX::mode_colortwinkle()
|
||||
if (random8() <= SEGMENT.intensity) {
|
||||
for (uint8_t times = 0; times < 5; times++) //attempt to spawn a new pixel 5 times
|
||||
{
|
||||
int i = SEGMENT.start + random16(SEGLEN);
|
||||
int i = random16(SEGLEN);
|
||||
if(getPixelColor(i) == 0) {
|
||||
fastled_col = ColorFromPalette(currentPalette, random8(), 64, NOBLEND);
|
||||
uint16_t index = (i - SEGMENT.start) >> 3;
|
||||
uint8_t bitNum = (i - SEGMENT.start) & 0x07;
|
||||
uint16_t index = i >> 3;
|
||||
uint8_t bitNum = i & 0x07;
|
||||
bitWrite(SEGENV.data[index], bitNum, true);
|
||||
setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
|
||||
break; //only spawn 1 new pixel per frame per 50 LEDs
|
||||
@ -1930,7 +1939,7 @@ uint16_t WS2812FX::mode_lake() {
|
||||
uint8_t wave3 = beatsin8(sp +2, 0,80);
|
||||
CRGB fastled_col;
|
||||
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++)
|
||||
for (uint16_t i = 0; i < SEGLEN; i++)
|
||||
{
|
||||
int index = cos8((i*15)+ wave1)/2 + cubicwave8((i*23)+ wave2)/2;
|
||||
uint8_t lum = (index > wave3) ? index - wave3 : 0;
|
||||
@ -1959,7 +1968,7 @@ uint16_t WS2812FX::mode_meteor() {
|
||||
{
|
||||
byte meteorTrailDecay = 128 + random8(127);
|
||||
trail[i] = scale8(trail[i], meteorTrailDecay);
|
||||
setPixelColor(SEGMENT.start + i, color_from_palette(trail[i], false, true, 255));
|
||||
setPixelColor(i, color_from_palette(trail[i], false, true, 255));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1971,7 +1980,7 @@ uint16_t WS2812FX::mode_meteor() {
|
||||
}
|
||||
|
||||
trail[index] = 240;
|
||||
setPixelColor(SEGMENT.start + index, color_from_palette(trail[index], false, true, 255));
|
||||
setPixelColor(index, color_from_palette(trail[index], false, true, 255));
|
||||
}
|
||||
|
||||
return FRAMETIME;
|
||||
@ -1997,7 +2006,7 @@ uint16_t WS2812FX::mode_meteor_smooth() {
|
||||
trail[i] += change;
|
||||
if (trail[i] > 245) trail[i] = 0;
|
||||
if (trail[i] > 240) trail[i] = 240;
|
||||
setPixelColor(SEGMENT.start + i, color_from_palette(trail[i], false, true, 255));
|
||||
setPixelColor(i, color_from_palette(trail[i], false, true, 255));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2007,7 +2016,7 @@ uint16_t WS2812FX::mode_meteor_smooth() {
|
||||
if(in + j >= SEGLEN) {
|
||||
index = (in + j - SEGLEN);
|
||||
}
|
||||
setPixelColor(SEGMENT.start + index, color_blend(getPixelColor(SEGMENT.start + index), color_from_palette(240, false, true, 255), 48));
|
||||
setPixelColor(index, color_blend(getPixelColor(index), color_from_palette(240, false, true, 255), 48));
|
||||
trail[index] = 240;
|
||||
}
|
||||
|
||||
@ -2034,10 +2043,10 @@ uint16_t WS2812FX::mode_railway()
|
||||
if (p0 < 255) pos = p0;
|
||||
}
|
||||
if (SEGENV.aux0) pos = 255 - pos;
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i += 2)
|
||||
for (uint16_t i = 0; i < SEGLEN; i += 2)
|
||||
{
|
||||
setPixelColor(i, color_from_palette(255 - pos, false, false, 255));
|
||||
if (i < SEGMENT.stop -1)
|
||||
if (i < SEGLEN -1)
|
||||
{
|
||||
setPixelColor(i + 1, color_from_palette(pos, false, false, 255));
|
||||
}
|
||||
@ -2088,12 +2097,12 @@ uint16_t WS2812FX::mode_ripple()
|
||||
for (int16_t v = left; v < left +4; v++)
|
||||
{
|
||||
uint8_t mag = scale8(cubicwave8((propF>>2)+(v-left)*64), amp);
|
||||
if (v < SEGMENT.stop && v >= SEGMENT.start)
|
||||
if (v < SEGLEN && v >= 0)
|
||||
{
|
||||
setPixelColor(v, color_blend(getPixelColor(v), col, mag));
|
||||
}
|
||||
int16_t w = left + propI*2 + 3 -(v-left);
|
||||
if (w < SEGMENT.stop && w >= SEGMENT.start)
|
||||
if (w < SEGLEN && w >= 0)
|
||||
{
|
||||
setPixelColor(w, color_blend(getPixelColor(w), col, mag));
|
||||
}
|
||||
@ -2105,7 +2114,7 @@ uint16_t WS2812FX::mode_ripple()
|
||||
if (random16(IBN + 10000) <= SEGMENT.intensity)
|
||||
{
|
||||
ripples[i].state = 1;
|
||||
ripples[i].pos = SEGMENT.start + random16(SEGLEN);
|
||||
ripples[i].pos = random16(SEGLEN);
|
||||
ripples[i].color = random8(); //color
|
||||
}
|
||||
}
|
||||
@ -2209,7 +2218,7 @@ uint16_t WS2812FX::twinklefox_base(bool cat)
|
||||
|
||||
uint8_t backgroundBrightness = bg.getAverageLight();
|
||||
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for (uint16_t i = 0; i < SEGLEN; i++) {
|
||||
|
||||
PRNG16 = (uint16_t)(PRNG16 * 2053) + 1384; // next 'random' number
|
||||
uint16_t myclockoffset16= PRNG16; // use that number as clock offset
|
||||
@ -2270,7 +2279,7 @@ uint16_t WS2812FX::mode_halloween_eyes()
|
||||
if (stateTime == 0) stateTime = 2000;
|
||||
|
||||
if (state == 0) { //spawn eyes
|
||||
SEGENV.aux0 = random16(SEGMENT.start, SEGMENT.stop - eyeLength); //start pos
|
||||
SEGENV.aux0 = random16(0, SEGLEN - eyeLength); //start pos
|
||||
SEGENV.aux1 = random8(); //color
|
||||
state = 1;
|
||||
}
|
||||
@ -2320,7 +2329,7 @@ uint16_t WS2812FX::mode_static_pattern()
|
||||
bool drawingLit = true;
|
||||
uint16_t cnt = 0;
|
||||
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for (uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(i, (drawingLit) ? color_from_palette(i, true, PALETTE_SOLID_WRAP, 0) : SEGCOLOR(1));
|
||||
cnt++;
|
||||
if (cnt >= ((drawingLit) ? lit : unlit)) {
|
||||
@ -2338,7 +2347,7 @@ uint16_t WS2812FX::mode_tri_static_pattern()
|
||||
uint8_t currSeg = 0;
|
||||
uint16_t currSegCount = 0;
|
||||
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for (uint16_t i = 0; i < SEGLEN; i++) {
|
||||
if ( currSeg % 3 == 0 ) {
|
||||
setPixelColor(i, SEGCOLOR(0));
|
||||
} else if( currSeg % 3 == 1) {
|
||||
@ -2373,7 +2382,7 @@ uint16_t WS2812FX::spots_base(uint16_t threshold)
|
||||
{
|
||||
uint16_t wave = triwave16((i * 0xFFFF) / zoneLen);
|
||||
if (wave > threshold) {
|
||||
uint16_t index = SEGMENT.start + pos + i;
|
||||
uint16_t index = 0 + pos + i;
|
||||
uint8_t s = (wave - threshold)*255 / (0xFFFF - threshold);
|
||||
setPixelColor(index, color_blend(color_from_palette(index, true, PALETTE_SOLID_WRAP, 0), SEGCOLOR(1), 255-s));
|
||||
}
|
||||
@ -2460,7 +2469,7 @@ uint16_t WS2812FX::mode_bouncing_balls(void) {
|
||||
}
|
||||
|
||||
uint16_t pos = round(balls[i].height * (SEGLEN - 1));
|
||||
setPixelColor(SEGMENT.start + pos, color);
|
||||
setPixelColor(pos, color);
|
||||
}
|
||||
|
||||
return FRAMETIME;
|
||||
@ -2478,7 +2487,7 @@ uint16_t WS2812FX::sinelon_base(bool dual, bool rainbow=false) {
|
||||
if (rainbow) {
|
||||
color1 = color_wheel((pos & 0x07) * 32);
|
||||
}
|
||||
setPixelColor(SEGMENT.start + pos, color1);
|
||||
setPixelColor(pos, color1);
|
||||
|
||||
if (dual) {
|
||||
uint32_t color2 = SEGCOLOR(2);
|
||||
@ -2486,7 +2495,7 @@ uint16_t WS2812FX::sinelon_base(bool dual, bool rainbow=false) {
|
||||
if (!color2) color2 = color_from_palette(pos, true, false, 0);
|
||||
if (rainbow) color2 = color1; //rainbow
|
||||
|
||||
setPixelColor(SEGMENT.start + SEGLEN-1-pos, color2);
|
||||
setPixelColor(SEGLEN-1-pos, color2);
|
||||
}
|
||||
|
||||
return FRAMETIME;
|
||||
@ -2512,7 +2521,7 @@ uint16_t WS2812FX::mode_glitter()
|
||||
|
||||
if (SEGMENT.intensity > random8())
|
||||
{
|
||||
setPixelColor(SEGMENT.start + random16(SEGLEN), ULTRAWHITE);
|
||||
setPixelColor(random16(SEGLEN), ULTRAWHITE);
|
||||
}
|
||||
|
||||
return FRAMETIME;
|
||||
@ -2559,8 +2568,8 @@ uint16_t WS2812FX::mode_popcorn(void) {
|
||||
uint32_t col = color_wheel(popcorn[i].colIndex);
|
||||
if (!SEGMENT.palette && popcorn[i].colIndex < NUM_COLORS) col = SEGCOLOR(popcorn[i].colIndex);
|
||||
|
||||
uint16_t ledIndex = SEGMENT.start + popcorn[i].pos;
|
||||
if(ledIndex >= SEGMENT.start && ledIndex < SEGMENT.stop) setPixelColor(ledIndex, col);
|
||||
uint16_t ledIndex = popcorn[i].pos;
|
||||
if (ledIndex < SEGLEN) setPixelColor(ledIndex, col);
|
||||
} else { // if kernel is inactive, randomly pop it
|
||||
if (random8() < 2) { // POP!!!
|
||||
popcorn[i].pos = 0.01f;
|
||||
@ -2607,7 +2616,7 @@ uint16_t WS2812FX::mode_candle()
|
||||
}
|
||||
SEGENV.aux0 = s;
|
||||
|
||||
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for (uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(i, color_blend(color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), SEGCOLOR(1), 255-s));
|
||||
}
|
||||
|
||||
@ -2747,7 +2756,7 @@ uint16_t WS2812FX::mode_starburst(void) {
|
||||
if (start == end) end++;
|
||||
if (end > SEGLEN) end = SEGLEN;
|
||||
for (int p = start; p < end; p++) {
|
||||
setPixelColor(SEGMENT.start+p, c.r, c.g, c.b);
|
||||
setPixelColor(p, c.r, c.g, c.b);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2795,7 +2804,7 @@ uint16_t WS2812FX::mode_exploding_fireworks(void)
|
||||
// launch
|
||||
if (flare->vel > 12 * gravity) {
|
||||
// flare
|
||||
setPixelColor(SEGMENT.start + int(flare->pos),flare->col,flare->col,flare->col);
|
||||
setPixelColor(int(flare->pos),flare->col,flare->col,flare->col);
|
||||
|
||||
flare->pos += flare->vel;
|
||||
flare->pos = constrain(flare->pos, 0, SEGLEN-1);
|
||||
@ -2849,7 +2858,7 @@ uint16_t WS2812FX::mode_exploding_fireworks(void)
|
||||
c.g = qsub8(c.g, cooling);
|
||||
c.b = qsub8(c.b, cooling * 2);
|
||||
}
|
||||
setPixelColor(SEGMENT.start + int(sparks[i].pos), c.red, c.green, c.blue);
|
||||
setPixelColor(int(sparks[i].pos), c.red, c.green, c.blue);
|
||||
}
|
||||
}
|
||||
dying_gravity *= .99; // as sparks burn out they fall slower
|
||||
|
35
wled00/FX.h
35
wled00/FX.h
@ -59,7 +59,7 @@
|
||||
#define SEGMENT _segments[_segment_index]
|
||||
#define SEGCOLOR(x) gamma32(_segments[_segment_index].colors[x])
|
||||
#define SEGENV _segment_runtimes[_segment_index]
|
||||
#define SEGLEN SEGMENT.length()
|
||||
#define SEGLEN _virtualSegmentLength
|
||||
#define SEGACT SEGMENT.stop
|
||||
#define SPEED_FORMULA_L 5 + (50*(255 - SEGMENT.speed))/SEGLEN
|
||||
#define RESET_RUNTIME memset(_segment_runtimes, 0, sizeof(_segment_runtimes))
|
||||
@ -199,16 +199,15 @@ class WS2812FX {
|
||||
|
||||
// segment parameters
|
||||
public:
|
||||
typedef struct Segment { // 25 bytes
|
||||
typedef struct Segment { // 24 bytes
|
||||
uint16_t start;
|
||||
uint16_t stop; //segment invalid if stop == 0
|
||||
uint16_t rawLength;
|
||||
uint8_t speed;
|
||||
uint8_t intensity;
|
||||
uint8_t palette;
|
||||
uint8_t mode;
|
||||
uint8_t options; //bit pattern: msb first: transitional tbd tbd tbd tbd paused reverse selected
|
||||
uint8_t group, spacing;
|
||||
uint8_t grouping, spacing;
|
||||
uint8_t opacity;
|
||||
uint32_t colors[NUM_COLORS];
|
||||
void setOption(uint8_t n, bool val)
|
||||
@ -236,8 +235,14 @@ class WS2812FX {
|
||||
{
|
||||
return stop - start;
|
||||
}
|
||||
uint16_t ledGroup() {
|
||||
return group + spacing;
|
||||
uint16_t groupLength()
|
||||
{
|
||||
return grouping + spacing;
|
||||
}
|
||||
uint16_t virtualLength()
|
||||
{
|
||||
uint16_t groupLen = groupLength();
|
||||
return (length() + groupLen -1) / groupLen;
|
||||
}
|
||||
} segment;
|
||||
|
||||
@ -381,7 +386,7 @@ class WS2812FX {
|
||||
}
|
||||
|
||||
void
|
||||
init(bool supportWhite, uint16_t countPixels, uint8_t group, uint8_t spacing, bool skipFirst),
|
||||
init(bool supportWhite, uint16_t countPixels, bool skipFirst),
|
||||
service(void),
|
||||
blur(uint8_t),
|
||||
fade_out(uint8_t r),
|
||||
@ -396,7 +401,7 @@ class WS2812FX {
|
||||
setShowCallback(show_callback cb),
|
||||
setTransitionMode(bool t),
|
||||
trigger(void),
|
||||
setSegment(uint8_t n, uint16_t start, uint16_t length, uint8_t group, uint8_t spacing),
|
||||
setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t grouping = 0, uint8_t spacing = 0),
|
||||
resetSegments(),
|
||||
setPixelColor(uint16_t n, uint32_t c),
|
||||
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0),
|
||||
@ -416,8 +421,6 @@ class WS2812FX {
|
||||
paletteBlend = 0,
|
||||
colorOrder = 0,
|
||||
milliampsPerLed = 55,
|
||||
_spacing = 0,
|
||||
_group = 1,
|
||||
getBrightness(void),
|
||||
getMode(void),
|
||||
getSpeed(void),
|
||||
@ -432,8 +435,7 @@ class WS2812FX {
|
||||
uint16_t
|
||||
ablMilliampsMax,
|
||||
currentMilliamps,
|
||||
triwave16(uint16_t),
|
||||
getUsableCount();
|
||||
triwave16(uint16_t);
|
||||
|
||||
uint32_t
|
||||
timebase,
|
||||
@ -564,7 +566,7 @@ class WS2812FX {
|
||||
CRGBPalette16 targetPalette;
|
||||
|
||||
uint32_t now;
|
||||
uint16_t _length;
|
||||
uint16_t _length, _lengthRaw, _virtualSegmentLength;
|
||||
uint16_t _rand16seed;
|
||||
uint8_t _brightness;
|
||||
static uint16_t _usedSegmentData;
|
||||
@ -610,11 +612,10 @@ class WS2812FX {
|
||||
|
||||
uint8_t _segment_index = 0;
|
||||
uint8_t _segment_index_palette_last = 99;
|
||||
segment _segments[MAX_NUM_SEGMENTS] = { // SRAM footprint: 25 bytes per element
|
||||
// start, stop, length, speed, intensity, palette, mode, options, group, spacing, opacity (unused), color[]
|
||||
{ 0, 7, 7, DEFAULT_SPEED, 128, 0, DEFAULT_MODE, NO_OPTIONS, 1, 0, 255, {DEFAULT_COLOR}}
|
||||
segment _segments[MAX_NUM_SEGMENTS] = { // SRAM footprint: 24 bytes per element
|
||||
// start, stop, speed, intensity, palette, mode, options, grouping, spacing, opacity (unused), color[]
|
||||
{ 0, 7, DEFAULT_SPEED, 128, 0, DEFAULT_MODE, NO_OPTIONS, 1, 0, 255, {DEFAULT_COLOR}}
|
||||
};
|
||||
|
||||
segment_runtime _segment_runtimes[MAX_NUM_SEGMENTS]; // SRAM footprint: 28 bytes per element
|
||||
friend class Segment_runtime;
|
||||
|
||||
|
@ -30,35 +30,27 @@
|
||||
#define LED_SKIP_AMOUNT 1
|
||||
#define MIN_SHOW_DELAY 15
|
||||
|
||||
void WS2812FX::init(bool supportWhite, uint16_t countPixels, uint8_t group, uint8_t spacing, bool skipFirst)
|
||||
void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst)
|
||||
{
|
||||
if (supportWhite == _rgbwMode && countPixels == _length && disableNLeds == _disableNLeds) return;
|
||||
if (supportWhite == _rgbwMode && countPixels == _length) return;
|
||||
RESET_RUNTIME;
|
||||
_rgbwMode = supportWhite;
|
||||
_skipFirstMode = skipFirst;
|
||||
_length = countPixels;
|
||||
_group = group;
|
||||
_spacing = spacing;
|
||||
|
||||
uint8_t ty = 1;
|
||||
if (supportWhite) ty = 2;
|
||||
uint16_t lengthRaw = _length + (_skipFirstMode ? LED_SKIP_AMOUNT : 0);
|
||||
|
||||
bus->Begin((NeoPixelType)ty, lengthRaw);
|
||||
|
||||
_segments[0].start = 0;
|
||||
|
||||
_segments[0].group = _group;
|
||||
_segments[0].spacing = _spacing;
|
||||
_segments[0].stop = getUsableCount();
|
||||
_segments[0].rawLength = _length;
|
||||
|
||||
setBrightness(_brightness);
|
||||
_lengthRaw = _length;
|
||||
if (_skipFirstMode) {
|
||||
_lengthRaw += LED_SKIP_AMOUNT;
|
||||
}
|
||||
|
||||
uint16_t WS2812FX::getUsableCount() {
|
||||
uint16_t ledGroup = _group + _spacing;
|
||||
return (_length + ledGroup -1) / ledGroup;
|
||||
bus->Begin((NeoPixelType)ty, _lengthRaw);
|
||||
|
||||
_segments[0].start = 0;
|
||||
_segments[0].stop = _length;
|
||||
|
||||
setBrightness(_brightness);
|
||||
}
|
||||
|
||||
void WS2812FX::service() {
|
||||
@ -73,6 +65,7 @@ void WS2812FX::service() {
|
||||
{
|
||||
if(nowUp > SEGENV.next_time || _triggered || (doShow && SEGMENT.mode == 0)) //last is temporary
|
||||
{
|
||||
_virtualSegmentLength = SEGMENT.virtualLength();
|
||||
doShow = true;
|
||||
handle_palette();
|
||||
uint16_t delay = (this->*_mode[SEGMENT.mode])();
|
||||
@ -81,6 +74,7 @@ void WS2812FX::service() {
|
||||
}
|
||||
}
|
||||
}
|
||||
_virtualSegmentLength = 0;
|
||||
if(doShow) {
|
||||
yield();
|
||||
show();
|
||||
@ -97,14 +91,13 @@ void WS2812FX::setPixelColor(uint16_t n, uint32_t c) {
|
||||
}
|
||||
|
||||
uint16_t WS2812FX::realPixelIndex(uint16_t i) {
|
||||
int16_t iGroup = (i - SEGMENT.start) * SEGMENT.ledGroup();
|
||||
int16_t iGroup = i * SEGMENT.groupLength();
|
||||
|
||||
/* reverse just an individual segment */
|
||||
int16_t realIndex;
|
||||
if IS_REVERSE
|
||||
realIndex = SEGMENT.rawLength + SEGMENT.start - iGroup -1;
|
||||
else
|
||||
realIndex = SEGMENT.start + iGroup;
|
||||
int16_t realIndex = iGroup;
|
||||
if (IS_REVERSE) realIndex = SEGMENT.length() -iGroup -1;
|
||||
|
||||
realIndex += SEGMENT.start;
|
||||
/* Reverse the whole string */
|
||||
if (reverseMode) realIndex = _length - 1 - realIndex;
|
||||
|
||||
@ -113,32 +106,42 @@ uint16_t WS2812FX::realPixelIndex(uint16_t i) {
|
||||
|
||||
void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w)
|
||||
{
|
||||
|
||||
RgbwColor color;
|
||||
color.W = w;
|
||||
|
||||
switch (colorOrder) //0 = Grb, default
|
||||
RgbwColor col;
|
||||
switch (colorOrder)
|
||||
{
|
||||
case 0: color.G = g; color.R = r; color.B = b; break; // 0 = GRB
|
||||
case 1: color.G = r; color.R = g; color.B = b; break; // 1 = RGB, common for WS2811
|
||||
case 2: color.G = b; color.R = r; color.B = g; break; // 2 = BRG
|
||||
case 3: color.G = r; color.R = b; color.B = g; break; // 3 = RBG
|
||||
case 0: col.G = g; col.R = r; col.B = b; break; //0 = GRB, default
|
||||
case 1: col.G = r; col.R = g; col.B = b; break; //1 = RGB, common for WS2811
|
||||
case 2: col.G = b; col.R = r; col.B = g; break; //2 = BRG
|
||||
case 3: col.G = r; col.R = b; col.B = g; break; //3 = RBG
|
||||
case 4: col.G = b; col.R = g; col.B = r; break; //4 = BGR
|
||||
default: col.G = g; col.R = b; col.B = r; break; //5 = GBR
|
||||
}
|
||||
col.W = w;
|
||||
|
||||
if (!_cronixieMode)
|
||||
{
|
||||
uint16_t skip = _skipFirstMode ? LED_SKIP_AMOUNT : 0;
|
||||
if (SEGLEN) {//from segment
|
||||
/* Set all the pixels in the group, ensuring _skipFirstMode is honored */
|
||||
bool reversed = reverseMode ^ IS_REVERSE;
|
||||
uint16_t realIndex = realPixelIndex(i);
|
||||
uint16_t skip = _skipFirstMode ? LED_SKIP_AMOUNT : 0;
|
||||
for (uint16_t l = 0; l < SEGMENT.ledGroup(); l++) {
|
||||
int16_t indexSet = realIndex + (reversed ? -l : l);
|
||||
if (indexSet >= SEGMENT.start && (indexSet < SEGMENT.start + SEGMENT.rawLength))
|
||||
bus->SetPixelColor(indexSet + skip, l < SEGMENT.group ? color : RgbwColor(0, 0, 0, 0));
|
||||
for (uint16_t l = 0; indexSet == 0 && l < skip; l++) {// Clear the skipped pixels
|
||||
bus->SetPixelColor(l, RgbwColor(0, 0, 0, 0));
|
||||
for (uint16_t j = 0; j < SEGMENT.grouping; j++) {
|
||||
int16_t indexSet = realIndex + (reversed ? -j : j);
|
||||
if (indexSet >= SEGMENT.start && indexSet < SEGMENT.stop) bus->SetPixelColor(indexSet + skip, col);
|
||||
}
|
||||
} else { //live data, etc.
|
||||
if (reverseMode) i = _length - 1 - i;
|
||||
bus->SetPixelColor(i + skip, col);
|
||||
}
|
||||
if (skip && i == 0) {
|
||||
for (uint16_t j = 0; j < skip; j++) {
|
||||
bus->SetPixelColor(j, RgbwColor(0, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
//CRONIXIE
|
||||
if(i>6)return;
|
||||
byte o = 10*i;
|
||||
if (_cronixieBacklightEnabled && _cronixieDigits[i] <11)
|
||||
@ -161,17 +164,16 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w)
|
||||
if (_skipFirstMode) o += LED_SKIP_AMOUNT;
|
||||
switch(_cronixieDigits[i])
|
||||
{
|
||||
case 0: bus->SetPixelColor(o+5, color); break;
|
||||
case 1: bus->SetPixelColor(o+0, color); break;
|
||||
case 2: bus->SetPixelColor(o+6, color); break;
|
||||
case 3: bus->SetPixelColor(o+1, color); break;
|
||||
case 4: bus->SetPixelColor(o+7, color); break;
|
||||
case 5: bus->SetPixelColor(o+2, color); break;
|
||||
case 6: bus->SetPixelColor(o+8, color); break;
|
||||
case 7: bus->SetPixelColor(o+3, color); break;
|
||||
case 8: bus->SetPixelColor(o+9, color); break;
|
||||
case 9: bus->SetPixelColor(o+4, color); break;
|
||||
}
|
||||
case 0: bus->SetPixelColor(o+5, col); break;
|
||||
case 1: bus->SetPixelColor(o+0, col); break;
|
||||
case 2: bus->SetPixelColor(o+6, col); break;
|
||||
case 3: bus->SetPixelColor(o+1, col); break;
|
||||
case 4: bus->SetPixelColor(o+7, col); break;
|
||||
case 5: bus->SetPixelColor(o+2, col); break;
|
||||
case 6: bus->SetPixelColor(o+8, col); break;
|
||||
case 7: bus->SetPixelColor(o+3, col); break;
|
||||
case 8: bus->SetPixelColor(o+9, col); break;
|
||||
case 9: bus->SetPixelColor(o+4, col); break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -387,6 +389,7 @@ uint32_t WS2812FX::getColor(void) {
|
||||
uint32_t WS2812FX::getPixelColor(uint16_t i)
|
||||
{
|
||||
i = realPixelIndex(i) + (_skipFirstMode ? LED_SKIP_AMOUNT : 0);
|
||||
|
||||
if (_cronixieMode)
|
||||
{
|
||||
if(i>6)return 0;
|
||||
@ -406,18 +409,20 @@ uint32_t WS2812FX::getPixelColor(uint16_t i)
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
uint16_t skip = _skipFirstMode ? LED_SKIP_AMOUNT : 0;
|
||||
if (i >= (_length + skip)) return 0;
|
||||
RgbwColor lColor = bus->GetPixelColorRgbw(i);
|
||||
byte r = lColor.R, g = lColor.G, b = lColor.B;
|
||||
if (i >= _lengthRaw) return 0;
|
||||
|
||||
RgbwColor col = bus->GetPixelColorRgbw(i);
|
||||
switch (colorOrder)
|
||||
{
|
||||
case 0: break; //0 = Grb
|
||||
case 1: r = lColor.G; g = lColor.R; break; //1 = Rgb, common for WS2811
|
||||
case 2: g = lColor.B; b = lColor.G; break; //2 = Brg
|
||||
case 3: r = lColor.B; g = lColor.R; b = lColor.G; //3 = Rbg
|
||||
// W G R B
|
||||
case 0: return ((col.W << 24) | (col.G << 8) | (col.R << 16) | (col.B)); //0 = GRB, default
|
||||
case 1: return ((col.W << 24) | (col.R << 8) | (col.G << 16) | (col.B)); //1 = RGB, common for WS2811
|
||||
case 2: return ((col.W << 24) | (col.B << 8) | (col.R << 16) | (col.G)); //2 = BRG
|
||||
case 3: return ((col.W << 24) | (col.R << 8) | (col.B << 16) | (col.G)); //3 = RBG
|
||||
case 4: return ((col.W << 24) | (col.B << 8) | (col.G << 16) | (col.R)); //4 = BGR
|
||||
case 5: return ((col.W << 24) | (col.G << 8) | (col.B << 16) | (col.R)); //5 = GBR
|
||||
}
|
||||
return ( (lColor.W << 24) | (r << 16) | (g << 8) | (b) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
WS2812FX::Segment& WS2812FX::getSegment(uint8_t id) {
|
||||
@ -437,27 +442,27 @@ uint32_t WS2812FX::getLastShow(void) {
|
||||
return _lastShow;
|
||||
}
|
||||
|
||||
void WS2812FX::setSegment(uint8_t n, uint16_t start, uint16_t length, uint8_t group, uint8_t spacing) {
|
||||
void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping, uint8_t spacing) {
|
||||
if (n >= MAX_NUM_SEGMENTS) return;
|
||||
Segment& seg = _segments[n];
|
||||
|
||||
if (seg.start == start && seg.rawLength == length && seg.group == group && seg.spacing == spacing) return;
|
||||
//return if neither bounds nor grouping have changed
|
||||
if (seg.start == i1 && seg.stop == i2 && (!grouping || (seg.grouping == grouping && seg.spacing == spacing))) return;
|
||||
|
||||
_segment_index = n; fill(0); //turn old segment range off
|
||||
|
||||
seg.rawLength = min(_length - start, length);
|
||||
if (seg.stop) setRange(seg.start, seg.stop -1, 0); //turn old segment range off
|
||||
if (i2 <= i1) //disable segment
|
||||
{
|
||||
seg.stop = 0; return;
|
||||
}
|
||||
if (i1 < _length) seg.start = i1;
|
||||
seg.stop = i2;
|
||||
if (i2 > _length) seg.stop = _length;
|
||||
if (grouping) {
|
||||
seg.grouping = grouping;
|
||||
seg.spacing = spacing;
|
||||
seg.group = group;
|
||||
seg.start = start;
|
||||
uint16_t ledGroup = seg.ledGroup();
|
||||
seg.stop = (seg.rawLength - seg.start + ledGroup -1) / ledGroup + seg.start;
|
||||
if (seg.start >= seg.stop) {
|
||||
seg.stop = 0;
|
||||
}
|
||||
else {
|
||||
_segment_runtimes[n].reset();
|
||||
}
|
||||
}
|
||||
|
||||
void WS2812FX::resetSegments() {
|
||||
memset(_segments, 0, sizeof(_segments));
|
||||
@ -467,16 +472,13 @@ void WS2812FX::resetSegments() {
|
||||
_segments[0].colors[0] = DEFAULT_COLOR;
|
||||
_segments[0].start = 0;
|
||||
_segments[0].speed = DEFAULT_SPEED;
|
||||
_segments[0].stop = getUsableCount();
|
||||
_segments[0].rawLength = _length;
|
||||
_segments[0].stop = _length;
|
||||
_segments[0].grouping = 1;
|
||||
_segments[0].setOption(0, 1); //select
|
||||
|
||||
_segments[0].group = _group;
|
||||
_segments[0].spacing = _spacing;
|
||||
|
||||
for (uint16_t i = 1; i < MAX_NUM_SEGMENTS; i++)
|
||||
{
|
||||
_segments[i].colors[0] = color_wheel(i*51);
|
||||
_segments[i].grouping = 1;
|
||||
_segment_runtimes[i].reset();
|
||||
}
|
||||
_segment_runtimes[0].reset();
|
||||
@ -536,7 +538,7 @@ uint32_t WS2812FX::color_blend(uint32_t color1, uint32_t color2, uint8_t blend)
|
||||
* Fills segment with color
|
||||
*/
|
||||
void WS2812FX::fill(uint32_t c) {
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
setPixelColor(i, c);
|
||||
}
|
||||
}
|
||||
@ -554,7 +556,7 @@ void WS2812FX::fade_out(uint8_t rate) {
|
||||
int g2 = (color >> 8) & 0xff;
|
||||
int b2 = color & 0xff;
|
||||
|
||||
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||
for(uint16_t i = 0; i < SEGLEN; i++) {
|
||||
color = getPixelColor(i);
|
||||
int w1 = (color >> 24) & 0xff;
|
||||
int r1 = (color >> 16) & 0xff;
|
||||
@ -584,14 +586,14 @@ void WS2812FX::blur(uint8_t blur_amount)
|
||||
uint8_t keep = 255 - blur_amount;
|
||||
uint8_t seep = blur_amount >> 1;
|
||||
CRGB carryover = CRGB::Black;
|
||||
for(uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++)
|
||||
for(uint16_t i = 0; i < SEGLEN; i++)
|
||||
{
|
||||
CRGB cur = col_to_crgb(getPixelColor(i));
|
||||
CRGB part = cur;
|
||||
part.nscale8(seep);
|
||||
cur.nscale8(keep);
|
||||
cur += carryover;
|
||||
if(i > SEGMENT.start) {
|
||||
if(i > 0) {
|
||||
uint32_t c = getPixelColor(i-1);
|
||||
uint8_t r = (c >> 16 & 0xFF);
|
||||
uint8_t g = (c >> 8 & 0xFF);
|
||||
@ -756,7 +758,7 @@ uint32_t WS2812FX::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8
|
||||
{
|
||||
if (SEGMENT.palette == 0 && mcol < 3) return SEGCOLOR(mcol); //WS2812FX default
|
||||
uint8_t paletteIndex = i;
|
||||
if (mapping) paletteIndex = map(i,SEGMENT.start,SEGMENT.stop-1,0,255);
|
||||
if (mapping) paletteIndex = (i*255)/(SEGLEN -1);
|
||||
if (!wrap) paletteIndex = scale8(paletteIndex, 240); //cut off blend at palette "end"
|
||||
CRGB fastled_col;
|
||||
fastled_col = ColorFromPalette( currentPalette, paletteIndex, pbri, (paletteBlend == 3)? NOBLEND:LINEARBLEND);
|
||||
|
@ -8,12 +8,16 @@ void deserializeSegment(JsonObject elem, byte it)
|
||||
if (id < strip.getMaxSegments())
|
||||
{
|
||||
WS2812FX::Segment& seg = strip.getSegment(id);
|
||||
uint16_t start = elem.containsKey("start") ? elem["start"] : seg.start;
|
||||
uint16_t len = elem.containsKey("len") ? elem["len"] : seg.rawLength;
|
||||
uint8_t group = max(1, elem["grp"] | seg.group);
|
||||
uint8_t spacing = elem.containsKey("spc") ? elem["spc"] : seg.spacing;
|
||||
uint16_t start = elem["start"] | seg.start;
|
||||
int stop = elem["stop"] | -1;
|
||||
|
||||
strip.setSegment(id, start, len, group, spacing);
|
||||
if (stop < 0) {
|
||||
uint16_t len = elem["len"];
|
||||
stop = (len > 0) ? start + len : seg.stop;
|
||||
}
|
||||
uint16_t grp = elem["grp"] | seg.grouping;
|
||||
uint16_t spc = elem["spc"] | seg.spacing;
|
||||
strip.setSegment(id, start, stop, grp, spc);
|
||||
|
||||
JsonArray colarr = elem["col"];
|
||||
if (!colarr.isNull())
|
||||
@ -163,7 +167,9 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id)
|
||||
root["id"] = id;
|
||||
root["start"] = seg.start;
|
||||
root["stop"] = seg.stop;
|
||||
root["len"] = seg.rawLength;
|
||||
root["len"] = seg.stop - seg.start;
|
||||
root["grp"] = seg.grouping;
|
||||
root["spc"] = seg.spacing;
|
||||
|
||||
JsonArray colarr = root.createNestedArray("col");
|
||||
|
||||
@ -182,8 +188,6 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id)
|
||||
root["ix"] = seg.intensity;
|
||||
root["pal"] = seg.palette;
|
||||
root["sel"] = seg.isSelected();
|
||||
root["grp"] = seg.group;
|
||||
root["spc"] = seg.spacing;
|
||||
root["rev"] = seg.getOption(1);
|
||||
}
|
||||
|
||||
@ -257,7 +261,9 @@ void serializeInfo(JsonObject root)
|
||||
|
||||
JsonObject wifi_info = root.createNestedObject("wifi");
|
||||
wifi_info["bssid"] = WiFi.BSSIDstr();
|
||||
wifi_info["signal"] = getSignalQuality(WiFi.RSSI());
|
||||
int qrssi = WiFi.RSSI();
|
||||
wifi_info["rssi"] = qrssi;
|
||||
wifi_info["signal"] = getSignalQuality(qrssi);
|
||||
wifi_info["channel"] = WiFi.channel();
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
@ -357,7 +363,7 @@ void serveJson(AsyncWebServerRequest* request)
|
||||
|
||||
void serveLiveLeds(AsyncWebServerRequest* request)
|
||||
{
|
||||
byte used = strip.getUsableCount();
|
||||
byte used = ledCount;
|
||||
byte n = (used -1) /MAX_LIVE_LEDS +1; //only serve every n'th LED if count over MAX_LIVE_LEDS
|
||||
char buffer[2000] = "{\"leds\":[";
|
||||
olen = 9;
|
||||
|
Loading…
x
Reference in New Issue
Block a user