Skip to content

Commit 06fc1eb

Browse files
committed
HUB75: use last brightness on re-init
avoids brightness flash when saving LED preferences
1 parent d6dedd0 commit 06fc1eb

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

wled00/bus_manager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ VirtualMatrixPanel* BusHub75Matrix::activeFourScanPanel = nullptr;
528528
HUB75_I2S_CFG BusHub75Matrix::activeMXconfig = HUB75_I2S_CFG();
529529
uint8_t BusHub75Matrix::activeType = 0;
530530
uint8_t BusHub75Matrix::instanceCount = 0;
531+
uint8_t BusHub75Matrix::last_bri = 0;
531532

532533

533534
// --------------------------
@@ -899,7 +900,7 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh
899900
USER_PRINTLN("MatrixPanel_I2S_DMA created");
900901
// let's adjust default brightness
901902
//display->setBrightness8(25); // range is 0-255, 0 - 0%, 255 - 100% // [setBrightness()] Tried to set output brightness before begin()
902-
_bri = 25;
903+
_bri = (last_bri > 0) ? last_bri : 25; // try to restore persistent brightness value
903904

904905
delay(24); // experimental
905906
DEBUG_PRINT(F("heap usage: ")); DEBUG_PRINTLN(int(lastHeap - ESP.getFreeHeap()));
@@ -917,6 +918,7 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh
917918
USER_PRINT(F("heap usage: ")); USER_PRINTLN(int(lastHeap - ESP.getFreeHeap()));
918919
delay(18); // experiment - give the driver a moment (~ one full frame @ 60hz) to settle
919920
_valid = true;
921+
display->setBrightness8(_bri); // range is 0-255, 0 - 0%, 255 - 100% // [setBrightness()] Tried to set output brightness before begin()
920922
display->clearScreen(); // initially clear the screen buffer
921923
USER_PRINTLN("MatrixPanel_I2S_DMA clear ok");
922924

@@ -1057,6 +1059,7 @@ void BusHub75Matrix::setBrightness(uint8_t b, bool immediate) {
10571059
MatrixPanel_I2S_DMA* display = BusHub75Matrix::activeDisplay;
10581060
// if (_bri > 238) _bri=238; // not strictly needed. Enable this line if you see glitches at highest brightness.
10591061
if ((_bri > 253) && (activeMXconfig.latch_blanking < 2)) _bri=253; // prevent glitches at highest brightness.
1062+
last_bri = _bri;
10601063
if (display) display->setBrightness(_bri);
10611064
}
10621065

wled00/bus_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ class BusHub75Matrix : public Bus {
411411
static HUB75_I2S_CFG activeMXconfig; // last used mxconfig
412412
static uint8_t activeType; // last used type
413413
static uint8_t instanceCount; // active instances - 0 or 1
414+
static uint8_t last_bri; // last used brightness value (persists on driver delete)
414415
};
415416
#endif
416417

wled00/wled00.ino

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ void esp_heap_trace_free_hook(void* ptr)
6161
unsigned long lastMillis = 0; //WLEDMM
6262
unsigned long loopCounter = 0; //WLEDMM
6363

64+
unsigned long lps = 0; // loops per second
65+
unsigned long lps2 = 0; // lps without "show"
66+
67+
unsigned long long showtime = 0; // time spent in "show" (micros)
68+
6469
void setup() __attribute__((used)); // needed for -flto
6570
void setup() {
6671
#ifdef WLED_DEBUG_HEAP
@@ -73,13 +78,22 @@ void loop() __attribute__((used)); // needed for -flto
7378
void loop() {
7479
//WLEDMM show loops per second
7580
loopCounter++;
76-
if (millis() - lastMillis >= 10000) {
81+
//if (millis() - lastMillis >= 10000) {
82+
if (millis() - lastMillis >= 8000) {
7783
long delta = millis() - lastMillis;
7884
if (delta > 0) {
85+
lps = (loopCounter*1000U) / delta;
7986
//USER_PRINTF("%lu lps\n",(loopCounter*1000U) / delta);
87+
if (delta > (showtime / 1000)) lps2 = (loopCounter*1000U) / (delta - (showtime / 1000));
88+
USER_PRINTF("%lu lps\t", lps);
89+
USER_PRINTF("%u fps\t", strip.getFps());
90+
USER_PRINTF("%lu lps without show\t\t", lps2);
91+
USER_PRINTF("frametime %d\t", int(strip.getFrameTime()));
92+
USER_PRINTF("targetFPS %d\n", int(strip.getTargetFps()));
8093
}
8194
lastMillis = millis();
8295
loopCounter = 0;
96+
showtime = 0;
8397
}
8498

8599
WLED::instance().loop();

0 commit comments

Comments
 (0)