Optimised 4 Line Display.
Added option to display Ethernet IP.
This commit is contained in:
parent
8517cc8211
commit
28bc07da2f
@ -54,11 +54,12 @@
|
|||||||
#define LINE_BUFFER_SIZE 16+1
|
#define LINE_BUFFER_SIZE 16+1
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
FLD_LINE_4_BRIGHTNESS = 0,
|
FLD_LINE_BRIGHTNESS = 0,
|
||||||
FLD_LINE_4_EFFECT_SPEED,
|
FLD_LINE_EFFECT_SPEED,
|
||||||
FLD_LINE_4_EFFECT_INTENSITY,
|
FLD_LINE_EFFECT_INTENSITY,
|
||||||
FLD_LINE_4_MODE,
|
FLD_LINE_MODE,
|
||||||
FLD_LINE_4_PALETTE
|
FLD_LINE_PALETTE,
|
||||||
|
FLD_LINE_TIME
|
||||||
} Line4Type;
|
} Line4Type;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -87,9 +88,6 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
bool sleepMode = true; // allow screen sleep?
|
bool sleepMode = true; // allow screen sleep?
|
||||||
bool clockMode = false; // display clock
|
bool clockMode = false; // display clock
|
||||||
|
|
||||||
// needRedraw marks if redraw is required to prevent often redrawing.
|
|
||||||
bool needRedraw = true;
|
|
||||||
|
|
||||||
// Next variables hold the previous known values to determine if redraw is
|
// Next variables hold the previous known values to determine if redraw is
|
||||||
// required.
|
// required.
|
||||||
String knownSsid = "";
|
String knownSsid = "";
|
||||||
@ -106,7 +104,7 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
unsigned long lastUpdate = 0;
|
unsigned long lastUpdate = 0;
|
||||||
unsigned long lastRedraw = 0;
|
unsigned long lastRedraw = 0;
|
||||||
unsigned long overlayUntil = 0;
|
unsigned long overlayUntil = 0;
|
||||||
Line4Type lineFourType = FLD_LINE_4_BRIGHTNESS;
|
Line4Type lineType = FLD_LINE_BRIGHTNESS;
|
||||||
// Set to 2 or 3 to mark lines 2 or 3. Other values ignored.
|
// Set to 2 or 3 to mark lines 2 or 3. Other values ignored.
|
||||||
byte markLineNum = 0;
|
byte markLineNum = 0;
|
||||||
|
|
||||||
@ -232,10 +230,11 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
*/
|
*/
|
||||||
void redraw(bool forceRedraw) {
|
void redraw(bool forceRedraw) {
|
||||||
static bool showName = false;
|
static bool showName = false;
|
||||||
|
unsigned long now = millis();
|
||||||
|
|
||||||
if (type==NONE) return;
|
if (type==NONE) return;
|
||||||
if (overlayUntil > 0) {
|
if (overlayUntil > 0) {
|
||||||
if (millis() >= overlayUntil) {
|
if (now >= overlayUntil) {
|
||||||
// Time to display the overlay has elapsed.
|
// Time to display the overlay has elapsed.
|
||||||
overlayUntil = 0;
|
overlayUntil = 0;
|
||||||
forceRedraw = true;
|
forceRedraw = true;
|
||||||
@ -247,83 +246,62 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if values which are shown on display changed from the last time.
|
// Check if values which are shown on display changed from the last time.
|
||||||
if (forceRedraw) {
|
if (forceRedraw ||
|
||||||
needRedraw = true;
|
(((apActive) ? String(apSSID) : WiFi.SSID()) != knownSsid) ||
|
||||||
} else if (((apActive) ? String(apSSID) : WiFi.SSID()) != knownSsid) {
|
(knownIp != (apActive ? IPAddress(4, 3, 2, 1) : Network.localIP())) ||
|
||||||
needRedraw = true;
|
(knownBrightness != bri) ||
|
||||||
} else if (knownIp != (apActive ? IPAddress(4, 3, 2, 1) : WiFi.localIP())) {
|
(knownEffectSpeed != effectSpeed) ||
|
||||||
needRedraw = true;
|
(knownEffectIntensity != effectIntensity) ||
|
||||||
} else if (knownBrightness != bri) {
|
(knownMode != strip.getMode()) ||
|
||||||
needRedraw = true;
|
(knownPalette != strip.getSegment(0).palette)) {
|
||||||
} else if (knownEffectSpeed != effectSpeed) {
|
knownHour = 99; // force time update
|
||||||
needRedraw = true;
|
clear();
|
||||||
} else if (knownEffectIntensity != effectIntensity) {
|
} else if (sleepMode && !displayTurnedOff && ((now - lastRedraw)/1000)%5 == 0) {
|
||||||
needRedraw = true;
|
// change line every 5s
|
||||||
} else if (knownMode != strip.getMode()) {
|
showName = !showName;
|
||||||
needRedraw = true;
|
switch (lineType) {
|
||||||
} else if (knownPalette != strip.getSegment(0).palette) {
|
case FLD_LINE_BRIGHTNESS:
|
||||||
needRedraw = true;
|
lineType = FLD_LINE_EFFECT_SPEED;
|
||||||
}
|
break;
|
||||||
|
case FLD_LINE_MODE:
|
||||||
if (!needRedraw) {
|
lineType = FLD_LINE_BRIGHTNESS;
|
||||||
|
break;
|
||||||
|
case FLD_LINE_PALETTE:
|
||||||
|
lineType = clockMode ? FLD_LINE_MODE : FLD_LINE_BRIGHTNESS;
|
||||||
|
break;
|
||||||
|
case FLD_LINE_EFFECT_SPEED:
|
||||||
|
lineType = FLD_LINE_EFFECT_INTENSITY;
|
||||||
|
break;
|
||||||
|
case FLD_LINE_EFFECT_INTENSITY:
|
||||||
|
lineType = FLD_LINE_PALETTE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
lineType = FLD_LINE_MODE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
knownHour = 99; // force time update
|
||||||
|
} 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.
|
||||||
knownHour = 99; // force screen clear
|
clear(); // force screen clear
|
||||||
sleepOrClock(true);
|
sleepOrClock(true);
|
||||||
} else if (displayTurnedOff && clockMode) {
|
} else if (displayTurnedOff && clockMode) {
|
||||||
showTime();
|
showTime();
|
||||||
} else if ((millis() - lastRedraw)/1000%3 == 0) {
|
|
||||||
// alternate IP address and server name
|
|
||||||
String serverName = serverDescription;
|
|
||||||
if (serverName != String("WLED")) {
|
|
||||||
showName = !showName;
|
|
||||||
for (uint8_t i=serverName.length(); i<getCols()-1; i++) serverName += ' ';
|
|
||||||
//drawGlyph(0, lineHeight, 68, u8x8_font_open_iconic_embedded_1x1); // wifi icon
|
|
||||||
if (showName) drawString(1, lineHeight, serverName.c_str());
|
|
||||||
else drawString(1, lineHeight, ((WiFi.localIP()).toString()).c_str());
|
|
||||||
}
|
|
||||||
// change 4th line every 3s
|
|
||||||
switch (lineFourType) {
|
|
||||||
case FLD_LINE_4_BRIGHTNESS:
|
|
||||||
setLineFourType(FLD_LINE_4_EFFECT_SPEED);
|
|
||||||
break;
|
|
||||||
case FLD_LINE_4_MODE:
|
|
||||||
setLineFourType(FLD_LINE_4_BRIGHTNESS);
|
|
||||||
break;
|
|
||||||
case FLD_LINE_4_PALETTE:
|
|
||||||
setLineFourType(clockMode ? FLD_LINE_4_MODE : FLD_LINE_4_BRIGHTNESS);
|
|
||||||
break;
|
|
||||||
case FLD_LINE_4_EFFECT_SPEED:
|
|
||||||
setLineFourType(FLD_LINE_4_EFFECT_INTENSITY);
|
|
||||||
break;
|
|
||||||
case FLD_LINE_4_EFFECT_INTENSITY:
|
|
||||||
setLineFourType(FLD_LINE_4_PALETTE);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
drawLineFour();
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
knownHour = 99; // force time display
|
|
||||||
clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
needRedraw = false;
|
if (((now - lastRedraw)/1000)%5 != 0) lastRedraw = now;
|
||||||
lastRedraw = millis();
|
|
||||||
|
|
||||||
if (displayTurnedOff) {
|
// Turn the display back on
|
||||||
// Turn the display back on
|
if (displayTurnedOff) sleepOrClock(false);
|
||||||
sleepOrClock(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update last known values.
|
// Update last known values.
|
||||||
knownSsid = apActive ? WiFi.softAPSSID() : WiFi.SSID();
|
knownSsid = apActive ? WiFi.softAPSSID() : WiFi.SSID();
|
||||||
knownIp = apActive ? IPAddress(4, 3, 2, 1) : WiFi.localIP();
|
knownIp = apActive ? IPAddress(4, 3, 2, 1) : Network.localIP();
|
||||||
knownBrightness = bri;
|
knownBrightness = bri;
|
||||||
knownMode = strip.getMode();
|
knownMode = strip.getMode();
|
||||||
knownPalette = strip.getSegment(0).palette;
|
knownPalette = strip.getSegment(0).palette;
|
||||||
@ -347,41 +325,50 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
if (apActive && bri == 0) {
|
if (apActive && bri == 0) {
|
||||||
drawString(1, lineHeight, apPass);
|
drawString(1, lineHeight, apPass);
|
||||||
} else {
|
} else {
|
||||||
drawString(1, lineHeight, (knownIp.toString()).c_str());
|
// alternate IP address and server name
|
||||||
|
String serverName = serverDescription;
|
||||||
|
if (serverName != String("WLED")) {
|
||||||
|
for (uint8_t i=serverName.length(); i<getCols()-1; i++) serverName += ' ';
|
||||||
|
//drawGlyph(0, lineHeight, 68, u8x8_font_open_iconic_embedded_1x1); // wifi icon
|
||||||
|
if (showName) drawString(1, lineHeight, serverName.c_str());
|
||||||
|
else drawString(1, lineHeight, (knownIp.toString()).c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Third row with mode name or current time
|
// draw third and fourth row
|
||||||
if (clockMode) showTime(false);
|
drawLine(2, clockMode ? lineType : FLD_LINE_MODE);
|
||||||
else showCurrentEffectOrPalette(knownMode, JSON_mode_names, 2);
|
drawLine(3, clockMode ? FLD_LINE_TIME : lineType);
|
||||||
|
|
||||||
// Fourth row
|
|
||||||
drawLineFour();
|
|
||||||
|
|
||||||
drawGlyph(0, 2*lineHeight, 66 + (bri > 0 ? 3 : 0), u8x8_font_open_iconic_weather_2x2); // sun/moon icon
|
drawGlyph(0, 2*lineHeight, 66 + (bri > 0 ? 3 : 0), u8x8_font_open_iconic_weather_2x2); // sun/moon icon
|
||||||
//if (markLineNum>1) drawGlyph(2, markLineNum*lineHeight, 66, u8x8_font_open_iconic_arrow_1x1); // arrow icon
|
//if (markLineNum>1) drawGlyph(2, markLineNum*lineHeight, 66, u8x8_font_open_iconic_arrow_1x1); // arrow icon
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawLineFour() {
|
void drawLine(uint8_t line, Line4Type lineType) {
|
||||||
char lineBuffer[LINE_BUFFER_SIZE];
|
char lineBuffer[LINE_BUFFER_SIZE];
|
||||||
switch(lineFourType) {
|
switch(lineType) {
|
||||||
case FLD_LINE_4_BRIGHTNESS:
|
case FLD_LINE_BRIGHTNESS:
|
||||||
sprintf_P(lineBuffer, PSTR("Brightness %3d"), bri);
|
sprintf_P(lineBuffer, PSTR("Brightness %3d"), bri);
|
||||||
drawString(2, 3*lineHeight, lineBuffer);
|
drawString(2, line*lineHeight, lineBuffer);
|
||||||
break;
|
break;
|
||||||
case FLD_LINE_4_EFFECT_SPEED:
|
case FLD_LINE_EFFECT_SPEED:
|
||||||
sprintf_P(lineBuffer, PSTR("FX Speed %3d"), effectSpeed);
|
sprintf_P(lineBuffer, PSTR("FX Speed %3d"), effectSpeed);
|
||||||
drawString(2, 3*lineHeight, lineBuffer);
|
drawString(2, line*lineHeight, lineBuffer);
|
||||||
break;
|
break;
|
||||||
case FLD_LINE_4_EFFECT_INTENSITY:
|
case FLD_LINE_EFFECT_INTENSITY:
|
||||||
sprintf_P(lineBuffer, PSTR("FX Intens. %3d"), effectIntensity);
|
sprintf_P(lineBuffer, PSTR("FX Intens. %3d"), effectIntensity);
|
||||||
drawString(2, 3*lineHeight, lineBuffer);
|
drawString(2, line*lineHeight, lineBuffer);
|
||||||
break;
|
break;
|
||||||
case FLD_LINE_4_MODE:
|
case FLD_LINE_MODE:
|
||||||
showCurrentEffectOrPalette(knownMode, JSON_mode_names, 3);
|
showCurrentEffectOrPalette(knownMode, JSON_mode_names, line);
|
||||||
|
break;
|
||||||
|
case FLD_LINE_PALETTE:
|
||||||
|
showCurrentEffectOrPalette(knownPalette, JSON_palette_names, line);
|
||||||
|
break;
|
||||||
|
case FLD_LINE_TIME:
|
||||||
|
showTime(false);
|
||||||
break;
|
break;
|
||||||
case FLD_LINE_4_PALETTE:
|
|
||||||
default:
|
default:
|
||||||
showCurrentEffectOrPalette(knownPalette, JSON_palette_names, 3);
|
// unknown type, do nothing
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -456,23 +443,6 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
overlayUntil = millis() + showHowLong;
|
overlayUntil = millis() + showHowLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Specify what data should be defined on line 4
|
|
||||||
* (the last line).
|
|
||||||
*/
|
|
||||||
void setLineFourType(Line4Type newLineFourType) {
|
|
||||||
if (newLineFourType == FLD_LINE_4_BRIGHTNESS ||
|
|
||||||
newLineFourType == FLD_LINE_4_EFFECT_SPEED ||
|
|
||||||
newLineFourType == FLD_LINE_4_EFFECT_INTENSITY ||
|
|
||||||
newLineFourType == FLD_LINE_4_MODE ||
|
|
||||||
newLineFourType == FLD_LINE_4_PALETTE) {
|
|
||||||
lineFourType = newLineFourType;
|
|
||||||
} else {
|
|
||||||
// Unknown value
|
|
||||||
lineFourType = FLD_LINE_4_BRIGHTNESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Line 3 or 4 (last two lines) can be marked with an
|
* Line 3 or 4 (last two lines) can be marked with an
|
||||||
* arrow in the first column. Pass 2 or 3 to this to
|
* arrow in the first column. Pass 2 or 3 to this to
|
||||||
@ -496,8 +466,7 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
if (clockMode) showTime();
|
if (clockMode) showTime();
|
||||||
else setPowerSave(1);
|
else setPowerSave(1);
|
||||||
displayTurnedOff = true;
|
displayTurnedOff = true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
setPowerSave(0);
|
setPowerSave(0);
|
||||||
displayTurnedOff = false;
|
displayTurnedOff = false;
|
||||||
}
|
}
|
||||||
@ -513,13 +482,13 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
|
|
||||||
updateLocalTime();
|
updateLocalTime();
|
||||||
byte minuteCurrent = minute(localTime);
|
byte minuteCurrent = minute(localTime);
|
||||||
byte hourCurrent = hour(localTime);
|
byte hourCurrent = hour(localTime);
|
||||||
byte secondCurrent = second(localTime);
|
byte secondCurrent = second(localTime);
|
||||||
if (knownMinute == minuteCurrent && knownHour == hourCurrent) {
|
if (knownMinute == minuteCurrent && knownHour == hourCurrent) {
|
||||||
// Time hasn't changed.
|
// Time hasn't changed.
|
||||||
if (!fullScreen) return;
|
if (!fullScreen) return;
|
||||||
} else {
|
} else {
|
||||||
if (fullScreen) clear();
|
//if (fullScreen) clear();
|
||||||
}
|
}
|
||||||
knownMinute = minuteCurrent;
|
knownMinute = minuteCurrent;
|
||||||
knownHour = hourCurrent;
|
knownHour = hourCurrent;
|
||||||
@ -529,7 +498,7 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
if (fullScreen)
|
if (fullScreen)
|
||||||
draw2x2String(DATE_INDENT, lineHeight==1 ? 0 : lineHeight, lineBuffer); // adjust for 8 line displays
|
draw2x2String(DATE_INDENT, lineHeight==1 ? 0 : lineHeight, lineBuffer); // adjust for 8 line displays
|
||||||
else
|
else
|
||||||
drawString(2, lineHeight*2, lineBuffer);
|
drawString(2, lineHeight*3, lineBuffer);
|
||||||
|
|
||||||
byte showHour = hourCurrent;
|
byte showHour = hourCurrent;
|
||||||
boolean isAM = false;
|
boolean isAM = false;
|
||||||
@ -553,11 +522,12 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
if (fullScreen) {
|
if (fullScreen) {
|
||||||
draw2x2String(TIME_INDENT+2, lineHeight*2, lineBuffer);
|
draw2x2String(TIME_INDENT+2, lineHeight*2, lineBuffer);
|
||||||
sprintf_P(lineBuffer, PSTR("%02d"), secondCurrent);
|
sprintf_P(lineBuffer, PSTR("%02d"), secondCurrent);
|
||||||
if (!useAMPM) drawString(12, lineHeight*2+1, lineBuffer, true); // even with double sized rows print seconds in 1 line
|
if (useAMPM) drawString(12+(fullScreen?0:2), lineHeight*2, (isAM ? "AM" : "PM"), true);
|
||||||
|
else drawString(12, lineHeight*2+1, lineBuffer, true); // even with double sized rows print seconds in 1 line
|
||||||
} else {
|
} else {
|
||||||
drawString(9+(useAMPM?0:2), lineHeight*2, lineBuffer);
|
drawString(9+(useAMPM?0:2), lineHeight*3, lineBuffer);
|
||||||
|
if (useAMPM) drawString(12+(fullScreen?0:2), lineHeight*3, (isAM ? "AM" : "PM"), true);
|
||||||
}
|
}
|
||||||
if (useAMPM) drawString(12+(fullScreen?0:2), lineHeight*2, (isAM ? "AM" : "PM"), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -640,7 +610,7 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
} else {
|
} else {
|
||||||
String str = top[FPSTR(_flip)]; // checkbox -> off or on
|
String str = top[FPSTR(_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
|
||||||
needRedraw |= true;
|
needsRedraw |= true;
|
||||||
}
|
}
|
||||||
contrast = top[FPSTR(_contrast)].as<int>();
|
contrast = top[FPSTR(_contrast)].as<int>();
|
||||||
refreshRate = top[FPSTR(_refreshRate)].as<int>() * 1000;
|
refreshRate = top[FPSTR(_refreshRate)].as<int>() * 1000;
|
||||||
@ -650,14 +620,14 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
} else {
|
} else {
|
||||||
String str = top[FPSTR(_sleepMode)]; // checkbox -> off or on
|
String str = top[FPSTR(_sleepMode)]; // checkbox -> off or on
|
||||||
sleepMode = (bool)(str!="off"); // off is guaranteed to be present
|
sleepMode = (bool)(str!="off"); // off is guaranteed to be present
|
||||||
needRedraw |= true;
|
needsRedraw |= true;
|
||||||
}
|
}
|
||||||
if (top[FPSTR(_clockMode)].is<bool>()) {
|
if (top[FPSTR(_clockMode)].is<bool>()) {
|
||||||
clockMode = top[FPSTR(_clockMode)].as<bool>();
|
clockMode = top[FPSTR(_clockMode)].as<bool>();
|
||||||
} else {
|
} else {
|
||||||
String str = top[FPSTR(_clockMode)]; // checkbox -> off or on
|
String str = top[FPSTR(_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
|
||||||
needRedraw |= true;
|
needsRedraw |= true;
|
||||||
}
|
}
|
||||||
DEBUG_PRINTLN(F("4 Line Display config (re)loaded."));
|
DEBUG_PRINTLN(F("4 Line Display config (re)loaded."));
|
||||||
} else {
|
} else {
|
||||||
@ -687,7 +657,7 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
type = newType;
|
type = newType;
|
||||||
lineHeight = type==SSD1306 ? 1 : 2;
|
lineHeight = type==SSD1306 ? 1 : 2;
|
||||||
setup();
|
setup();
|
||||||
needRedraw |= true;
|
needsRedraw |= true;
|
||||||
}
|
}
|
||||||
setContrast(contrast);
|
setContrast(contrast);
|
||||||
setFlipMode(flip);
|
setFlipMode(flip);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 2106131
|
#define VERSION 2106151
|
||||||
|
|
||||||
//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
|
||||||
|
Loading…
Reference in New Issue
Block a user