pull/119/merge
coelholm 2021-04-28 13:38:48 +02:00 committed by GitHub
commit fdb6e7c3cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 397 additions and 159 deletions

View File

@ -73,7 +73,7 @@ String WeatherApiKey = ""; // Your API Key from http://openweathermap.org/
// Default City Location (use http://openweathermap.org/find to find city ID) // Default City Location (use http://openweathermap.org/find to find city ID)
int CityIDs[] = { 5304391 }; //Only USE ONE for weather marquee int CityIDs[] = { 5304391 }; //Only USE ONE for weather marquee
boolean IS_METRIC = false; // false = Imperial and true = Metric boolean IS_METRIC = false; // false = Imperial and true = Metric
// Languages: ar, bg, ca, cz, de, el, en, fa, fi, fr, gl, hr, hu, it, ja, kr, la, lt, mk, nl, pl, pt, ro, ru, se, sk, sl, es, tr, ua, vi, zh_cn, zh_tw // Languages: ar, bg, ca, cz, de, el, en, fa, fi, fr, gl, hr, hu, it, ja, kr, la, lt, mk, nl, pl, pt, pt_br, ro, ru, se, sk, sl, es, tr, ua, vi, zh_cn, zh_tw
String WeatherLanguage = "en"; //Default (en) English String WeatherLanguage = "en"; //Default (en) English
// Webserver // Webserver
@ -96,6 +96,16 @@ const int SCL_PIN = D5; // original code D5 -- Monitor Easy Board use D1
boolean INVERT_DISPLAY = false; // true = pins at top | false = pins at the bottom boolean INVERT_DISPLAY = false; // true = pins at top | false = pins at the bottom
//#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common //#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common
// Display Advanced Settings
boolean DISPLAY_SLEEP = false; // true = Turn off or change display brightness / false = don't change display operation
int BeginSleepHour = 0;
int BeginSleepMin = 0;
int EndSleepHour = 0;
int EndSleepMin = 0;
boolean DISPLAY_SLEEP_TURNOFF = true; // true = Turno off display / false = change brightness
int SLEEP_BRIGHTNESS = 50; // Sleep Mode Display Brightness
int DISPLAY_BRIGHTNESS = 255; // Default Display Brightness
// LED Settings // LED Settings
const int externalLight = LED_BUILTIN; // LED will always flash on bootup or Wifi Errors const int externalLight = LED_BUILTIN; // LED will always flash on bootup or Wifi Errors
boolean USE_FLASH = true; // true = System LED will Flash on Service Calls; false = disabled LED flashing boolean USE_FLASH = true; // true = System LED will Flash on Service Calls; false = disabled LED flashing

View File

