From 602bf84f4c9639abbb7b44699aed7d3d2d4c69bc Mon Sep 17 00:00:00 2001 From: derpicknicker1 <10minutemail@web.de> Date: Thu, 20 Sep 2018 09:35:17 +0200 Subject: [PATCH] Added option to invert display Added the option to invert the display to the config menu. So noone has to care about this beforre flashing the firmware. --- printermonitor/Settings.h | 3 ++- printermonitor/printermonitor.ino | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/printermonitor/Settings.h b/printermonitor/Settings.h index 5cd795c..5a0ccbe 100644 --- a/printermonitor/Settings.h +++ b/printermonitor/Settings.h @@ -1,6 +1,7 @@ /** The MIT License (MIT) Copyright (c) 2018 David Payne +Copyright (c) 2018 Florian Schütte Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -81,7 +82,7 @@ boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = 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; -const 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 boolean ENABLE_OTA = true; // this will allow you to load firmware to the device over WiFi (see OTA for ESP8266) diff --git a/printermonitor/printermonitor.ino b/printermonitor/printermonitor.ino index 9914324..6b65082 100644 --- a/printermonitor/printermonitor.ino +++ b/printermonitor/printermonitor.ino @@ -1,6 +1,7 @@ /** The MIT License (MIT) Copyright (c) 2018 David Payne +Copyright (c) 2018 Florian Schütte Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -112,6 +113,7 @@ String CHANGE_FORM = "
Display Clock when printer is off

" "

Use 24 Hour Clock (military time)

" + "

Flip display?

" "

Clock Sync / Weather Refresh (minutes)

" "

Theme Color

" "


" @@ -400,6 +402,7 @@ void handleUpdateWeather() { } void handleUpdateConfig() { + boolean flipOld = INVERT_DISPLAY; if (!server.authenticate(www_username, www_password)) { return server.requestAuthentication(); } @@ -411,6 +414,7 @@ void handleUpdateConfig() { OctoAuthPass = server.arg("octoPass"); DISPLAYCLOCK = server.hasArg("isClockEnabled"); IS_24HOUR = server.hasArg("is24hour"); + INVERT_DISPLAY = server.hasArg("invDisp"); minutesBetweenDataRefresh = server.arg("refresh").toInt(); themeColor = server.arg("theme"); UtcOffset = server.arg("utcoffset").toFloat(); @@ -421,6 +425,12 @@ void handleUpdateConfig() { writeSettings(); findMDNS(); printerClient.getPrinterJobResults(); + if (INVERT_DISPLAY != flipOld) { + ui.init(); + if(INVERT_DISPLAY) + display.flipScreenVertically(); + ui.update(); + } checkDisplay(); lastEpoch = 0; redirectHome(); @@ -512,6 +522,11 @@ void handleConfigure() { is24hourChecked = "checked='checked'"; } form.replace("%IS_24HOUR_CHECKED%", is24hourChecked); + String isInvDisp = ""; + if (INVERT_DISPLAY) { + isInvDisp = "checked='checked'"; + } + form.replace("%IS_INVDISP_CHECKED%", isInvDisp); String options = ""; options.replace(">"+String(minutesBetweenDataRefresh)+"<", " selected>"+String(minutesBetweenDataRefresh)+"<"); form.replace("%OPTIONS%", options); @@ -937,6 +952,7 @@ void writeSettings() { f.println("www_password=" + String(www_password)); f.println("DISPLAYCLOCK=" + String(DISPLAYCLOCK)); f.println("is24hour=" + String(IS_24HOUR)); + f.println("invertDisp=" + String(INVERT_DISPLAY)); f.println("isWeather=" + String(DISPLAYWEATHER)); f.println("weatherKey=" + WeatherApiKey); f.println("CityID=" + String(CityIDs[0])); @@ -1020,6 +1036,10 @@ void readSettings() { IS_24HOUR = line.substring(line.lastIndexOf("is24hour=") + 9).toInt(); Serial.println("IS_24HOUR=" + String(IS_24HOUR)); } + if(line.indexOf("invertDisp=") >= 0) { + INVERT_DISPLAY = line.substring(line.lastIndexOf("invertDisp=") + 11).toInt(); + Serial.println("INVERT_DISPLAY=" + String(INVERT_DISPLAY)); + } if (line.indexOf("isWeather=") >= 0) { DISPLAYWEATHER = line.substring(line.lastIndexOf("isWeather=") + 10).toInt(); Serial.println("DISPLAYWEATHER=" + String(DISPLAYWEATHER));