Bugfix for AutoSave & 4LD.
This commit is contained in:
parent
8d4636bbab
commit
d0440122b9
@ -38,7 +38,7 @@ class AutoSaveUsermod : public Usermod {
|
|||||||
bool applyAutoSaveOnBoot = false; // do we load auto-saved preset on boot?
|
bool applyAutoSaveOnBoot = false; // do we load auto-saved preset on boot?
|
||||||
|
|
||||||
// If we've detected the need to auto save, this will be non zero.
|
// If we've detected the need to auto save, this will be non zero.
|
||||||
uint16_t autoSaveAfter = 0;
|
unsigned long autoSaveAfter = 0;
|
||||||
|
|
||||||
uint8_t knownBrightness = 0;
|
uint8_t knownBrightness = 0;
|
||||||
uint8_t knownEffectSpeed = 0;
|
uint8_t knownEffectSpeed = 0;
|
||||||
@ -87,6 +87,12 @@ class AutoSaveUsermod : public Usermod {
|
|||||||
display = (FourLineDisplayUsermod*) usermods.lookup(USERMOD_ID_FOUR_LINE_DISP);
|
display = (FourLineDisplayUsermod*) usermods.lookup(USERMOD_ID_FOUR_LINE_DISP);
|
||||||
#endif
|
#endif
|
||||||
initDone = true;
|
initDone = true;
|
||||||
|
if (enabled && applyAutoSaveOnBoot) applyPreset(autoSavePreset);
|
||||||
|
knownBrightness = bri;
|
||||||
|
knownEffectSpeed = effectSpeed;
|
||||||
|
knownEffectIntensity = effectIntensity;
|
||||||
|
knownMode = strip.getMode();
|
||||||
|
knownPalette = strip.getSegment(0).palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
// gets called every time WiFi is (re-)connected. Initialize own network
|
// gets called every time WiFi is (re-)connected. Initialize own network
|
||||||
@ -97,21 +103,11 @@ class AutoSaveUsermod : public Usermod {
|
|||||||
* Da loop.
|
* Da loop.
|
||||||
*/
|
*/
|
||||||
void loop() {
|
void loop() {
|
||||||
if (!autoSaveAfterSec || !enabled || strip.isUpdating()) return; // setting 0 as autosave seconds disables autosave
|
if (!autoSaveAfterSec || !enabled || strip.isUpdating() || currentPreset>0) return; // setting 0 as autosave seconds disables autosave
|
||||||
|
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
uint8_t currentMode = strip.getMode();
|
uint8_t currentMode = strip.getMode();
|
||||||
uint8_t currentPalette = strip.getSegment(0).palette;
|
uint8_t currentPalette = strip.getSegment(0).palette;
|
||||||
if (firstLoop) {
|
|
||||||
firstLoop = false;
|
|
||||||
if (applyAutoSaveOnBoot) applyPreset(autoSavePreset);
|
|
||||||
knownBrightness = bri;
|
|
||||||
knownEffectSpeed = effectSpeed;
|
|
||||||
knownEffectIntensity = effectIntensity;
|
|
||||||
knownMode = currentMode;
|
|
||||||
knownPalette = currentPalette;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long wouldAutoSaveAfter = now + autoSaveAfterSec*1000;
|
unsigned long wouldAutoSaveAfter = now + autoSaveAfterSec*1000;
|
||||||
if (knownBrightness != bri) {
|
if (knownBrightness != bri) {
|
||||||
|
@ -346,8 +346,8 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
(knownEffectIntensity != effectIntensity) ||
|
(knownEffectIntensity != effectIntensity) ||
|
||||||
(knownMode != strip.getMode()) ||
|
(knownMode != strip.getMode()) ||
|
||||||
(knownPalette != strip.getSegment(0).palette)) {
|
(knownPalette != strip.getSegment(0).palette)) {
|
||||||
knownHour = 99; // force time update
|
knownHour = 99; // force time update
|
||||||
clear();
|
lastRedraw = now; // update lastRedraw marker
|
||||||
} else if (sleepMode && !displayTurnedOff && ((now - lastRedraw)/1000)%5 == 0) {
|
} else if (sleepMode && !displayTurnedOff && ((now - lastRedraw)/1000)%5 == 0) {
|
||||||
// change line every 5s
|
// change line every 5s
|
||||||
showName = !showName;
|
showName = !showName;
|
||||||
@ -372,13 +372,13 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
knownHour = 99; // force time update
|
knownHour = 99; // force time update
|
||||||
|
// do not update lastRedraw marker if just switching row contenet
|
||||||
} else {
|
} else {
|
||||||
// Nothing to change.
|
// Nothing to change.
|
||||||
// Turn off display after 3 minutes with no change.
|
// Turn off display after 3 minutes with no change.
|
||||||
if(sleepMode && !displayTurnedOff && (millis() - lastRedraw > screenTimeout)) {
|
if(sleepMode && !displayTurnedOff && (millis() - lastRedraw > screenTimeout)) {
|
||||||
// We will still check if there is a change in redraw()
|
// We will still check if there is a change in redraw()
|
||||||
// and turn it back on if it changed.
|
// and turn it back on if it changed.
|
||||||
clear(); // force screen clear
|
|
||||||
sleepOrClock(true);
|
sleepOrClock(true);
|
||||||
} else if (displayTurnedOff && clockMode) {
|
} else if (displayTurnedOff && clockMode) {
|
||||||
showTime();
|
showTime();
|
||||||
@ -386,9 +386,6 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not update lastRedraw marker if just switching row contenet
|
|
||||||
if (((now - lastRedraw)/1000)%5 != 0) lastRedraw = now;
|
|
||||||
|
|
||||||
// Turn the display back on
|
// Turn the display back on
|
||||||
if (displayTurnedOff) sleepOrClock(false);
|
if (displayTurnedOff) sleepOrClock(false);
|
||||||
|
|
||||||
@ -409,7 +406,7 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
center(line, getCols()-2);
|
center(line, getCols()-2);
|
||||||
drawString(1, 0, line.c_str());
|
drawString(1, 0, line.c_str());
|
||||||
// Print `~` char to indicate that SSID is longer, than our display
|
// Print `~` char to indicate that SSID is longer, than our display
|
||||||
if (knownSsid.length() > getCols()-1) {
|
if (knownSsid.length() > (int)getCols()-1) {
|
||||||
drawString(getCols() - 1, 0, "~");
|
drawString(getCols() - 1, 0, "~");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,14 +520,23 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
*/
|
*/
|
||||||
void overlay(const char* line1, const char *line2, long showHowLong) {
|
void overlay(const char* line1, const char *line2, long showHowLong) {
|
||||||
if (displayTurnedOff) {
|
if (displayTurnedOff) {
|
||||||
// Turn the display back on
|
// Turn the display back on (includes clear())
|
||||||
sleepOrClock(false);
|
sleepOrClock(false);
|
||||||
|
} else {
|
||||||
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the overlay
|
// Print the overlay
|
||||||
clear();
|
if (line1) {
|
||||||
if (line1) drawString(0, 1*lineHeight, line1);
|
String buf = line1;
|
||||||
if (line2) drawString(0, 2*lineHeight, line2);
|
center(buf, getCols());
|
||||||
|
drawString(0, 1*lineHeight, buf.c_str());
|
||||||
|
}
|
||||||
|
if (line2) {
|
||||||
|
String buf = line2;
|
||||||
|
center(buf, getCols());
|
||||||
|
drawString(0, 2*lineHeight, buf.c_str());
|
||||||
|
}
|
||||||
overlayUntil = millis() + showHowLong;
|
overlayUntil = millis() + showHowLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,6 +563,7 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
* Enable sleep (turn the display off) or clock mode.
|
* Enable sleep (turn the display off) or clock mode.
|
||||||
*/
|
*/
|
||||||
void sleepOrClock(bool enabled) {
|
void sleepOrClock(bool enabled) {
|
||||||
|
clear();
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
if (clockMode) showTime();
|
if (clockMode) showTime();
|
||||||
else setPowerSave(1);
|
else setPowerSave(1);
|
||||||
@ -582,8 +589,6 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
if (knownMinute == minuteCurrent && knownHour == hourCurrent) {
|
if (knownMinute == minuteCurrent && knownHour == hourCurrent) {
|
||||||
// Time hasn't changed.
|
// Time hasn't changed.
|
||||||
if (!fullScreen) return;
|
if (!fullScreen) return;
|
||||||
} else {
|
|
||||||
//if (fullScreen) clear();
|
|
||||||
}
|
}
|
||||||
knownMinute = minuteCurrent;
|
knownMinute = minuteCurrent;
|
||||||
knownHour = hourCurrent;
|
knownHour = hourCurrent;
|
||||||
|
Loading…
Reference in New Issue
Block a user