usermod bugfixes
fixing some "missed corner cases" in popular usermods. * acessing unitialized arrays * trying to draw on a non-initialized display
This commit is contained in:
@@ -79,6 +79,10 @@ class AutoSaveUsermod : public Usermod {
|
||||
month(localTime), day(localTime),
|
||||
hour(localTime), minute(localTime), second(localTime));
|
||||
cacheInvalidate++; // force reload of presets
|
||||
DEBUG_PRINT(F("UM autosave: saving preset "));
|
||||
DEBUG_PRINT(autoSavePreset);
|
||||
DEBUG_PRINT(F(" => "));
|
||||
DEBUG_PRINTLN(presetNameBuffer);
|
||||
savePreset(autoSavePreset, presetNameBuffer);
|
||||
}
|
||||
|
||||
@@ -86,7 +90,7 @@ class AutoSaveUsermod : public Usermod {
|
||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||
if (display != nullptr) {
|
||||
display->wakeDisplay();
|
||||
display->overlay("Settings", "Auto Saved", 1500);
|
||||
if (display->canDraw()) display->overlay("Settings", "Auto Saved", 1500); // WLEDMM bugfix
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -215,12 +215,14 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
}
|
||||
void drawString(uint8_t col, uint8_t row, const char *string, bool ignoreLH=false) {
|
||||
if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
|
||||
u8x8->setFont(u8x8_font_chroma48medium8_r); // crashes randomly on ESP32
|
||||
if (!ignoreLH && lineHeight==2) u8x8->draw1x2String(col, row, string); // crashes randomly on ESP32
|
||||
if (u8x8 == nullptr) return;
|
||||
u8x8->setFont(u8x8_font_chroma48medium8_r);
|
||||
if (!ignoreLH && lineHeight==2) u8x8->draw1x2String(col, row, string);
|
||||
else u8x8->drawString(col, row, string);
|
||||
}
|
||||
void draw2x2String(uint8_t col, uint8_t row, const char *string) {
|
||||
if (!typeOK || !enabled) return;
|
||||
if (u8x8 == nullptr) return;
|
||||
u8x8->setFont(u8x8_font_chroma48medium8_r);
|
||||
u8x8->draw2x2String(col, row, string);
|
||||
}
|
||||
@@ -504,6 +506,7 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
|
||||
//function to to check if a redraw or overlay draw is active. Needed for UM Rotary, to avoid random/concurrent drawing
|
||||
bool canDraw(void) {
|
||||
if (!typeOK || !enabled || !initDone) return(false); // WLEDMM make sure the display is initialized before we try to draw on it
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(FLD_ESP32_USE_THREADS) // only necessary on ESP32
|
||||
if (drawing) return(false); // overlay draws someting
|
||||
if (reDrawing) return(false); // redraw task draws something
|
||||
@@ -781,6 +784,7 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
*/
|
||||
bool wakeDisplay() {
|
||||
if (!typeOK || !enabled) return false;
|
||||
if (!initDone) return false;
|
||||
if (displayTurnedOff) {
|
||||
unsigned long now = millis();
|
||||
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
|
||||
@@ -802,6 +806,7 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
*/
|
||||
void overlay(const char* line1, long showHowLong, byte glyphType) {
|
||||
if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
|
||||
if (!initDone) return; // WLEDMM bugfix
|
||||
unsigned long now = millis();
|
||||
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
|
||||
while ((reDrawing && overlayUntil == 0) && (millis()-now < 250)) delay(10); // wait if someone else is re-drawing
|
||||
@@ -828,6 +833,7 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
*/
|
||||
void overlayLogo(long showHowLong) {
|
||||
if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
|
||||
if (!initDone) return; // WLEDMM bugfix
|
||||
unsigned long now = millis();
|
||||
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
|
||||
drawing = true;
|
||||
@@ -890,6 +896,7 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
*/
|
||||
void overlay(const char* line1, const char* line2, long showHowLong) {
|
||||
if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
|
||||
if (!initDone) return; // WLEDMM bugfix
|
||||
unsigned long now = millis();
|
||||
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
|
||||
while ((reDrawing && overlayUntil == 0) && (millis()-now < 250)) delay(10); // wait if someone else is re-drawing
|
||||
@@ -913,6 +920,7 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
|
||||
void networkOverlay(const char* line1, long showHowLong) {
|
||||
if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
|
||||
if (!initDone) return; // WLEDMM bugfix
|
||||
unsigned long now = millis();
|
||||
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
|
||||
drawing = true;
|
||||
|
||||
@@ -348,8 +348,10 @@ public:
|
||||
findCurrentEffectAndPalette();
|
||||
}
|
||||
|
||||
if (modes_alpha_indexes[effectCurrentIndex] != effectCurrent || palettes_alpha_indexes[effectPaletteIndex] != effectPalette) {
|
||||
currentEffectAndPaletteInitialized = false;
|
||||
if (modes_alpha_indexes != nullptr) { // WLEDMM bugfix
|
||||
if (modes_alpha_indexes[effectCurrentIndex] != effectCurrent || palettes_alpha_indexes[effectPaletteIndex] != effectPalette) {
|
||||
currentEffectAndPaletteInitialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentTime - loopTime >= 2) // 2ms since last check of encoder = 500Hz
|
||||
@@ -469,11 +471,13 @@ public:
|
||||
|
||||
void displayNetworkInfo() {
|
||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||
if (display != nullptr)
|
||||
display->networkOverlay(PSTR("NETWORK INFO"), 10000);
|
||||
#endif
|
||||
}
|
||||
|
||||
void findCurrentEffectAndPalette() {
|
||||
if (modes_alpha_indexes == nullptr) return; // WLEDMM bugfix
|
||||
currentEffectAndPaletteInitialized = true;
|
||||
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
||||
if (modes_alpha_indexes[i] == effectCurrent) {
|
||||
@@ -541,7 +545,7 @@ public:
|
||||
display->updateRedrawTime();
|
||||
#endif
|
||||
effectCurrentIndex = max(min((increase ? effectCurrentIndex+1 : effectCurrentIndex-1), strip.getModeCount()-1), 0);
|
||||
effectCurrent = modes_alpha_indexes[effectCurrentIndex];
|
||||
if (modes_alpha_indexes != nullptr) effectCurrent = modes_alpha_indexes[effectCurrentIndex];
|
||||
stateChanged = true;
|
||||
if (applyToAll) {
|
||||
for (byte i=0; i<strip.getSegmentsNum(); i++) {
|
||||
@@ -936,7 +940,7 @@ public:
|
||||
enabled = false;
|
||||
return true;
|
||||
}
|
||||
setup();
|
||||
if (enabled) setup(); // WLEDMM no pin stealing!
|
||||
}
|
||||
}
|
||||
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
||||
|
||||
Reference in New Issue
Block a user