Merge pull request #48 from derpicknicker1/disp_flip

Set display orientation in web config
pull/52/head
Qrome 2018-09-27 07:34:17 -07:00 committed by GitHub
commit 0884f0ac03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 31 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
printermonitor/my_Settings.h

View File

@ -48,6 +48,8 @@ SOFTWARE.
* 0.96" OLED I2C 128x64 Display (12864) SSD1306: https://amzn.to/2InSNF0
* (optional) 1.3" I2C OLED Display: https://amzn.to/2IP0gRU (must uncomment #define DISPLAY_SH1106 in the Settings.h to use the 1.3" SSH1106 display)
Note: Using the links provided here help to support these types of projects. Thank you for the support.
## Wiring for the Wemos D1 Mini to the I2C SSD1306 OLED
SDA -> D2
SCL -> D5
@ -100,6 +102,11 @@ used to open a browser to the Web Interface. **Everything** can be configured t
<img src="/images/shot_04.png" width="200"/>
</p>
## Donate or Tip
Please do not feel obligated, but donations and tips are warmly welcomed. I have added the donation button at the request of a few people that wanted to contribute and show appreciation. Thank you, and enjoy the application and project.
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6VPMTLASLSKWE)
## Contributors
David Payne
Daniel Eichhorn -- Author of the TimeClient class and OLEDDisplayUi .

View File

@ -70,7 +70,6 @@ boolean IS_METRIC = false; // false = Imperial and true = Metric
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]/
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_password = "password"; // Password for the Web Interface
float UtcOffset = -7; // Hour offset from GMT for your timezone
@ -82,7 +81,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)

View File

@ -1,4 +1,4 @@
/** The MIT License (MIT)
/** The MIT License (MIT)
Copyright (c) 2018 David Payne
@ -112,10 +112,10 @@ String CHANGE_FORM = "<form class='w3-container' action='/updateconfig' method=
"<p><label>OctoPrint Password </label><input class='w3-input w3-border w3-margin-bottom' type='password' name='octoPass' value='%OCTOPASS%'></p><hr>"
"<p><input name='isClockEnabled' class='w3-check w3-margin-top' type='checkbox' %IS_CLOCK_CHECKED%> Display Clock when printer is off</p>"
"<p><input name='is24hour' class='w3-check w3-margin-top' type='checkbox' %IS_24HOUR_CHECKED%> Use 24 Hour Clock (military time)</p>"
"<p><input name='invDisp' class='w3-check w3-margin-top' type='checkbox' %IS_INVDISP_CHECKED%> Flip display?</p>"
"<p>Clock Sync / Weather Refresh (minutes) <select class='w3-option w3-padding' name='refresh'>%OPTIONS%</select></p>"
"<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>"
"<input name='isBasicAuth' class='w3-check w3-margin-top' type='checkbox' %IS_BASICAUTH_CHECKED%> Use Security Credentials for Configuration Changes"
"<p><label>User ID (for this interface)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='userid' value='%USERID%' maxlength='20'></p>"
"<p><label>Password </label><input class='w3-input w3-border w3-margin-bottom' type='password' name='stationpassword' value='%STATIONPASSWORD%'></p>"
"<button class='w3-button w3-block w3-grey w3-section w3-padding' type='submit'>Save</button></form>";
@ -374,15 +374,8 @@ void getUpdateTime() {
digitalWrite(externalLight, HIGH); // turn off the LED
}
boolean authentication() {
if (IS_BASIC_AUTH && (strlen(www_username) >= 1 && strlen(www_password) >= 1)) {
return server.authenticate(www_username, www_password);
}
return true; // Authentication not required
}
void handleSystemReset() {
if (!authentication()) {
if (!server.authenticate(www_username, www_password)) {
return server.requestAuthentication();
}
Serial.println("Reset System Configuration");
@ -393,7 +386,7 @@ void handleSystemReset() {
}
void handleUpdateWeather() {
if (!authentication()) {
if (!server.authenticate(www_username, www_password)) {
return server.requestAuthentication();
}
DISPLAYWEATHER = server.hasArg("isWeatherEnabled");
@ -408,7 +401,8 @@ void handleUpdateWeather() {
}
void handleUpdateConfig() {
if (!authentication()) {
boolean flipOld = INVERT_DISPLAY;
if (!server.authenticate(www_username, www_password)) {
return server.requestAuthentication();
}
OctoPrintApiKey = server.arg("octoPrintApiKey");
@ -419,10 +413,10 @@ 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();
IS_BASIC_AUTH = server.hasArg("isBasicAuth");
String temp = server.arg("userid");
temp.toCharArray(www_username, sizeof(temp));
temp = server.arg("stationpassword");
@ -430,13 +424,19 @@ void handleUpdateConfig() {
writeSettings();
findMDNS();
printerClient.getPrinterJobResults();
if (INVERT_DISPLAY != flipOld) {
ui.init();
if(INVERT_DISPLAY)
display.flipScreenVertically();
ui.update();
}
checkDisplay();
lastEpoch = 0;
redirectHome();
}
void handleWifiReset() {
if (!authentication()) {
if (!server.authenticate(www_username, www_password)) {
return server.requestAuthentication();
}
//WiFiManager
@ -448,7 +448,7 @@ void handleWifiReset() {
}
void handleWeatherConfigure() {
if (!authentication()) {
if (!server.authenticate(www_username, www_password)) {
return server.requestAuthentication();
}
digitalWrite(externalLight, LOW);
@ -488,7 +488,7 @@ void handleWeatherConfigure() {
}
void handleConfigure() {
if (!authentication()) {
if (!server.authenticate(www_username, www_password)) {
return server.requestAuthentication();
}
digitalWrite(externalLight, LOW);
@ -521,6 +521,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 = "<option>10</option><option>15</option><option>20</option><option>30</option><option>60</option>";
options.replace(">"+String(minutesBetweenDataRefresh)+"<", " selected>"+String(minutesBetweenDataRefresh)+"<");
form.replace("%OPTIONS%", options);
@ -528,11 +533,6 @@ void handleConfigure() {
themeOptions.replace(">"+String(themeColor)+"<", " selected>"+String(themeColor)+"<");
form.replace("%THEME_OPTIONS%", themeOptions);
form.replace("%UTCOFFSET%", String(UtcOffset));
String isUseSecurityChecked = "";
if (IS_BASIC_AUTH) {
isUseSecurityChecked = "checked='checked'";
}
form.replace("%IS_BASICAUTH_CHECKED%", isUseSecurityChecked);
form.replace("%USERID%", String(www_username));
form.replace("%STATIONPASSWORD%", String(www_password));
@ -947,11 +947,11 @@ void writeSettings() {
f.println("octoPass=" + OctoAuthPass);
f.println("refreshRate=" + String(minutesBetweenDataRefresh));
f.println("themeColor=" + themeColor);
f.println("IS_BASIC_AUTH=" + String(IS_BASIC_AUTH));
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.println("invertDisp=" + String(INVERT_DISPLAY));
f.println("isWeather=" + String(DISPLAYWEATHER));
f.println("weatherKey=" + WeatherApiKey);
f.println("CityID=" + String(CityIDs[0]));
@ -1015,10 +1015,6 @@ void readSettings() {
themeColor.trim();
Serial.println("themeColor=" + themeColor);
}
if (line.indexOf("IS_BASIC_AUTH=") >= 0) {
IS_BASIC_AUTH = line.substring(line.lastIndexOf("IS_BASIC_AUTH=") + 14).toInt();
Serial.println("IS_BASIC_AUTH=" + String(IS_BASIC_AUTH));
}
if (line.indexOf("www_username=") >= 0) {
String temp = line.substring(line.lastIndexOf("www_username=") + 13);
temp.trim();
@ -1039,6 +1035,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));