diff --git a/html-ui/configureprinter.html b/html-ui/configureprinter.html new file mode 100644 index 0000000..84a818c --- /dev/null +++ b/html-ui/configureprinter.html @@ -0,0 +1,255 @@ + +
+ + + + + +Configuration
+| Name | +Type | +Hostname | +IP | +State | +Api Key/User/Password | ++ |
|---|---|---|---|---|---|---|
| I3 Mega | +Klipper | +-- | +192.168.0.241:7125 | +Offline | +Offline | ++ + | +
Theme Color
" ""; -static const char WEATHER_FORM[] PROGMEM = "" - ""; - -static const char LANG_OPTIONS[] PROGMEM = "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - ""; - static const char COLOR_THEMES[] PROGMEM = "" "" "" @@ -101,10 +56,12 @@ void WebServer::setup() { this->server->on("/", []() { obj->displayPrinterStatus(); }); this->server->on("/systemreset", []() { obj->handleSystemReset(); }); this->server->on("/forgetwifi", []() { obj->handleWifiReset(); }); - this->server->on("/updateconfig", []() { obj->handleUpdateConfig(); }); - this->server->on("/updateweatherconfig", []() { obj->handleUpdateWeather(); }); - this->server->on("/configure", []() { obj->handleConfigure(); }); + this->server->on("/configurestation", []() { obj->handleConfigureStation(); }); + this->server->on("/configureprinter", []() { obj->handleConfigurePrinter(); }); this->server->on("/configureweather", []() { obj->handleWeatherConfigure(); }); + this->server->on("/updateconfig", []() { obj->handleUpdateConfig(); }); + this->server->on("/updatestationconfig", []() { obj->handleUpdateStation(); }); + this->server->on("/updateweatherconfig", []() { obj->handleUpdateWeather(); }); this->server->on("/update", HTTP_GET, []() { obj->handleUpdatePage(); }); this->server->onNotFound([]() { obj->redirectHome(); }); this->serverUpdater->setup(this->server, "/update", this->globalDataController->getWebserverUsername(), this->globalDataController->getWebserverPassword()); @@ -252,28 +209,7 @@ void WebServer::displayPrinterStatus() { WebserverMemoryVariables::sendFooter(this->server, this->globalDataController); } -void WebServer::handleSystemReset() { - if (!this->authentication()) { - return this->server->requestAuthentication(); - } - this->debugController->printLn("Reset System Configuration"); - if (this->globalDataController->resetConfig()) { - redirectHome(); - ESP.restart(); - } -} -void WebServer::handleWifiReset() { - if (!this->authentication()) { - return this->server->requestAuthentication(); - } - //WiFiManager - //Local intialization. Once its business is done, there is no need to keep it around - redirectHome(); - WiFiManager wifiManager; - wifiManager.resetSettings(); - ESP.restart(); -} void WebServer::handleUpdateConfig() { boolean flipOld = this->globalDataController->isDisplayInverted(); @@ -349,23 +285,7 @@ void WebServer::findMDNS() { } } -void WebServer::handleUpdateWeather() { - if (!this->authentication()) { - return this->server->requestAuthentication(); - } - this->globalDataController->setWeatherShow(this->server->hasArg("isWeatherEnabled")); - this->globalDataController->setWeatherApiKey(this->server->arg("openWeatherMapApiKey")); - this->globalDataController->setWeatherCityId(this->server->arg("city1").toInt()); - this->globalDataController->setWeatherIsMetric(this->server->hasArg("metric")); - this->globalDataController->setWeatherLang(this->server->arg("language")); - this->globalDataController->writeSettings(); - - //isClockOn = false; // this will force a check for the display - //checkDisplay(); - this->globalDataController->getTimeClient()->resetLastEpoch(); - this->redirectHome(); -} - +/* void WebServer::handleConfigure() { if (!this->authentication()) { return this->server->requestAuthentication(); @@ -470,55 +390,27 @@ void WebServer::handleConfigure() { form.replace("%PRINTERPASS%", this->globalDataController->getPrinterAuthPass()); this->server->sendContent(form); - form = FPSTR(CLOCK_FORM); - String isClockChecked = ""; - if (DISPLAYCLOCK) { - isClockChecked = "checked='checked'"; - } - form.replace("%IS_CLOCK_CHECKED%", isClockChecked); - String is24hourChecked = ""; - if (this->globalDataController->getClockIs24h()) { - is24hourChecked = "checked='checked'"; - } - form.replace("%IS_24HOUR_CHECKED%", is24hourChecked); - String isInvDisp = ""; - if (this->globalDataController->isDisplayInverted()) { - isInvDisp = "checked='checked'"; - } - form.replace("%IS_INVDISP_CHECKED%", isInvDisp); - String isFlashLED = ""; - if (USE_FLASH) { - isFlashLED = "checked='checked'"; - } - form.replace("%USEFLASH%", isFlashLED); - String hasPSUchecked = ""; - if (this->globalDataController->hasPrinterPsu()) { - hasPSUchecked = "checked='checked'"; - } - form.replace("%HAS_PSU_CHECKED%", hasPSUchecked); - - String options = ""; - options.replace(">"+String(this->globalDataController->getClockResyncMinutes())+"<", " selected>"+String(this->globalDataController->getClockResyncMinutes())+"<"); - form.replace("%OPTIONS%", options); - this->server->sendContent(form); - - form = FPSTR(THEME_FORM); - String themeOptions = FPSTR(COLOR_THEMES); - themeOptions.replace(">"+String(this->globalDataController->getWebserverTheme())+"<", " selected>"+String(this->globalDataController->getWebserverTheme())+"<"); - form.replace("%THEME_OPTIONS%", themeOptions); - form.replace("%UTCOFFSET%", String(this->globalDataController->getClockUtcOffset())); - String isUseSecurityChecked = ""; - if (this->globalDataController->getWebserverIsBasicAuth()) { - isUseSecurityChecked = "checked='checked'"; - } - form.replace("%IS_BASICAUTH_CHECKED%", isUseSecurityChecked); - form.replace("%USERID%", String(this->globalDataController->getWebserverUsername())); - form.replace("%STATIONPASSWORD%", String(this->globalDataController->getWebserverPassword())); + WebserverMemoryVariables::sendFooter(this->server, this->globalDataController); +}*/ - this->server->sendContent(form); + + + + + + + + + + +void WebServer::handleConfigurePrinter() { + if (!this->authentication()) { + return this->server->requestAuthentication(); + } + WebserverMemoryVariables::sendHeader(this->server, this->globalDataController, "Configure", "Printers"); WebserverMemoryVariables::sendFooter(this->server, this->globalDataController); } @@ -538,6 +430,51 @@ void WebServer::handleConfigure() { + + + +/** + * @brief Send station configuration page to client + */ +void WebServer::handleConfigureStation() { + if (!this->authentication()) { + return this->server->requestAuthentication(); + } + WebserverMemoryVariables::sendHeader(this->server, this->globalDataController, "Configure", "Station"); + WebserverMemoryVariables::sendStationConfigForm(this->server, this->globalDataController); + WebserverMemoryVariables::sendFooter(this->server, this->globalDataController); +} + +/** + * @brief Update configuration for station + */ +void WebServer::handleUpdateStation() { + boolean flipOld = this->globalDataController->isDisplayInverted(); + if (!this->authentication()) { + return this->server->requestAuthentication(); + } + + this->globalDataController->setDisplayClock(this->server->hasArg("isClockEnabled")); + this->globalDataController->setIsDisplayInverted(this->server->hasArg("invDisp")); + this->globalDataController->setUseLedFlash(this->server->hasArg("useFlash")); + this->globalDataController->setClockIs24h(this->server->hasArg("is24hour")); + this->globalDataController->setClockResyncMinutes(this->server->arg("refresh").toInt()); + this->globalDataController->setClockUtcOffset(this->server->arg("utcoffset").toFloat()); + this->globalDataController->setWebserverIsBasicAuth(this->server->hasArg("isBasicAuth")); + String temp = this->server->arg("userid"); + this->globalDataController->setWebserverUsername(temp); + temp = this->server->arg("stationpassword"); + this->globalDataController->setWebserverPassword(temp); + this->globalDataController->writeSettings(); + + if (this->globalDataController->isDisplayInverted() != flipOld) { + this->globalDataController->getDisplayClient()->flipDisplayUpdate(); + } + this->globalDataController->getDisplayClient()->handleUpdate(); + this->globalDataController->getTimeClient()->resetLastEpoch(); + this->redirectHome(); +} + /** * @brief Send weather configuration page to client */ @@ -546,34 +483,58 @@ void WebServer::handleWeatherConfigure() { return this->server->requestAuthentication(); } WebserverMemoryVariables::sendHeader(this->server, this->globalDataController, "Configure", "Weather"); - - String html = ""; - - - - String form = FPSTR(WEATHER_FORM); - String isWeatherChecked = ""; - if (DISPLAYWEATHER) { - isWeatherChecked = "checked='checked'"; - } - form.replace("%IS_WEATHER_CHECKED%", this->globalDataController->getWeatherShow() ? "1" : "0"); - form.replace("%WEATHERKEY%", this->globalDataController->getWeatherApiKey()); - form.replace("%CITYNAME1%", this->globalDataController->getWeatherClient()->getCity(0)); - form.replace("%CITY1%", String(this->globalDataController->getWeatherCityId())); - String checked = ""; - if (this->globalDataController->getWeatherIsMetric()) { - checked = "checked='checked'"; - } - form.replace("%METRIC%", checked); - String options = FPSTR(LANG_OPTIONS); - options.replace(">"+String(this->globalDataController->getWeatherLang())+"<", " selected>"+String(this->globalDataController->getWeatherLang())+"<"); - form.replace("%LANGUAGEOPTIONS%", options); - this->server->sendContent(form); - - + WebserverMemoryVariables::sendWeatherConfigForm(this->server, this->globalDataController); WebserverMemoryVariables::sendFooter(this->server, this->globalDataController); } +/** + * @brief Update configuration for weather + */ +void WebServer::handleUpdateWeather() { + if (!this->authentication()) { + return this->server->requestAuthentication(); + } + this->globalDataController->setWeatherShow(this->server->hasArg("isWeatherEnabled")); + this->globalDataController->setWeatherApiKey(this->server->arg("openWeatherMapApiKey")); + this->globalDataController->setWeatherCityId(this->server->arg("city1").toInt()); + this->globalDataController->setWeatherIsMetric(this->server->hasArg("metric")); + this->globalDataController->setWeatherLang(this->server->arg("language")); + this->globalDataController->writeSettings(); + + this->globalDataController->getDisplayClient()->handleUpdate(); + this->globalDataController->getTimeClient()->resetLastEpoch(); + this->redirectHome(); +} + +/** + * @brief Reset internal configuration data + */ +void WebServer::handleSystemReset() { + if (!this->authentication()) { + return this->server->requestAuthentication(); + } + this->debugController->printLn("Reset System Configuration"); + if (this->globalDataController->resetConfig()) { + redirectHome(); + ESP.restart(); + } +} + +/** + * @brief Reset internal WiFi configuration data + */ +void WebServer::handleWifiReset() { + if (!this->authentication()) { + return this->server->requestAuthentication(); + } + //WiFiManager + //Local intialization. Once its business is done, there is no need to keep it around + redirectHome(); + WiFiManager wifiManager; + wifiManager.resetSettings(); + ESP.restart(); +} + /** * @brief Send firmware/filesystem update page to client */ diff --git a/src/Network/WebServer.h b/src/Network/WebServer.h index 97f02e1..a79803f 100644 --- a/src/Network/WebServer.h +++ b/src/Network/WebServer.h @@ -26,8 +26,10 @@ public: void handleSystemReset(); void handleWifiReset(); void handleUpdateConfig(); + void handleUpdateStation(); void handleUpdateWeather(); - void handleConfigure(); + void handleConfigurePrinter(); + void handleConfigureStation(); void handleWeatherConfigure(); void handleUpdatePage(); }; diff --git a/src/Network/WebserverMemoryVariables.cpp b/src/Network/WebserverMemoryVariables.cpp index 8e7be17..84c6041 100644 --- a/src/Network/WebserverMemoryVariables.cpp +++ b/src/Network/WebserverMemoryVariables.cpp @@ -33,59 +33,30 @@ void WebserverMemoryVariables::sendHeader( server->setContentLength(CONTENT_LENGTH_UNKNOWN); server->send(200, "text/html", ""); - server->sendContent("" - "