Skip to content

Commit b2364bf

Browse files
committed
chunchun effect bugfixes (for strips >256 pixels)
* avoid 16bit overflows * improve time resolution * limit to 32 birds (=max for 256 pixels) * fix fade_out
1 parent 6c87799 commit b2364bf

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

wled00/FX.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4377,20 +4377,20 @@ static const char _data_FX_MODE_FLOW[] PROGMEM = "Flow@!,Zones;;!;;m12=1"; //ver
43774377
*/
43784378
uint16_t mode_chunchun(void)
43794379
{
4380-
if (SEGLEN == 1) return mode_static();
4380+
if (SEGLEN <= 1) return mode_static();
43814381
if (SEGENV.call == 0) {SEGENV.setUpLeds(); SEGMENT.fill(BLACK);} // WLEDMM use lossless getPixelColor()
4382-
SEGMENT.fade_out(254); // add a bit of trail
4383-
uint16_t counter = strip.now * (6 + (SEGMENT.speed >> 4));
4384-
uint16_t numBirds = 2 + (SEGLEN >> 3); // 2 + 1/8 of a segment
4385-
uint16_t span = (SEGMENT.intensity << 8) / numBirds;
4382+
SEGMENT.fade_out(253); // add a bit of trail // WLEDMM fade rate above 253 has no effect
4383+
uint32_t counter = ((strip.now * (96 + SEGMENT.speed)) >> 4); // WLEDMM same result, better resolution
4384+
uint16_t numBirds = min(32, 2 + (SEGLEN >> 3)); // 2 + 1/8 of a segment - WLEDMM max 32
4385+
uint32_t span = (SEGMENT.intensity << 8) / numBirds;
43864386

4387-
for (int i = 0; i < numBirds; i++)
4387+
for (unsigned i = 0; i < numBirds; i++)
43884388
{
43894389
counter -= span;
43904390
uint16_t megumin = sin16_t(counter) + 0x8000;
43914391
uint16_t bird = uint32_t(megumin * SEGLEN) >> 16;
43924392
uint32_t c = SEGMENT.color_from_palette((i * 255)/ numBirds, false, false, 0); // no palette wrapping
4393-
bird = constrain(bird, 0, SEGLEN-1);
4393+
bird = min(bird, uint16_t(SEGLEN-1)); // WLEDMM unsigned is always >= 0
43944394
SEGMENT.setPixelColor(bird, c);
43954395
}
43964396
return FRAMETIME;

0 commit comments

Comments
 (0)