Add Night Mode to turn off or change brightness of display during sleep hours. New configuration parameters were added to configuration menu.
parent
a9a0348efb
commit
481936e599
|
|
@ -1,114 +1,124 @@
|
||||||
/** The MIT License (MIT)
|
/** The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2018 David Payne
|
Copyright (c) 2018 David Payne
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Additional Contributions:
|
// Additional Contributions:
|
||||||
/* 15 Jan 2019 : Owen Carter : Add psucontrol setting */
|
/* 15 Jan 2019 : Owen Carter : Add psucontrol setting */
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Printer Monitor is designed for the Wemos D1 ESP8266
|
* Printer Monitor is designed for the Wemos D1 ESP8266
|
||||||
* Wemos D1 Mini: https://amzn.to/2qLyKJd
|
* Wemos D1 Mini: https://amzn.to/2qLyKJd
|
||||||
* 0.96" OLED I2C 128x64 Display (12864) SSD1306
|
* 0.96" OLED I2C 128x64 Display (12864) SSD1306
|
||||||
* OLED Display: https://amzn.to/2JDEAUF
|
* OLED Display: https://amzn.to/2JDEAUF
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* NOTE: The settings here are the default settings for the first loading.
|
* 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.
|
* 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
|
* 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
|
* erase the file system on the Wemos or use the “Reset Settings” option in
|
||||||
* the Web Interface.
|
* the Web Interface.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
#include <WiFiManager.h>
|
#include <WiFiManager.h>
|
||||||
#include <ESP8266mDNS.h>
|
#include <ESP8266mDNS.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
#include <ESP8266HTTPUpdateServer.h>
|
#include <ESP8266HTTPUpdateServer.h>
|
||||||
#include "TimeClient.h"
|
#include "TimeClient.h"
|
||||||
#include "RepetierClient.h"
|
#include "RepetierClient.h"
|
||||||
#include "OctoPrintClient.h"
|
#include "OctoPrintClient.h"
|
||||||
#include "OpenWeatherMapClient.h"
|
#include "OpenWeatherMapClient.h"
|
||||||
#include "WeatherStationFonts.h"
|
#include "WeatherStationFonts.h"
|
||||||
#include "FS.h"
|
#include "FS.h"
|
||||||
#include "SH1106Wire.h"
|
#include "SH1106Wire.h"
|
||||||
#include "SSD1306Wire.h"
|
#include "SSD1306Wire.h"
|
||||||
#include "OLEDDisplayUi.h"
|
#include "OLEDDisplayUi.h"
|
||||||
|
|
||||||
//******************************
|
//******************************
|
||||||
// Start Settings
|
// Start Settings
|
||||||
//******************************
|
//******************************
|
||||||
|
|
||||||
// OctoPrint / Repetier Monitoring -- Monitor your 3D OctoPrint or Repetier Server
|
// 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
|
//#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 PrinterApiKey = ""; // ApiKey from your User Account on OctoPrint / Repetier
|
||||||
String PrinterHostName = "octopi";// Default 'octopi' -- or hostname if different (optional if your IP changes)
|
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://)
|
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);
|
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 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)
|
String PrinterAuthPass = ""; // only used with haproxy or basic auth (only needed if you must authenticate)
|
||||||
|
|
||||||
// Weather Configuration
|
// Weather Configuration
|
||||||
boolean DISPLAYWEATHER = true; // true = show weather when not printing / false = no weather
|
boolean DISPLAYWEATHER = true; // true = show weather when not printing / false = no weather
|
||||||
String WeatherApiKey = ""; // Your API Key from http://openweathermap.org/
|
String WeatherApiKey = ""; // Your API Key from http://openweathermap.org/
|
||||||
// Default City Location (use http://openweathermap.org/find to find city ID)
|
// Default City Location (use http://openweathermap.org/find to find city ID)
|
||||||
int CityIDs[] = { 5304391 }; //Only USE ONE for weather marquee
|
int CityIDs[] = { 5304391 }; //Only USE ONE for weather marquee
|
||||||
boolean IS_METRIC = false; // false = Imperial and true = Metric
|
boolean IS_METRIC = false; // false = Imperial and true = Metric
|
||||||
// Languages: ar, bg, ca, cz, de, el, en, fa, fi, fr, gl, hr, hu, it, ja, kr, la, lt, mk, nl, pl, pt, ro, ru, se, sk, sl, es, tr, ua, vi, zh_cn, zh_tw
|
// Languages: ar, bg, ca, cz, de, el, en, fa, fi, fr, gl, hr, hu, it, ja, kr, la, lt, mk, nl, pl, pt, pt_br, ro, ru, se, sk, sl, es, tr, ua, vi, zh_cn, zh_tw
|
||||||
String WeatherLanguage = "en"; //Default (en) English
|
String WeatherLanguage = "en"; //Default (en) English
|
||||||
|
|
||||||
// Webserver
|
// Webserver
|
||||||
const int WEBSERVER_PORT = 80; // The port you can access this device on over HTTP
|
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]/
|
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
|
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_username = "admin"; // User account for the Web Interface
|
||||||
char* www_password = "password"; // Password for the Web Interface
|
char* www_password = "password"; // Password for the Web Interface
|
||||||
|
|
||||||
// Date and Time
|
// Date and Time
|
||||||
float UtcOffset = -7; // Hour offset from GMT for your timezone
|
float UtcOffset = -7; // Hour offset from GMT for your timezone
|
||||||
boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock
|
boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock
|
||||||
int minutesBetweenDataRefresh = 15;
|
int minutesBetweenDataRefresh = 15;
|
||||||
boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = turn off display when not printing
|
boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = turn off display when not printing
|
||||||
|
|
||||||
// Display Settings
|
// Display Settings
|
||||||
const int I2C_DISPLAY_ADDRESS = 0x3c; // I2C Address of your Display (usually 0x3c or 0x3d)
|
const int I2C_DISPLAY_ADDRESS = 0x3c; // I2C Address of your Display (usually 0x3c or 0x3d)
|
||||||
const int SDA_PIN = D2;
|
const int SDA_PIN = D2;
|
||||||
const int SCL_PIN = D5; // original code D5 -- Monitor Easy Board use D1
|
const int SCL_PIN = D5; // original code D5 -- Monitor Easy Board use D1
|
||||||
boolean INVERT_DISPLAY = false; // true = pins at top | false = pins at the bottom
|
boolean INVERT_DISPLAY = false; // true = pins at top | false = pins at the bottom
|
||||||
//#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common
|
//#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common
|
||||||
|
|
||||||
// LED Settings
|
// Display Advanced Settings
|
||||||
const int externalLight = LED_BUILTIN; // LED will always flash on bootup or Wifi Errors
|
boolean DISPLAY_SLEEP = false; // true = Turn off or change display brightness / false = don't change display operation
|
||||||
boolean USE_FLASH = true; // true = System LED will Flash on Service Calls; false = disabled LED flashing
|
int BeginSleepHour = 0;
|
||||||
|
int BeginSleepMin = 0;
|
||||||
// PSU Control
|
int EndSleepHour = 0;
|
||||||
boolean HAS_PSU = false; // Set to true if https://github.com/kantlivelong/OctoPrint-PSUControl/ in use
|
int EndSleepMin = 0;
|
||||||
|
boolean DISPLAY_SLEEP_TURNOFF = true; // true = Turno off display / false = change brightness
|
||||||
// OTA Updates
|
int SLEEP_BRIGHTNESS = 50; // Sleep Mode Display Brightness
|
||||||
boolean ENABLE_OTA = true; // this will allow you to load firmware to the device over WiFi (see OTA for ESP8266)
|
int DISPLAY_BRIGHTNESS = 255; // Default Display Brightness
|
||||||
String OTA_Password = ""; // Set an OTA password here -- leave blank if you don't want to be prompted for password
|
|
||||||
|
// LED Settings
|
||||||
//******************************
|
const int externalLight = LED_BUILTIN; // LED will always flash on bootup or Wifi Errors
|
||||||
// End Settings
|
boolean USE_FLASH = true; // true = System LED will Flash on Service Calls; false = disabled LED flashing
|
||||||
//******************************
|
|
||||||
|
// PSU Control
|
||||||
String themeColor = "light-green"; // this can be changed later in the web interface.
|
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.
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ SOFTWARE.
|
||||||
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
#define VERSION "3.0"
|
#define VERSION "3.1"
|
||||||
|
|
||||||
#define HOSTNAME "PrintMon-"
|
#define HOSTNAME "PrintMon-"
|
||||||
#define CONFIG "/conf.txt"
|
#define CONFIG "/conf.txt"
|
||||||
|
|
@ -83,6 +83,7 @@ String lastMinute = "xx";
|
||||||
String lastSecond = "xx";
|
String lastSecond = "xx";
|
||||||
String lastReportStatus = "";
|
String lastReportStatus = "";
|
||||||
boolean displayOn = true;
|
boolean displayOn = true;
|
||||||
|
bool displaySleepOn = false;
|
||||||
|
|
||||||
// Printer Client
|
// Printer Client
|
||||||
#if defined(USE_REPETIER_CLIENT)
|
#if defined(USE_REPETIER_CLIENT)
|
||||||
|
|
@ -119,6 +120,13 @@ static const char CLOCK_FORM[] PROGMEM = "<hr><p><input name='isClockEnabled' cl
|
||||||
"<p><input name='hasPSU' class='w3-check w3-margin-top' type='checkbox' %HAS_PSU_CHECKED%> Use OctoPrint PSU control plugin for clock/blank</p>"
|
"<p><input name='hasPSU' class='w3-check w3-margin-top' type='checkbox' %HAS_PSU_CHECKED%> Use OctoPrint PSU control plugin for clock/blank</p>"
|
||||||
"<p>Clock Sync / Weather Refresh (minutes) <select class='w3-option w3-padding' name='refresh'>%OPTIONS%</select></p>";
|
"<p>Clock Sync / Weather Refresh (minutes) <select class='w3-option w3-padding' name='refresh'>%OPTIONS%</select></p>";
|
||||||
|
|
||||||
|
static const char SLEEP_FORM[] PROGMEM = "<hr><p><input name='isDisplaySleepEnabled' class='w3-check w3-margin-top' type='checkbox' %IS_DISPSLEEP_CHECKED%> Display Sleep Mode (Set Brightness or Turn Off)</p>"
|
||||||
|
"<p>Sleep Starts at (hour:minute) <select class='w3-option w3-padding' name='BeginSleepHour'>%BEGIN_HOUR_OPTIONS%</select>:<select class='w3-option w3-padding' name='BeginSleepMin'>%BEGIN_MINUTE_OPTIONS%</select></p>"
|
||||||
|
"<p>Sleep Stops at (hour:minute) <select class='w3-option w3-padding' name='EndSleepHour'>%END_HOUR_OPTIONS%</select>:<select class='w3-option w3-padding' name='EndSleepMin'>%END_MINUTE_OPTIONS%</select></p>"
|
||||||
|
"<p><input name='isDisplaySleepTurnOff' class='w3-check w3-margin-top' type='checkbox' %IS_DISPSLEEPTURNOFF_CHECKED%> Display Sleep will Turn Off Display</p>"
|
||||||
|
"<p>Display Sleep Brightness <select class='w3-option w3-padding' name='SleepBrightness'>%DISPLAY_BRI_OPTIONS%</select></p>"
|
||||||
|
"<p>Display Brightness Default <select class='w3-option w3-padding' name='DefaultBrightness'>%DISPLAY_DEF_BRI_OPTIONS%</select></p><hr>";
|
||||||
|
|
||||||
static const char THEME_FORM[] PROGMEM = "<p>Theme Color <select class='w3-option w3-padding' name='theme'>%THEME_OPTIONS%</select></p>"
|
static const char THEME_FORM[] PROGMEM = "<p>Theme Color <select class='w3-option w3-padding' name='theme'>%THEME_OPTIONS%</select></p>"
|
||||||
"<p><label>UTC Time Offset</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='utcoffset' value='%UTCOFFSET%' maxlength='12'></p><hr>"
|
"<p><label>UTC Time Offset</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='utcoffset' value='%UTCOFFSET%' maxlength='12'></p><hr>"
|
||||||
"<p><input name='isBasicAuth' class='w3-check w3-margin-top' type='checkbox' %IS_BASICAUTH_CHECKED%> Use Security Credentials for Configuration Changes</p>"
|
"<p><input name='isBasicAuth' class='w3-check w3-margin-top' type='checkbox' %IS_BASICAUTH_CHECKED%> Use Security Credentials for Configuration Changes</p>"
|
||||||
|
|
@ -159,6 +167,7 @@ static const char LANG_OPTIONS[] PROGMEM = "<option>ar</option>"
|
||||||
"<option>nl</option>"
|
"<option>nl</option>"
|
||||||
"<option>pl</option>"
|
"<option>pl</option>"
|
||||||
"<option>pt</option>"
|
"<option>pt</option>"
|
||||||
|
"<option>pt_br</option>"
|
||||||
"<option>ro</option>"
|
"<option>ro</option>"
|
||||||
"<option>ru</option>"
|
"<option>ru</option>"
|
||||||
"<option>se</option>"
|
"<option>se</option>"
|
||||||
|
|
@ -483,6 +492,13 @@ void handleUpdateConfig() {
|
||||||
temp.toCharArray(www_username, sizeof(temp));
|
temp.toCharArray(www_username, sizeof(temp));
|
||||||
temp = server.arg("stationpassword");
|
temp = server.arg("stationpassword");
|
||||||
temp.toCharArray(www_password, sizeof(temp));
|
temp.toCharArray(www_password, sizeof(temp));
|
||||||
|
DISPLAY_SLEEP = server.hasArg("isDisplaySleepEnabled");
|
||||||
|
BeginSleepHour = server.arg("BeginSleepHour").toInt();
|
||||||
|
BeginSleepMin = server.arg("BeginSleepMin").toInt();
|
||||||
|
EndSleepHour = server.arg("EndSleepHour").toInt();
|
||||||
|
EndSleepMin = server.arg("EndSleepMin").toInt();
|
||||||
|
DISPLAY_SLEEP_TURNOFF = server.hasArg("isDisplaySleepTurnOff");
|
||||||
|
SLEEP_BRIGHTNESS = server.arg("SleepBrightness").toInt();
|
||||||
writeSettings();
|
writeSettings();
|
||||||
findMDNS();
|
findMDNS();
|
||||||
printerClient.getPrinterJobResults();
|
printerClient.getPrinterJobResults();
|
||||||
|
|
@ -655,6 +671,39 @@ void handleConfigure() {
|
||||||
|
|
||||||
server.sendContent(form);
|
server.sendContent(form);
|
||||||
|
|
||||||
|
form = FPSTR(SLEEP_FORM);
|
||||||
|
String isDisplaySleepEnabledChecked="";
|
||||||
|
if (DISPLAY_SLEEP) {
|
||||||
|
isDisplaySleepEnabledChecked="checked='checked'";
|
||||||
|
}
|
||||||
|
form.replace("%IS_DISPSLEEP_CHECKED%", isDisplaySleepEnabledChecked);
|
||||||
|
String isDisplaySleepTurnOffChecked="";
|
||||||
|
if (DISPLAY_SLEEP_TURNOFF) {
|
||||||
|
isDisplaySleepTurnOffChecked="checked='checked'";
|
||||||
|
}
|
||||||
|
form.replace("%IS_DISPSLEEPTURNOFF_CHECKED%", isDisplaySleepTurnOffChecked);
|
||||||
|
|
||||||
|
String optionsBeginSleepHour = "<option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option>";
|
||||||
|
optionsBeginSleepHour.replace(">"+String(zeroPad(BeginSleepHour))+"<", " selected>"+String(zeroPad(BeginSleepHour))+"<");
|
||||||
|
form.replace("%BEGIN_HOUR_OPTIONS%", optionsBeginSleepHour);
|
||||||
|
String optionsEndSleepHour = "<option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option>";
|
||||||
|
optionsEndSleepHour.replace(">"+String(zeroPad(EndSleepHour))+"<", " selected>"+String(zeroPad(EndSleepHour))+"<");
|
||||||
|
form.replace("%END_HOUR_OPTIONS%", optionsEndSleepHour);
|
||||||
|
String optionsBeginSleepMin = genOptions(0,59,1,true);
|
||||||
|
optionsBeginSleepMin.replace(">"+String(zeroPad(BeginSleepMin))+"<", " selected>"+String(zeroPad(BeginSleepMin))+"<");
|
||||||
|
form.replace("%BEGIN_MINUTE_OPTIONS%", optionsBeginSleepMin);
|
||||||
|
String optionsEndSleepMin = genOptions(0,59,1,true);
|
||||||
|
optionsEndSleepMin.replace(">"+String(zeroPad(EndSleepMin))+"<", " selected>"+String(zeroPad(EndSleepMin))+"<");
|
||||||
|
form.replace("%END_MINUTE_OPTIONS%", optionsEndSleepMin);
|
||||||
|
String optionsSleepBrightness = genOptions(0,255,15,false);
|
||||||
|
optionsSleepBrightness.replace(">"+String(SLEEP_BRIGHTNESS)+"<", " selected>"+String(SLEEP_BRIGHTNESS)+"<");
|
||||||
|
form.replace("%DISPLAY_BRI_OPTIONS%", optionsSleepBrightness);
|
||||||
|
String optionsDefaultBrightness = genOptions(0,255,15,false);
|
||||||
|
optionsDefaultBrightness.replace(">"+String(DISPLAY_BRIGHTNESS)+"<", " selected>"+String(DISPLAY_BRIGHTNESS)+"<");
|
||||||
|
form.replace("%DISPLAY_DEF_BRI_OPTIONS%", optionsDefaultBrightness);
|
||||||
|
|
||||||
|
server.sendContent(form);
|
||||||
|
|
||||||
form = FPSTR(THEME_FORM);
|
form = FPSTR(THEME_FORM);
|
||||||
|
|
||||||
String themeOptions = FPSTR(COLOR_THEMES);
|
String themeOptions = FPSTR(COLOR_THEMES);
|
||||||
|
|
@ -1143,6 +1192,14 @@ void writeSettings() {
|
||||||
f.println("isMetric=" + String(IS_METRIC));
|
f.println("isMetric=" + String(IS_METRIC));
|
||||||
f.println("language=" + String(WeatherLanguage));
|
f.println("language=" + String(WeatherLanguage));
|
||||||
f.println("hasPSU=" + String(HAS_PSU));
|
f.println("hasPSU=" + String(HAS_PSU));
|
||||||
|
f.println("DISPLAY_SLEEP=" + String(DISPLAY_SLEEP));
|
||||||
|
f.println("BeginSleepHour=" + String(BeginSleepHour));
|
||||||
|
f.println("BeginSleepMin=" + String(BeginSleepMin));
|
||||||
|
f.println("EndSleepHour=" + String(EndSleepHour));
|
||||||
|
f.println("EndSleepMin=" + String(EndSleepMin));
|
||||||
|
f.println("DISPLAY_SLEEP_TURNOFF=" + String(DISPLAY_SLEEP_TURNOFF));
|
||||||
|
f.println("SLEEP_BRIGHTNESS=" + String(SLEEP_BRIGHTNESS));
|
||||||
|
f.println("DISPLAY_BRIGHTNESS=" + String(DISPLAY_BRIGHTNESS));
|
||||||
}
|
}
|
||||||
f.close();
|
f.close();
|
||||||
readSettings();
|
readSettings();
|
||||||
|
|
@ -1266,6 +1323,15 @@ void readSettings() {
|
||||||
WeatherLanguage.trim();
|
WeatherLanguage.trim();
|
||||||
Serial.println("WeatherLanguage=" + WeatherLanguage);
|
Serial.println("WeatherLanguage=" + WeatherLanguage);
|
||||||
}
|
}
|
||||||
|
if (line.indexOf("DISPLAY_SLEEP=") >= 0) { DISPLAY_SLEEP = line.substring(line.lastIndexOf("DISPLAY_SLEEP=") + sizeof("DISPLAY_SLEEP=")-1).toInt(); Serial.println("DISPLAY_SLEEP=" + String(DISPLAY_SLEEP) ); }
|
||||||
|
if (line.indexOf("BeginSleepHour=") >= 0) { BeginSleepHour = line.substring(line.lastIndexOf("BeginSleepHour=") + sizeof("BeginSleepHour=")-1).toInt(); Serial.println("BeginSleepHour=" + String(BeginSleepHour) ); }
|
||||||
|
if (line.indexOf("BeginSleepMin=") >= 0) { BeginSleepMin = line.substring(line.lastIndexOf("BeginSleepMin=") + sizeof("BeginSleepMin=")-1).toInt(); Serial.println("BeginSleepMin=" + String(BeginSleepMin) ); }
|
||||||
|
if (line.indexOf("EndSleepHour=") >= 0) { EndSleepHour = line.substring(line.lastIndexOf("EndSleepHour=") + sizeof("EndSleepHour=")-1).toInt(); Serial.println("EndSleepHour=" + String(EndSleepHour) ); }
|
||||||
|
if (line.indexOf("EndSleepMin=") >= 0) { EndSleepMin = line.substring(line.lastIndexOf("EndSleepMin=") + sizeof("EndSleepMin=")-1).toInt(); Serial.println("EndSleepMin=" + String(EndSleepMin) ); }
|
||||||
|
if (line.indexOf("DISPLAY_SLEEP_TURNOFF=") >= 0) { DISPLAY_SLEEP_TURNOFF = line.substring(line.lastIndexOf("DISPLAY_SLEEP_TURNOFF=") + sizeof("DISPLAY_SLEEP_TURNOFF=")-1).toInt(); Serial.println("DISPLAY_SLEEP_TURNOFF=" + String(DISPLAY_SLEEP_TURNOFF) ); }
|
||||||
|
if (line.indexOf("SLEEP_BRIGHTNESS=") >= 0) { SLEEP_BRIGHTNESS = line.substring(line.lastIndexOf("SLEEP_BRIGHTNESS=") + sizeof("SLEEP_BRIGHTNESS=")-1).toInt(); Serial.println("SLEEP_BRIGHTNESS=" + String(SLEEP_BRIGHTNESS) ); }
|
||||||
|
if (line.indexOf("DISPLAY_BRIGHTNESS=") >= 0) { DISPLAY_BRIGHTNESS = line.substring(line.lastIndexOf("DISPLAY_BRIGHTNESS=") + sizeof("DISPLAY_BRIGHTNESS=")-1).toInt(); Serial.println("DISPLAY_BRIGHTNESS=" + String(DISPLAY_BRIGHTNESS) ); }
|
||||||
|
|
||||||
}
|
}
|
||||||
fr.close();
|
fr.close();
|
||||||
printerClient.updatePrintClient(PrinterApiKey, PrinterServer, PrinterPort, PrinterAuthUser, PrinterAuthPass, HAS_PSU);
|
printerClient.updatePrintClient(PrinterApiKey, PrinterServer, PrinterPort, PrinterAuthUser, PrinterAuthPass, HAS_PSU);
|
||||||
|
|
@ -1288,8 +1354,16 @@ 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
|
||||||
|
checkSleepDisplay();
|
||||||
if (!displayOn && DISPLAYCLOCK) {
|
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) {
|
if (displayOn && !printerClient.isPrinting() && !DISPLAYCLOCK) {
|
||||||
// Put Display to sleep
|
// Put Display to sleep
|
||||||
|
|
@ -1320,6 +1394,18 @@ void checkDisplay() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (DISPLAYCLOCK) {
|
} 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) {
|
if ((!printerClient.isPrinting() || printerClient.isPSUoff()) && !isClockOn) {
|
||||||
Serial.println("Clock Mode is turned on.");
|
Serial.println("Clock Mode is turned on.");
|
||||||
if (!DISPLAYWEATHER) {
|
if (!DISPLAYWEATHER) {
|
||||||
|
|
@ -1335,6 +1421,17 @@ 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) {
|
||||||
|
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.");
|
Serial.println("Printer Monitor is active.");
|
||||||
ui.setFrames(frames, numberOfFrames);
|
ui.setFrames(frames, numberOfFrames);
|
||||||
ui.setOverlays(overlays, numberOfOverlays);
|
ui.setOverlays(overlays, numberOfOverlays);
|
||||||
|
|
@ -1360,3 +1457,73 @@ void enableDisplay(boolean enable) {
|
||||||
displayOffEpoch = lastEpoch;
|
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 += "<option>";
|
||||||
|
if (pad) {
|
||||||
|
temp += String(zeroPad(i));
|
||||||
|
} else {
|
||||||
|
temp += String(i);
|
||||||
|
}
|
||||||
|
temp += "</option>";
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue