Fixed Chase modes

This commit is contained in:
cschwinne 2020-02-29 18:24:51 +01:00
parent d0d56c4416
commit 14a5ab6740
2 changed files with 71 additions and 66 deletions

View File

@ -379,7 +379,7 @@ uint16_t WS2812FX::mode_rainbow_cycle(void) {
/* /*
* theater chase function * theater chase function
*/ */
uint16_t WS2812FX::theater_chase(uint32_t color1, uint32_t color2, bool dopalette) { uint16_t WS2812FX::theater_chase(uint32_t color1, uint32_t color2, bool do_palette) {
byte gap = 2 + ((255 - SEGMENT.intensity) >> 5); byte gap = 2 + ((255 - SEGMENT.intensity) >> 5);
uint32_t cycleTime = 50 + (255 - SEGMENT.speed)*2; uint32_t cycleTime = 50 + (255 - SEGMENT.speed)*2;
uint32_t it = now / cycleTime; uint32_t it = now / cycleTime;
@ -391,7 +391,7 @@ uint16_t WS2812FX::theater_chase(uint32_t color1, uint32_t color2, bool dopalett
for(uint16_t i = 0; i < SEGLEN; i++) { for(uint16_t i = 0; i < SEGLEN; i++) {
if((i % gap) == SEGENV.aux0) { if((i % gap) == SEGENV.aux0) {
if (dopalette) if (do_palette)
{ {
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
} else { } else {
@ -690,58 +690,68 @@ uint16_t WS2812FX::mode_android(void) {
* color1 = background color * color1 = background color
* color2 and color3 = colors of two adjacent leds * color2 and color3 = colors of two adjacent leds
*/ */
uint16_t WS2812FX::chase(uint32_t color1, uint32_t color2, uint32_t color3, bool dopalette) { uint16_t WS2812FX::chase(uint32_t color1, uint32_t color2, uint32_t color3, bool do_palette) {
uint16_t counter = now * ((SEGMENT.speed >> 2) + 1); uint16_t counter = now * ((SEGMENT.speed >> 2) + 1);
uint16_t a = counter * SEGLEN >> 16; uint16_t a = counter * SEGLEN >> 16;
bool chase_random = (SEGMENT.mode == FX_MODE_CHASE_RANDOM);
if (chase_random) {
if (a < SEGENV.step) //we hit the start again, choose new color for Chase random
{
SEGENV.aux1 = SEGENV.aux0; //store previous random color
SEGENV.aux0 = get_random_wheel_index(SEGENV.aux0);
}
color1 = color_wheel(SEGENV.aux0);
}
SEGENV.step = a; SEGENV.step = a;
uint8_t size = 1 + (SEGMENT.intensity * SEGLEN >> 10);
if (SEGENV.call == 0) {SEGENV.aux0 = 0; SEGENV.aux1 = a;}
// Use intensity setting to vary chase up to 1/2 string length // Use intensity setting to vary chase up to 1/2 string length
uint16_t b = (a + size) % SEGLEN; uint8_t size = 1 + (SEGMENT.intensity * SEGLEN >> 10);
uint16_t c = (b + size) % SEGLEN;
if (dopalette) color1 = color_from_palette(a, true, PALETTE_SOLID_WRAP, 1); uint16_t b = a + size; //"trail" of chase, filled with color1
if (b > SEGLEN) b -= SEGLEN;
uint16_t c = b + size;
if (c > SEGLEN) c -= SEGLEN;
setPixelColor(a, color1); //background
if (SEGENV.aux0 == 0) { // catch the first pixels after color change from "chase random" (because they have the "old" color) if (do_palette)
for (uint16_t i = 0; i < a; i++) { {
uint32_t color = getPixelColor(0); for(uint16_t i = 0; i < SEGLEN; i++) {
setPixelColor(i, color1); setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 1));
} }
SEGENV.aux0 = 1; } else fill(color1);
}
setPixelColor(b, color2);
setPixelColor(c, color3);
if (a != SEGENV.aux1) { // when speed is too fast, this catches the gaps //if random, fill old background between a and end
if (a > SEGENV.aux1) { if (chase_random)
for (uint16_t i = SEGENV.aux1; i <= a; i++) { // sometimes the step-length varies from one to the next call - therefor "<= a" and not "< a" {
setPixelColor(i, color1); color1 = color_wheel(SEGENV.aux1);
uint16_t b1 = (i + size) % SEGLEN; for (uint16_t i = a; i < SEGLEN; i++)
uint16_t c1 = (b1 + size) % SEGLEN; setPixelColor(i, color1);
setPixelColor(b1, color2); }
setPixelColor(c1, color3);
} //fill between points a and b with color2
} else { if (a < b)
for (uint16_t i = SEGENV.aux1; i <= SEGLEN; i++) { // from last position to the end {
setPixelColor(i, color1); for (uint16_t i = a; i < b; i++)
uint16_t b1 = (i + size) % SEGLEN; setPixelColor(i, color2);
uint16_t c1 = (b1 + size) % SEGLEN; } else {
setPixelColor(b1, color2); for (uint16_t i = a; i < SEGLEN; i++) //fill until end
setPixelColor(c1, color3); setPixelColor(i, color2);
} for (uint16_t i = 0; i < b; i++) //fill from start until b
for (uint16_t i = 0; i < a; i++) { // from 0 to the actual position setPixelColor(i, color2);
setPixelColor(i, color1); }
uint16_t b1 = (i + size) % SEGLEN;
uint16_t c1 = (b1 + size) % SEGLEN; //fill between points b and c with color2
setPixelColor(b1, color2); if (b < c)
setPixelColor(c1, color3); {
} for (uint16_t i = b; i < c; i++)
SEGENV.step = 0; setPixelColor(i, color3);
SEGENV.aux0 = 0; } else {
} for (uint16_t i = b; i < SEGLEN; i++) //fill until end
setPixelColor(i, color3);
for (uint16_t i = 0; i < c; i++) //fill from start until c
setPixelColor(i, color3);
} }
SEGENV.aux1 = ++a;
return FRAMETIME; return FRAMETIME;
} }
@ -751,7 +761,7 @@ uint16_t WS2812FX::chase(uint32_t color1, uint32_t color2, uint32_t color3, bool
* Bicolor chase, more primary color. * Bicolor chase, more primary color.
*/ */
uint16_t WS2812FX::mode_chase_color(void) { uint16_t WS2812FX::mode_chase_color(void) {
return chase(SEGCOLOR(1), SEGCOLOR(0), SEGCOLOR(0), true); return chase(SEGCOLOR(1), (SEGCOLOR(2)) ? SEGCOLOR(2) : SEGCOLOR(0), SEGCOLOR(0), true);
} }
@ -759,12 +769,19 @@ uint16_t WS2812FX::mode_chase_color(void) {
* Primary running followed by random color. * Primary running followed by random color.
*/ */
uint16_t WS2812FX::mode_chase_random(void) { uint16_t WS2812FX::mode_chase_random(void) {
if (!SEGENV.allocateData(2)) return mode_static(); //allocation failed return chase(SEGCOLOR(1), (SEGCOLOR(2)) ? SEGCOLOR(2) : SEGCOLOR(0), SEGCOLOR(0), false);
if (SEGENV.call == 0) SEGENV.data[0] = 0; }
if (SEGENV.step == 0) {
SEGENV.data[0] = get_random_wheel_index(SEGENV.data[0]);
} /*
return chase(color_wheel(SEGENV.data[0]), SEGCOLOR(0), SEGCOLOR(0), false); * Primary, secondary running on rainbow.
*/
uint16_t WS2812FX::mode_chase_rainbow(void) {
uint8_t color_sep = 256 / SEGLEN;
uint8_t color_index = SEGENV.call & 0xFF;
uint32_t color = color_wheel(((SEGENV.step * color_sep) + color_index) & 0xFF);
return chase(color, SEGCOLOR(0), SEGCOLOR(1), false);
} }
@ -860,18 +877,6 @@ uint16_t WS2812FX::mode_traffic_light(void) {
} }
/*
* Primary, secondary running on rainbow.
*/
uint16_t WS2812FX::mode_chase_rainbow(void) {
uint8_t color_sep = 256 / SEGLEN;
uint8_t color_index = SEGENV.call & 0xFF;
uint32_t color = color_wheel(((SEGENV.step * color_sep) + color_index) & 0xFF);
return chase(color, SEGCOLOR(0), SEGCOLOR(1), 0);
}
/* /*
* Sec flashes running on prim. * Sec flashes running on prim.
*/ */
@ -3161,4 +3166,4 @@ uint16_t WS2812FX::mode_heartbeat(void) {
} }
return FRAMETIME; return FRAMETIME;
} }

View File

@ -119,7 +119,7 @@
#endif #endif
//version code in format yymmddb (b = daily build) //version code in format yymmddb (b = daily build)
#define VERSION 2002252 #define VERSION 2002291
char versionString[] = "0.9.1"; char versionString[] = "0.9.1";