Skip to content

Commit d044012

Browse files
committed
Bugfix for AutoSave & 4LD.
1 parent 8d4636b commit d044012

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

usermods/usermod_v2_auto_save/usermod_v2_auto_save.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AutoSaveUsermod : public Usermod {
3838
bool applyAutoSaveOnBoot = false; // do we load auto-saved preset on boot?
3939

4040
// If we've detected the need to auto save, this will be non zero.
41-
uint16_t autoSaveAfter = 0;
41+
unsigned long autoSaveAfter = 0;
4242

4343
uint8_t knownBrightness = 0;
4444
uint8_t knownEffectSpeed = 0;
@@ -87,6 +87,12 @@ class AutoSaveUsermod : public Usermod {
8787
display = (FourLineDisplayUsermod*) usermods.lookup(USERMOD_ID_FOUR_LINE_DISP);
8888
#endif
8989
initDone = true;
90+
if (enabled && applyAutoSaveOnBoot) applyPreset(autoSavePreset);
91+
knownBrightness = bri;
92+
knownEffectSpeed = effectSpeed;
93+
knownEffectIntensity = effectIntensity;
94+
knownMode = strip.getMode();
95+
knownPalette = strip.getSegment(0).palette;
9096
}
9197

9298
// gets called every time WiFi is (re-)connected. Initialize own network
@@ -97,21 +103,11 @@ class AutoSaveUsermod : public Usermod {
97103
* Da loop.
98104
*/
99105
void loop() {
100-
if (!autoSaveAfterSec || !enabled || strip.isUpdating()) return; // setting 0 as autosave seconds disables autosave
106+
if (!autoSaveAfterSec || !enabled || strip.isUpdating() || currentPreset>0) return; // setting 0 as autosave seconds disables autosave
101107

102108
unsigned long now = millis();
103109
uint8_t currentMode = strip.getMode();
104110
uint8_t currentPalette = strip.getSegment(0).palette;
105-
if (firstLoop) {
106-
firstLoop = false;
107-
if (applyAutoSaveOnBoot) applyPreset(autoSavePreset);
108-
knownBrightness = bri;
109-
knownEffectSpeed = effectSpeed;
110-
knownEffectIntensity = effectIntensity;
111-
knownMode = currentMode;
112-
knownPalette = currentPalette;
113-
return;
114-
}
115111

116112
unsigned long wouldAutoSaveAfter = now + autoSaveAfterSec*1000;
117113
if (knownBrightness != bri) {

usermods/usermod_v2_four_line_display/usermod_v2_four_line_display.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ class FourLineDisplayUsermod : public Usermod {
346346
(knownEffectIntensity != effectIntensity) ||
347347
(knownMode != strip.getMode()) ||
348348
(knownPalette != strip.getSegment(0).palette)) {
349-
knownHour = 99; // force time update
350-
clear();
349+
knownHour = 99; // force time update
350+
lastRedraw = now; // update lastRedraw marker
351351
} else if (sleepMode && !displayTurnedOff && ((now - lastRedraw)/1000)%5 == 0) {
352352
// change line every 5s
353353
showName = !showName;
@@ -372,23 +372,20 @@ class FourLineDisplayUsermod : public Usermod {
372372
break;
373373
}
374374
knownHour = 99; // force time update
375+
// do not update lastRedraw marker if just switching row contenet
375376
} else {
376377
// Nothing to change.
377378
// Turn off display after 3 minutes with no change.
378379
if(sleepMode && !displayTurnedOff && (millis() - lastRedraw > screenTimeout)) {
379380
// We will still check if there is a change in redraw()
380381
// and turn it back on if it changed.
381-
clear(); // force screen clear
382382
sleepOrClock(true);
383383
} else if (displayTurnedOff && clockMode) {
384384
showTime();
385385
}
386386
return;
387387
}
388388

389-
// do not update lastRedraw marker if just switching row contenet
390-
if (((now - lastRedraw)/1000)%5 != 0) lastRedraw = now;
391-
392389
// Turn the display back on
393390
if (displayTurnedOff) sleepOrClock(false);
394391

@@ -409,7 +406,7 @@ class FourLineDisplayUsermod : public Usermod {
409406
center(line, getCols()-2);
410407
drawString(1, 0, line.c_str());
411408
// Print `~` char to indicate that SSID is longer, than our display
412-
if (knownSsid.length() > getCols()-1) {
409+
if (knownSsid.length() > (int)getCols()-1) {
413410
drawString(getCols() - 1, 0, "~");
414411
}
415412

@@ -523,14 +520,23 @@ class FourLineDisplayUsermod : public Usermod {
523520
*/
524521
void overlay(const char* line1, const char *line2, long showHowLong) {
525522
if (displayTurnedOff) {
526-
// Turn the display back on
523+
// Turn the display back on (includes clear())
527524
sleepOrClock(false);
525+
} else {
526+
clear();
528527
}
529528

530529
// Print the overlay
531-
clear();
532-
if (line1) drawString(0, 1*lineHeight, line1);
533-
if (line2) drawString(0, 2*lineHeight, line2);
530+
if (line1) {
531+
String buf = line1;
532+
center(buf, getCols());
533+
drawString(0, 1*lineHeight, buf.c_str());
534+
}
535+
if (line2) {
536+
String buf = line2;
537+
center(buf, getCols());
538+
drawString(0, 2*lineHeight, buf.c_str());
539+
}
534540
overlayUntil = millis() + showHowLong;
535541
}
536542

@@ -557,6 +563,7 @@ class FourLineDisplayUsermod : public Usermod {
557563
* Enable sleep (turn the display off) or clock mode.
558564
*/
559565
void sleepOrClock(bool enabled) {
566+
clear();
560567
if (enabled) {
561568
if (clockMode) showTime();
562569
else setPowerSave(1);
@@ -582,8 +589,6 @@ class FourLineDisplayUsermod : public Usermod {
582589
if (knownMinute == minuteCurrent && knownHour == hourCurrent) {
583590
// Time hasn't changed.
584591
if (!fullScreen) return;
585-
} else {
586-
//if (fullScreen) clear();
587592
}
588593
knownMinute = minuteCurrent;
589594
knownHour = hourCurrent;

0 commit comments

Comments
 (0)