Minor tweaks.

This commit is contained in:
Blaz Kristan 2021-04-12 23:32:54 +02:00
parent 6a096fbb27
commit 3623afa721
2 changed files with 8 additions and 2 deletions

View File

@ -104,7 +104,7 @@ class AutoSaveUsermod : public Usermod {
* Da loop. * Da loop.
*/ */
void loop() { void loop() {
if (!autoSaveAfterSec || !bri) return; // setting 0 as autosave seconds disables autosave as does 0 brightness if (!autoSaveAfterSec) 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

@ -630,6 +630,8 @@ class FourLineDisplayUsermod : public Usermod {
*/ */
void readFromJsonState(JsonObject& root) { void readFromJsonState(JsonObject& root) {
if (!initDone) return; // prevent crash on boot applyPreset() if (!initDone) return; // prevent crash on boot applyPreset()
bool needsRedraw = false;
DisplayType newType = type; DisplayType newType = type;
int8_t newScl = sclPin; int8_t newScl = sclPin;
int8_t newSda = sdaPin; int8_t newSda = sdaPin;
@ -643,6 +645,7 @@ class FourLineDisplayUsermod : public Usermod {
if (root[F("4LineDisplay_contrast")] != nullptr) { if (root[F("4LineDisplay_contrast")] != nullptr) {
contrast = min(255,max(1,(int)root[F("4LineDisplay_contrast")])); contrast = min(255,max(1,(int)root[F("4LineDisplay_contrast")]));
setContrast(contrast); setContrast(contrast);
needsRedraw |= true;
} }
if (root[F("4LineDisplay_refreshRate")] != nullptr) refreshRate = min(60,max(1,(int)root[F("4LineDisplay_refreshRate")]))*1000; if (root[F("4LineDisplay_refreshRate")] != nullptr) refreshRate = min(60,max(1,(int)root[F("4LineDisplay_refreshRate")]))*1000;
if (root[F("4LineDisplay_screenTimeOut")] != nullptr) screenTimeout = min(900,max(0,(int)root[F("4LineDisplay_screenTimeOut")]))*1000; if (root[F("4LineDisplay_screenTimeOut")] != nullptr) screenTimeout = min(900,max(0,(int)root[F("4LineDisplay_screenTimeOut")]))*1000;
@ -650,6 +653,7 @@ class FourLineDisplayUsermod : public Usermod {
String str = root[F("4LineDisplay_flip")]; // checkbox -> off or on String str = root[F("4LineDisplay_flip")]; // checkbox -> off or on
flip = (bool)(str!="off"); // off is guaranteed to be present flip = (bool)(str!="off"); // off is guaranteed to be present
setFlipMode(flip); setFlipMode(flip);
needsRedraw |= true;
} }
if (root[F("4LineDisplay_sleepMode")] != nullptr) { if (root[F("4LineDisplay_sleepMode")] != nullptr) {
String str = root[F("4LineDisplay_sleepMode")]; // checkbox -> off or on String str = root[F("4LineDisplay_sleepMode")]; // checkbox -> off or on
@ -659,6 +663,7 @@ class FourLineDisplayUsermod : public Usermod {
String str = root[F("4LineDisplay_clockMode")]; // checkbox -> off or on String str = root[F("4LineDisplay_clockMode")]; // checkbox -> off or on
clockMode = (bool)(str!="off"); // off is guaranteed to be present clockMode = (bool)(str!="off"); // off is guaranteed to be present
setLineThreeType(clockMode ? FLD_LINE_3_MODE : FLD_LINE_3_BRIGHTNESS); setLineThreeType(clockMode ? FLD_LINE_3_MODE : FLD_LINE_3_BRIGHTNESS);
needsRedraw |= true;
} }
if (sclPin!=newScl || sdaPin!=newSda || type!=newType) { if (sclPin!=newScl || sdaPin!=newSda || type!=newType) {
@ -675,8 +680,9 @@ class FourLineDisplayUsermod : public Usermod {
type = newType; type = newType;
lineHeight = type==SH1106 ? 2 : 1; lineHeight = type==SH1106 ? 2 : 1;
setup(); setup();
needRedraw |= true;
} }
if (!wakeDisplay()) redraw(true); if (needsRedraw && !wakeDisplay()) redraw(true);
} }
/* /*