4LD & AutoSave usermod fixes.

Debugging usermod time.
This commit is contained in:
Blaz Kristan 2021-09-11 23:32:36 +02:00
parent c1d47290b1
commit 9be995bb08
4 changed files with 42 additions and 20 deletions

View File

@ -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;
@ -104,7 +104,7 @@ 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();

View File

@ -346,7 +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
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;
@ -371,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();
@ -385,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);
@ -522,13 +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
if (line1) drawString(0, 1*lineHeight, line1); if (line1) {
if (line2) drawString(0, 2*lineHeight, line2); String buf = line1;
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;
} }
@ -555,12 +563,12 @@ 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);
displayTurnedOff = true; displayTurnedOff = true;
} else { } else {
clear();
setPowerSave(0); setPowerSave(0);
displayTurnedOff = false; displayTurnedOff = false;
} }

View File

@ -204,6 +204,10 @@ void WiFiEvent(WiFiEvent_t event)
void WLED::loop() void WLED::loop()
{ {
#ifdef WLED_DEBUG
static unsigned long maxUsermodMillis = 0;
#endif
handleTime(); handleTime();
handleIR(); // 2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too handleIR(); // 2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too
handleConnection(); handleConnection();
@ -214,7 +218,15 @@ void WLED::loop()
handleDMX(); handleDMX();
#endif #endif
userLoop(); userLoop();
#ifdef WLED_DEBUG
unsigned long usermodMillis = millis();
#endif
usermods.loop(); usermods.loop();
#ifdef WLED_DEBUG
usermodMillis = millis() - usermodMillis;
if (usermodMillis > maxUsermodMillis) maxUsermodMillis = usermodMillis;
#endif
yield(); yield();
handleIO(); handleIO();
@ -312,7 +324,7 @@ void WLED::loop()
// DEBUG serial logging // DEBUG serial logging
#ifdef WLED_DEBUG #ifdef WLED_DEBUG
if (millis() - debugTime > 59999) { if (millis() - debugTime > 29999) {
DEBUG_PRINTLN(F("---DEBUG INFO---")); DEBUG_PRINTLN(F("---DEBUG INFO---"));
DEBUG_PRINT(F("Runtime: ")); DEBUG_PRINTLN(millis()); DEBUG_PRINT(F("Runtime: ")); DEBUG_PRINTLN(millis());
DEBUG_PRINT(F("Unix time: ")); toki.printTime(toki.getTime()); DEBUG_PRINT(F("Unix time: ")); toki.printTime(toki.getTime());
@ -324,17 +336,19 @@ void WLED::loop()
} else } else
DEBUG_PRINTLN(F("No PSRAM")); DEBUG_PRINTLN(F("No PSRAM"));
#endif #endif
DEBUG_PRINT(F("Wifi state: ")); DEBUG_PRINTLN(WiFi.status()); DEBUG_PRINT(F("Wifi state: ")); DEBUG_PRINTLN(WiFi.status());
if (WiFi.status() != lastWifiState) { if (WiFi.status() != lastWifiState) {
wifiStateChangedTime = millis(); wifiStateChangedTime = millis();
} }
lastWifiState = WiFi.status(); lastWifiState = WiFi.status();
DEBUG_PRINT(F("State time: ")); DEBUG_PRINTLN(wifiStateChangedTime); DEBUG_PRINT(F("State time: ")); DEBUG_PRINTLN(wifiStateChangedTime);
DEBUG_PRINT(F("NTP last sync: ")); DEBUG_PRINTLN(ntpLastSyncTime); DEBUG_PRINT(F("NTP last sync: ")); DEBUG_PRINTLN(ntpLastSyncTime);
DEBUG_PRINT(F("Client IP: ")); DEBUG_PRINTLN(Network.localIP()); DEBUG_PRINT(F("Client IP: ")); DEBUG_PRINTLN(Network.localIP());
DEBUG_PRINT(F("Loops/sec: ")); DEBUG_PRINTLN(loops / 10); DEBUG_PRINT(F("Loops/sec: ")); DEBUG_PRINTLN(loops / 60);
DEBUG_PRINT(F("Max UM time[ms]: ")); DEBUG_PRINTLN(maxUsermodMillis);
loops = 0; loops = 0;
maxUsermodMillis = 0;
debugTime = millis(); debugTime = millis();
} }
loops++; loops++;

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2109071 #define VERSION 2109111
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG
@ -566,7 +566,7 @@ WLED_GLOBAL JsonDocument* fileDoc;
WLED_GLOBAL bool doCloseFile _INIT(false); WLED_GLOBAL bool doCloseFile _INIT(false);
// presets // presets
WLED_GLOBAL int16_t currentPreset _INIT(-1); WLED_GLOBAL int8_t currentPreset _INIT(-1);
WLED_GLOBAL byte errorFlag _INIT(0); WLED_GLOBAL byte errorFlag _INIT(0);
@ -628,7 +628,7 @@ WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager());
WLED_GLOBAL unsigned long debugTime _INIT(0); WLED_GLOBAL unsigned long debugTime _INIT(0);
WLED_GLOBAL int lastWifiState _INIT(3); WLED_GLOBAL int lastWifiState _INIT(3);
WLED_GLOBAL unsigned long wifiStateChangedTime _INIT(0); WLED_GLOBAL unsigned long wifiStateChangedTime _INIT(0);
WLED_GLOBAL int loops _INIT(0); WLED_GLOBAL unsigned long loops _INIT(0);
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32