Bug fix when exit sleep time when display was turned off.

pull/119/head
Luciano Coelho 2020-10-22 23:06:19 -03:00
parent 481936e599
commit 5f86c26e49
1 changed files with 86 additions and 40 deletions

View File

@ -30,7 +30,7 @@ SOFTWARE.
#include "Settings.h" #include "Settings.h"
#define VERSION "3.1" #define VERSION "3.1.1"
#define HOSTNAME "PrintMon-" #define HOSTNAME "PrintMon-"
#define CONFIG "/conf.txt" #define CONFIG "/conf.txt"
@ -83,7 +83,8 @@ String lastMinute = "xx";
String lastSecond = "xx"; String lastSecond = "xx";
String lastReportStatus = ""; String lastReportStatus = "";
boolean displayOn = true; boolean displayOn = true;
bool displaySleepOn = false; boolean displaySleepOn = false;
boolean isSleepTime = false;
// Printer Client // Printer Client
#if defined(USE_REPETIER_CLIENT) #if defined(USE_REPETIER_CLIENT)
@ -1357,11 +1358,12 @@ void checkDisplay() {
// Enable or disable Display Sleep mode // Enable or disable Display Sleep mode
checkSleepDisplay(); checkSleepDisplay();
if (!displayOn && DISPLAYCLOCK) { 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 if (!DISPLAY_SLEEP_TURNOFF) { // Turn on display in brightness sleep mode, otherwise display stays off
enableDisplay(true); enableDisplay(true);
} }
} else { } else if (!isSleepTime) {
enableDisplay(true); enableDisplay(true);
} }
} }
@ -1394,19 +1396,21 @@ void checkDisplay() {
return; return;
} }
} else if (DISPLAYCLOCK) { } else if (DISPLAYCLOCK) {
if (displayOn && (!printerClient.isPrinting() || printerClient.isPSUoff()) && displaySleepOn && DISPLAY_SLEEP_TURNOFF) { if (displayOn && !displaySleepOn && isSleepTime && DISPLAY_SLEEP_TURNOFF && (!printerClient.isPrinting() || printerClient.isPSUoff())) {
isClockOn = true; enableSleepDisplay(true);
display.clear(); display.clear();
display.display(); display.display();
display.setFont(ArialMT_Plain_16); display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_CENTER); display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(64, 5, "Printer Offline\nDisplay\nSleep Mode"); display.drawString(64, 5, "Printer Offline\nDisplay\nSleep Mode");
display.display(); 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); delay(5000);
enableDisplay(false); enableDisplay(false);
} isClockOn = true; // Avoid set clock mode in display sleep with display off
if ((!printerClient.isPrinting() || printerClient.isPSUoff()) && !isClockOn) { } else if (displayOn && !displaySleepOn && isSleepTime && !DISPLAY_SLEEP_TURNOFF) {
enableSleepDisplay(true);
} else if ((!printerClient.isPrinting() || printerClient.isPSUoff()) && !isClockOn) {
Serial.println("Clock Mode is turned on."); Serial.println("Clock Mode is turned on.");
if (!DISPLAYWEATHER) { if (!DISPLAYWEATHER) {
ui.disableAutoTransition(); ui.disableAutoTransition();
@ -1451,20 +1455,40 @@ void enableDisplay(boolean enable) {
} }
display.displayOn(); display.displayOn();
Serial.println("Display was turned ON: " + timeClient.getFormattedTime()); 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 { } 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;
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() { void checkSleepDisplay() {
isSleepTime=checkSleepTime();
if (displaySleepOn) { if (displaySleepOn) {
if(!enableSleepDisplay()) { if(!isSleepTime) {
isClockOn=false;
enableSleepDisplay(false);
// Disable Sleep Display // Disable Sleep Display
Serial.println("Display Sleep FINISH: " + timeClient.getFormattedTime()); Serial.println("Display Sleep FINISH: " + timeClient.getFormattedTime());
display.setBrightness(DISPLAY_BRIGHTNESS); display.setBrightness(DISPLAY_BRIGHTNESS);
Serial.println("Display Brightness NORMAL: " + String(DISPLAY_BRIGHTNESS)); Serial.println("Display Brightness NORMAL: " + String(DISPLAY_BRIGHTNESS));
if (DISPLAY_SLEEP_TURNOFF) {
enableDisplay(true); enableDisplay(true);
display.clear(); display.clear();
display.display(); display.display();
@ -1474,22 +1498,44 @@ void checkSleepDisplay() {
display.drawString(64, 5, "Display\nWake up..."); display.drawString(64, 5, "Display\nWake up...");
display.display(); display.display();
Serial.println("Display waking up..."); 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); delay(5000);
} }
} else if (enableSleepDisplay()) { }
} else if (isSleepTime && !displaySleepOn) {
// Enable Sleep Display // Enable Sleep Display
Serial.println("Display Sleep START: " + timeClient.getFormattedTime()); Serial.println("Display Sleep START: " + timeClient.getFormattedTime());
display.setBrightness(SLEEP_BRIGHTNESS); 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() { void enableSleepDisplay(boolean enable) {
displaySleepOn=isSleepTime(DISPLAY_SLEEP,BeginSleepHour,BeginSleepMin,EndSleepHour,EndSleepMin); displaySleepOn=enable;
return displaySleepOn;
} }
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) { if (DISPLAY_SLEEP) {
int curHour = timeClient.getHours().toInt(); int curHour = timeClient.getHours().toInt();
int curMin = timeClient.getMinutes().toInt(); int curMin = timeClient.getMinutes().toInt();