From 2fce15db94d389740e58b2224b40365819fe3544 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Wed, 19 Jul 2023 16:22:34 +0200 Subject: [PATCH] Restore brightness immediately after show() --- wled00/FX_fcn.cpp | 14 +++---- wled00/bus_wrapper.h | 98 -------------------------------------------- 2 files changed, 6 insertions(+), 106 deletions(-) diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index d7e47ae1..ce845ce3 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -1082,11 +1082,6 @@ void WS2812FX::service() { // last condition ensures all solid segments are updated at the same time if (seg.isActive() && (nowUp > seg.next_time || _triggered || (doShow && seg.mode == FX_MODE_STATIC))) { - if (!doShow) { - // returning bus brightness to its original value is done here, as to not interfere with asyncronous show() - // TODO if it is safe, prefer to restore brightness in show() - busses.setBrightness(_brightness, true); // "repaint" all pixels if brightness has changed - } doShow = true; uint16_t delay = FRAMETIME; @@ -1247,9 +1242,10 @@ void WS2812FX::show(void) { // See https://github.com/Makuna/NeoPixelBus/wiki/ESP32-NeoMethods#neoesp32rmt-methods busses.show(); - // returning bus brightness to its original value is done in the next frame, as to not interfere with asyncronous show() - // TODO if it is safe, prefer to restore brightness here - //if (newBri < _brightness) busses.setBrightness(_brightness, true); + // restore bus brightness to its original value + // this is done right after show, so this is only OK if LED updates are completed before show() returns + // or async show has a separate buffer (ESP32 RMT and I2S are ok) + if (newBri < _brightness) busses.setBrightness(_brightness, true); #ifdef WLED_DEBUG sumMicros += micros() - microsStart; @@ -1321,6 +1317,8 @@ void WS2812FX::setCCT(uint16_t k) { } } +// direct=true either expects the caller to call show() themselves (realtime modes) or be ok waiting for the next frame for the change to apply +// direct=false immediately triggers an effect redraw void WS2812FX::setBrightness(uint8_t b, bool direct) { if (gammaCorrectBri) b = gamma8(b); if (_brightness == b) return; diff --git a/wled00/bus_wrapper.h b/wled00/bus_wrapper.h index 8b6ee660..72b4435e 100644 --- a/wled00/bus_wrapper.h +++ b/wled00/bus_wrapper.h @@ -911,104 +911,6 @@ class PolyBus { } } - static void applyPostAdjustments(void* busPtr, uint8_t busType) { - switch (busType) { - case I_NONE: break; - #ifdef ESP8266 - case I_8266_U0_NEO_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_U1_NEO_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_DM_NEO_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_BB_NEO_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_U0_NEO_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_U1_NEO_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_DM_NEO_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_BB_NEO_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_U0_400_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_U1_400_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_DM_400_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_BB_400_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_U0_TM1_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_U1_TM1_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_DM_TM1_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_BB_TM1_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_U0_TM2_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_U1_TM2_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_DM_TM2_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_BB_TM2_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_U0_UCS_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_U1_UCS_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_DM_UCS_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_BB_UCS_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_U0_UCS_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_U1_UCS_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_DM_UCS_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_8266_BB_UCS_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif - #ifdef ARDUINO_ARCH_ESP32 - case I_32_RN_NEO_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #ifndef WLED_NO_I2S0_PIXELBUS - case I_32_I0_NEO_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif - #ifndef WLED_NO_I2S1_PIXELBUS - case I_32_I1_NEO_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif -// case I_32_BB_NEO_3: (static_cast(busPtr))->SetLuminance(b); (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_32_RN_NEO_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #ifndef WLED_NO_I2S0_PIXELBUS - case I_32_I0_NEO_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif - #ifndef WLED_NO_I2S1_PIXELBUS - case I_32_I1_NEO_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif -// case I_32_BB_NEO_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_32_RN_400_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #ifndef WLED_NO_I2S0_PIXELBUS - case I_32_I0_400_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif - #ifndef WLED_NO_I2S1_PIXELBUS - case I_32_I1_400_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif -// case I_32_BB_400_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_32_RN_TM1_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_32_RN_TM2_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #ifndef WLED_NO_I2S0_PIXELBUS - case I_32_I0_TM1_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_32_I0_TM2_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif - #ifndef WLED_NO_I2S1_PIXELBUS - case I_32_I1_TM1_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_32_I1_TM2_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif - case I_32_RN_UCS_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #ifndef WLED_NO_I2S0_PIXELBUS - case I_32_I0_UCS_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif - #ifndef WLED_NO_I2S1_PIXELBUS - case I_32_I1_UCS_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif -// case I_32_BB_UCS_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_32_RN_UCS_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #ifndef WLED_NO_I2S0_PIXELBUS - case I_32_I0_UCS_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif - #ifndef WLED_NO_I2S1_PIXELBUS - case I_32_I1_UCS_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif -// case I_32_BB_UCS_4: (static_cast(busPtr))->ApplyPostAdjustments(); break; - #endif - case I_HS_DOT_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_SS_DOT_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_HS_LPD_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_SS_LPD_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_HS_LPO_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_SS_LPO_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_HS_WS1_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_SS_WS1_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_HS_P98_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - case I_SS_P98_3: (static_cast(busPtr))->ApplyPostAdjustments(); break; - } - } - static uint32_t getPixelColor(void* busPtr, uint8_t busType, uint16_t pix, uint8_t co) { RgbwColor col(0,0,0,0); switch (busType) {