This commit is contained in:
Blaž Kristan 2024-12-25 15:18:34 +01:00
parent f001846e00
commit 0441ede229
2 changed files with 15 additions and 22 deletions

View File

@ -642,11 +642,12 @@ static const char _data_FX_MODE_TWINKLE[] PROGMEM = "Twinkle@!,!;!,!;!;;m12=0";
* Dissolve function * Dissolve function
*/ */
uint16_t dissolve(uint32_t color) { uint16_t dissolve(uint32_t color) {
unsigned dataSize = (SEGLEN+7) >> 3; //1 bit per LED unsigned dataSize = sizeof(uint32_t) * SEGLEN;
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
uint32_t* pixels = reinterpret_cast<uint32_t*>(SEGENV.data);
if (SEGENV.call == 0) { if (SEGENV.call == 0) {
memset(SEGMENT.data, 0xFF, dataSize); // start by fading pixels up for (unsigned i = 0; i < SEGLEN; i++) pixels[i] = SEGCOLOR(1);
SEGENV.aux0 = 1; SEGENV.aux0 = 1;
} }
@ -654,33 +655,26 @@ uint16_t dissolve(uint32_t color) {
if (hw_random8() <= SEGMENT.intensity) { if (hw_random8() <= SEGMENT.intensity) {
for (size_t times = 0; times < 10; times++) { //attempt to spawn a new pixel 10 times for (size_t times = 0; times < 10; times++) { //attempt to spawn a new pixel 10 times
unsigned i = hw_random16(SEGLEN); unsigned i = hw_random16(SEGLEN);
unsigned index = i >> 3;
unsigned bitNum = i & 0x07;
bool fadeUp = bitRead(SEGENV.data[index], bitNum);
if (SEGENV.aux0) { //dissolve to primary/palette if (SEGENV.aux0) { //dissolve to primary/palette
if (fadeUp) { if (pixels[i] == SEGCOLOR(1)) {
if (color == SEGCOLOR(0)) { pixels[i] = color == SEGCOLOR(0) ? SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0) : color;
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
} else {
SEGMENT.setPixelColor(i, color);
}
bitWrite(SEGENV.data[index], bitNum, false);
break; //only spawn 1 new pixel per frame per 50 LEDs break; //only spawn 1 new pixel per frame per 50 LEDs
} }
} else { //dissolve to secondary } else { //dissolve to secondary
if (!fadeUp) { if (pixels[i] != SEGCOLOR(1)) {
SEGMENT.setPixelColor(i, SEGCOLOR(1)); break; pixels[i] = SEGCOLOR(1);
bitWrite(SEGENV.data[index], bitNum, true); break;
} }
} }
} }
} }
} }
// fix for #4401
for (unsigned i = 0; i < SEGLEN; i++) SEGMENT.setPixelColor(i, pixels[i]);
if (SEGENV.step > (255 - SEGMENT.speed) + 15U) { if (SEGENV.step > (255 - SEGMENT.speed) + 15U) {
SEGENV.aux0 = !SEGENV.aux0; SEGENV.aux0 = !SEGENV.aux0;
SEGENV.step = 0; SEGENV.step = 0;
memset(SEGMENT.data, (SEGENV.aux0 ? 0xFF : 0), dataSize); // switch fading
} else { } else {
SEGENV.step++; SEGENV.step++;
} }
@ -6577,7 +6571,7 @@ uint16_t mode_matripix(void) { // Matripix. By Andrew Tuline.
int volumeRaw = *(int16_t*)um_data->u_data[1]; int volumeRaw = *(int16_t*)um_data->u_data[1];
if (SEGENV.call == 0) { if (SEGENV.call == 0) {
for (int i = 0; i < SEGLEN; i++) pixels[i] = BLACK; // may not be needed as resetIfRequired() clears buffer for (unsigned i = 0; i < SEGLEN; i++) pixels[i] = BLACK; // may not be needed as resetIfRequired() clears buffer
} }
uint8_t secondHand = micros()/(256-SEGMENT.speed)/500 % 16; uint8_t secondHand = micros()/(256-SEGMENT.speed)/500 % 16;
@ -7161,7 +7155,7 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin
if (FFT_MajorPeak < 1) FFT_MajorPeak = 1; // log10(0) is "forbidden" (throws exception) if (FFT_MajorPeak < 1) FFT_MajorPeak = 1; // log10(0) is "forbidden" (throws exception)
if (SEGENV.call == 0) { if (SEGENV.call == 0) {
for (int i = 0; i < SEGLEN; i++) pixels[i] = BLACK; // may not be needed as resetIfRequired() clears buffer for (unsigned i = 0; i < SEGLEN; i++) pixels[i] = BLACK; // may not be needed as resetIfRequired() clears buffer
SEGENV.aux0 = 255; SEGENV.aux0 = 255;
SEGMENT.custom1 = *binNum; SEGMENT.custom1 = *binNum;
SEGMENT.custom2 = *maxVol * 2; SEGMENT.custom2 = *maxVol * 2;
@ -7178,7 +7172,7 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin
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. 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.
if (FFT_MajorPeak < 182.0f) pixCol = 0; // handle underflow if (FFT_MajorPeak < 182.0f) pixCol = 0; // handle underflow
int k = SEGLEN-1; unsigned k = SEGLEN-1;
if (samplePeak) { if (samplePeak) {
pixels[k] = (uint32_t)CRGB(CHSV(92,92,92)); pixels[k] = (uint32_t)CRGB(CHSV(92,92,92));
} else { } else {

View File

@ -73,8 +73,7 @@ byte scaledBri(byte in)
//applies global brightness //applies global brightness
void applyBri() { void applyBri() {
if (!realtimeMode || !arlsForceMaxBri) if (!(realtimeMode && arlsForceMaxBri)) {
{
//DEBUG_PRINTF_P(PSTR("Applying strip brightness: %d (%d,%d)\n"), (int)briT, (int)bri, (int)briOld); //DEBUG_PRINTF_P(PSTR("Applying strip brightness: %d (%d,%d)\n"), (int)briT, (int)bri, (int)briOld);
strip.setBrightness(scaledBri(briT)); strip.setBrightness(scaledBri(briT));
} }
@ -86,6 +85,7 @@ void applyFinalBri() {
briOld = bri; briOld = bri;
briT = bri; briT = bri;
applyBri(); applyBri();
strip.trigger();
} }
@ -146,7 +146,6 @@ void stateUpdated(byte callMode) {
transitionStartTime = millis(); transitionStartTime = millis();
} else { } else {
applyFinalBri(); applyFinalBri();
strip.trigger();
} }
} }