Merge pull request #507 from fishbone-git/framerate

More framerate conversions, etc
This commit is contained in:
Aircoookie 2019-12-23 20:47:40 +01:00 committed by GitHub
commit 9839bab8dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 80 deletions

View File

@ -688,9 +688,11 @@ uint16_t WS2812FX::mode_android(void) {
* 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 dopalette) {
uint16_t a = SEGENV.step; uint16_t counter = now * (SEGMENT.speed >> 3) + 1;
uint16_t b = (a + 1) % SEGLEN; uint16_t a = counter * SEGLEN >> 16;
uint16_t c = (b + 1) % SEGLEN; // Use intensity setting to vary chase up to 1/2 string length
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(SEGMENT.start + a, true, PALETTE_SOLID_WRAP, 1);
@ -698,9 +700,7 @@ uint16_t WS2812FX::chase(uint32_t color1, uint32_t color2, uint32_t color3, bool
setPixelColor(SEGMENT.start + b, color2); setPixelColor(SEGMENT.start + b, color2);
setPixelColor(SEGMENT.start + c, color3); setPixelColor(SEGMENT.start + c, color3);
SEGENV.step++; return FRAMETIME;
if (SEGENV.step >= SEGLEN) SEGENV.step = 0;
return SPEED_FORMULA_L;
} }
@ -978,19 +978,40 @@ uint16_t WS2812FX::mode_running_random(void) {
/* /*
* K.I.T.T. * K.I.T.T.
*/ */
uint16_t WS2812FX::mode_larson_scanner(void) { uint16_t WS2812FX::mode_larson_scanner(void){
return larson_scanner(false);
}
uint16_t WS2812FX::larson_scanner(bool dual) {
uint16_t counter = now * ((SEGMENT.speed >> 2) +8);
uint16_t index = counter * SEGLEN >> 16;
fade_out(SEGMENT.intensity); fade_out(SEGMENT.intensity);
uint16_t index = 0; if (SEGENV.step > index && SEGENV.step - index > SEGLEN/2) {
if(SEGENV.step < SEGLEN) { SEGENV.aux0 = !SEGENV.aux0;
index = SEGMENT.start + SEGENV.step;
} else {
index = SEGMENT.start + ((SEGLEN * 2) - SEGENV.step) - 2;
} }
setPixelColor(index, color_from_palette(index, true, PALETTE_SOLID_WRAP, 0));
SEGENV.step = (SEGENV.step + 1) % ((SEGLEN * 2) - 2); for (uint16_t i = SEGENV.step; i < index; i++) {
return SPEED_FORMULA_L; uint16_t j = (SEGENV.aux0)?i:SEGLEN-1-i;
setPixelColor(j, color_from_palette(j, true, PALETTE_SOLID_WRAP, 0));
}
if (dual) {
uint32_t c;
if (SEGCOLOR(2) != 0) {
c = SEGCOLOR(2);
} else {
c = color_from_palette(index, true, PALETTE_SOLID_WRAP, 0);
}
for (uint16_t i = SEGENV.step; i < index; i++) {
uint16_t j = (SEGENV.aux0)?SEGLEN-1-i:i;
setPixelColor(j, c);
}
}
SEGENV.step = index;
return FRAMETIME;
} }
@ -998,13 +1019,14 @@ uint16_t WS2812FX::mode_larson_scanner(void) {
* Firing comets from one end. * Firing comets from one end.
*/ */
uint16_t WS2812FX::mode_comet(void) { uint16_t WS2812FX::mode_comet(void) {
uint16_t counter = now * (SEGMENT.speed >>3) +1;
uint16_t index = counter * SEGLEN >> 16;
fade_out(SEGMENT.intensity); fade_out(SEGMENT.intensity);
uint16_t index = SEGMENT.start + SEGENV.step;
setPixelColor(index, color_from_palette(index, true, PALETTE_SOLID_WRAP, 0)); setPixelColor(index, color_from_palette(index, true, PALETTE_SOLID_WRAP, 0));
SEGENV.step = (SEGENV.step + 1) % SEGLEN; return FRAMETIME;
return SPEED_FORMULA_L;
} }
@ -1087,6 +1109,9 @@ uint16_t WS2812FX::mode_fire_flicker(void) {
* Gradient run base function * Gradient run base function
*/ */
uint16_t WS2812FX::gradient_base(bool loading) { 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 (SEGENV.call == 0) SEGENV.step = 0; if (SEGENV.call == 0) SEGENV.step = 0;
float per,val; //0.0 = sec 1.0 = pri float per,val; //0.0 = sec 1.0 = pri
float brd = SEGMENT.intensity; float brd = SEGMENT.intensity;
@ -1109,10 +1134,7 @@ uint16_t WS2812FX::gradient_base(bool loading) {
setPixelColor(i, color_blend(SEGCOLOR(0), color_from_palette(i, true, PALETTE_SOLID_WRAP, 1), per*255)); setPixelColor(i, color_blend(SEGCOLOR(0), color_from_palette(i, true, PALETTE_SOLID_WRAP, 1), per*255));
} }
SEGENV.step++; return FRAMETIME;
if (SEGENV.step >= SEGMENT.stop) SEGENV.step = SEGMENT.start;
if (SEGMENT.speed == 0) SEGENV.step = SEGMENT.start + (SEGLEN >> 1);
return SPEED_FORMULA_L;
} }
@ -1189,19 +1211,22 @@ uint16_t WS2812FX::mode_two_dots()
* Tricolor chase function * Tricolor chase function
*/ */
uint16_t WS2812FX::tricolor_chase(uint32_t color1, uint32_t color2) { uint16_t WS2812FX::tricolor_chase(uint32_t color1, uint32_t color2) {
uint16_t index = SEGENV.step % 6; uint32_t cycleTime = 50 + (255 - SEGMENT.speed)*2;
uint32_t it = now / cycleTime;
uint8_t width = (1 + SEGMENT.intensity/32) * 3; //value of 1-8 for each colour
uint8_t index = it % width;
for(uint16_t i=0; i < SEGLEN; i++, index++) { for(uint16_t i=0; i < SEGLEN; i++, index++) {
if(index > 5) index = 0; if(index > width-1) index = 0;
uint32_t color = color1; uint32_t color = color1;
if(index > 3) color = color_from_palette(i, true, PALETTE_SOLID_WRAP, 1); if(index > width*2/3-1) color = color_from_palette(i, true, PALETTE_SOLID_WRAP, 1);
else if(index > 1) color = color2; else if(index > width/3-1) color = color2;
setPixelColor(SEGMENT.stop - i -1, color); setPixelColor(SEGMENT.stop - i -1, color);
} }
SEGENV.step++; return FRAMETIME;
return 35 + ((350 * (uint32_t)(255 - SEGMENT.speed)) / 255);
} }
@ -1362,31 +1387,7 @@ uint16_t WS2812FX::mode_multi_comet(void)
* Custom mode by Keith Lord: https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/DualLarson.h * Custom mode by Keith Lord: https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/DualLarson.h
*/ */
uint16_t WS2812FX::mode_dual_larson_scanner(void){ uint16_t WS2812FX::mode_dual_larson_scanner(void){
if (SEGENV.aux0) return larson_scanner(true);
{
SEGENV.step--;
} else
{
SEGENV.step++;
}
fade_out(SEGMENT.intensity);
uint16_t index = SEGMENT.start + SEGENV.step;
setPixelColor(index, color_from_palette(index, true, PALETTE_SOLID_WRAP, 0));
index = SEGMENT.stop - SEGENV.step -1;
if (SEGCOLOR(2) != 0)
{
setPixelColor(index, SEGCOLOR(2));
} else
{
setPixelColor(index, color_from_palette(index, true, PALETTE_SOLID_WRAP, 0));
}
if(SEGENV.step >= SEGLEN -1 || SEGENV.step <= 0)
SEGENV.aux0 = !SEGENV.aux0;
return SPEED_FORMULA_L;
} }
@ -1396,6 +1397,10 @@ uint16_t WS2812FX::mode_dual_larson_scanner(void){
*/ */
uint16_t WS2812FX::mode_random_chase(void) uint16_t WS2812FX::mode_random_chase(void)
{ {
uint32_t cycleTime = 25 + (3 * (uint32_t)(255 - SEGMENT.speed));
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=SEGMENT.stop -1; i>SEGMENT.start; i--) {
setPixelColor(i, getPixelColor(i-1)); setPixelColor(i, getPixelColor(i-1));
} }
@ -1406,7 +1411,8 @@ uint16_t WS2812FX::mode_random_chase(void)
uint8_t b = random8(6) != 0 ? (color & 0xFF) : random8(); uint8_t b = random8(6) != 0 ? (color & 0xFF) : random8();
setPixelColor(SEGMENT.start, r, g, b); setPixelColor(SEGMENT.start, r, g, b);
return SPEED_FORMULA_L; SEGENV.step = it;
return FRAMETIME;
} }
@ -1417,25 +1423,35 @@ typedef struct Oscillator {
int8_t speed; int8_t speed;
} oscillator; } oscillator;
/*
/ Oscillating bars of color, updated with standard framerate
*/
uint16_t WS2812FX::mode_oscillate(void) uint16_t WS2812FX::mode_oscillate(void)
{ {
static oscillator oscillators[2] = { static oscillator oscillators[NUM_COLORS] = {
{SEGLEN/4, SEGLEN/8, 1, 1}, {SEGLEN/4, SEGLEN/8, 1, 1},
{SEGLEN/4*3, SEGLEN/8, 1, 2},
{SEGLEN/4*2, SEGLEN/8, -1, 1} {SEGLEN/4*2, SEGLEN/8, -1, 1}
//{SEGLEN/4*3, SEGLEN/8, 1, 2}
}; };
uint32_t cycleTime = 20 + (2 * (uint32_t)(255 - SEGMENT.speed));
uint32_t it = now / cycleTime;
for(int8_t i=0; i < sizeof(oscillators)/sizeof(oscillators[0]); i++) { for(int8_t i=0; i < sizeof(oscillators)/sizeof(oscillators[0]); i++) {
oscillators[i].pos += oscillators[i].dir * oscillators[i].speed; // if the counter has increased, move the oscillator by the random step
if (it != SEGENV.step) oscillators[i].pos += oscillators[i].dir * oscillators[i].speed;
oscillators[i].size = SEGLEN/(3+SEGMENT.intensity/8);
if((oscillators[i].dir == -1) && (oscillators[i].pos <= 0)) { if((oscillators[i].dir == -1) && (oscillators[i].pos <= 0)) {
oscillators[i].pos = 0; oscillators[i].pos = 0;
oscillators[i].dir = 1; oscillators[i].dir = 1;
oscillators[i].speed = random8(1, 3); // make bigger steps for faster speeds
oscillators[i].speed = SEGMENT.speed > 100 ? random8(2, 4):random8(1, 3);
} }
if((oscillators[i].dir == 1) && (oscillators[i].pos >= (SEGLEN - 1))) { if((oscillators[i].dir == 1) && (oscillators[i].pos >= (SEGLEN - 1))) {
oscillators[i].pos = SEGLEN - 1; oscillators[i].pos = SEGLEN - 1;
oscillators[i].dir = -1; oscillators[i].dir = -1;
oscillators[i].speed = random8(1, 3); oscillators[i].speed = SEGMENT.speed > 100 ? random8(2, 4):random8(1, 3);
} }
} }
@ -1448,7 +1464,9 @@ uint16_t WS2812FX::mode_oscillate(void)
} }
setPixelColor(SEGMENT.start + i, color); setPixelColor(SEGMENT.start + i, color);
} }
return 15 + (uint32_t)(255 - SEGMENT.speed);
SEGENV.step = it;
return FRAMETIME;
} }
@ -1882,7 +1900,8 @@ uint16_t WS2812FX::mode_lake() {
// adapted from https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectMeteorRain // adapted from https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectMeteorRain
uint16_t WS2812FX::mode_meteor() { uint16_t WS2812FX::mode_meteor() {
byte meteorSize= 1+ SEGLEN / 10; byte meteorSize= 1+ SEGLEN / 10;
uint16_t in = SEGMENT.start + SEGENV.step; uint16_t counter = now * ((SEGMENT.speed >> 2) +8);
uint16_t in = counter * SEGLEN >> 16;
// fade all leds to colors[1] in LEDs one step // fade all leds to colors[1] in LEDs one step
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) { for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
@ -1905,8 +1924,7 @@ uint16_t WS2812FX::mode_meteor() {
setPixelColor(index, color_from_palette(_locked[index], false, true, 255)); setPixelColor(index, color_from_palette(_locked[index], false, true, 255));
} }
SEGENV.step = (SEGENV.step + 1) % (SEGLEN); return FRAMETIME;
return SPEED_FORMULA_L;
} }

View File

@ -543,6 +543,7 @@ class WS2812FX {
scan(bool), scan(bool),
theater_chase(uint32_t, uint32_t, bool), theater_chase(uint32_t, uint32_t, bool),
running_base(bool), running_base(bool),
larson_scanner(bool),
dissolve(uint32_t), dissolve(uint32_t),
chase(uint32_t, uint32_t, uint32_t, bool), chase(uint32_t, uint32_t, uint32_t, bool),
gradient_base(bool), gradient_base(bool),