From 481936e599ac8532db7039c73e54e65f618970d4 Mon Sep 17 00:00:00 2001 From: Luciano Coelho Date: Thu, 22 Oct 2020 02:24:29 -0300 Subject: [PATCH 1/6] 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; +} From 5f86c26e4933f8c2428efc741bc78400a3256048 Mon Sep 17 00:00:00 2001 From: Luciano Coelho Date: Thu, 22 Oct 2020 23:06:19 -0300 Subject: [PATCH 2/6] Bug fix when exit sleep time when display was turned off. --- printermonitor/printermonitor.ino | 126 ++++++++++++++++++++---------- 1 file changed, 86 insertions(+), 40 deletions(-) diff --git a/printermonitor/printermonitor.ino b/printermonitor/printermonitor.ino index 4cf113a..cc23c69 100644 --- a/printermonitor/printermonitor.ino +++ b/printermonitor/printermonitor.ino @@ -30,7 +30,7 @@ SOFTWARE. #include "Settings.h" -#define VERSION "3.1" +#define VERSION "3.1.1" #define HOSTNAME "PrintMon-" #define CONFIG "/conf.txt" @@ -83,7 +83,8 @@ String lastMinute = "xx"; String lastSecond = "xx"; String lastReportStatus = ""; boolean displayOn = true; -bool displaySleepOn = false; +boolean displaySleepOn = false; +boolean isSleepTime = false; // Printer Client #if defined(USE_REPETIER_CLIENT) @@ -1357,12 +1358,13 @@ void checkDisplay() { // Enable or disable Display Sleep mode checkSleepDisplay(); if (!displayOn && DISPLAYCLOCK) { - if (displaySleepOn) { + if (isSleepTime && !displaySleepOn) { + enableSleepDisplay(true); if (!DISPLAY_SLEEP_TURNOFF) { // Turn on display in brightness sleep mode, otherwise display stays off enableDisplay(true); } - } else { - enableDisplay(true); + } else if (!isSleepTime) { + enableDisplay(true); } } if (displayOn && !printerClient.isPrinting() && !DISPLAYCLOCK) { @@ -1394,32 +1396,34 @@ void checkDisplay() { return; } } else if (DISPLAYCLOCK) { - if (displayOn && (!printerClient.isPrinting() || printerClient.isPSUoff()) && displaySleepOn && DISPLAY_SLEEP_TURNOFF) { - isClockOn = true; + if (displayOn && !displaySleepOn && isSleepTime && DISPLAY_SLEEP_TURNOFF && (!printerClient.isPrinting() || printerClient.isPSUoff())) { + 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.."); + 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) { - 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; + isClockOn = true; // Avoid set clock mode in display sleep with display off + } else if (displayOn && !displaySleepOn && isSleepTime && !DISPLAY_SLEEP_TURNOFF) { + enableSleepDisplay(true); + } else 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); + isClockOn = true; } else if (printerClient.isPrinting() && !printerClient.isPSUoff() && isClockOn) { if (displaySleepOn && DISPLAY_SLEEP_TURNOFF) { enableDisplay(true); @@ -1451,45 +1455,87 @@ void enableDisplay(boolean enable) { } display.displayOn(); Serial.println("Display was turned ON: " + timeClient.getFormattedTime()); + Serial.println("enableDisplayOn displayOn: " + String(displayOn)); + Serial.println("enableDisplayOn DISPLAYCLOCK: " + String(DISPLAYCLOCK)); + Serial.println("enableDisplayOn isSleepTime: " + String(isSleepTime)); + Serial.println("enableDisplayOn displaySleepOn: " + String(displaySleepOn)); + Serial.println("enableDisplayOn DISPLAY_SLEEP_TURNOFF: " + String(DISPLAY_SLEEP_TURNOFF)); + Serial.println("enableDisplayOn isClockOn: " + String(isClockOn)); + Serial.println("enableDisplayOn printerClient.isPrinting(): " + String(printerClient.isPrinting())); + Serial.println("enableDisplayOn printerClient.isPSUoff(): " + String(printerClient.isPSUoff())); } else { display.displayOff(); Serial.println("Display was turned OFF: " + timeClient.getFormattedTime()); displayOffEpoch = lastEpoch; + Serial.println("enableDisplayOff displayOn: " + String(displayOn)); + Serial.println("enableDisplayOff DISPLAYCLOCK: " + String(DISPLAYCLOCK)); + Serial.println("enableDisplayOff isSleepTime: " + String(isSleepTime)); + Serial.println("enableDisplayOff displaySleepOn: " + String(displaySleepOn)); + Serial.println("enableDisplayOff DISPLAY_SLEEP_TURNOFF: " + String(DISPLAY_SLEEP_TURNOFF)); + Serial.println("enableDisplayOff isClockOn: " + String(isClockOn)); + Serial.println("enableDisplayOff printerClient.isPrinting(): " + String(printerClient.isPrinting())); + Serial.println("enableDisplayOff printerClient.isPSUoff(): " + String(printerClient.isPSUoff())); } } void checkSleepDisplay() { + isSleepTime=checkSleepTime(); if (displaySleepOn) { - if(!enableSleepDisplay()) { + if(!isSleepTime) { + isClockOn=false; + enableSleepDisplay(false); // 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); + 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..."); + + Serial.println("checkSleepDisplay Display Brightness SLEEP MODE: " + String(SLEEP_BRIGHTNESS)); + Serial.println("checkSleepDisplay displayOn: " + String(displayOn)); + Serial.println("checkSleepDisplay DISPLAYCLOCK: " + String(DISPLAYCLOCK)); + Serial.println("checkSleepDisplay isSleepTime: " + String(isSleepTime)); + Serial.println("checkSleepDisplay displaySleepOn: " + String(displaySleepOn)); + Serial.println("checkSleepDisplay DISPLAY_SLEEP_TURNOFF: " + String(DISPLAY_SLEEP_TURNOFF)); + Serial.println("checkSleepDisplay isClockOn: " + String(isClockOn)); + Serial.println("checkSleepDisplay printerClient.isPrinting(): " + String(printerClient.isPrinting())); + Serial.println("checkSleepDisplay printerClient.isPSUoff(): " + String(printerClient.isPSUoff())); + delay(5000); + } } - } else if (enableSleepDisplay()) { + } else if (isSleepTime && !displaySleepOn) { // Enable Sleep Display Serial.println("Display Sleep START: " + timeClient.getFormattedTime()); display.setBrightness(SLEEP_BRIGHTNESS); - Serial.println("Display Brightness SLEEP MODE: " + String(SLEEP_BRIGHTNESS)); + Serial.println("checkSleepDisplay Display Brightness SLEEP MODE: " + String(SLEEP_BRIGHTNESS)); + Serial.println("checkSleepDisplay displayOn: " + String(displayOn)); + Serial.println("checkSleepDisplay DISPLAYCLOCK: " + String(DISPLAYCLOCK)); + Serial.println("checkSleepDisplay isSleepTime: " + String(isSleepTime)); + Serial.println("checkSleepDisplay displaySleepOn: " + String(displaySleepOn)); + Serial.println("checkSleepDisplay DISPLAY_SLEEP_TURNOFF: " + String(DISPLAY_SLEEP_TURNOFF)); + Serial.println("checkSleepDisplay isClockOn: " + String(isClockOn)); + Serial.println("checkSleepDisplay printerClient.isPrinting(): " + String(printerClient.isPrinting())); + Serial.println("checkSleepDisplay printerClient.isPSUoff(): " + String(printerClient.isPSUoff())); } } -bool enableSleepDisplay() { - displaySleepOn=isSleepTime(DISPLAY_SLEEP,BeginSleepHour,BeginSleepMin,EndSleepHour,EndSleepMin); - return displaySleepOn; +void enableSleepDisplay(boolean enable) { + displaySleepOn=enable; } -bool isSleepTime(bool DISPLAY_SLEEP,int BeginSleepHour,int BeginSleepMin,int EndSleepHour,int EndSleepMin) { +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(); From 501c6a1aeea576849d17b14c7aced638aaef4708 Mon Sep 17 00:00:00 2001 From: Luciano Coelho Date: Fri, 23 Oct 2020 00:10:13 -0300 Subject: [PATCH 3/6] Remove debug messages --- printermonitor/printermonitor.ino | 35 ------------------------------- 1 file changed, 35 deletions(-) diff --git a/printermonitor/printermonitor.ino b/printermonitor/printermonitor.ino index cc23c69..d28e066 100644 --- a/printermonitor/printermonitor.ino +++ b/printermonitor/printermonitor.ino @@ -1454,27 +1454,10 @@ void enableDisplay(boolean enable) { displayOffEpoch = 0; // reset } display.displayOn(); - Serial.println("Display was turned ON: " + timeClient.getFormattedTime()); - Serial.println("enableDisplayOn displayOn: " + String(displayOn)); - Serial.println("enableDisplayOn DISPLAYCLOCK: " + String(DISPLAYCLOCK)); - Serial.println("enableDisplayOn isSleepTime: " + String(isSleepTime)); - Serial.println("enableDisplayOn displaySleepOn: " + String(displaySleepOn)); - Serial.println("enableDisplayOn DISPLAY_SLEEP_TURNOFF: " + String(DISPLAY_SLEEP_TURNOFF)); - Serial.println("enableDisplayOn isClockOn: " + String(isClockOn)); - Serial.println("enableDisplayOn printerClient.isPrinting(): " + String(printerClient.isPrinting())); - Serial.println("enableDisplayOn printerClient.isPSUoff(): " + String(printerClient.isPSUoff())); } else { display.displayOff(); Serial.println("Display was turned OFF: " + timeClient.getFormattedTime()); displayOffEpoch = lastEpoch; - Serial.println("enableDisplayOff displayOn: " + String(displayOn)); - Serial.println("enableDisplayOff DISPLAYCLOCK: " + String(DISPLAYCLOCK)); - Serial.println("enableDisplayOff isSleepTime: " + String(isSleepTime)); - Serial.println("enableDisplayOff displaySleepOn: " + String(displaySleepOn)); - Serial.println("enableDisplayOff DISPLAY_SLEEP_TURNOFF: " + String(DISPLAY_SLEEP_TURNOFF)); - Serial.println("enableDisplayOff isClockOn: " + String(isClockOn)); - Serial.println("enableDisplayOff printerClient.isPrinting(): " + String(printerClient.isPrinting())); - Serial.println("enableDisplayOff printerClient.isPSUoff(): " + String(printerClient.isPSUoff())); } } @@ -1498,16 +1481,6 @@ void checkSleepDisplay() { display.drawString(64, 5, "Display\nWake up..."); display.display(); Serial.println("Display waking up..."); - - Serial.println("checkSleepDisplay Display Brightness SLEEP MODE: " + String(SLEEP_BRIGHTNESS)); - Serial.println("checkSleepDisplay displayOn: " + String(displayOn)); - Serial.println("checkSleepDisplay DISPLAYCLOCK: " + String(DISPLAYCLOCK)); - Serial.println("checkSleepDisplay isSleepTime: " + String(isSleepTime)); - Serial.println("checkSleepDisplay displaySleepOn: " + String(displaySleepOn)); - Serial.println("checkSleepDisplay DISPLAY_SLEEP_TURNOFF: " + String(DISPLAY_SLEEP_TURNOFF)); - Serial.println("checkSleepDisplay isClockOn: " + String(isClockOn)); - Serial.println("checkSleepDisplay printerClient.isPrinting(): " + String(printerClient.isPrinting())); - Serial.println("checkSleepDisplay printerClient.isPSUoff(): " + String(printerClient.isPSUoff())); delay(5000); } } @@ -1516,14 +1489,6 @@ void checkSleepDisplay() { Serial.println("Display Sleep START: " + timeClient.getFormattedTime()); display.setBrightness(SLEEP_BRIGHTNESS); Serial.println("checkSleepDisplay Display Brightness SLEEP MODE: " + String(SLEEP_BRIGHTNESS)); - Serial.println("checkSleepDisplay displayOn: " + String(displayOn)); - Serial.println("checkSleepDisplay DISPLAYCLOCK: " + String(DISPLAYCLOCK)); - Serial.println("checkSleepDisplay isSleepTime: " + String(isSleepTime)); - Serial.println("checkSleepDisplay displaySleepOn: " + String(displaySleepOn)); - Serial.println("checkSleepDisplay DISPLAY_SLEEP_TURNOFF: " + String(DISPLAY_SLEEP_TURNOFF)); - Serial.println("checkSleepDisplay isClockOn: " + String(isClockOn)); - Serial.println("checkSleepDisplay printerClient.isPrinting(): " + String(printerClient.isPrinting())); - Serial.println("checkSleepDisplay printerClient.isPSUoff(): " + String(printerClient.isPSUoff())); } } From 888d9d9b1d6ab74f0c000db29e9be32572223dfd Mon Sep 17 00:00:00 2001 From: Luciano Coelho Date: Sat, 24 Oct 2020 01:14:22 -0300 Subject: [PATCH 4/6] Fix behavior when "Schedule Display Sleep Mode" is configured without "Display Clock when printer is off". Debug function mydebug, variable enableDebug=false (default) Code optimization of "Schedule Display Sleep Mode" --- printermonitor/printermonitor.ino | 178 +++++++++++++++++++----------- 1 file changed, 113 insertions(+), 65 deletions(-) diff --git a/printermonitor/printermonitor.ino b/printermonitor/printermonitor.ino index d28e066..86782a1 100644 --- a/printermonitor/printermonitor.ino +++ b/printermonitor/printermonitor.ino @@ -30,7 +30,7 @@ SOFTWARE. #include "Settings.h" -#define VERSION "3.1.1" +#define VERSION "3.1.2" #define HOSTNAME "PrintMon-" #define CONFIG "/conf.txt" @@ -85,6 +85,7 @@ String lastReportStatus = ""; boolean displayOn = true; boolean displaySleepOn = false; boolean isSleepTime = false; +boolean enableDebug = false; // Printer Client #if defined(USE_REPETIER_CLIENT) @@ -386,6 +387,7 @@ void loop() { } if (lastMinute != timeClient.getMinutes() && !printerClient.isPrinting()) { + mydebug("loop 60s"); // Check status every 60 seconds ledOnOff(true); lastMinute = timeClient.getMinutes(); // reset the check value @@ -395,6 +397,7 @@ void loop() { } else if (printerClient.isPrinting()) { if (lastSecond != timeClient.getSeconds() && timeClient.getSeconds().endsWith("0")) { lastSecond = timeClient.getSeconds(); + mydebug("loop 10s"); // every 10 seconds while printing get an update ledOnOff(true); printerClient.getPrinterJobResults(); @@ -1355,7 +1358,7 @@ int getMinutesFromLastDisplay() { // Toggle on and off the display if user defined times void checkDisplay() { - // Enable or disable Display Sleep mode + // Check if it is time to Display Sleep mode checkSleepDisplay(); if (!displayOn && DISPLAYCLOCK) { if (isSleepTime && !displaySleepOn) { @@ -1363,54 +1366,70 @@ void checkDisplay() { if (!DISPLAY_SLEEP_TURNOFF) { // Turn on display in brightness sleep mode, otherwise display stays off enableDisplay(true); } - } else if (!isSleepTime) { + } else if (!isSleepTime) { // Turn on display if clock is configured and not in sleep time range enableDisplay(true); } } - if (displayOn && !printerClient.isPrinting() && !DISPLAYCLOCK) { - // 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 && !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; + if (!DISPLAYCLOCK) { // Clock is not configured + if (isSleepTime && !displaySleepOn) { + enableSleepDisplay(true); } - } else if (DISPLAYCLOCK) { - if (displayOn && !displaySleepOn && isSleepTime && DISPLAY_SLEEP_TURNOFF && (!printerClient.isPrinting() || printerClient.isPSUoff())) { - 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); - isClockOn = true; // Avoid set clock mode in display sleep with display off - } else if (displayOn && !displaySleepOn && isSleepTime && !DISPLAY_SLEEP_TURNOFF) { - enableSleepDisplay(true); - } else if ((!printerClient.isPrinting() || printerClient.isPSUoff()) && !isClockOn) { + 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 && !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(); @@ -1425,7 +1444,7 @@ void checkDisplay() { ui.setOverlays(clockOverlay, numberOfOverlays); isClockOn = true; } else if (printerClient.isPrinting() && !printerClient.isPSUoff() && isClockOn) { - if (displaySleepOn && DISPLAY_SLEEP_TURNOFF) { + if (displaySleepOn && DISPLAY_SLEEP_TURNOFF) { // Turn on display is start printing during sleep time range with display off enableDisplay(true); display.clear(); display.display(); @@ -1436,6 +1455,7 @@ void checkDisplay() { Serial.println("Printer Online and Display Sleep mode on, waking up..."); delay(5000); } + // Set Printer Monitor mode Serial.println("Printer Monitor is active."); ui.setFrames(frames, numberOfFrames); ui.setOverlays(overlays, numberOfOverlays); @@ -1454,10 +1474,13 @@ void enableDisplay(boolean enable) { displayOffEpoch = 0; // reset } display.displayOn(); + Serial.println("Display was turned ON: " + timeClient.getFormattedTime()); + mydebug("enableDisplayOn"); } else { display.displayOff(); Serial.println("Display was turned OFF: " + timeClient.getFormattedTime()); displayOffEpoch = lastEpoch; + mydebug("enableDisplayOff"); } } @@ -1465,35 +1488,45 @@ void checkSleepDisplay() { isSleepTime=checkSleepTime(); if (displaySleepOn) { if(!isSleepTime) { - isClockOn=false; - enableSleepDisplay(false); // Disable Sleep Display - Serial.println("Display Sleep FINISH: " + timeClient.getFormattedTime()); + enableSleepDisplay(false); + Serial.println("Display Sleep FINISH Brightness (" + String(DISPLAY_BRIGHTNESS) + "): " + timeClient.getFormattedTime()); display.setBrightness(DISPLAY_BRIGHTNESS); - Serial.println("Display Brightness NORMAL: " + String(DISPLAY_BRIGHTNESS)); - 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..."); - delay(5000); + 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: " + timeClient.getFormattedTime()); + Serial.println("Display Sleep START Brightness (" + String(SLEEP_BRIGHTNESS) + "): " + timeClient.getFormattedTime()); display.setBrightness(SLEEP_BRIGHTNESS); - Serial.println("checkSleepDisplay Display Brightness SLEEP MODE: " + String(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() { @@ -1509,7 +1542,6 @@ bool SleepTime(bool DISPLAY_SLEEP,int BeginSleepHour,int BeginSleepMin,int EndSl int endTime = EndSleepHour * 60 + EndSleepMin; if (beginTime < endTime ) { if ((curTime >= beginTime) && (curTime < endTime)) { - return true; } else { return false; @@ -1538,3 +1570,19 @@ String genOptions(int start,int end, int step, bool pad) { } 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())); +} From f7208ebee12bfb45b93df49b9b49cb8061ab3709 Mon Sep 17 00:00:00 2001 From: Luciano Coelho Date: Sat, 24 Oct 2020 01:42:12 -0300 Subject: [PATCH 5/6] Small fix --- printermonitor/printermonitor.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/printermonitor/printermonitor.ino b/printermonitor/printermonitor.ino index 86782a1..3b9ea85 100644 --- a/printermonitor/printermonitor.ino +++ b/printermonitor/printermonitor.ino @@ -85,7 +85,7 @@ String lastReportStatus = ""; boolean displayOn = true; boolean displaySleepOn = false; boolean isSleepTime = false; -boolean enableDebug = false; +boolean enableDebug = true; // Printer Client #if defined(USE_REPETIER_CLIENT) @@ -1427,6 +1427,8 @@ void checkDisplay() { } 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 From 229fb8aca84dd1058abddfff0b8f3f15736a59a1 Mon Sep 17 00:00:00 2001 From: coelholm <63363549+coelholm@users.noreply.github.com> Date: Sat, 24 Oct 2020 01:53:04 -0300 Subject: [PATCH 6/6] Disable debug --- printermonitor/printermonitor.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printermonitor/printermonitor.ino b/printermonitor/printermonitor.ino index 3b9ea85..26a59cd 100644 --- a/printermonitor/printermonitor.ino +++ b/printermonitor/printermonitor.ino @@ -85,7 +85,7 @@ String lastReportStatus = ""; boolean displayOn = true; boolean displaySleepOn = false; boolean isSleepTime = false; -boolean enableDebug = true; +boolean enableDebug = false; // Printer Client #if defined(USE_REPETIER_CLIENT)