Modifications to 4LD

This commit is contained in:
Blaz Kristan 2022-01-02 11:28:44 +01:00
parent 1e947a34a8
commit 1ce325ee8a

View File

@ -264,7 +264,7 @@ class FourLineDisplayUsermod : public Usermod {
bool enabled = true; bool enabled = true;
// needRedraw marks if redraw is required to prevent often redrawing. // needRedraw marks if redraw is required to prevent often redrawing.
bool needRedraw = true; //bool needRedraw = true;
// Next variables hold the previous known values to determine if redraw is // Next variables hold the previous known values to determine if redraw is
// required. // required.
@ -466,6 +466,7 @@ class FourLineDisplayUsermod : public Usermod {
* or if forceRedraw). * or if forceRedraw).
*/ */
void redraw(bool forceRedraw) { void redraw(bool forceRedraw) {
bool needRedraw = false;
unsigned long now = millis(); unsigned long now = millis();
if (type == NONE || !enabled) return; if (type == NONE || !enabled) return;
@ -489,6 +490,7 @@ class FourLineDisplayUsermod : public Usermod {
} else if ((bri == 0 && powerON) || (bri > 0 && !powerON)) { //trigger power icon } else if ((bri == 0 && powerON) || (bri > 0 && !powerON)) { //trigger power icon
powerON = !powerON; powerON = !powerON;
drawStatusIcons(); drawStatusIcons();
updateBrightness();
lastRedraw = millis(); lastRedraw = millis();
return; return;
} else if (knownnightlight != nightlightActive) { //trigger moon icon } else if (knownnightlight != nightlightActive) { //trigger moon icon
@ -505,27 +507,27 @@ class FourLineDisplayUsermod : public Usermod {
} else if (knownMode != effectCurrent) { } else if (knownMode != effectCurrent) {
knownMode = effectCurrent; knownMode = effectCurrent;
if (displayTurnedOff) needRedraw = true; if (displayTurnedOff) needRedraw = true;
else showCurrentEffectOrPalette(knownMode, JSON_mode_names, 3); else { showCurrentEffectOrPalette(knownMode, JSON_mode_names, 3); return; }
} else if (knownPalette != effectPalette) { } else if (knownPalette != effectPalette) {
knownPalette = effectPalette; knownPalette = effectPalette;
if (displayTurnedOff) needRedraw = true; if (displayTurnedOff) needRedraw = true;
else showCurrentEffectOrPalette(knownPalette, JSON_palette_names, 2); else { showCurrentEffectOrPalette(knownPalette, JSON_palette_names, 2); return; }
} else if (knownBrightness != bri) { } else if (knownBrightness != bri) {
if (displayTurnedOff && nightlightActive) { needRedraw = false; knownBrightness = bri; } if (displayTurnedOff && nightlightActive) { needRedraw = false; knownBrightness = bri; }
else if (displayTurnedOff) needRedraw = true; else if (displayTurnedOff) needRedraw = true;
else updateBrightness(); else { updateBrightness(); return; }
} else if (knownEffectSpeed != effectSpeed) { } else if (knownEffectSpeed != effectSpeed) {
if (displayTurnedOff) needRedraw = true; if (displayTurnedOff) needRedraw = true;
else updateSpeed(); else { updateSpeed(); return; }
} else if (knownEffectIntensity != effectIntensity) { } else if (knownEffectIntensity != effectIntensity) {
if (displayTurnedOff) needRedraw = true; if (displayTurnedOff) needRedraw = true;
else updateIntensity(); else { updateIntensity(); return; }
} }
if (!needRedraw) { if (!needRedraw) {
// Nothing to change. // Nothing to change.
// Turn off display after 1 minutes with no change. // Turn off display after 1 minutes with no change.
if (sleepMode && !displayTurnedOff && (now - 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(); clear();
@ -536,14 +538,10 @@ class FourLineDisplayUsermod : public Usermod {
return; return;
} }
needRedraw = false; lastRedraw = now;
lastRedraw = millis();
if (displayTurnedOff) { // Turn the display back on
// Turn the display back on wakeDisplay();
sleepOrClock(false);
clear();
}
// Update last known values. // Update last known values.
knownBrightness = bri; knownBrightness = bri;
@ -707,12 +705,10 @@ class FourLineDisplayUsermod : public Usermod {
*/ */
bool wakeDisplay() { bool wakeDisplay() {
if (type == NONE || !enabled) return false; if (type == NONE || !enabled) return false;
knownHour = 99;
if (displayTurnedOff) { if (displayTurnedOff) {
clear(); clear();
// Turn the display back on // Turn the display back on
sleepOrClock(false); sleepOrClock(false);
redraw(true);
return true; return true;
} }
return false; return false;
@ -724,13 +720,9 @@ class FourLineDisplayUsermod : public Usermod {
* Clears the screen and prints. * Clears the screen and prints.
*/ */
void overlay(const char* line1, long showHowLong, byte glyphType) { void overlay(const char* line1, long showHowLong, byte glyphType) {
if (displayTurnedOff) { // Turn the display back on
// Turn the display back on wakeDisplay();
sleepOrClock(false);
}
// Print the overlay // Print the overlay
clear();
if (glyphType > 0) { if (glyphType > 0) {
if (lineHeight == 2) drawGlyph(5, 0, glyphType, u8x8_font_benji_custom_icons_6x6, true); if (lineHeight == 2) drawGlyph(5, 0, glyphType, u8x8_font_benji_custom_icons_6x6, true);
else drawGlyph(7, lineHeight, glyphType, u8x8_font_benji_custom_icons_2x2, true); else drawGlyph(7, lineHeight, glyphType, u8x8_font_benji_custom_icons_2x2, true);
@ -742,13 +734,9 @@ class FourLineDisplayUsermod : public Usermod {
} }
void networkOverlay(const char* line1, long showHowLong) { void networkOverlay(const char* line1, long showHowLong) {
if (displayTurnedOff) { // Turn the display back on
// Turn the display back on wakeDisplay();
sleepOrClock(false);
}
// Print the overlay // Print the overlay
clear();
// First row string
if (line1) { if (line1) {
String l1 = line1; String l1 = line1;
l1.trim(); l1.trim();
@ -785,15 +773,15 @@ class FourLineDisplayUsermod : public Usermod {
*/ */
void sleepOrClock(bool enabled) { void sleepOrClock(bool enabled) {
if (enabled) { if (enabled) {
displayTurnedOff = true;
if (clockMode) { if (clockMode) {
knownMinute = knownHour = 99; knownMinute = knownHour = 99;
showTime(); showTime();
} else } else
setPowerSave(1); setPowerSave(1);
displayTurnedOff = true;
} else { } else {
setPowerSave(0);
displayTurnedOff = false; displayTurnedOff = false;
setPowerSave(0);
} }
} }