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"pull/119/head
parent
501c6a1aee
commit
888d9d9b1d
|
|
@ -30,7 +30,7 @@ SOFTWARE.
|
||||||
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
#define VERSION "3.1.1"
|
#define VERSION "3.1.2"
|
||||||
|
|
||||||
#define HOSTNAME "PrintMon-"
|
#define HOSTNAME "PrintMon-"
|
||||||
#define CONFIG "/conf.txt"
|
#define CONFIG "/conf.txt"
|
||||||
|
|
@ -85,6 +85,7 @@ String lastReportStatus = "";
|
||||||
boolean displayOn = true;
|
boolean displayOn = true;
|
||||||
boolean displaySleepOn = false;
|
boolean displaySleepOn = false;
|
||||||
boolean isSleepTime = false;
|
boolean isSleepTime = false;
|
||||||
|
boolean enableDebug = false;
|
||||||
|
|
||||||
// Printer Client
|
// Printer Client
|
||||||
#if defined(USE_REPETIER_CLIENT)
|
#if defined(USE_REPETIER_CLIENT)
|
||||||
|
|
@ -386,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
|
||||||
|
|
@ -395,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();
|
||||||
|
|
@ -1355,7 +1358,7 @@ 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() {
|
||||||
// Enable or disable Display Sleep mode
|
// Check if it is time to Display Sleep mode
|
||||||
checkSleepDisplay();
|
checkSleepDisplay();
|
||||||
if (!displayOn && DISPLAYCLOCK) {
|
if (!displayOn && DISPLAYCLOCK) {
|
||||||
if (isSleepTime && !displaySleepOn) {
|
if (isSleepTime && !displaySleepOn) {
|
||||||
|
|
@ -1363,40 +1366,54 @@ void checkDisplay() {
|
||||||
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 if (!isSleepTime) {
|
} else if (!isSleepTime) { // Turn on display if clock is configured and not in sleep time range
|
||||||
enableDisplay(true);
|
enableDisplay(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (displayOn && !printerClient.isPrinting() && !DISPLAYCLOCK) {
|
if (!DISPLAYCLOCK) { // Clock is not configured
|
||||||
|
if (isSleepTime && !displaySleepOn) {
|
||||||
|
enableSleepDisplay(true);
|
||||||
|
}
|
||||||
|
if (displayOn) {
|
||||||
|
if (!printerClient.isOperational()) {
|
||||||
// Put Display to sleep
|
// Put Display to sleep
|
||||||
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.setContrast(255); // default is 255
|
// display.setContrast(255); // default is 255
|
||||||
display.drawString(64, 5, "Printer Offline\nSleep Mode...");
|
display.drawString(64, 5, "Printer Offline\nSleep Mode...");
|
||||||
display.display();
|
display.display();
|
||||||
delay(5000);
|
delay(5000);
|
||||||
enableDisplay(false);
|
enableDisplay(false);
|
||||||
Serial.println("Printer is offline going down to sleep...");
|
Serial.println("Printer is offline going down to sleep...");
|
||||||
return;
|
return;
|
||||||
} else if (!displayOn && !DISPLAYCLOCK) {
|
}
|
||||||
if (printerClient.isOperational()) {
|
} else if (!displayOn) { // Display is off
|
||||||
|
if (printerClient.isOperational()) { // Turn on display if printer is Operational
|
||||||
// Wake the Screen up
|
// Wake the Screen up
|
||||||
enableDisplay(true);
|
enableDisplay(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.setContrast(255); // default is 255
|
// display.setContrast(255); // default is 255
|
||||||
display.drawString(64, 5, "Printer Online\nWake up...");
|
display.drawString(64, 5, "Printer Online\nWake up...");
|
||||||
display.display();
|
display.display();
|
||||||
Serial.println("Printer is online waking up...");
|
Serial.println("Printer is online waking up...");
|
||||||
delay(5000);
|
delay(5000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (DISPLAYCLOCK) {
|
} else if (printerClient.isPrinting() && !printerClient.isPSUoff() && isClockOn) { // Set Printer Monitor mode when printing
|
||||||
if (displayOn && !displaySleepOn && isSleepTime && DISPLAY_SLEEP_TURNOFF && (!printerClient.isPrinting() || printerClient.isPSUoff())) {
|
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);
|
enableSleepDisplay(true);
|
||||||
display.clear();
|
display.clear();
|
||||||
display.display();
|
display.display();
|
||||||
|
|
@ -1407,10 +1424,12 @@ void checkDisplay() {
|
||||||
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
|
} else if (!DISPLAY_SLEEP_TURNOFF) { // Set display sleep mode without changing display (Already set brightness to sleep mode)
|
||||||
} else if (displayOn && !displaySleepOn && isSleepTime && !DISPLAY_SLEEP_TURNOFF) {
|
|
||||||
enableSleepDisplay(true);
|
enableSleepDisplay(true);
|
||||||
} else if ((!printerClient.isPrinting() || printerClient.isPSUoff()) && !isClockOn) {
|
}
|
||||||
|
} 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.");
|
Serial.println("Clock Mode is turned on.");
|
||||||
if (!DISPLAYWEATHER) {
|
if (!DISPLAYWEATHER) {
|
||||||
ui.disableAutoTransition();
|
ui.disableAutoTransition();
|
||||||
|
|
@ -1425,7 +1444,7 @@ void checkDisplay() {
|
||||||
ui.setOverlays(clockOverlay, numberOfOverlays);
|
ui.setOverlays(clockOverlay, numberOfOverlays);
|
||||||
isClockOn = true;
|
isClockOn = true;
|
||||||
} else if (printerClient.isPrinting() && !printerClient.isPSUoff() && isClockOn) {
|
} 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);
|
enableDisplay(true);
|
||||||
display.clear();
|
display.clear();
|
||||||
display.display();
|
display.display();
|
||||||
|
|
@ -1436,6 +1455,7 @@ void checkDisplay() {
|
||||||
Serial.println("Printer Online and Display Sleep mode on, waking up...");
|
Serial.println("Printer Online and Display Sleep mode on, waking up...");
|
||||||
delay(5000);
|
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);
|
||||||
|
|
@ -1454,10 +1474,13 @@ void enableDisplay(boolean enable) {
|
||||||
displayOffEpoch = 0; // reset
|
displayOffEpoch = 0; // reset
|
||||||
}
|
}
|
||||||
display.displayOn();
|
display.displayOn();
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1465,12 +1488,16 @@ void checkSleepDisplay() {
|
||||||
isSleepTime=checkSleepTime();
|
isSleepTime=checkSleepTime();
|
||||||
if (displaySleepOn) {
|
if (displaySleepOn) {
|
||||||
if(!isSleepTime) {
|
if(!isSleepTime) {
|
||||||
isClockOn=false;
|
|
||||||
enableSleepDisplay(false);
|
|
||||||
// Disable Sleep Display
|
// 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);
|
display.setBrightness(DISPLAY_BRIGHTNESS);
|
||||||
Serial.println("Display Brightness NORMAL: " + String(DISPLAY_BRIGHTNESS));
|
if (!displayOn) {
|
||||||
|
display.displayOff(); // Keep display off after brightness change
|
||||||
|
}
|
||||||
|
mydebug("checkSleepDisplay FINISH");
|
||||||
|
if (DISPLAYCLOCK) {
|
||||||
|
isClockOn=false;
|
||||||
if (DISPLAY_SLEEP_TURNOFF) {
|
if (DISPLAY_SLEEP_TURNOFF) {
|
||||||
enableDisplay(true);
|
enableDisplay(true);
|
||||||
display.clear();
|
display.clear();
|
||||||
|
|
@ -1481,19 +1508,25 @@ 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...");
|
||||||
|
mydebug("checkSleepDisplay WAKEUP");
|
||||||
delay(5000);
|
delay(5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (isSleepTime && !displaySleepOn) {
|
} else if (isSleepTime && !displaySleepOn) {
|
||||||
// Enable Sleep Display
|
// 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);
|
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) {
|
void enableSleepDisplay(boolean enable) {
|
||||||
displaySleepOn=enable;
|
displaySleepOn=enable;
|
||||||
|
mydebug("enableSleepDisplay " + String(enable));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checkSleepTime() {
|
bool checkSleepTime() {
|
||||||
|
|
@ -1509,7 +1542,6 @@ bool SleepTime(bool DISPLAY_SLEEP,int BeginSleepHour,int BeginSleepMin,int EndSl
|
||||||
int endTime = EndSleepHour * 60 + EndSleepMin;
|
int endTime = EndSleepHour * 60 + EndSleepMin;
|
||||||
if (beginTime < endTime ) {
|
if (beginTime < endTime ) {
|
||||||
if ((curTime >= beginTime) && (curTime < endTime)) {
|
if ((curTime >= beginTime) && (curTime < endTime)) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1538,3 +1570,19 @@ String genOptions(int start,int end, int step, bool pad) {
|
||||||
}
|
}
|
||||||
return temp;
|
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()));
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue