From 481936e599ac8532db7039c73e54e65f618970d4 Mon Sep 17 00:00:00 2001 From: Luciano Coelho Date: Thu, 22 Oct 2020 02:24:29 -0300 Subject: [PATCH] Add Night Mode to turn off or change brightness of display during sleep hours. New configuration parameters were added to configuration menu. --- printermonitor/Settings.h | 238 ++++++++++++++++-------------- printermonitor/printermonitor.ino | 171 ++++++++++++++++++++- 2 files changed, 293 insertions(+), 116 deletions(-) diff --git a/printermonitor/Settings.h b/printermonitor/Settings.h index a149b82..4fd12db 100644 --- a/printermonitor/Settings.h +++ b/printermonitor/Settings.h @@ -1,114 +1,124 @@ -/** The MIT License (MIT) - -Copyright (c) 2018 David Payne - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -// Additional Contributions: -/* 15 Jan 2019 : Owen Carter : Add psucontrol setting */ - -/****************************************************************************** - * Printer Monitor is designed for the Wemos D1 ESP8266 - * Wemos D1 Mini: https://amzn.to/2qLyKJd - * 0.96" OLED I2C 128x64 Display (12864) SSD1306 - * OLED Display: https://amzn.to/2JDEAUF - ******************************************************************************/ -/****************************************************************************** - * NOTE: The settings here are the default settings for the first loading. - * After loading you will manage changes to the settings via the Web Interface. - * If you want to change settings again in the settings.h, you will need to - * erase the file system on the Wemos or use the “Reset Settings” option in - * the Web Interface. - ******************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include "TimeClient.h" -#include "RepetierClient.h" -#include "OctoPrintClient.h" -#include "OpenWeatherMapClient.h" -#include "WeatherStationFonts.h" -#include "FS.h" -#include "SH1106Wire.h" -#include "SSD1306Wire.h" -#include "OLEDDisplayUi.h" - -//****************************** -// Start Settings -//****************************** - -// OctoPrint / Repetier Monitoring -- Monitor your 3D OctoPrint or Repetier Server -//#define USE_REPETIER_CLIENT // Uncomment this line to use the Repetier Printer Server -- OctoPrint is used by default and is most common -String PrinterApiKey = ""; // ApiKey from your User Account on OctoPrint / Repetier -String PrinterHostName = "octopi";// Default 'octopi' -- or hostname if different (optional if your IP changes) -String PrinterServer = ""; // IP or Address of your OctoPrint / Repetier Server (DO NOT include http://) -int PrinterPort = 80; // the port you are running your OctoPrint / Repetier server on (usually 80); -String PrinterAuthUser = ""; // only used if you have haproxy or basic athentintication turned on (not default) -String PrinterAuthPass = ""; // only used with haproxy or basic auth (only needed if you must authenticate) - -// Weather Configuration -boolean DISPLAYWEATHER = true; // true = show weather when not printing / false = no weather -String WeatherApiKey = ""; // Your API Key from http://openweathermap.org/ -// Default City Location (use http://openweathermap.org/find to find city ID) -int CityIDs[] = { 5304391 }; //Only USE ONE for weather marquee -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 -String WeatherLanguage = "en"; //Default (en) English - -// Webserver -const int WEBSERVER_PORT = 80; // The port you can access this device on over HTTP -const boolean WEBSERVER_ENABLED = true; // Device will provide a web interface via http://[ip]:[port]/ -boolean IS_BASIC_AUTH = true; // true = require athentication to change configuration settings / false = no auth -char* www_username = "admin"; // User account for the Web Interface -char* www_password = "password"; // Password for the Web Interface - -// Date and Time -float UtcOffset = -7; // Hour offset from GMT for your timezone -boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock -int minutesBetweenDataRefresh = 15; -boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = turn off display when not printing - -// Display Settings -const int I2C_DISPLAY_ADDRESS = 0x3c; // I2C Address of your Display (usually 0x3c or 0x3d) -const int SDA_PIN = D2; -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 -//#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common - -// LED Settings -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 - -// PSU Control -boolean HAS_PSU = false; // Set to true if https://github.com/kantlivelong/OctoPrint-PSUControl/ in use - -// OTA Updates -boolean ENABLE_OTA = true; // this will allow you to load firmware to the device over WiFi (see OTA for ESP8266) -String OTA_Password = ""; // Set an OTA password here -- leave blank if you don't want to be prompted for password - -//****************************** -// End Settings -//****************************** - -String themeColor = "light-green"; // this can be changed later in the web interface. +/** The MIT License (MIT) + +Copyright (c) 2018 David Payne + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +// Additional Contributions: +/* 15 Jan 2019 : Owen Carter : Add psucontrol setting */ + +/****************************************************************************** + * Printer Monitor is designed for the Wemos D1 ESP8266 + * Wemos D1 Mini: https://amzn.to/2qLyKJd + * 0.96" OLED I2C 128x64 Display (12864) SSD1306 + * OLED Display: https://amzn.to/2JDEAUF + ******************************************************************************/ +/****************************************************************************** + * NOTE: The settings here are the default settings for the first loading. + * After loading you will manage changes to the settings via the Web Interface. + * If you want to change settings again in the settings.h, you will need to + * erase the file system on the Wemos or use the “Reset Settings” option in + * the Web Interface. + ******************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "TimeClient.h" +#include "RepetierClient.h" +#include "OctoPrintClient.h" +#include "OpenWeatherMapClient.h" +#include "WeatherStationFonts.h" +#include "FS.h" +#include "SH1106Wire.h" +#include "SSD1306Wire.h" +#include "OLEDDisplayUi.h" + +//****************************** +// Start Settings +//****************************** + +// OctoPrint / Repetier Monitoring -- Monitor your 3D OctoPrint or Repetier Server +//#define USE_REPETIER_CLIENT // Uncomment this line to use the Repetier Printer Server -- OctoPrint is used by default and is most common +String PrinterApiKey = ""; // ApiKey from your User Account on OctoPrint / Repetier +String PrinterHostName = "octopi";// Default 'octopi' -- or hostname if different (optional if your IP changes) +String PrinterServer = ""; // IP or Address of your OctoPrint / Repetier Server (DO NOT include http://) +int PrinterPort = 80; // the port you are running your OctoPrint / Repetier server on (usually 80); +String PrinterAuthUser = ""; // only used if you have haproxy or basic athentintication turned on (not default) +String PrinterAuthPass = ""; // only used with haproxy or basic auth (only needed if you must authenticate) + +// Weather Configuration +boolean DISPLAYWEATHER = true; // true = show weather when not printing / false = no weather +String WeatherApiKey = ""; // Your API Key from http://openweathermap.org/ +// Default City Location (use http://openweathermap.org/find to find city ID) +int CityIDs[] = { 5304391 }; //Only USE ONE for weather marquee +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, pt_br, ro, ru, se, sk, sl, es, tr, ua, vi, zh_cn, zh_tw +String WeatherLanguage = "en"; //Default (en) English + +// Webserver +const int WEBSERVER_PORT = 80; // The port you can access this device on over HTTP +const boolean WEBSERVER_ENABLED = true; // Device will provide a web interface via http://[ip]:[port]/ +boolean IS_BASIC_AUTH = true; // true = require athentication to change configuration settings / false = no auth +char* www_username = "admin"; // User account for the Web Interface +char* www_password = "password"; // Password for the Web Interface + +// Date and Time +float UtcOffset = -7; // Hour offset from GMT for your timezone +boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock +int minutesBetweenDataRefresh = 15; +boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = turn off display when not printing + +// Display Settings +const int I2C_DISPLAY_ADDRESS = 0x3c; // I2C Address of your Display (usually 0x3c or 0x3d) +const int SDA_PIN = D2; +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 +//#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 +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 + +// PSU Control +boolean HAS_PSU = false; // Set to true if https://github.com/kantlivelong/OctoPrint-PSUControl/ in use + +// OTA Updates +boolean ENABLE_OTA = true; // this will allow you to load firmware to the device over WiFi (see OTA for ESP8266) +String OTA_Password = ""; // Set an OTA password here -- leave blank if you don't want to be prompted for password + +//****************************** +// End Settings +//****************************** + +String themeColor = "light-green"; // this can be changed later in the web interface. diff --git a/printermonitor/printermonitor.ino b/printermonitor/printermonitor.ino index 8849850..4cf113a 100644 --- a/printermonitor/printermonitor.ino +++ b/printermonitor/printermonitor.ino @@ -30,7 +30,7 @@ SOFTWARE. #include "Settings.h" -#define VERSION "3.0" +#define VERSION "3.1" #define HOSTNAME "PrintMon-" #define CONFIG "/conf.txt" @@ -83,6 +83,7 @@ String lastMinute = "xx"; String lastSecond = "xx"; String lastReportStatus = ""; boolean displayOn = true; +bool displaySleepOn = false; // Printer Client #if defined(USE_REPETIER_CLIENT) @@ -119,6 +120,13 @@ static const char CLOCK_FORM[] PROGMEM = "

Use OctoPrint PSU control plugin for clock/blank

" "

Clock Sync / Weather Refresh (minutes)

"; +static const char SLEEP_FORM[] PROGMEM = "

Display Sleep Mode (Set Brightness or Turn Off)

" + "

Sleep Starts at (hour:minute) :

" + "

Sleep Stops at (hour:minute) :

" + "

Display Sleep will Turn Off Display

" + "

Display Sleep Brightness

" + "

Display Brightness Default


"; + static const char THEME_FORM[] PROGMEM = "

Theme Color

" "


" "

Use Security Credentials for Configuration Changes

" @@ -159,6 +167,7 @@ static const char LANG_OPTIONS[] PROGMEM = "" "" "" "" + "" "" "" "" @@ -483,6 +492,13 @@ void handleUpdateConfig() { temp.toCharArray(www_username, sizeof(temp)); temp = server.arg("stationpassword"); 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(); findMDNS(); printerClient.getPrinterJobResults(); @@ -655,6 +671,39 @@ void handleConfigure() { 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 = ""; + optionsBeginSleepHour.replace(">"+String(zeroPad(BeginSleepHour))+"<", " selected>"+String(zeroPad(BeginSleepHour))+"<"); + form.replace("%BEGIN_HOUR_OPTIONS%", optionsBeginSleepHour); + String optionsEndSleepHour = ""; + 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); String themeOptions = FPSTR(COLOR_THEMES); @@ -1143,6 +1192,14 @@ void writeSettings() { f.println("isMetric=" + String(IS_METRIC)); f.println("language=" + String(WeatherLanguage)); 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(); readSettings(); @@ -1266,6 +1323,15 @@ void readSettings() { WeatherLanguage.trim(); 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(); printerClient.updatePrintClient(PrinterApiKey, PrinterServer, PrinterPort, PrinterAuthUser, PrinterAuthPass, HAS_PSU); @@ -1288,8 +1354,16 @@ int getMinutesFromLastDisplay() { // Toggle on and off the display if user defined times void checkDisplay() { + // Enable or disable Display Sleep mode + checkSleepDisplay(); if (!displayOn && DISPLAYCLOCK) { - enableDisplay(true); + if (displaySleepOn) { + if (!DISPLAY_SLEEP_TURNOFF) { // Turn on display in brightness sleep mode, otherwise display stays off + enableDisplay(true); + } + } else { + enableDisplay(true); + } } if (displayOn && !printerClient.isPrinting() && !DISPLAYCLOCK) { // Put Display to sleep @@ -1320,6 +1394,18 @@ void checkDisplay() { return; } } else if (DISPLAYCLOCK) { + if (displayOn && (!printerClient.isPrinting() || printerClient.isPSUoff()) && displaySleepOn && DISPLAY_SLEEP_TURNOFF) { + isClockOn = 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); + } if ((!printerClient.isPrinting() || printerClient.isPSUoff()) && !isClockOn) { Serial.println("Clock Mode is turned on."); if (!DISPLAYWEATHER) { @@ -1335,6 +1421,17 @@ void checkDisplay() { ui.setOverlays(clockOverlay, numberOfOverlays); isClockOn = true; } else if (printerClient.isPrinting() && !printerClient.isPSUoff() && isClockOn) { + if (displaySleepOn && DISPLAY_SLEEP_TURNOFF) { + 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); + } Serial.println("Printer Monitor is active."); ui.setFrames(frames, numberOfFrames); ui.setOverlays(overlays, numberOfOverlays); @@ -1360,3 +1457,73 @@ void enableDisplay(boolean enable) { displayOffEpoch = lastEpoch; } } + +void checkSleepDisplay() { + if (displaySleepOn) { + if(!enableSleepDisplay()) { + // Disable Sleep Display + Serial.println("Display Sleep FINISH: " + timeClient.getFormattedTime()); + display.setBrightness(DISPLAY_BRIGHTNESS); + Serial.println("Display Brightness NORMAL: " + String(DISPLAY_BRIGHTNESS)); + 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..."); + delay(5000); + } + } else if (enableSleepDisplay()) { + // Enable Sleep Display + Serial.println("Display Sleep START: " + timeClient.getFormattedTime()); + display.setBrightness(SLEEP_BRIGHTNESS); + Serial.println("Display Brightness SLEEP MODE: " + String(SLEEP_BRIGHTNESS)); + } +} + +bool enableSleepDisplay() { + displaySleepOn=isSleepTime(DISPLAY_SLEEP,BeginSleepHour,BeginSleepMin,EndSleepHour,EndSleepMin); + return displaySleepOn; +} + +bool isSleepTime(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 += ""; + } + return temp; +}