@ -30,7 +30,7 @@ SOFTWARE.
#include "Settings.h" #include "Settings.h"
#define VERSION "3.0" #define VERSION "3.1.2"
#define HOSTNAME "PrintMon-" #define HOSTNAME "PrintMon-"
#define CONFIG "/conf.txt" #define CONFIG "/conf.txt"
@ -83,6 +83,9 @@ String lastMinute = "xx";
String lastSecond = "xx"; String lastSecond = "xx";
String lastReportStatus = ""; String lastReportStatus = "";
boolean displayOn = true; boolean displayOn = true;
boolean displaySleepOn = false;
boolean isSleepTime = false;
boolean enableDebug = false;
// Printer Client // Printer Client
#if defined(USE_REPETIER_CLIENT) #if defined(USE_REPETIER_CLIENT)
@ -119,6 +122,13 @@ static const char CLOCK_FORM[] PROGMEM = "<hr><p><input name='isClockEnabled' cl
"<p><input name='hasPSU' class='w3-check w3-margin-top' type='checkbox' %HAS_PSU_CHECKED%> Use OctoPrint PSU control plugin for clock/blank</p>" "<p><input name='hasPSU' class='w3-check w3-margin-top' type='checkbox' %HAS_PSU_CHECKED%> Use OctoPrint PSU control plugin for clock/blank</p>"
"<p>Clock Sync / Weather Refresh (minutes) <select class='w3-option w3-padding' name='refresh'>%OPTIONS%</select></p>"; "<p>Clock Sync / Weather Refresh (minutes) <select class='w3-option w3-padding' name='refresh'>%OPTIONS%</select></p>";
static const char SLEEP_FORM[] PROGMEM = "<hr><p><input name='isDisplaySleepEnabled' class='w3-check w3-margin-top' type='checkbox' %IS_DISPSLEEP_CHECKED%> Display Sleep Mode (Set Brightness or Turn Off)</p>"
"<p>Sleep Starts at (hour:minute) <select class='w3-option w3-padding' name='BeginSleepHour'>%BEGIN_HOUR_OPTIONS%</select>:<select class='w3-option w3-padding' name='BeginSleepMin'>%BEGIN_MINUTE_OPTIONS%</select></p>"
"<p>Sleep Stops at (hour:minute) <select class='w3-option w3-padding' name='EndSleepHour'>%END_HOUR_OPTIONS%</select>:<select class='w3-option w3-padding' name='EndSleepMin'>%END_MINUTE_OPTIONS%</select></p>"
"<p><input name='isDisplaySleepTurnOff' class='w3-check w3-margin-top' type='checkbox' %IS_DISPSLEEPTURNOFF_CHECKED%> Display Sleep will Turn Off Display</p>"
"<p>Display Sleep Brightness <select class='w3-option w3-padding' name='SleepBrightness'>%DISPLAY_BRI_OPTIONS%</select></p>"
"<p>Display Brightness Default <select class='w3-option w3-padding' name='DefaultBrightness'>%DISPLAY_DEF_BRI_OPTIONS%</select></p><hr>";
static const char THEME_FORM[] PROGMEM = "<p>Theme Color <select class='w3-option w3-padding' name='theme'>%THEME_OPTIONS%</select></p>" static const char THEME_FORM[] PROGMEM = "<p>Theme Color <select class='w3-option w3-padding' name='theme'>%THEME_OPTIONS%</select></p>"
"<p><label>UTC Time Offset</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='utcoffset' value='%UTCOFFSET%' maxlength='12'></p><hr>" "<p><label>UTC Time Offset</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='utcoffset' value='%UTCOFFSET%' maxlength='12'></p><hr>"
"<p><input name='isBasicAuth' class='w3-check w3-margin-top' type='checkbox' %IS_BASICAUTH_CHECKED%> Use Security Credentials for Configuration Changes</p>" "<p><input name='isBasicAuth' class='w3-check w3-margin-top' type='checkbox' %IS_BASICAUTH_CHECKED%> Use Security Credentials for Configuration Changes</p>"
@ -159,6 +169,7 @@ static const char LANG_OPTIONS[] PROGMEM = "<option>ar</option>"
"<option>nl</option>" "<option>nl</option>"
"<option>pl</option>" "<option>pl</option>"
"<option>pt</option>" "<option>pt</option>"
"<option>pt_br</option>"
"<option>ro</option>" "<option>ro</option>"
"<option>ru</option>" "<option>ru</option>"
"<option>se</option>" "<option>se</option>"
@ -376,6 +387,7 @@ void loop() {
} }
if (lastMinute != timeClient.getMinutes() && !printerClient.isPrinting()) { if (lastMinute != timeClient.getMinutes() && !printerClient.isPrinting()) {
mydebug("loop 60s");
// Check status every 60 seconds // Check status every 60 seconds
ledOnOff(true); ledOnOff(true);
lastMinute = timeClient.getMinutes(); // reset the check value lastMinute = timeClient.getMinutes(); // reset the check value
@ -385,6 +397,7 @@ void loop() {
} else if (printerClient.isPrinting()) { } else if (printerClient.isPrinting()) {
if (lastSecond != timeClient.getSeconds() && timeClient.getSeconds().endsWith("0")) { if (lastSecond != timeClient.getSeconds() && timeClient.getSeconds().endsWith("0")) {
lastSecond = timeClient.getSeconds(); lastSecond = timeClient.getSeconds();
mydebug("loop 10s");
// every 10 seconds while printing get an update // every 10 seconds while printing get an update
ledOnOff(true); ledOnOff(true);
printerClient.getPrinterJobResults(); printerClient.getPrinterJobResults();
@ -483,6 +496,13 @@ void handleUpdateConfig() {
temp.toCharArray(www_username, sizeof(temp)); temp.toCharArray(www_username, sizeof(temp));
temp = server.arg("stationpassword"); temp = server.arg("stationpassword");
temp.toCharArray(www_password, sizeof(temp)); temp.toCharArray(www_password, sizeof(temp));
DISPLAY_SLEEP = server.hasArg("isDisplaySleepEnabled");
BeginSleepHour = server.arg("BeginSleepHour").toInt();
BeginSleepMin = server.arg("BeginSleepMin").toInt();
EndSleepHour = server.arg("EndSleepHour").toInt();
EndSleepMin = server.arg("EndSleepMin").toInt();
DISPLAY_SLEEP_TURNOFF = server.hasArg("isDisplaySleepTurnOff");
SLEEP_BRIGHTNESS = server.arg("SleepBrightness").toInt();
writeSettings(); writeSettings();
findMDNS(); findMDNS();
printerClient.getPrinterJobResults(); printerClient.getPrinterJobResults();
@ -655,6 +675,39 @@ void handleConfigure() {
server.sendContent(form); server.sendContent(form);
form = FPSTR(SLEEP_FORM);
String isDisplaySleepEnabledChecked="";
if (DISPLAY_SLEEP) {
isDisplaySleepEnabledChecked="checked='checked'";
}
form.replace("%IS_DISPSLEEP_CHECKED%", isDisplaySleepEnabledChecked);
String isDisplaySleepTurnOffChecked="";
if (DISPLAY_SLEEP_TURNOFF) {
isDisplaySleepTurnOffChecked="checked='checked'";
}
form.replace("%IS_DISPSLEEPTURNOFF_CHECKED%", isDisplaySleepTurnOffChecked);
String optionsBeginSleepHour = "<option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option>";
optionsBeginSleepHour.replace(">"+String(zeroPad(BeginSleepHour))+"<", " selected>"+String(zeroPad(BeginSleepHour))+"<");
form.replace("%BEGIN_HOUR_OPTIONS%", optionsBeginSleepHour);
String optionsEndSleepHour = "<option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option>";
optionsEndSleepHour.replace(">"+String(zeroPad(EndSleepHour))+"<", " selected>"+String(zeroPad(EndSleepHour))+"<");
form.replace("%END_HOUR_OPTIONS%", optionsEndSleepHour);
String optionsBeginSleepMin = genOptions(0,59,1,true);
optionsBeginSleepMin.replace(">"+String(zeroPad(BeginSleepMin))+"<", " selected>"+String(zeroPad(BeginSleepMin))+"<");
form.replace("%BEGIN_MINUTE_OPTIONS%", optionsBeginSleepMin);
String optionsEndSleepMin = genOptions(0,59,1,true);
optionsEndSleepMin.replace(">"+String(zeroPad(EndSleepMin))+"<", " selected>"+String(zeroPad(EndSleepMin))+"<");
form.replace("%END_MINUTE_OPTIONS%", optionsEndSleepMin);
String optionsSleepBrightness = genOptions(0,255,15,false);
optionsSleepBrightness.replace(">"+String(SLEEP_BRIGHTNESS)+"<", " selected>"+String(SLEEP_BRIGHTNESS)+"<");
form.replace("%DISPLAY_BRI_OPTIONS%", optionsSleepBrightness);
String optionsDefaultBrightness = genOptions(0,255,15,false);
optionsDefaultBrightness.replace(">"+String(DISPLAY_BRIGHTNESS)+"<", " selected>"+String(DISPLAY_BRIGHTNESS)+"<");
form.replace("%DISPLAY_DEF_BRI_OPTIONS%", optionsDefaultBrightness);
server.sendContent(form);
form = FPSTR(THEME_FORM); form = FPSTR(THEME_FORM);
String themeOptions = FPSTR(COLOR_THEMES); String themeOptions = FPSTR(COLOR_THEMES);
@ -1143,6 +1196,14 @@ void writeSettings() {
f.println("isMetric=" + String(IS_METRIC)); f.println("isMetric=" + String(IS_METRIC));
f.println("language=" + String(WeatherLanguage)); f.println("language=" + String(WeatherLanguage));
f.println("hasPSU=" + String(HAS_PSU)); f.println("hasPSU=" + String(HAS_PSU));
f.println("DISPLAY_SLEEP=" + String(DISPLAY_SLEEP));
f.println("BeginSleepHour=" + String(BeginSleepHour));
f.println("BeginSleepMin=" + String(BeginSleepMin));
f.println("EndSleepHour=" + String(EndSleepHour));
f.println("EndSleepMin=" + String(EndSleepMin));
f.println("DISPLAY_SLEEP_TURNOFF=" + String(DISPLAY_SLEEP_TURNOFF));
f.println("SLEEP_BRIGHTNESS=" + String(SLEEP_BRIGHTNESS));
f.println("DISPLAY_BRIGHTNESS=" + String(DISPLAY_BRIGHTNESS));
} }
f.close(); f.close();
readSettings(); readSettings();
@ -1266,6 +1327,15 @@ void readSettings() {
WeatherLanguage.trim(); WeatherLanguage.trim();
Serial.println("WeatherLanguage=" + WeatherLanguage); Serial.println("WeatherLanguage=" + WeatherLanguage);
} }
if (line.indexOf("DISPLAY_SLEEP=") >= 0) { DISPLAY_SLEEP = line.substring(line.lastIndexOf("DISPLAY_SLEEP=") + sizeof("DISPLAY_SLEEP=")-1).toInt(); Serial.println("DISPLAY_SLEEP=" + String(DISPLAY_SLEEP) ); }
if (line.indexOf("BeginSleepHour=") >= 0) { BeginSleepHour = line.substring(line.lastIndexOf("BeginSleepHour=") + sizeof("BeginSleepHour=")-1).toInt(); Serial.println("BeginSleepHour=" + String(BeginSleepHour) ); }
if (line.indexOf("BeginSleepMin=") >= 0) { BeginSleepMin = line.substring(line.lastIndexOf("BeginSleepMin=") + sizeof("BeginSleepMin=")-1).toInt(); Serial.println("BeginSleepMin=" + String(BeginSleepMin) ); }
if (line.indexOf("EndSleepHour=") >= 0) { EndSleepHour = line.substring(line.lastIndexOf("EndSleepHour=") + sizeof("EndSleepHour=")-1).toInt(); Serial.println("EndSleepHour=" + String(EndSleepHour) ); }
if (line.indexOf("EndSleepMin=") >= 0) { EndSleepMin = line.substring(line.lastIndexOf("EndSleepMin=") + sizeof("EndSleepMin=")-1).toInt(); Serial.println("EndSleepMin=" + String(EndSleepMin) ); }
if (line.indexOf("DISPLAY_SLEEP_TURNOFF=") >= 0) { DISPLAY_SLEEP_TURNOFF = line.substring(line.lastIndexOf("DISPLAY_SLEEP_TURNOFF=") + sizeof("DISPLAY_SLEEP_TURNOFF=")-1).toInt(); Serial.println("DISPLAY_SLEEP_TURNOFF=" + String(DISPLAY_SLEEP_TURNOFF) ); }
if (line.indexOf("SLEEP_BRIGHTNESS=") >= 0) { SLEEP_BRIGHTNESS = line.substring(line.lastIndexOf("SLEEP_BRIGHTNESS=") + sizeof("SLEEP_BRIGHTNESS=")-1).toInt(); Serial.println("SLEEP_BRIGHTNESS=" + String(SLEEP_BRIGHTNESS) ); }
if (line.indexOf("DISPLAY_BRIGHTNESS=") >= 0) { DISPLAY_BRIGHTNESS = line.substring(line.lastIndexOf("DISPLAY_BRIGHTNESS=") + sizeof("DISPLAY_BRIGHTNESS=")-1).toInt(); Serial.println("DISPLAY_BRIGHTNESS=" + String(DISPLAY_BRIGHTNESS) ); }
} }
fr.close(); fr.close();
printerClient.updatePrintClient(PrinterApiKey, PrinterServer, PrinterPort, PrinterAuthUser, PrinterAuthPass, HAS_PSU); printerClient.updatePrintClient(PrinterApiKey, PrinterServer, PrinterPort, PrinterAuthUser, PrinterAuthPass, HAS_PSU);
@ -1288,53 +1358,106 @@ int getMinutesFromLastDisplay() {
// Toggle on and off the display if user defined times // Toggle on and off the display if user defined times
void checkDisplay() { void checkDisplay() {
// Check if it is time to Display Sleep mode
checkSleepDisplay();
if (!displayOn && DISPLAYCLOCK) { if (!displayOn && DISPLAYCLOCK) {
enableDisplay(true); if (isSleepTime && !displaySleepOn) {
} enableSleepDisplay(true);
if (displayOn && !printerClient.isPrinting() && !DISPLAYCLOCK) { if (!DISPLAY_SLEEP_TURNOFF) { // Turn on display in brightness sleep mode, otherwise display stays off
// Put Display to sleep enableDisplay(true);
display.clear();
display.display();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.setContrast(255); // default is 255
display.drawString(64, 5, "Printer Offline\nSleep Mode...");
display.display();
delay(5000);
enableDisplay(false);
Serial.println("Printer is offline going down to sleep...");
return;
} else if (!displayOn && !DISPLAYCLOCK) {
if (printerClient.isOperational()) {
// Wake the Screen up
enableDisplay(true);
display.clear();
display.display();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.setContrast(255); // default is 255
display.drawString(64, 5, "Printer Online\nWake up...");
display.display();
Serial.println("Printer is online waking up...");
delay(5000);
return;
}
} else if (DISPLAYCLOCK) {
if ((!printerClient.isPrinting() || printerClient.isPSUoff()) && !isClockOn) {
Serial.println("Clock Mode is turned on.");
if (!DISPLAYWEATHER) {
ui.disableAutoTransition();
ui.setFrames(clockFrame, 1);
clockFrame[0] = drawClock;
} else {
ui.enableAutoTransition();
ui.setFrames(clockFrame, 2);
clockFrame[0] = drawClock;
clockFrame[1] = drawWeather;
} }
ui.setOverlays(clockOverlay, numberOfOverlays); } else if (!isSleepTime) { // Turn on display if clock is configured and not in sleep time range
isClockOn = true; enableDisplay(true);
}
}
if (!DISPLAYCLOCK) { // Clock is not configured
if (isSleepTime && !displaySleepOn) {
enableSleepDisplay(true);
}
if (displayOn) {
if (!printerClient.isOperational()) {
// Put Display to sleep
display.clear();
display.display();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_CENTER);
// display.setContrast(255); // default is 255
display.drawString(64, 5, "Printer Offline\nSleep Mode...");
display.display();
delay(5000);
enableDisplay(false);
Serial.println("Printer is offline going down to sleep...");
return;
}
} else if (!displayOn) { // Display is off
if (printerClient.isOperational()) { // Turn on display if printer is Operational
// Wake the Screen up
enableDisplay(true);
display.clear();
display.display();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_CENTER);
// display.setContrast(255); // default is 255
display.drawString(64, 5, "Printer Online\nWake up...");
display.display();
Serial.println("Printer is online waking up...");
delay(5000);
return;
}
} else if (printerClient.isPrinting() && !printerClient.isPSUoff() && isClockOn) { // Set Printer Monitor mode when printing
Serial.println("Printer Monitor is active.");
ui.setFrames(frames, numberOfFrames);
ui.setOverlays(overlays, numberOfOverlays);
ui.enableAutoTransition();
isClockOn = false;
}
} else if (DISPLAYCLOCK) { // Clock is configured
if (displayOn && !displaySleepOn && isSleepTime) {
if (DISPLAY_SLEEP_TURNOFF && (!printerClient.isPrinting() || printerClient.isPSUoff())) { // Turn off display during sleep time range
enableSleepDisplay(true);
display.clear();
display.display();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(64, 5, "Printer Offline\nDisplay\nSleep Mode");
display.display();
Serial.println("Printer Offline and Display Sleep mode on, going down to sleep...");
delay(5000);
enableDisplay(false);
} else if (!DISPLAY_SLEEP_TURNOFF) { // Set display sleep mode without changing display (Already set brightness to sleep mode)
enableSleepDisplay(true);
}
} else if (displayOn && isSleepTime && displaySleepOn && DISPLAY_SLEEP_TURNOFF && !printerClient.isPrinting()) {
enableDisplay(false);
} else if (!displayOn && !DISPLAY_SLEEP_TURNOFF) { // Turn on display
enableDisplay(true);
} else if ((!printerClient.isPrinting() || printerClient.isPSUoff()) && !isClockOn) { // Set Clock mode if not printing
Serial.println("Clock Mode is turned on.");
if (!DISPLAYWEATHER) {
ui.disableAutoTransition();
ui.setFrames(clockFrame, 1);
clockFrame[0] = drawClock;
} else {
ui.enableAutoTransition();
ui.setFrames(clockFrame, 2);
clockFrame[0] = drawClock;
clockFrame[1] = drawWeather;
}
ui.setOverlays(clockOverlay, numberOfOverlays);
isClockOn = true;
} else if (printerClient.isPrinting() && !printerClient.isPSUoff() && isClockOn) { } else if (printerClient.isPrinting() && !printerClient.isPSUoff() && isClockOn) {
if (displaySleepOn && DISPLAY_SLEEP_TURNOFF) { // Turn on display is start printing during sleep time range with display off
enableDisplay(true);
display.clear();
display.display();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(64, 5, "Printer Online\nDisplay\nSleep Mode");
display.display();
Serial.println("Printer Online and Display Sleep mode on, waking up...");
delay(5000);
}
// Set Printer Monitor mode
Serial.println("Printer Monitor is active."); Serial.println("Printer Monitor is active.");
ui.setFrames(frames, numberOfFrames); ui.setFrames(frames, numberOfFrames);
ui.setOverlays(overlays, numberOfOverlays); ui.setOverlays(overlays, numberOfOverlays);
@ -1354,9 +1477,114 @@ void enableDisplay(boolean enable) {
} }
display.displayOn(); display.displayOn();
Serial.println("Display was turned ON: " + timeClient.getFormattedTime()); Serial.println("Display was turned ON: " + timeClient.getFormattedTime());
mydebug("enableDisplayOn");
} else { } else {
display.displayOff(); display.displayOff();
Serial.println("Display was turned OFF: " + timeClient.getFormattedTime()); Serial.println("Display was turned OFF: " + timeClient.getFormattedTime());
displayOffEpoch = lastEpoch; displayOffEpoch = lastEpoch;
mydebug("enableDisplayOff");
} }
} }
void checkSleepDisplay() {
isSleepTime=checkSleepTime();
if (displaySleepOn) {
if(!isSleepTime) {
// Disable Sleep Display
enableSleepDisplay(false);
Serial.println("Display Sleep FINISH Brightness (" + String(DISPLAY_BRIGHTNESS) + "): " + timeClient.getFormattedTime());
display.setBrightness(DISPLAY_BRIGHTNESS);
if (!displayOn) {
display.displayOff(); // Keep display off after brightness change
}
mydebug("checkSleepDisplay FINISH");
if (DISPLAYCLOCK) {
isClockOn=false;
if (DISPLAY_SLEEP_TURNOFF) {
enableDisplay(true);
display.clear();
display.display();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.setContrast(255); // default is 255
display.drawString(64, 5, "Display\nWake up...");
display.display();
Serial.println("Display waking up...");
mydebug("checkSleepDisplay WAKEUP");
delay(5000);
}
}
}
} else if (isSleepTime && !displaySleepOn) {
// Enable Sleep Display
Serial.println("Display Sleep START Brightness (" + String(SLEEP_BRIGHTNESS) + "): " + timeClient.getFormattedTime());
display.setBrightness(SLEEP_BRIGHTNESS);
if (!displayOn) {
display.displayOff(); // Keep display off after brightness change
}
mydebug("checkSleepDisplay START");
}
}
void enableSleepDisplay(boolean enable) {
displaySleepOn=enable;
mydebug("enableSleepDisplay " + String(enable));
}
bool checkSleepTime() {
return SleepTime(DISPLAY_SLEEP,BeginSleepHour,BeginSleepMin,EndSleepHour,EndSleepMin);
}
bool SleepTime(bool DISPLAY_SLEEP,int BeginSleepHour,int BeginSleepMin,int EndSleepHour,int EndSleepMin) {
if (DISPLAY_SLEEP) {
int curHour = timeClient.getHours().toInt();
int curMin = timeClient.getMinutes().toInt();
int curTime = curHour * 60 + curMin;
int beginTime = BeginSleepHour * 60 + BeginSleepMin;
int endTime = EndSleepHour * 60 + EndSleepMin;
if (beginTime < endTime ) {
if ((curTime >= beginTime) && (curTime < endTime)) {
return true;
} else {
return false;
}
} else if (beginTime > endTime ) {
if ((curTime >= beginTime) || (curTime < endTime)) {
return true;
} else {
return false;
}
}
}
return false;
}
String genOptions(int start,int end, int step, bool pad) {
String temp = "";
for (int i=start; i<=end; i = i + step) {
temp += "<option>";
if (pad) {
temp += String(zeroPad(i));
} else {
temp += String(i);
}
temp += "</option>";
}
return temp;
}
void mydebug(String ori) {
if (!enableDebug) {
return; // Debug not enabled
}
Serial.println(ori + " DISPLAYCLOCK: " + String(DISPLAYCLOCK));
Serial.println(ori + " DISPLAY_SLEEP_TURNOFF: " + String(DISPLAY_SLEEP_TURNOFF));
Serial.println(ori + " displayOn: " + String(displayOn));
Serial.println(ori + " displaySleepOn: " + String(displaySleepOn));
Serial.println(ori + " isSleepTime: " + String(isSleepTime));
Serial.println(ori + " isClockOn: " + String(isClockOn));
Serial.println(ori + " printerClient.isOperational(): " + String(printerClient.isOperational()));
Serial.println(ori + " printerClient.isPrinting(): " + String(printerClient.isPrinting()));
Serial.println(ori + " printerClient.isPSUoff(): " + String(printerClient.isPSUoff()));
Serial.println(ori + " printerClient.getState(): " + String(printerClient.getState()));
}