Skip to content

Commit 0441ede

Browse files
committed
Fix for wled#4401
1 parent f001846 commit 0441ede

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

wled00/FX.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -642,45 +642,39 @@ static const char _data_FX_MODE_TWINKLE[] PROGMEM = "Twinkle@!,!;!,!;!;;m12=0";
642642
* Dissolve function
643643
*/
644644
uint16_t dissolve(uint32_t color) {
645-
unsigned dataSize = (SEGLEN+7) >> 3; //1 bit per LED
645+
unsigned dataSize = sizeof(uint32_t) * SEGLEN;
646646
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
647+
uint32_t* pixels = reinterpret_cast<uint32_t*>(SEGENV.data);
647648

648649
if (SEGENV.call == 0) {
649-
memset(SEGMENT.data, 0xFF, dataSize); // start by fading pixels up
650+
for (unsigned i = 0; i < SEGLEN; i++) pixels[i] = SEGCOLOR(1);
650651
SEGENV.aux0 = 1;
651652
}
652653

653654
for (unsigned j = 0; j <= SEGLEN / 15; j++) {
654655
if (hw_random8() <= SEGMENT.intensity) {
655656
for (size_t times = 0; times < 10; times++) { //attempt to spawn a new pixel 10 times
656657
unsigned i = hw_random16(SEGLEN);
657-
unsigned index = i >> 3;
658-
unsigned bitNum = i & 0x07;
659-
bool fadeUp = bitRead(SEGENV.data[index], bitNum);
660658
if (SEGENV.aux0) { //dissolve to primary/palette
661-
if (fadeUp) {
662-
if (color == SEGCOLOR(0)) {
663-
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
664-
} else {
665-
SEGMENT.setPixelColor(i, color);
666-
}
667-
bitWrite(SEGENV.data[index], bitNum, false);
659+
if (pixels[i] == SEGCOLOR(1)) {
660+
pixels[i] = color == SEGCOLOR(0) ? SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0) : color;
668661
break; //only spawn 1 new pixel per frame per 50 LEDs
669662
}
670663
} else { //dissolve to secondary
671-
if (!fadeUp) {
672-
SEGMENT.setPixelColor(i, SEGCOLOR(1)); break;
673-
bitWrite(SEGENV.data[index], bitNum, true);
664+
if (pixels[i] != SEGCOLOR(1)) {
665+
pixels[i] = SEGCOLOR(1);
666+
break;
674667
}
675668
}
676669
}
677670
}
678671
}
672+
// fix for #4401
673+
for (unsigned i = 0; i < SEGLEN; i++) SEGMENT.setPixelColor(i, pixels[i]);
679674

680675
if (SEGENV.step > (255 - SEGMENT.speed) + 15U) {
681676
SEGENV.aux0 = !SEGENV.aux0;
682677
SEGENV.step = 0;
683-
memset(SEGMENT.data, (SEGENV.aux0 ? 0xFF : 0), dataSize); // switch fading
684678
} else {
685679
SEGENV.step++;
686680
}
@@ -6577,7 +6571,7 @@ uint16_t mode_matripix(void) { // Matripix. By Andrew Tuline.
65776571
int volumeRaw = *(int16_t*)um_data->u_data[1];
65786572

65796573
if (SEGENV.call == 0) {
6580-
for (int i = 0; i < SEGLEN; i++) pixels[i] = BLACK; // may not be needed as resetIfRequired() clears buffer
6574+
for (unsigned i = 0; i < SEGLEN; i++) pixels[i] = BLACK; // may not be needed as resetIfRequired() clears buffer
65816575
}
65826576

65836577
uint8_t secondHand = micros()/(256-SEGMENT.speed)/500 % 16;
@@ -7161,7 +7155,7 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin
71617155
if (FFT_MajorPeak < 1) FFT_MajorPeak = 1; // log10(0) is "forbidden" (throws exception)
71627156

71637157
if (SEGENV.call == 0) {
7164-
for (int i = 0; i < SEGLEN; i++) pixels[i] = BLACK; // may not be needed as resetIfRequired() clears buffer
7158+
for (unsigned i = 0; i < SEGLEN; i++) pixels[i] = BLACK; // may not be needed as resetIfRequired() clears buffer
71657159
SEGENV.aux0 = 255;
71667160
SEGMENT.custom1 = *binNum;
71677161
SEGMENT.custom2 = *maxVol * 2;
@@ -7178,7 +7172,7 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin
71787172
uint8_t pixCol = (log10f(FFT_MajorPeak) - 2.26f) * 150; // 22Khz sampling - log10 frequency range is from 2.26 (182hz) to 3.967 (9260hz). Let's scale accordingly.
71797173
if (FFT_MajorPeak < 182.0f) pixCol = 0; // handle underflow
71807174

7181-
int k = SEGLEN-1;
7175+
unsigned k = SEGLEN-1;
71827176
if (samplePeak) {
71837177
pixels[k] = (uint32_t)CRGB(CHSV(92,92,92));
71847178
} else {

wled00/led.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ byte scaledBri(byte in)
7373

7474
//applies global brightness
7575
void applyBri() {
76-
if (!realtimeMode || !arlsForceMaxBri)
77-
{
76+
if (!(realtimeMode && arlsForceMaxBri)) {
7877
//DEBUG_PRINTF_P(PSTR("Applying strip brightness: %d (%d,%d)\n"), (int)briT, (int)bri, (int)briOld);
7978
strip.setBrightness(scaledBri(briT));
8079
}
@@ -86,6 +85,7 @@ void applyFinalBri() {
8685
briOld = bri;
8786
briT = bri;
8887
applyBri();
88+
strip.trigger();
8989
}
9090

9191

@@ -146,7 +146,6 @@ void stateUpdated(byte callMode) {
146146
transitionStartTime = millis();
147147
} else {
148148
applyFinalBri();
149-
strip.trigger();
150149
}
151150
}
152151

0 commit comments

Comments
 (0)