From f3844ea773f7fb1d45385d463368649669565c7f Mon Sep 17 00:00:00 2001 From: Chrome Legion Date: Thu, 24 May 2018 07:11:12 -0700 Subject: [PATCH 1/2] Qrome - added 24 hour clock format --- printermonitor/Settings.h | 1 + printermonitor/printermonitor.ino | 45 ++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/printermonitor/Settings.h b/printermonitor/Settings.h index a5abcec..96adc95 100644 --- a/printermonitor/Settings.h +++ b/printermonitor/Settings.h @@ -60,6 +60,7 @@ const boolean WEBSERVER_ENABLED = true; // Device will provide a web interface char* www_username = "admin"; // User account for the Web Interface char* www_password = "password"; // Password for the Web Interface float UtcOffset = -7; // Hour offset from GMT for your timezone +boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock int minutesBetweenDataRefresh = 60; boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = turn off display when not printing diff --git a/printermonitor/printermonitor.ino b/printermonitor/printermonitor.ino index 79d64fa..11e360d 100644 --- a/printermonitor/printermonitor.ino +++ b/printermonitor/printermonitor.ino @@ -27,7 +27,7 @@ SOFTWARE. #include "Settings.h" -#define VERSION "1.2" +#define VERSION "1.3" #define HOSTNAME "ESP8266-" #define CONFIG "/conf.txt" @@ -98,6 +98,7 @@ const String CHANGE_FORM = "
OctoPrint Address (do not include http://)" "" " Display Clock when printer is off

" + " Use 24 Hour Clock (military time)

" "Time Refresh (minutes)

" "Theme Color

" "" @@ -329,6 +330,7 @@ void handleUpdateConfig() { OctoPrintServer = server.arg("octoPrintAddress"); OctoPrintPort = server.arg("octoPrintPort").toInt(); DISPLAYCLOCK = server.hasArg("isClockEnabled"); + IS_24HOUR = server.hasArg("is24hour"); minutesBetweenDataRefresh = server.arg("refresh").toInt(); themeColor = server.arg("theme"); UtcOffset = server.arg("utcoffset").toFloat(); @@ -381,6 +383,11 @@ void handleConfigure() { isClockChecked = "checked='checked'"; } form.replace("%IS_CLOCK_CHECKED%", isClockChecked); + String is24hourChecked = ""; + if (IS_24HOUR) { + is24hourChecked = "checked='checked'"; + } + form.replace("%IS_24HOUR_CHECKED%", is24hourChecked); String options = ""; options.replace(">"+String(minutesBetweenDataRefresh)+"<", " selected>"+String(minutesBetweenDataRefresh)+"<"); form.replace("%OPTIONS%", options); @@ -491,7 +498,12 @@ void displayPrinterStatus() { server.send(200, "text/html", ""); server.sendContent(String(getHeader(true))); - html += "

Time: " + timeClient.getAmPmHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds() + " " + timeClient.getAmPm() + "

"; + String displayTime = timeClient.getAmPmHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds() + " " + timeClient.getAmPm(); + if (IS_24HOUR) { + displayTime = timeClient.getHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds(); + } + + html += "

Time: " + displayTime + "

"; html += "

"; if (printerClient.getError() != "") { html += "Error: " + printerClient.getError() + "
"; @@ -610,8 +622,11 @@ void drawScreen3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int void drawClock(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { display->setTextAlignment(TEXT_ALIGN_CENTER); display->setFont(ArialMT_Plain_24); - String time = timeClient.getAmPmHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds(); - display->drawString(64 + x, 10 + y, time); + String displayTime = timeClient.getAmPmHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds(); + if (IS_24HOUR) { + displayTime = timeClient.getHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds(); + } + display->drawString(64 + x, 10 + y, displayTime); } String zeroPad(int value) { @@ -625,12 +640,19 @@ String zeroPad(int value) { void drawHeaderOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) { display->setColor(WHITE); display->setFont(ArialMT_Plain_16); - String time = timeClient.getAmPmHours() + ":" + timeClient.getMinutes(); + String displayTime = timeClient.getAmPmHours() + ":" + timeClient.getMinutes(); + if (IS_24HOUR) { + displayTime = timeClient.getHours() + ":" + timeClient.getMinutes(); + } display->setTextAlignment(TEXT_ALIGN_LEFT); - display->drawString(0, 48, time); - String ampm = timeClient.getAmPm(); - display->setFont(ArialMT_Plain_10); - display->drawString(39, 54, ampm); + display->drawString(0, 48, displayTime); + + if (!IS_24HOUR) { + String ampm = timeClient.getAmPm(); + display->setFont(ArialMT_Plain_10); + display->drawString(39, 54, ampm); + } + display->setFont(ArialMT_Plain_16); display->setTextAlignment(TEXT_ALIGN_LEFT); String percent = String(printerClient.getProgressCompletion()) + "%"; @@ -705,6 +727,7 @@ void writeSettings() { f.println("www_username=" + String(www_username)); f.println("www_password=" + String(www_password)); f.println("DISPLAYCLOCK=" + String(DISPLAYCLOCK)); + f.println("is24hour=" + String(IS_24HOUR)); } f.close(); readSettings(); @@ -765,6 +788,10 @@ void readSettings() { DISPLAYCLOCK = line.substring(line.lastIndexOf("DISPLAYCLOCK=") + 13).toInt(); Serial.println("DISPLAYCLOCK=" + String(DISPLAYCLOCK)); } + if (line.indexOf("is24hour=") >= 0) { + IS_24HOUR = line.substring(line.lastIndexOf("is24hour=") + 9).toInt(); + Serial.println("IS_24HOUR=" + String(IS_24HOUR)); + } } fr.close(); printerClient.updateOctoPrintClient(OctoPrintApiKey, OctoPrintServer, OctoPrintPort); From 886bb7fb6be2c80bd1c2641a397dfb1916541a6e Mon Sep 17 00:00:00 2001 From: Qrome <32021227+Qrome@users.noreply.github.com> Date: Thu, 24 May 2018 07:12:44 -0700 Subject: [PATCH 2/2] Updated features --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a4ba517..571dce6 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ SOFTWARE. * Screen turns off when printer is turned off or disconnected * Screen turns on when printer is Operational or connected * Option to display a clock screen instead of sleep mode +* Option to display 24 hour clock or AM/PM style * Sample rate is every 60 seconds when not printing * Sample rate is every 10 seconds when printing * Fully configurable from the web interface (not required to update Settings.h)