This commit is contained in:
Blaz Kristan 2023-03-19 14:26:54 +01:00
parent 11b687cdc2
commit 2e362fbb64

View File

@ -106,6 +106,7 @@ class FourLineDisplayUsermod : public Usermod {
static FourLineDisplayUsermod *instance; static FourLineDisplayUsermod *instance;
bool initDone = false; bool initDone = false;
volatile bool drawing = false; volatile bool drawing = false;
volatile bool lockRedraw = false;
// HW interface & configuration // HW interface & configuration
U8X8 *u8x8 = nullptr; // pointer to U8X8 display object U8X8 *u8x8 = nullptr; // pointer to U8X8 display object
@ -198,25 +199,33 @@ class FourLineDisplayUsermod : public Usermod {
} }
void drawString(uint8_t col, uint8_t row, const char *string, bool ignoreLH=false) { void drawString(uint8_t col, uint8_t row, const char *string, bool ignoreLH=false) {
if (type == NONE || !enabled) return; if (type == NONE || !enabled) return;
drawing = true;
u8x8->setFont(u8x8_font_chroma48medium8_r); u8x8->setFont(u8x8_font_chroma48medium8_r);
if (!ignoreLH && lineHeight==2) u8x8->draw1x2String(col, row, string); if (!ignoreLH && lineHeight==2) u8x8->draw1x2String(col, row, string);
else u8x8->drawString(col, row, string); else u8x8->drawString(col, row, string);
drawing = false;
} }
void draw2x2String(uint8_t col, uint8_t row, const char *string) { void draw2x2String(uint8_t col, uint8_t row, const char *string) {
if (type == NONE || !enabled) return; if (type == NONE || !enabled) return;
drawing = true;
u8x8->setFont(u8x8_font_chroma48medium8_r); u8x8->setFont(u8x8_font_chroma48medium8_r);
u8x8->draw2x2String(col, row, string); u8x8->draw2x2String(col, row, string);
drawing = false;
} }
void drawGlyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font, bool ignoreLH=false) { void drawGlyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font, bool ignoreLH=false) {
if (type == NONE || !enabled) return; if (type == NONE || !enabled) return;
drawing = true;
u8x8->setFont(font); u8x8->setFont(font);
if (!ignoreLH && lineHeight==2) u8x8->draw1x2Glyph(col, row, glyph); if (!ignoreLH && lineHeight==2) u8x8->draw1x2Glyph(col, row, glyph);
else u8x8->drawGlyph(col, row, glyph); else u8x8->drawGlyph(col, row, glyph);
drawing = false;
} }
void draw2x2Glyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font) { void draw2x2Glyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font) {
if (type == NONE || !enabled) return; if (type == NONE || !enabled) return;
drawing = true;
u8x8->setFont(font); u8x8->setFont(font);
u8x8->draw2x2Glyph(col, row, glyph); u8x8->draw2x2Glyph(col, row, glyph);
drawing = false;
} }
uint8_t getCols() { uint8_t getCols() {
if (type==NONE || !enabled) return 0; if (type==NONE || !enabled) return 0;
@ -224,7 +233,9 @@ class FourLineDisplayUsermod : public Usermod {
} }
void clear() { void clear() {
if (type == NONE || !enabled) return; if (type == NONE || !enabled) return;
drawing = true;
u8x8->clear(); u8x8->clear();
drawing = false;
} }
void setPowerSave(uint8_t save) { void setPowerSave(uint8_t save) {
if (type == NONE || !enabled) return; if (type == NONE || !enabled) return;
@ -238,6 +249,7 @@ class FourLineDisplayUsermod : public Usermod {
} }
void draw2x2GlyphIcons() { void draw2x2GlyphIcons() {
drawing = true;
if (lineHeight == 2) { if (lineHeight == 2) {
drawGlyph( 1, 0, 1, u8x8_4LineDisplay_WLED_icons_2x2, true); //brightness icon drawGlyph( 1, 0, 1, u8x8_4LineDisplay_WLED_icons_2x2, true); //brightness icon
drawGlyph( 5, 0, 2, u8x8_4LineDisplay_WLED_icons_2x2, true); //speed icon drawGlyph( 5, 0, 2, u8x8_4LineDisplay_WLED_icons_2x2, true); //speed icon
@ -251,6 +263,7 @@ class FourLineDisplayUsermod : public Usermod {
drawGlyph(15, 2, 4, u8x8_4LineDisplay_WLED_icons_1x1); //palette icon drawGlyph(15, 2, 4, u8x8_4LineDisplay_WLED_icons_1x1); //palette icon
drawGlyph(15, 3, 5, u8x8_4LineDisplay_WLED_icons_1x1); //effect icon drawGlyph(15, 3, 5, u8x8_4LineDisplay_WLED_icons_1x1); //effect icon
} }
drawing = false;
} }
/** /**
@ -262,8 +275,8 @@ class FourLineDisplayUsermod : public Usermod {
if (type == NONE || !enabled || !displayTurnedOff) return; if (type == NONE || !enabled || !displayTurnedOff) return;
unsigned long now = millis(); unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing while (drawing && millis()-now < 125) delay(1); // wait if someone else is drawing
drawing = true; if (drawing) return;
char lineBuffer[LINE_BUFFER_SIZE]; char lineBuffer[LINE_BUFFER_SIZE];
static byte lastSecond; static byte lastSecond;
@ -299,7 +312,23 @@ class FourLineDisplayUsermod : public Usermod {
sprintf_P(lineBuffer, PSTR("%02d"), secondCurrent); sprintf_P(lineBuffer, PSTR("%02d"), secondCurrent);
drawString(12, lineHeight*2+1, lineBuffer, true); // even with double sized rows print seconds in 1 line drawString(12, lineHeight*2+1, lineBuffer, true); // even with double sized rows print seconds in 1 line
} }
drawing = false; }
/**
* Enable sleep (turn the display off) or clock mode.
*/
void sleepOrClock(bool enabled) {
if (enabled) {
displayTurnedOff = true;
if (clockMode && ntpEnabled) {
knownMinute = knownHour = 99;
showTime();
} else
setPowerSave(1);
} else {
displayTurnedOff = false;
setPowerSave(0);
}
} }
public: public:
@ -483,7 +512,8 @@ class FourLineDisplayUsermod : public Usermod {
} }
} }
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing while (drawing && millis()-now < 25) delay(1); // wait if someone else is drawing
if (drawing || lockRedraw) return;
if (apActive && WLED_WIFI_CONFIGURED && now<15000) { if (apActive && WLED_WIFI_CONFIGURED && now<15000) {
knownSsid = apSSID; knownSsid = apSSID;
@ -546,7 +576,7 @@ class FourLineDisplayUsermod : public Usermod {
} }
lastRedraw = now; lastRedraw = now;
// Turn the display back on // Turn the display back on
wakeDisplay(); wakeDisplay();
@ -580,44 +610,49 @@ class FourLineDisplayUsermod : public Usermod {
void updateBrightness() { void updateBrightness() {
knownBrightness = bri; knownBrightness = bri;
if (overlayUntil == 0) { if (overlayUntil == 0) {
lockRedraw = true;
brightness100 = ((uint16_t)bri*100)/255; brightness100 = ((uint16_t)bri*100)/255;
char lineBuffer[4]; char lineBuffer[4];
sprintf_P(lineBuffer, PSTR("%-3d"), brightness100); sprintf_P(lineBuffer, PSTR("%-3d"), brightness100);
drawString(1, lineHeight, lineBuffer); drawString(1, lineHeight, lineBuffer);
//lastRedraw = millis(); lockRedraw = false;
} }
} }
void updateSpeed() { void updateSpeed() {
knownEffectSpeed = effectSpeed; knownEffectSpeed = effectSpeed;
if (overlayUntil == 0) { if (overlayUntil == 0) {
lockRedraw = true;
fxspeed100 = ((uint16_t)effectSpeed*100)/255; fxspeed100 = ((uint16_t)effectSpeed*100)/255;
char lineBuffer[4]; char lineBuffer[4];
sprintf_P(lineBuffer, PSTR("%-3d"), fxspeed100); sprintf_P(lineBuffer, PSTR("%-3d"), fxspeed100);
drawString(5, lineHeight, lineBuffer); drawString(5, lineHeight, lineBuffer);
//lastRedraw = millis(); lockRedraw = false;
} }
} }
void updateIntensity() { void updateIntensity() {
knownEffectIntensity = effectIntensity; knownEffectIntensity = effectIntensity;
if (overlayUntil == 0) { if (overlayUntil == 0) {
lockRedraw = true;
fxintensity100 = ((uint16_t)effectIntensity*100)/255; fxintensity100 = ((uint16_t)effectIntensity*100)/255;
char lineBuffer[4]; char lineBuffer[4];
sprintf_P(lineBuffer, PSTR("%-3d"), fxintensity100); sprintf_P(lineBuffer, PSTR("%-3d"), fxintensity100);
drawString(9, lineHeight, lineBuffer); drawString(9, lineHeight, lineBuffer);
//lastRedraw = millis(); lockRedraw = false;
} }
} }
void drawStatusIcons() { void drawStatusIcons() {
uint8_t col = 15; uint8_t col = 15;
uint8_t row = 0; uint8_t row = 0;
lockRedraw = true;
drawGlyph(col, row, (wificonnected ? 20 : 0), u8x8_4LineDisplay_WLED_icons_1x1, true); // wifi icon drawGlyph(col, row, (wificonnected ? 20 : 0), u8x8_4LineDisplay_WLED_icons_1x1, true); // wifi icon
if (lineHeight==2) { col--; } else { row++; } if (lineHeight==2) { col--; } else { row++; }
drawGlyph(col, row, (bri > 0 ? 9 : 0), u8x8_4LineDisplay_WLED_icons_1x1, true); // power icon drawGlyph(col, row, (bri > 0 ? 9 : 0), u8x8_4LineDisplay_WLED_icons_1x1, true); // power icon
if (lineHeight==2) { col--; } else { col = row = 0; } if (lineHeight==2) { col--; } else { col = row = 0; }
drawGlyph(col, row, (nightlightActive ? 6 : 0), u8x8_4LineDisplay_WLED_icons_1x1, true); // moon icon for nighlight mode drawGlyph(col, row, (nightlightActive ? 6 : 0), u8x8_4LineDisplay_WLED_icons_1x1, true); // moon icon for nighlight mode
lockRedraw = false;
} }
/** /**
@ -632,7 +667,9 @@ class FourLineDisplayUsermod : public Usermod {
//Draw the arrow for the current setting beiong changed //Draw the arrow for the current setting beiong changed
void drawArrow() { void drawArrow() {
lockRedraw = true;
if (markColNum != 255 && markLineNum !=255) drawGlyph(markColNum, markLineNum*lineHeight, 21, u8x8_4LineDisplay_WLED_icons_1x1); if (markColNum != 255 && markLineNum !=255) drawGlyph(markColNum, markLineNum*lineHeight, 21, u8x8_4LineDisplay_WLED_icons_1x1);
lockRedraw = false;
} }
//Display the current effect or palette (desiredEntry) //Display the current effect or palette (desiredEntry)
@ -640,6 +677,7 @@ class FourLineDisplayUsermod : public Usermod {
void showCurrentEffectOrPalette(int inputEffPal, const char *qstring, uint8_t row) { void showCurrentEffectOrPalette(int inputEffPal, const char *qstring, uint8_t row) {
char lineBuffer[MAX_JSON_CHARS]; char lineBuffer[MAX_JSON_CHARS];
if (overlayUntil == 0) { if (overlayUntil == 0) {
lockRedraw = true;
// Find the mode name in JSON // Find the mode name in JSON
uint8_t printedChars = extractModeName(inputEffPal, qstring, lineBuffer, MAX_JSON_CHARS-1); uint8_t printedChars = extractModeName(inputEffPal, qstring, lineBuffer, MAX_JSON_CHARS-1);
if (lineBuffer[0]=='*' && lineBuffer[1]==' ') { if (lineBuffer[0]=='*' && lineBuffer[1]==' ') {
@ -692,6 +730,7 @@ class FourLineDisplayUsermod : public Usermod {
smallBuffer3[smallChars3] = 0; smallBuffer3[smallChars3] = 0;
drawString(1, row*lineHeight, smallBuffer3, true); drawString(1, row*lineHeight, smallBuffer3, true);
} }
lockRedraw = false;
} }
} }
@ -706,12 +745,12 @@ class FourLineDisplayUsermod : public Usermod {
if (displayTurnedOff) { if (displayTurnedOff) {
unsigned long now = millis(); unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true; if (drawing) return false;
lockRedraw = true;
clear(); clear();
// Turn the display back on // Turn the display back on
sleepOrClock(false); sleepOrClock(false);
//lastRedraw = millis(); lockRedraw = false;
drawing = false;
return true; return true;
} }
return false; return false;
@ -724,8 +763,9 @@ class FourLineDisplayUsermod : public Usermod {
*/ */
void overlay(const char* line1, long showHowLong, byte glyphType) { void overlay(const char* line1, long showHowLong, byte glyphType) {
unsigned long now = millis(); unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing while (drawing && millis()-now < 125) delay(1); // wait if someone else is drawing
drawing = true; if (drawing) return;
lockRedraw = true;
// Turn the display back on // Turn the display back on
if (!wakeDisplay()) clear(); if (!wakeDisplay()) clear();
// Print the overlay // Print the overlay
@ -739,7 +779,7 @@ class FourLineDisplayUsermod : public Usermod {
drawString(0, (glyphType<255?3:0)*lineHeight, buf.c_str()); drawString(0, (glyphType<255?3:0)*lineHeight, buf.c_str());
} }
overlayUntil = millis() + showHowLong; overlayUntil = millis() + showHowLong;
drawing = false; lockRedraw = false;
} }
/** /**
@ -748,8 +788,9 @@ class FourLineDisplayUsermod : public Usermod {
*/ */
void overlayLogo(long showHowLong) { void overlayLogo(long showHowLong) {
unsigned long now = millis(); unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing while (drawing && millis()-now < 125) delay(1); // wait if someone else is drawing
drawing = true; if (drawing) return;
lockRedraw = true;
// Turn the display back on // Turn the display back on
if (!wakeDisplay()) clear(); if (!wakeDisplay()) clear();
// Print the overlay // Print the overlay
@ -799,7 +840,7 @@ class FourLineDisplayUsermod : public Usermod {
} }
} }
overlayUntil = millis() + showHowLong; overlayUntil = millis() + showHowLong;
drawing = false; lockRedraw = false;
} }
/** /**
@ -809,8 +850,9 @@ class FourLineDisplayUsermod : public Usermod {
*/ */
void overlay(const char* line1, const char* line2, long showHowLong) { void overlay(const char* line1, const char* line2, long showHowLong) {
unsigned long now = millis(); unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing while (drawing && millis()-now < 125) delay(1); // wait if someone else is drawing
drawing = true; if (drawing) return;
lockRedraw = true;
// Turn the display back on // Turn the display back on
if (!wakeDisplay()) clear(); if (!wakeDisplay()) clear();
// Print the overlay // Print the overlay
@ -825,13 +867,14 @@ class FourLineDisplayUsermod : public Usermod {
drawString(0, 2*lineHeight, buf.c_str()); drawString(0, 2*lineHeight, buf.c_str());
} }
overlayUntil = millis() + showHowLong; overlayUntil = millis() + showHowLong;
drawing = false; lockRedraw = false;
} }
void networkOverlay(const char* line1, long showHowLong) { void networkOverlay(const char* line1, long showHowLong) {
unsigned long now = millis(); unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing while (drawing && millis()-now < 125) delay(1); // wait if someone else is drawing
drawing = true; if (drawing) return;
lockRedraw = true;
String line; String line;
// Turn the display back on // Turn the display back on
@ -863,27 +906,10 @@ class FourLineDisplayUsermod : public Usermod {
center(line, getCols()); center(line, getCols());
drawString(0, lineHeight*3, line.c_str()); drawString(0, lineHeight*3, line.c_str());
overlayUntil = millis() + showHowLong; overlayUntil = millis() + showHowLong;
drawing = false; lockRedraw = false;
} }
/**
* Enable sleep (turn the display off) or clock mode.
*/
void sleepOrClock(bool enabled) {
if (enabled) {
displayTurnedOff = true;
if (clockMode && ntpEnabled) {
knownMinute = knownHour = 99;
showTime();
} else
setPowerSave(1);
} else {
displayTurnedOff = false;
setPowerSave(0);
}
}
/** /**
* handleButton() can be used to override default button behaviour. Returning true * handleButton() can be used to override default button behaviour. Returning true
* will prevent button working in a default way. * will prevent button working in a default way.