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;
bool initDone = false;
volatile bool drawing = false;
volatile bool lockRedraw = false;
// HW interface & configuration
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) {
if (type == NONE || !enabled) return;
drawing = true;
u8x8->setFont(u8x8_font_chroma48medium8_r);
if (!ignoreLH && lineHeight==2) u8x8->draw1x2String(col, row, string);
else u8x8->drawString(col, row, string);
drawing = false;
}
void draw2x2String(uint8_t col, uint8_t row, const char *string) {
if (type == NONE || !enabled) return;
drawing = true;
u8x8->setFont(u8x8_font_chroma48medium8_r);
u8x8->draw2x2String(col, row, string);
drawing = false;
}
void drawGlyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font, bool ignoreLH=false) {
if (type == NONE || !enabled) return;
drawing = true;
u8x8->setFont(font);
if (!ignoreLH && lineHeight==2) u8x8->draw1x2Glyph(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) {
if (type == NONE || !enabled) return;
drawing = true;
u8x8->setFont(font);
u8x8->draw2x2Glyph(col, row, glyph);
drawing = false;
}
uint8_t getCols() {
if (type==NONE || !enabled) return 0;
@ -224,7 +233,9 @@ class FourLineDisplayUsermod : public Usermod {
}
void clear() {
if (type == NONE || !enabled) return;
drawing = true;
u8x8->clear();
drawing = false;
}
void setPowerSave(uint8_t save) {
if (type == NONE || !enabled) return;
@ -238,6 +249,7 @@ class FourLineDisplayUsermod : public Usermod {
}
void draw2x2GlyphIcons() {
drawing = true;
if (lineHeight == 2) {
drawGlyph( 1, 0, 1, u8x8_4LineDisplay_WLED_icons_2x2, true); //brightness 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, 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;
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
while (drawing && millis()-now < 125) delay(1); // wait if someone else is drawing
if (drawing) return;
char lineBuffer[LINE_BUFFER_SIZE];
static byte lastSecond;
@ -299,7 +312,23 @@ class FourLineDisplayUsermod : public Usermod {
sprintf_P(lineBuffer, PSTR("%02d"), secondCurrent);
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:
@ -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) {
knownSsid = apSSID;
@ -546,7 +576,7 @@ class FourLineDisplayUsermod : public Usermod {
}
lastRedraw = now;
// Turn the display back on
wakeDisplay();
@ -580,44 +610,49 @@ class FourLineDisplayUsermod : public Usermod {
void updateBrightness() {
knownBrightness = bri;
if (overlayUntil == 0) {
lockRedraw = true;
brightness100 = ((uint16_t)bri*100)/255;
char lineBuffer[4];
sprintf_P(lineBuffer, PSTR("%-3d"), brightness100);
drawString(1, lineHeight, lineBuffer);
//lastRedraw = millis();
lockRedraw = false;
}
}
void updateSpeed() {
knownEffectSpeed = effectSpeed;
if (overlayUntil == 0) {
lockRedraw = true;
fxspeed100 = ((uint16_t)effectSpeed*100)/255;
char lineBuffer[4];
sprintf_P(lineBuffer, PSTR("%-3d"), fxspeed100);
drawString(5, lineHeight, lineBuffer);
//lastRedraw = millis();
lockRedraw = false;
}
}
void updateIntensity() {
knownEffectIntensity = effectIntensity;
if (overlayUntil == 0) {
lockRedraw = true;
fxintensity100 = ((uint16_t)effectIntensity*100)/255;
char lineBuffer[4];
sprintf_P(lineBuffer, PSTR("%-3d"), fxintensity100);
drawString(9, lineHeight, lineBuffer);
//lastRedraw = millis();
lockRedraw = false;
}
}
void drawStatusIcons() {
uint8_t col = 15;
uint8_t row = 0;
lockRedraw = true;
drawGlyph(col, row, (wificonnected ? 20 : 0), u8x8_4LineDisplay_WLED_icons_1x1, true); // wifi icon
if (lineHeight==2) { col--; } else { row++; }
drawGlyph(col, row, (bri > 0 ? 9 : 0), u8x8_4LineDisplay_WLED_icons_1x1, true); // power icon
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
lockRedraw = false;
}
/**
@ -632,7 +667,9 @@ class FourLineDisplayUsermod : public Usermod {
//Draw the arrow for the current setting beiong changed
void drawArrow() {
lockRedraw = true;
if (markColNum != 255 && markLineNum !=255) drawGlyph(markColNum, markLineNum*lineHeight, 21, u8x8_4LineDisplay_WLED_icons_1x1);
lockRedraw = false;
}
//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) {
char lineBuffer[MAX_JSON_CHARS];
if (overlayUntil == 0) {
lockRedraw = true;
// Find the mode name in JSON
uint8_t printedChars = extractModeName(inputEffPal, qstring, lineBuffer, MAX_JSON_CHARS-1);
if (lineBuffer[0]=='*' && lineBuffer[1]==' ') {
@ -692,6 +730,7 @@ class FourLineDisplayUsermod : public Usermod {
smallBuffer3[smallChars3] = 0;
drawString(1, row*lineHeight, smallBuffer3, true);
}
lockRedraw = false;
}
}
@ -706,12 +745,12 @@ class FourLineDisplayUsermod : public Usermod {
if (displayTurnedOff) {
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
if (drawing) return false;
lockRedraw = true;
clear();
// Turn the display back on
sleepOrClock(false);
//lastRedraw = millis();
drawing = false;
lockRedraw = false;
return true;
}
return false;
@ -724,8 +763,9 @@ class FourLineDisplayUsermod : public Usermod {
*/
void overlay(const char* line1, long showHowLong, byte glyphType) {
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
while (drawing && millis()-now < 125) delay(1); // wait if someone else is drawing
if (drawing) return;
lockRedraw = true;
// Turn the display back on
if (!wakeDisplay()) clear();
// Print the overlay
@ -739,7 +779,7 @@ class FourLineDisplayUsermod : public Usermod {
drawString(0, (glyphType<255?3:0)*lineHeight, buf.c_str());
}
overlayUntil = millis() + showHowLong;
drawing = false;
lockRedraw = false;
}
/**
@ -748,8 +788,9 @@ class FourLineDisplayUsermod : public Usermod {
*/
void overlayLogo(long showHowLong) {
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
while (drawing && millis()-now < 125) delay(1); // wait if someone else is drawing
if (drawing) return;
lockRedraw = true;
// Turn the display back on
if (!wakeDisplay()) clear();
// Print the overlay
@ -799,7 +840,7 @@ class FourLineDisplayUsermod : public Usermod {
}
}
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) {
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
while (drawing && millis()-now < 125) delay(1); // wait if someone else is drawing
if (drawing) return;
lockRedraw = true;
// Turn the display back on
if (!wakeDisplay()) clear();
// Print the overlay
@ -825,13 +867,14 @@ class FourLineDisplayUsermod : public Usermod {
drawString(0, 2*lineHeight, buf.c_str());
}
overlayUntil = millis() + showHowLong;
drawing = false;
lockRedraw = false;
}
void networkOverlay(const char* line1, long showHowLong) {
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
while (drawing && millis()-now < 125) delay(1); // wait if someone else is drawing
if (drawing) return;
lockRedraw = true;
String line;
// Turn the display back on
@ -863,27 +906,10 @@ class FourLineDisplayUsermod : public Usermod {
center(line, getCols());
drawString(0, lineHeight*3, line.c_str());
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
* will prevent button working in a default way.