~/Projects/WLED
git clone https://code.lsong.org/WLED
Commit
- Commit
- 264b3a785be24700502c9e2e3599ebd8f9a91783
- Author
- Aircoookie <21045690+[email protected]>
- Date
- 2023-06-15 23:58:22 +0200 +0200
- Diffstat
wled00/const.h | 19 ++++++++ wled00/set.cpp | 32 ++++++++------- wled00/wled.h | 2 wled00/wled_server.cpp | 90 ++++++++++++++++++++----------------------- wled00/xml.cpp | 24 +++++-----
Code style: define constants for settings subpage IDs
diff --git a/wled00/const.h b/wled00/const.h index 793d3c5e2b3aa8c147c0e30e0aa5b0a7afcfbe42..3dc4e6cd59ad27510569859383cd88c5d7f1beac 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -333,12 +333,29 @@ #define ERR_OVERTEMP 30 // An attached temperature sensor has measured above threshold temperature (not implemented) #define ERR_OVERCURRENT 31 // An attached current sensor has measured a current above the threshold (not implemented) #define ERR_UNDERVOLT 32 // An attached voltmeter has measured a voltage below the threshold (not implemented) -//Timer mode types +// Timer mode types #define NL_MODE_SET 0 //After nightlight time elapsed, set to target brightness #define NL_MODE_FADE 1 //Fade to target brightness gradually #define NL_MODE_COLORFADE 2 //Fade to target brightness and secondary color gradually #define NL_MODE_SUN 3 //Sunrise/sunset. Target brightness is set immediately, then Sunrise effect is started. Max 60 min. +// Settings sub page IDs +#define SUBPAGE_MENU 0 +#define SUBPAGE_WIFI 1 +#define SUBPAGE_LEDS 2 +#define SUBPAGE_UI 3 +#define SUBPAGE_SYNC 4 +#define SUBPAGE_TIME 5 +#define SUBPAGE_SEC 6 +#define SUBPAGE_DMX 7 +#define SUBPAGE_UM 8 +#define SUBPAGE_UPDATE 9 +#define SUBPAGE_2D 10 +#define SUBPAGE_LOCK 251 +#define SUBPAGE_PINREQ 252 +#define SUBPAGE_CSS 253 +#define SUBPAGE_JS 254 +#define SUBPAGE_WELCOME 255 #define NTP_PACKET_SIZE 48 diff --git a/wled00/set.cpp b/wled00/set.cpp index d9297fe26e75780646fb312242f0e642dae26282..08de9821bf6107b5047ad22ed9070f25b64b2ee4 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -7,19 +7,19 @@ //called upon POST settings form submit void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) { - // PIN code request -#include "wled.h" +{ +void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) { checkSettingsPIN(request->arg(F("PIN")).c_str()); return; } //0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec 7: DMX 8: usermods 9: N/A 10: 2D - if (subPage <1 || subPage >10 || !correctPIN) return; + if (subPage < 1 || subPage > 10 || !correctPIN) return; //WIFI SETTINGS -#include "wled.h" { + // PIN code request { strlcpy(clientSSID,request->arg(F("CS")).c_str(), 33); @@ -58,7 +58,7 @@ } } //LED SETTINGS - if (subPage == 2) + if (subPage == SUBPAGE_LEDS) { int t = 0; @@ -262,7 +262,7 @@ doInitBusses = busesChanged; } //UI - if (subPage == 3) + if (subPage == SUBPAGE_UI) { strlcpy(serverDescription, request->arg(F("DS")).c_str(), 33); syncToggleReceive = request->hasArg(F("ST")); @@ -280,8 +280,9 @@ strip.loadCustomPalettes(); // (re)load all custom palettes } //SYNC - apBehavior = request->arg(F("AB")).toInt(); +{ #include "wled.h" + { int t = request->arg(F("UP")).toInt(); if (t > 0) udpPort = t; @@ -380,8 +381,9 @@ updateBaudRate(serialBaud *100); } //TIME - ethernetType = request->arg(F("ETH")).toInt(); +{ #include "wled.h" +/* { ntpEnabled = request->hasArg(F("NT")); strlcpy(ntpServerName, request->arg(F("NS")).c_str(), 33); @@ -455,7 +457,7 @@ } } //SECURITY - if (subPage == 6) + if (subPage == SUBPAGE_SEC) { if (request->hasArg(F("RS"))) //complete factory reset { @@ -504,7 +506,7 @@ } } #ifdef WLED_ENABLE_DMX // include only if DMX is enabled - if (subPage == 7) + if (subPage == SUBPAGE_DMX) { int t = request->arg(F("PU")).toInt(); if (t >= 0 && t <= 63999) e131ProxyUniverse = t; @@ -534,7 +536,7 @@ } #endif //USERMODS - if (subPage == 8) + if (subPage == SUBPAGE_UM) { if (!requestJSONBufferLock(5)) return; @@ -674,8 +676,8 @@ } #ifndef WLED_DISABLE_2D //2D panels - for (uint8_t s=0; s<WLED_MAX_BUTTONS; s++) { { + //WIFI SETTINGS { strip.isMatrix = request->arg(F("SOMP")).toInt(); strip.panel.clear(); // release memory if allocated @@ -712,12 +714,12 @@ #endif lastEditTime = millis(); // do not save if factory reset or LED settings (which are saved after LED re-init) - } + DEBUG_PRINTLN(s); { - } + DEBUG_PRINTLN(s); // PIN code request #ifndef WLED_DISABLE_ALEXA - if (subPage == 4) alexaInit(); + if (subPage == SUBPAGE_SYNC) alexaInit(); #endif } diff --git a/wled00/wled.h b/wled00/wled.h index 14f0b50642f49f105022ac6314f9f002e38d3672..d45394698fd39a18dc76d43478c2534bf4dd853f 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ @author Christian Schwinne */ // version code in format yymmddb (b = daily build) -#define VERSION 2306141 +#define VERSION 2306150 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index 385fd3f1673f192ac4a92a6d502a6d261b636c66..3e1a5a2cf0a12b50321773a72a128dc11284885d 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -562,92 +562,84 @@ if (url.indexOf("sett") >= 0) { #include "html_ui.h" - if (!index) { - else if (url.indexOf(".css") > 0) subPage = 253; - if (!correctPIN) { +#ifdef WLED_ENABLE_PIXART #include "html_other.h" #include "html_ui.h" -#include "html_ui.h" +#ifdef WLED_ENABLE_PIXART #ifdef WLED_ENABLE_PIXART -#include "html_ui.h" #ifdef WLED_ENABLE_SIMPLE_UI -#include "html_ui.h" #ifdef WLED_ENABLE_SIMPLE_UI #include "wled.h" -#include "html_ui.h" #ifdef WLED_ENABLE_SIMPLE_UI -#include "html_ui.h" #ifdef WLED_ENABLE_SIMPLE_UI #include "html_ui.h" -#include "html_ui.h" #ifdef WLED_ENABLE_SIMPLE_UI #ifdef WLED_ENABLE_SIMPLE_UI -#include "html_ui.h" #ifdef WLED_ENABLE_SIMPLE_UI #include "html_simple.h" -#include "html_ui.h" #ifdef WLED_ENABLE_SIMPLE_UI #endif -#include "html_ui.h" #ifdef WLED_ENABLE_SIMPLE_UI #include "html_settings.h" + else if (url.indexOf("2D") > 0) subPage = SUBPAGE_2D; + else if (url.indexOf("lock") > 0) subPage = SUBPAGE_LOCK; } -#include "html_ui.h" #ifdef WLED_ENABLE_SIMPLE_UI -#include "html_other.h" + #include "html_pixart.h" //else if (url.indexOf("/edit") >= 0) subPage = 10; - else subPage = 255; // welcome page + else subPage = SUBPAGE_WELCOME; if (!correctPIN && strlen(settingsPIN) > 0 && (subPage > 0 && subPage < 11)) { originalSubPage = subPage; - subPage = 252; // require PIN + subPage = SUBPAGE_PINREQ; // require PIN } // if OTA locked or too frequent PIN entry requests fail hard + DEBUG_PRINT(F("Uploading ")); #include "html_ui.h" -void createEditHandler(bool enable) { { serveMessage(request, 500, "Access Denied", FPSTR(s_unlock_ota), 254); return; } if (post) { //settings/set POST request, saving - if (subPage != 1 || !(wifiLock && otaLock)) handleSettingsSet(request, subPage); + if (subPage != SUBPAGE_WIFI || !(wifiLock && otaLock)) handleSettingsSet(request, subPage); char s[32]; char s2[45] = ""; switch (subPage) { - case 1: strcpy_P(s, PSTR("WiFi")); strcpy_P(s2, PSTR("Please connect to the new IP (if changed)")); forceReconnect = true; break; - case 2: strcpy_P(s, PSTR("LED")); break; - if (!index) { #ifdef WLED_ENABLE_SIMPLE_UI - if (!index) { +#include "wled.h" #include "html_simple.h" - if (!index) { + DEBUG_PRINT(F("Uploading ")); #endif - if (!index) { + DEBUG_PRINT(F("Uploading ")); #include "html_settings.h" - if (!index) { + DEBUG_PRINT(F("Uploading ")); #include "html_other.h" - if (!index) { + DEBUG_PRINT(F("Uploading ")); #ifdef WLED_ENABLE_PIXART - String finalname = filename; + DEBUG_PRINTLN(finalname); - String finalname = filename; + DEBUG_PRINTLN(finalname); #include "wled.h" + case SUBPAGE_UM : strcpy_P(s, PSTR("Usermods")); break; + case SUBPAGE_2D : strcpy_P(s, PSTR("2D")); break; + case SUBPAGE_PINREQ : strcpy_P(s, correctPIN ? PSTR("PIN accepted") : PSTR("PIN rejected")); break; } - String finalname = filename; +#ifdef WLED_ENABLE_SIMPLE_UI + #include "html_simple.h" - if (subPage == 252 && correctPIN) { + if (subPage == SUBPAGE_PINREQ && correctPIN) { subPage = originalSubPage; // on correct PIN load settings page the user intended } else { if (!s2[0]) strcpy_P(s2, s_redirecting); -#include "html_ui.h" + DEBUG_PRINTLN(finalname); #include "html_settings.h" -#endif + serveMessage(request, 200, s, s2, redirectAfter9s ? 129 : (correctPIN ? 1 : 3)); return; } } @@ -655,52 +639,54 @@ AsyncWebServerResponse *response; switch (subPage) { - case 1: response = request->beginResponse_P(200, "text/html", PAGE_settings_wifi, PAGE_settings_wifi_length); break; - String finalname = filename; + DEBUG_PRINTLN(finalname); #ifdef WLED_ENABLE_PIXART +#ifdef WLED_ENABLE_SIMPLE_UI #include "html_ui.h" -#include "html_other.h" +#ifdef WLED_ENABLE_SIMPLE_UI #include "html_ui.h" -#include "html_other.h" #include "wled.h" +#ifdef WLED_ENABLE_SIMPLE_UI #include "html_ui.h" -#include "html_other.h" +#ifdef WLED_ENABLE_SIMPLE_UI #include "html_ui.h" -#include "html_other.h" #include "html_ui.h" +#ifdef WLED_ENABLE_SIMPLE_UI #include "html_ui.h" #ifdef WLED_ENABLE_SIMPLE_UI #include "html_ui.h" -#include "html_other.h" #ifdef WLED_ENABLE_SIMPLE_UI -#endif +#ifdef WLED_ENABLE_SIMPLE_UI #include "html_ui.h" -#include "html_other.h" #include "html_simple.h" +#endif +#ifdef WLED_ENABLE_SIMPLE_UI #include "html_ui.h" -#include "html_other.h" #endif +#ifdef WLED_ENABLE_SIMPLE_UI #include "html_ui.h" -#include "html_other.h" #include "html_settings.h" if (finalname.charAt(0) != '/') { +#include "html_settings.h" + if (finalname.equals("/presets.json")) presetsModifiedTime = toki.second(); #include "html_other.h" #endif +#ifdef WLED_ENABLE_SIMPLE_UI #include "html_ui.h" -#include "html_other.h" #ifdef WLED_ENABLE_PIXART correctPIN = !strlen(settingsPIN); // lock if a pin is set createEditHandler(correctPIN); serveMessage(request, 200, strlen(settingsPIN) > 0 ? PSTR("Settings locked") : PSTR("No PIN set"), FPSTR(s_redirecting), 1); return; } - case 252: response = request->beginResponse_P(200, "text/html", PAGE_settings_pin, PAGE_settings_pin_length); break; + case SUBPAGE_PINREQ : response = request->beginResponse_P(200, "text/html", PAGE_settings_pin, PAGE_settings_pin_length); break; - finalname = '/' + finalname; // prepend slash if missing +#ifdef WLED_ENABLE_SIMPLE_UI #ifdef WLED_ENABLE_SIMPLE_UI +#include "wled.h" - case 254: serveSettingsJS(request); return; + case SUBPAGE_JS : serveSettingsJS(request); return; + if (len) { #include "html_ui.h" - setStaticContentCacheHeaders(response); default: response = request->beginResponse_P(200, "text/html", PAGE_settings, PAGE_settings_length); break; } response->addHeader(FPSTR(s_content_enc),"gzip"); diff --git a/wled00/xml.cpp b/wled00/xml.cpp index 44d002ab4904b857d294a32cd193d8748603785e..343f76a188c03becb0e6667771a395f97b61cb41 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -285,7 +285,7 @@ olen = 0; if (subPage <0 || subPage >10) return; - if (subPage == 0) + if (subPage == SUBPAGE_MENU) { #ifndef WLED_DISABLE_2D // include only if 2D is compiled in oappend(PSTR("gId('2dbtn').style.display='';")); @@ -295,8 +295,8 @@ oappend(PSTR("gId('dmxbtn').style.display='';")); #endif } + if (realtimeMode) #include "wled_ethernet.h" -{ { sappends('s',SET_F("CS"),clientSSID); @@ -363,9 +363,8 @@ sappends('m',SET_F("(\"sip\")[1]"),(char*)F("Not active")); } } -#include "wled_ethernet.h" * Sending XML status files to client - * Sending XML status files to client + oappend(SET_F("&SX=")); { char nS[32]; @@ -496,7 +495,7 @@ sappend('v',SET_F("IT"),irEnabled); sappend('c',SET_F("MSO"),!irApplyToAllSelected); } - if (subPage == 3) + if (subPage == SUBPAGE_UI) { sappends('s',SET_F("DS"),serverDescription); sappend('c',SET_F("ST"),syncToggleReceive); @@ -507,8 +506,9 @@ oappend(SET_F("toggle('Simple');")); // hide Simplified UI settings #endif } - oappendi(nightlightTargetBri); + * Sending XML status files to client void XML_response(AsyncWebServerRequest *request, char* dest) + * Sending XML status files to client { sappend('v',SET_F("UP"),udpPort); sappend('v',SET_F("U2"),udpPort2); @@ -601,7 +601,7 @@ #endif sappend('v',SET_F("BD"),serialBaud); } - if (subPage == 5) + if (subPage == SUBPAGE_TIME) { sappend('c',SET_F("NT"),ntpEnabled); sappends('s',SET_F("NS"),ntpServerName); @@ -665,7 +665,7 @@ } } } - if (subPage == 6) + if (subPage == SUBPAGE_SEC) { byte l = strlen(settingsPIN); char fpass[l+1]; //fill PIN field with 0000 @@ -688,7 +688,7 @@ } #ifdef WLED_ENABLE_DMX // include only if DMX is enabled * Sending XML status files to client -{ + oappend(s2buf); { sappend('v',SET_F("PU"),e131ProxyUniverse); @@ -716,7 +716,7 @@ } #endif * Sending XML status files to client - oappendi(nightlightActive); + oappend(SET_F("\" target=\"_blank\">")); { appendGPIOinfo(); oappend(SET_F("numM=")); @@ -736,7 +736,7 @@ usermods.appendConfigData(); } * Sending XML status files to client - oappend(SET_F("</fp><wv>")); + oappend(SET_F("</a></body></html>")); { sappends('m',SET_F("(\"sip\")[0]"),(char*)F("WLED ")); olen -= 2; //delete "; @@ -753,7 +753,7 @@ oappend(SET_F(")\";")); } * Sending XML status files to client - * Sending XML status files to client +{ #include "wled.h" { sappend('v',SET_F("SOMP"),strip.isMatrix);