diff --git a/wled00/WS2812FX.cpp b/wled00/WS2812FX.cpp index f821ba04..e25a93f3 100644 --- a/wled00/WS2812FX.cpp +++ b/wled00/WS2812FX.cpp @@ -246,7 +246,7 @@ void WS2812FX::mode_static(void) { /* - * Normal blinking. 50% on/off time. + * Normal blinking. on/off duty time set by FX intensity. */ void WS2812FX::mode_blink(void) { if(_counter_mode_call % 2 == 1) { @@ -254,16 +254,15 @@ void WS2812FX::mode_blink(void) { if (!_locked[i]) setPixelColor(i, _color); } - show(); + _mode_delay = (100 + ((1986 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX))*(float)(_intensity/128.0); } else { for(uint16_t i=0; i < _led_count; i++) { if (!_locked[i]) setPixelColor(i, _color_sec); } - show(); + _mode_delay = (100 + ((1986 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX))*(float)(2.0-(_intensity/128.0)); } - - _mode_delay = 100 + ((1986 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX); + show(); } @@ -342,12 +341,11 @@ void WS2812FX::mode_single_dynamic(void) { /* - * Lights every LED in a random color. Changes all LED at the same time - * to new random colors. + * Lights multiple random leds in a random color (higher intensity, more updates) */ void WS2812FX::mode_multi_dynamic(void) { for(uint16_t i=0; i < _led_count; i++) { - if (!_locked[i]) + if (!_locked[i] && random(256)<=_intensity) setPixelColor(i, color_wheel(random(256))); } show(); @@ -493,7 +491,7 @@ void WS2812FX::mode_rainbow(void) { void WS2812FX::mode_rainbow_cycle(void) { for(uint16_t i=0; i < _led_count; i++) { if (!_locked[i]) - setPixelColor(i, color_wheel(((i * 256 / _led_count) + _counter_mode_step) % 256)); + setPixelColor(i, color_wheel(((i * 256 / ((uint16_t)(_led_count*(float)(_intensity/128.0))+1)) + _counter_mode_step) % 256)); } show(); diff --git a/wled00/data/index.htm b/wled00/data/index.htm index 50d3d6cb..1c92ada9 100644 --- a/wled00/data/index.htm +++ b/wled00/data/index.htm @@ -56,10 +56,12 @@ } else { uwv = false; } - if (d.activeElement != Cf.TX) Cf.TX.selectedIndex = this.responseXML.getElementsByTagName('fx')[0].childNodes[0].nodeValue; + Cf.TX.selectedIndex = this.responseXML.getElementsByTagName('fx')[0].childNodes[0].nodeValue; d.Cf.SX.value = this.responseXML.getElementsByTagName('sx')[0].childNodes[0].nodeValue; d.Cf.IX.value = this.responseXML.getElementsByTagName('ix')[0].childNodes[0].nodeValue; nla = (this.responseXML.getElementsByTagName('nl')[0].innerHTML)!=0?true:false; + d.Cf.SN.value = this.responseXML.getElementsByTagName('nd')[0].childNodes[0].nodeValue; + d.Cf.ST.value = this.responseXML.getElementsByTagName('nt')[0].childNodes[0].nodeValue; nState = 0; nState = (this.responseXML.getElementsByTagName('nr')[0].innerHTML)!=0?1:0; nState += (this.responseXML.getElementsByTagName('ns')[0].innerHTML)!=0?2:0; @@ -332,11 +334,11 @@ diff --git a/wled00/data/settings.htm b/wled00/data/settings.htm index 02adbd7c..ef83ea03 100644 --- a/wled00/data/settings.htm +++ b/wled00/data/settings.htm @@ -31,11 +31,11 @@ -
-
-
-
-
-
+
+
+
+
+
+
\ No newline at end of file diff --git a/wled00/data/settings_leds.htm b/wled00/data/settings_leds.htm index bdc1feb0..ccec6d62 100644 Binary files a/wled00/data/settings_leds.htm and b/wled00/data/settings_leds.htm differ diff --git a/wled00/data/settings_sec.htm b/wled00/data/settings_sec.htm index f8b5d624..40513789 100644 Binary files a/wled00/data/settings_sec.htm and b/wled00/data/settings_sec.htm differ diff --git a/wled00/data/settings_sync.htm b/wled00/data/settings_sync.htm index eea7ce1c..bd890409 100644 Binary files a/wled00/data/settings_sync.htm and b/wled00/data/settings_sync.htm differ diff --git a/wled00/data/settings_time.htm b/wled00/data/settings_time.htm index f2cd8c10..84d13011 100644 Binary files a/wled00/data/settings_time.htm and b/wled00/data/settings_time.htm differ diff --git a/wled00/data/settings_ui.htm b/wled00/data/settings_ui.htm index 4d179fee..9138b409 100644 Binary files a/wled00/data/settings_ui.htm and b/wled00/data/settings_ui.htm differ diff --git a/wled00/data/settings_wifi.htm b/wled00/data/settings_wifi.htm index 264436f0..bb3ef33d 100644 Binary files a/wled00/data/settings_wifi.htm and b/wled00/data/settings_wifi.htm differ diff --git a/wled00/data/themes.txt b/wled00/data/themes.txt new file mode 100644 index 00000000..37f8155f --- /dev/null +++ b/wled00/data/themes.txt @@ -0,0 +1,20 @@ +6. Amber: +--aCol: #f7c331; +--bCol: #dcc7aa; +--cCol: #6b7a8f; +--dCol: #f7882f; +--sCol: #0007; + +7. Club +--aCol: #fc3; +--bCol: #124; +--cCol: #334; +--dCol: #f1d; +--sCol: #f00; + +8: Air: +--aCol: #0ac; +--bCol: #124; +--cCol: #334; +--dCol: #00ced1; +--sCol: #003eff; \ No newline at end of file diff --git a/wled00/htmls00.h b/wled00/htmls00.h index eefe7d06..23c425ea 100644 --- a/wled00/htmls00.h +++ b/wled00/htmls00.h @@ -3,20 +3,182 @@ */ //head0 (js) const char PAGE_index0[] PROGMEM = R"=====( - + + + +WLED 0.5dev + )====="; //head1 (css) const char PAGE_index1[] PROGMEM = R"=====( - +.ctrl_box{margin:auto;width:80vw;background-color:var(--cCol);position:absolute;top:55%;left:50%;transform:translate(-50%,-50%);filter:drop-shadow(-5px -5px 5px var(--sCol))}.sds{width:100%;height:12vh;margin-top:2vh}.sl{margin-left:auto;margin-right:auto;margin-top:2vh;width:77vw}#slA{margin-top:0vh;background:linear-gradient(to right,black,yellow)}#slR{background:linear-gradient(to right,black,red)}#slG{background:linear-gradient(to right,black,green)}#slB{background:linear-gradient(to right,black,blue)}#slW{background:linear-gradient(to right,black,white)}#slH{background:linear-gradient(to right,red,orange,yellow,green,cyan,blue,violet,red)}#slS{background:linear-gradient(to right,grey,green)}#slN{background:linear-gradient(to right,black,turquoise)}#slT{background:linear-gradient(to right,black,yellow)}.tools{margin-left:auto;margin-right:auto;margin-top:2vh;width:77vw}#slX{background:linear-gradient(to right,black,white)}#slI{background:linear-gradient(to right,black,red)}body{font-family:Verdana,Helvetica,sans-serif;text-align:center;background:linear-gradient(var(--bCol),black);height:100%;margin:0;background-repeat:no-repeat;background-attachment:fixed;color:var(--dCol)}html{height:100%}iframe{display:none;border:0;filter:drop-shadow(-5px -5px 5px var(--sCol));margin:auto;width:80vw;height:60vh;position:absolute;top:55%;left:50%;transform:translate(-50%,-50%)}svg{fill:var(--dCol);width:12vw;height:10vmin;filter:drop-shadow(-5px -5px 5px var(--sCol))}input{filter:drop-shadow(-5px -5px 5px var(--sCol))}button{background:var(--bCol);color:var(--dCol);border:.5ch solid var(--bCol);margin-bottom:1vh;filter:drop-shadow(-5px -5px 5px var(--sCol))}select{background:var(--bCol);color:var(--dCol);border:.5ch solid var(--bCol);filter:drop-shadow(-5px -5px 5px var(--sCol))}input[type=number]{background:var(--bCol);color:var(--dCol);border:.5ch solid var(--bCol);width:3em}input[type=range]{-webkit-appearance:none;margin:-4px 0}input[type=range]:focus{outline:0}input[type=range]::-webkit-slider-runnable-track{width:100%;height:12vh;cursor:pointer;background:var(--bCol)}input[type=range]::-webkit-slider-thumb{filter:drop-shadow(-5px -5px 5px var(--sCol));height:10vh;width:10vh;background:var(--aCol);cursor:pointer;-webkit-appearance:none;margin-top:1vh}input[type=range]::-moz-range-track{width:100%;height:12vh;cursor:pointer;background:var(--bCol)}input[type=range]::-moz-range-thumb{filter:drop-shadow(-5px -5px 5px var(--sCol));height:10vh;width:10vh;background:var(--aCol);cursor:pointer;margin-top:1vh}input[type=range]::-ms-track{width:100%;height:12vh;cursor:pointer;background:transparent;border-color:transparent;color:transparent}input[type=range]::-ms-fill-lower{background:#var(--bCol)}input[type=range]::-ms-fill-upper{background:#var(--bCol)}input[type=range]::-ms-thumb{width:10vh;background:var(--aCol);cursor:pointer;height:10vh} + + +Loading... )====="; //body0 (svg defs) const char PAGE_index2[] PROGMEM = R"=====( - + + +//Linearicons.com/free + + + + + + + + + + + + + + + )====="; //body1 (html) const char PAGE_index3[] PROGMEM = R"=====( - +
+ + + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Effect Panel

+ + + +

+

+Set secondary color to + + + + + +or +
+
Custom Theater Chase
+using primary and + secondary color LEDs,
+doing steps per tick, +from start and end. +
+
+
+
+
+
+
+Favorite Presets

+ + + + +


+Click checkmark to apply brightness, color and effects.
+Effect 0 is the configuration when the light is powered up. +
+
+Timed Light

+

+Gradually dim down
+1st slider sets duration (1-255min), 2nd sets target brightness. +
+
+
+
+
+
+
+
+ + + )====="; diff --git a/wled00/htmls01.h b/wled00/htmls01.h index 6d213b5e..c21fc551 100644 --- a/wled00/htmls01.h +++ b/wled00/htmls01.h @@ -1,17 +1,346 @@ /* * Settings html */ -const char PAGE_settings0[] PROGMEM = R"=====( +const char PAGE_settingsCss[] PROGMEM = R"=====( +body{font-family:Verdana,Helvetica,sans-serif;text-align:center;background:var(--cCol);color:var(--dCol);line-height:200%;margin:0;background-attachment:fixed}hr{border-color:var(--dCol);filter:drop-shadow(-5px -5px 5px var(--sCol))}button{background:var(--bCol);color:var(--dCol);border:.3ch solid var(--bCol);display:inline-block;filter:drop-shadow(-5px -5px 5px var(--sCol));font-size:20px;margin:8px;margin-top:12px}.helpB{text-align:left;position:absolute;width:60px}input{background:var(--bCol);color:var(--dCol);border:.5ch solid var(--bCol);filter:drop-shadow(-5px -5px 5px var(--sCol))}input[type=number]{width:3em}select{background:var(--bCol);color:var(--dCol);border:0.5ch solid var(--bCol);filter:drop-shadow( -5px -5px 5px var(--sCol) );} +)====="; +const char PAGE_settings0[] PROGMEM = R"=====( + + + +WLED Settings )====="; const char PAGE_settings1[] PROGMEM = R"=====( +body{font-family:Verdana,Helvetica,sans-serif;text-align:center;background:var(--cCol);height:100%;margin:0;background-attachment:fixed}button{background:var(--bCol);color:var(--dCol);border:.3ch solid var(--bCol);display:inline-block;filter:drop-shadow(-5px -5px 5px var(--sCol));font-size:9vmin;width:95%;margin-top:2.4vh} + + +
+
+
+
+
+
+ + +)====="; + +const char PAGE_settings_wifi0[] PROGMEM = R"=====( + + + +WiFi Settings +)====="; +const char PAGE_msg1[] PROGMEM = R"=====( +button{background:var(--bCol);color:var(--dCol);border:.3ch solid var(--bCol);display:inline-block;filter:drop-shadow(-5px -5px 5px var(--sCol));font-size:20px;margin:8px;margin-top:12px}body{font-family:Verdana,Helvetica,sans-serif;text-align:center;background:var(--cCol);color:var(--dCol);line-height:200%;margin:0;background-attachment:fixed} + + +)====="; + +const char PAGE_welcome0[] PROGMEM = R"=====( + + +WLED Welcome! +)====="; +const char PAGE_welcome1[] PROGMEM = R"=====( +body{font-family:Verdana, Helvetica, sans-serif;text-align:center;background:linear-gradient(var(--bCol),black);height:100%;margin:0;background-repeat:no-repeat;background-attachment: fixed;color: var(--dCol);}svg {fill: var(--dCol);} + + + + + + +

+ +

Welcome to WLED!

+

Thank you for installing my application!

+Take a quick look at the wiki!
+If you encounter a bug or have a question/feature suggestion, feel free to open a GitHub issue!

+Next steps:

+Connect the module to your local WiFi here!

+Just trying this out in AP mode? Here are the controls.
+ +)====="; + /* * SPIFFS editor html */ @@ -11,7 +49,7 @@ eval(function(p,a,c,k,e,r){e=function(c){return(c
)====="; #else -const char PAGE_edit[] PROGMEM = R"=====(SPIFFS disabled by firmware)====="; +const char PAGE_edit[] PROGMEM = R"=====(SPIFFS disabled)====="; #endif /* * favicon diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 490b4b21..6c57f433 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -26,10 +26,11 @@ #include "src/dependencies/timezone/Timezone.h" #include "htmls00.h" #include "htmls01.h" +#include "htmls02.h" #include "WS2812FX.h" //version in format yymmddb (b = daily build) -#define VERSION 1801180 +#define VERSION 1802193 const String versionName = "WLED 0.5dev"; //AP and OTA default passwords (change them!) @@ -37,7 +38,7 @@ String appass = "wled1234"; String otapass = "wledota"; //If you have an RGBW strip, also uncomment first line in WS2812FX.h! -boolean useRGBW = false; +bool useRGBW = false; //overlays, needed for clocks etc. #define USEOVERLAYS @@ -82,7 +83,8 @@ bool ntpEnabled = true; #endif //Default CONFIG -String serverDescription = "WLED 0.5dev"; +String serverDescription = versionName; +uint8_t currentTheme = 0; String clientssid = "Your_Network_Here"; String clientpass = "Dummy_Pass"; String cmdns = "led"; @@ -98,26 +100,27 @@ IPAddress staticip(0, 0, 0, 0); IPAddress staticgateway(0, 0, 0, 0); IPAddress staticsubnet(255, 255, 255, 0); IPAddress staticdns(8, 8, 8, 8); //only for NTP -boolean useHSB = false, useHSBDefault = false; -boolean turnOnAtBoot = true; +bool useHSB = false, useHSBDefault = false; +bool turnOnAtBoot = true; uint8_t bootPreset = 0; byte col_s[]{255, 159, 0}; byte col_sec_s[]{0, 0, 0}; byte white_s = 0; byte white_sec_s = 0; byte bri_s = 127; -uint8_t bri_nl = 0, bri_nls; -boolean fadeTransition = true; -boolean sweepTransition = false; boolean sweepDirection = true; +uint8_t nightlightTargetBri = 0, bri_nl_t; +bool fadeTransition = true; +bool sweepTransition = false, sweepDirection = true; uint16_t transitionDelay = 1200; -boolean otaLock = true; -boolean onlyAP = false; -boolean buttonEnabled = true; -boolean notifyDirect = true, notifyButton = true, notifyDirectDefault = true, alexaNotify = false, macroNotify = false; -boolean receiveNotifications = true, receiveNotificationsDefault = true; -uint8_t bri_n = 100; +bool otaLock = true; +bool aOtaEnabled = true; +bool onlyAP = false; +bool buttonEnabled = true; +bool notifyDirect = true, notifyButton = true, notifyDirectDefault = true, alexaNotify = false, macroNotify = false; +bool receiveNotifications = true, receiveNotificationBrightness = true, receiveNotificlationColor = true, receiveNotificationEffects = true; +uint8_t briMultiplier = 100; uint8_t nightlightDelayMins = 60; -boolean nightlightFade = true; +bool nightlightFade = true; uint16_t udpPort = 21324; uint8_t effectDefault = 0; uint8_t effectSpeedDefault = 75; @@ -178,6 +181,8 @@ uint8_t effectSpeed = 75; uint8_t effectIntensity = 128; boolean udpConnected = false; byte udpIn[1026]; +String cssCol[]={"","","","","",""}; +String cssColorString=""; //NTP stuff boolean ntpConnected = false; unsigned int ntpLocalPort = 2390; @@ -217,17 +222,16 @@ boolean arlsSign = true; uint8_t auxTime = 0; unsigned long auxStartTime; boolean auxActive, auxActiveBefore; -boolean initialBoot = false; +boolean showWelcomePage = false; boolean useGammaCorrectionBri = false; boolean useGammaCorrectionRGB = true; int arlsOffset = -22; //10: -22 assuming arls52 -//alexa +//alexa udp WiFiUDP UDP; IPAddress ipMulti(239, 255, 255, 250); unsigned int portMulti = 1900; -unsigned int localPort = 1900; char packetBuffer[255]; String escapedMac; @@ -289,6 +293,10 @@ const uint8_t gamma8[] = { 177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213, 215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 }; +String txd = "Please disable OTA Lock in security settings!"; + +void serveMessage(int,String,String,bool=false); + void down() { bri_t = 0; @@ -316,7 +324,7 @@ void loop() { yield(); handleButton(); handleNetworkTime(); - if (!otaLock) ArduinoOTA.handle(); + if (!otaLock && aOtaEnabled) ArduinoOTA.handle(); #ifdef CRONIXIE handleCronixie(); #endif diff --git a/wled00/wled01_eeprom.ino b/wled00/wled01_eeprom.ino index 37bce9fc..0ac58132 100644 --- a/wled00/wled01_eeprom.ino +++ b/wled00/wled01_eeprom.ino @@ -19,6 +19,10 @@ void saveSettingsToEEPROM() { clearEEPROM(); EEPROM.write(233, 233); + showWelcomePage = true; + } else + { + showWelcomePage = false; } for (int i = 0; i < 32; ++i) @@ -67,17 +71,17 @@ void saveSettingsToEEPROM() EEPROM.write(247, col_s[1]); EEPROM.write(248, col_s[2]); EEPROM.write(249, bri_s); - EEPROM.write(250, receiveNotificationsDefault); + EEPROM.write(250, receiveNotificationBrightness); EEPROM.write(251, fadeTransition); EEPROM.write(253, (transitionDelay >> 0) & 0xFF); EEPROM.write(254, (transitionDelay >> 8) & 0xFF); - EEPROM.write(255, bri_n); + EEPROM.write(255, briMultiplier); //255,250,231,230,226 notifier bytes for (int i = 256; i < 288; ++i) { EEPROM.write(i, otapass.charAt(i-256)); } - EEPROM.write(288, bri_nl); + EEPROM.write(288, nightlightTargetBri); EEPROM.write(289, otaLock); EEPROM.write(290, (udpPort >> 0) & 0xFF); EEPROM.write(291, (udpPort >> 8) & 0xFF); @@ -123,6 +127,19 @@ void saveSettingsToEEPROM() EEPROM.write(387, cc_fromEnd); EEPROM.write(388, cc_step); EEPROM.write(389, bootPreset); + EEPROM.write(390, aOtaEnabled); + EEPROM.write(391, receiveNotificationColor); + EEPROM.write(392, receiveNotificationEffects); + if (currentTheme == 15) + { + for (int k=0;k<6;k++){ + for (int i = 900+k*8; i < (908+k*8); ++i) + { + EEPROM.write(i, cssCol[k].charAt(i-900)); + }} + } + EEPROM.write(948,currentTheme); + EEPROM.commit(); } @@ -197,18 +214,17 @@ void loadSettingsFromEEPROM(bool first) { bri = 0; bri_last = bri_s; } - receiveNotifications = EEPROM.read(250); - receiveNotificationsDefault = receiveNotifications; + receiveNotificationBrightness = EEPROM.read(250); fadeTransition = EEPROM.read(251); transitionDelay = ((EEPROM.read(253) << 0) & 0xFF) + ((EEPROM.read(254) << 8) & 0xFF00); - bri_n = EEPROM.read(255); + briMultiplier = EEPROM.read(255); otapass = ""; for (int i = 256; i < 288; ++i) { if (EEPROM.read(i) == 0) break; otapass += char(EEPROM.read(i)); } - bri_nl = EEPROM.read(288); + nightlightTargetBri = EEPROM.read(288); otaLock = EEPROM.read(289); udpPort = ((EEPROM.read(290) << 0) & 0xFF) + ((EEPROM.read(291) << 8) & 0xFF00); serverDescription = ""; @@ -261,12 +277,28 @@ void loadSettingsFromEEPROM(bool first) } if (lastEEPROMversion > 3) { effectIntensityDefault = EEPROM.read(326); effectIntensity = effectIntensityDefault; + aOtaEnabled = EEPROM.read(390); + receiveNotificationColor = EEPROM.read(391); + receiveNotificationEffects = EEPROM.read(392); } + receiveNotifications = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects); + bootPreset = EEPROM.read(389); //favorite setting memory (25 slots/ each 20byte) //400 - 899 reserved + currentTheme = EEPROM.read(948); + if (currentTheme == 15) + { + for (int k=0;k<6;k++){ + for (int i = 900+k*8; i < (908+k*8); ++i) + { + if (EEPROM.read(i) == 0) break; + cssCol[k] += char(EEPROM.read(i)); + }} + } + //custom macro memory (16 slots/ each 64byte) //1024-2047 reserved diff --git a/wled00/wled02_xml.ino b/wled00/wled02_xml.ino index bdad0002..ef091096 100644 --- a/wled00/wled02_xml.ino +++ b/wled00/wled02_xml.ino @@ -29,7 +29,13 @@ void XML_response() resp = resp + receiveNotifications; resp = resp + ""; resp = resp + nightlightActive; - resp = resp + ""; + resp = resp + ""; + resp = resp + nightlightFade; + resp = resp + ""; + resp = resp + nightlightDelayMins; + resp = resp + ""; + resp = resp + nightlightTargetBri; + resp = resp + ""; resp = resp + effectCurrent; resp = resp + ""; resp = resp + effectSpeed; @@ -46,7 +52,6 @@ void XML_response() resp = resp + ""; resp = resp + serverDescription; resp = resp + ""; - //enable toolbar here resp = resp + ""; server.send(200, "text/xml", resp); } @@ -58,118 +63,147 @@ String getSettings(uint8_t subPage) DEBUG_PRINTLN(subPage); String resp = ""; + if (subPage <1 || subPage >6) return resp; + String ds = "d.Sf."; String dg = "d.getElementsByClassName"; String v = ".value="; String c = ".checked="; String ih = ".innerHTML="; - - resp += ds + "CSSID" + v + "\"" + clientssid + "\";"; - resp += ds + "CPASS" + v + "\""; - for (int i = 0; i < clientpass.length(); i++) - { - resp += "*"; - } - resp += "\";"; - resp += ds + "CSIP0" + v + staticip[0] +";"; - resp += ds + "CSIP1" + v + staticip[1] +";"; - resp += ds + "CSIP2" + v + staticip[2] +";"; - resp += ds + "CSIP3" + v + staticip[3] +";"; - resp += ds + "CSGW0" + v + staticgateway[0] +";"; - resp += ds + "CSGW1" + v + staticgateway[1] +";"; - resp += ds + "CSGW2" + v + staticgateway[2] +";"; - resp += ds + "CSGW3" + v + staticgateway[3] +";"; - resp += ds + "CSSN0" + v + staticsubnet[0] +";"; - resp += ds + "CSSN1" + v + staticsubnet[1] +";"; - resp += ds + "CSSN2" + v + staticsubnet[2] +";"; - resp += ds + "CSSN3" + v + staticsubnet[3] +";"; - resp += ds + "CMDNS" + v + "\"" + cmdns + "\";"; - resp += ds + "APWTM" + v + apWaitTimeSecs +";"; - resp += ds + "APSSID" + v + "\"" + apssid + "\";"; - resp += ds + "APHSSID" + c + aphide + ";"; - resp += ds + "APPASS" + v + "\""; - for (int i = 0; i < clientpass.length(); i++) - { - resp += "*"; - } - resp += "\";"; - resp += ds + "APCHAN" + v + apchannel +";"; - resp += ds + "DESC" + v + "\"" + serverDescription + "\";"; - resp += ds + "COLMD" + c + useHSBDefault + ";"; - resp += ds + "LEDCN" + v + ledcount +";"; - resp += ds + "CLDFR" + v + col_s[0] +";"; - resp += ds + "CLDFG" + v + col_s[1] +";"; - resp += ds + "CLDFB" + v + col_s[2] +";"; - resp += ds + "CLDFA" + v + bri_s +";"; - if (useRGBW) { - resp += ds + "CLDFW" + v + white_s +";"; - } else { - resp += ds + "CLDFW" + v + "-1;"; + if (subPage == 1) { + resp += ds + "CSSID" + v + "\"" + clientssid + "\";"; + resp += ds + "CPASS" + v + "\""; + for (int i = 0; i < clientpass.length(); i++) + { + resp += "*"; + } + resp += "\";"; + resp += ds + "CSIP0" + v + staticip[0] +";"; + resp += ds + "CSIP1" + v + staticip[1] +";"; + resp += ds + "CSIP2" + v + staticip[2] +";"; + resp += ds + "CSIP3" + v + staticip[3] +";"; + resp += ds + "CSGW0" + v + staticgateway[0] +";"; + resp += ds + "CSGW1" + v + staticgateway[1] +";"; + resp += ds + "CSGW2" + v + staticgateway[2] +";"; + resp += ds + "CSGW3" + v + staticgateway[3] +";"; + resp += ds + "CSSN0" + v + staticsubnet[0] +";"; + resp += ds + "CSSN1" + v + staticsubnet[1] +";"; + resp += ds + "CSSN2" + v + staticsubnet[2] +";"; + resp += ds + "CSSN3" + v + staticsubnet[3] +";"; + resp += ds + "CMDNS" + v + "\"" + cmdns + "\";"; + resp += ds + "APWTM" + v + apWaitTimeSecs +";"; + resp += ds + "APSSID" + v + "\"" + apssid + "\";"; + resp += ds + "APHSSID" + c + aphide + ";"; + resp += ds + "APPASS" + v + "\""; + for (int i = 0; i < clientpass.length(); i++) + { + resp += "*"; + } + resp += "\";"; + resp += ds + "APCHAN" + v + apchannel +";"; + resp += dg + "(\"sip\")[0]" + ih + "\""; + if (!WiFi.localIP()[0] == 0) + { + resp += WiFi.localIP()[0]; + resp += + "."; + resp += WiFi.localIP()[1]; + resp += "."; + resp += WiFi.localIP()[2]; + resp += "."; + resp += WiFi.localIP()[3]; + } else + { + resp += "Not connected"; + } + resp += "\";"; + resp += dg + "(\"sip\")[1]" + ih + "\""; + if (!WiFi.softAPIP()[0] == 0) + { + resp += WiFi.softAPIP()[0]; + resp += + "."; + resp += WiFi.softAPIP()[1]; + resp += "."; + resp += WiFi.softAPIP()[2]; + resp += "."; + resp += WiFi.softAPIP()[3]; + } else + { + resp += "Not active"; + } + resp += "\";"; } - resp += ds + "CSECR" + v + col_sec_s[0] +";"; - resp += ds + "CSECG" + v + col_sec_s[1] +";"; - resp += ds + "CSECB" + v + col_sec_s[2] +";"; - resp += ds + "CSECW" + v + white_s +";"; - resp += ds + "BOOTN" + c + turnOnAtBoot +";"; - resp += ds + "BOOTP" + v + bootPreset +";"; - resp += ds + "FXDEF" + v + effectDefault +";"; - resp += ds + "SXDEF" + v + effectSpeedDefault +";"; - resp += ds + "GCBRI" + c + useGammaCorrectionBri +";"; - resp += ds + "GCRGB" + c + useGammaCorrectionRGB +";"; - resp += ds + "BTNON" + c + buttonEnabled +";"; - resp += ds + "TFADE" + c + fadeTransition +";"; - resp += ds + "TSWEE" + c + sweepTransition +";"; - resp += ds + "TSDIR" + c + !sweepDirection +";"; - resp += ds + "TDLAY" + v + transitionDelay +";"; - resp += ds + "TLBRI" + v + bri_nl +";"; - resp += ds + "TLDUR" + v + nightlightDelayMins +";"; - resp += ds + "TLFDE" + c + nightlightFade +";"; - resp += ds + "NUDPP" + v + udpPort +";"; - resp += ds + "NRBRI" + v + bri_n +";"; - resp += ds + "NRCVE" + c + receiveNotificationsDefault +";"; - resp += ds + "NSDIR" + c + notifyDirectDefault +";"; - resp += ds + "NSBTN" + c + notifyButton +";"; - resp += ds + "NTPON" + c + ntpEnabled +";"; - resp += ds + "ALEXA" + c + alexaEnabled +";"; - resp += ds + "AINVN" + v + "\"" + alexaInvocationName + "\";"; - resp += ds + "NSALX" + c + alexaNotify +";"; - resp += dg + "(\"times\")[0]" + ih + "\"" + getTimeString() + "\";"; - resp += ds + "OLDEF" + v + overlayDefault +";"; - resp += ds + "WOFFS" + v + arlsOffset +";"; - resp += ds + "NOOTA" + c + otaLock +";"; - resp += ds + "NORAP" + c + recoveryAPDisabled +";"; - resp += dg + "(\"sip\")[0]" + ih + "\""; - if (!WiFi.localIP()[0] == 0) - { - resp += WiFi.localIP()[0]; - resp += + "."; - resp += WiFi.localIP()[1]; - resp += "."; - resp += WiFi.localIP()[2]; - resp += "."; - resp += WiFi.localIP()[3]; - } else - { - resp += "Not connected"; + + if (subPage == 2) { + resp += ds + "LEDCN" + v + ledcount +";"; + resp += ds + "CLDFR" + v + col_s[0] +";"; + resp += ds + "CLDFG" + v + col_s[1] +";"; + resp += ds + "CLDFB" + v + col_s[2] +";"; + resp += ds + "CLDFA" + v + bri_s +";"; + if (useRGBW) { + resp += ds + "CLDFW" + v + white_s +";"; + } else { + resp += ds + "CLDFW" + v + "-1;"; + } + resp += ds + "CSECR" + v + col_sec_s[0] +";"; + resp += ds + "CSECG" + v + col_sec_s[1] +";"; + resp += ds + "CSECB" + v + col_sec_s[2] +";"; + resp += ds + "CSECW" + v + white_s +";"; + resp += ds + "BOOTN" + c + turnOnAtBoot +";"; + resp += ds + "BOOTP" + v + bootPreset +";"; + resp += ds + "FXDEF" + v + effectDefault +";"; + resp += ds + "SXDEF" + v + effectSpeedDefault +";"; + resp += ds + "GCBRI" + c + useGammaCorrectionBri +";"; + resp += ds + "GCRGB" + c + useGammaCorrectionRGB +";"; + resp += ds + "TFADE" + c + fadeTransition +";"; + resp += ds + "TSWEE" + c + sweepTransition +";"; + resp += ds + "TSDIR" + c + !sweepDirection +";"; + resp += ds + "TDLAY" + v + transitionDelay +";"; + resp += ds + "NRBRI" + v + briMultiplier +";"; + resp += ds + "TLBRI" + v + nightlightTargetBri +";"; + resp += ds + "TLDUR" + v + nightlightDelayMins +";"; + resp += ds + "TLFDE" + c + nightlightFade +";"; + resp += ds + "OLDEF" + v + overlayDefault +";"; + resp += ds + "WOFFS" + v + arlsOffset +";"; } - resp += "\";"; - resp += dg + "(\"sip\")[1]" + ih + "\""; - if (!WiFi.softAPIP()[0] == 0) - { - resp += WiFi.softAPIP()[0]; - resp += + "."; - resp += WiFi.softAPIP()[1]; - resp += "."; - resp += WiFi.softAPIP()[2]; - resp += "."; - resp += WiFi.softAPIP()[3]; - } else - { - resp += "Not active"; + + if (subPage == 3) + { + resp += ds + "DESC" + v + "\"" + serverDescription + "\";"; + resp += ds + "COLMD" + c + useHSBDefault + ";"; + resp += ds + "THEME.selectedIndex=" + String(currentTheme) + ";"; + for(int i=0;i<5;i++) + resp += ds + "CCOL" + i + v + "\"" + cssCol[i] + "\";"; } - resp += "\";"; - resp += dg + "(\"msg\")[0]" + ih + "\""+ versionName +" (build " + VERSION + ") OK\";"; + + if (subPage == 4) + { + resp += ds + "BTNON" + c + buttonEnabled +";"; + resp += ds + "NUDPP" + v + udpPort +";"; + resp += ds + "NRCBR" + c + receiveNotificationBrightness +";"; + resp += ds + "NRCCL" + c + receiveNotificationColor +";"; + resp += ds + "NRCFX" + c + receiveNotificationEffects +";"; + resp += ds + "NSDIR" + c + notifyDirectDefault +";"; + resp += ds + "NSBTN" + c + notifyButton +";"; + resp += ds + "ALEXA" + c + alexaEnabled +";"; + resp += ds + "AINVN" + v + "\"" + alexaInvocationName + "\";"; + resp += ds + "NSALX" + c + alexaNotify +";"; + } + + if (subPage == 5) + { + resp += ds + "NTPON" + c + ntpEnabled +";"; + resp += dg + "(\"times\")[0]" + ih + "\"" + getTimeString() + "\";"; + } + + if (subPage == 6) + { + resp += ds + "NOOTA" + c + otaLock +";"; + resp += ds + "AROTA" + c + aOtaEnabled +";"; + resp += ds + "NORAP" + c + recoveryAPDisabled +";"; + resp += dg + "(\"msg\")[0]" + ih + "\""+ versionName +" (build " + VERSION + ") OK\";"; + } + resp += "}"; return resp; } diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index 707069e7..4d2399ce 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -19,260 +19,302 @@ void _setRandomColor(bool _sec) } } -void handleSettingsSet() +void handleSettingsSet(uint8_t subPage) { - if (server.hasArg("CSSID")) clientssid = server.arg("CSSID"); - if (server.hasArg("CPASS")) + //0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec + if (subPage <1 || subPage >6) return; + + //WIFI SETTINGS + if (subPage == 1) { - if (!server.arg("CPASS").indexOf('*') == 0) + if (server.hasArg("CSSID")) clientssid = server.arg("CSSID"); + if (server.hasArg("CPASS")) { - DEBUG_PRINTLN("Setting pass"); - clientpass = server.arg("CPASS"); - } - } - if (server.hasArg("CMDNS")) cmdns = server.arg("CMDNS"); - if (server.hasArg("APWTM")) - { - int i = server.arg("APWTM").toInt(); - if (i >= 0 && i <= 255) apWaitTimeSecs = i; - } - if (server.hasArg("APSSID")) apssid = server.arg("APSSID"); - aphide = server.hasArg("APHSSID"); - if (server.hasArg("APPASS")) - { - if (!server.arg("APPASS").indexOf('*') == 0) appass = server.arg("APPASS"); - } - if (server.hasArg("APCHAN")) - { - int chan = server.arg("APCHAN").toInt(); - if (chan > 0 && chan < 14) apchannel = chan; - } - if (server.hasArg("RESET")) //might be dangerous in case arg is always sent - { - clearEEPROM(); - server.send(200, "text/plain", "Settings erased. Rebooting..."); - reset(); - } - if (server.hasArg("CSIP0")) - { - int i = server.arg("CSIP0").toInt(); - if (i >= 0 && i <= 255) staticip[0] = i; - } - if (server.hasArg("CSIP1")) - { - int i = server.arg("CSIP1").toInt(); - if (i >= 0 && i <= 255) staticip[1] = i; - } - if (server.hasArg("CSIP2")) - { - int i = server.arg("CSIP2").toInt(); - if (i >= 0 && i <= 255) staticip[2] = i; - } - if (server.hasArg("CSIP3")) - { - int i = server.arg("CSIP3").toInt(); - if (i >= 0 && i <= 255) staticip[3] = i; - } - if (server.hasArg("CSGW0")) - { - int i = server.arg("CSGW0").toInt(); - if (i >= 0 && i <= 255) staticgateway[0] = i; - } - if (server.hasArg("CSGW1")) - { - int i = server.arg("CSGW1").toInt(); - if (i >= 0 && i <= 255) staticgateway[1] = i; - } - if (server.hasArg("CSGW2")) - { - int i = server.arg("CSGW2").toInt(); - if (i >= 0 && i <= 255) staticgateway[2] = i; - } - if (server.hasArg("CSGW3")) - { - int i = server.arg("CSGW3").toInt(); - if (i >= 0 && i <= 255) staticgateway[3] = i; - } - if (server.hasArg("CSSN0")) - { - int i = server.arg("CSSN0").toInt(); - if (i >= 0 && i <= 255) staticsubnet[0] = i; - } - if (server.hasArg("CSSN1")) - { - int i = server.arg("CSSN1").toInt(); - if (i >= 0 && i <= 255) staticsubnet[1] = i; - } - if (server.hasArg("CSSN2")) - { - int i = server.arg("CSSN2").toInt(); - if (i >= 0 && i <= 255) staticsubnet[2] = i; - } - if (server.hasArg("CSSN3")) - { - int i = server.arg("CSSN3").toInt(); - if (i >= 0 && i <= 255) staticsubnet[3] = i; - } - if (server.hasArg("DESC")) serverDescription = server.arg("DESC"); - useHSBDefault = server.hasArg("COLMD"); - useHSB = useHSBDefault; - if (server.hasArg("LEDCN")) - { - int i = server.arg("LEDCN").toInt(); - if (i >= 0 && i <= LEDCOUNT) ledcount = i; - strip.setLedCount(ledcount); - } - if (server.hasArg("CBEOR")) //ignore settings and save current brightness, colors and fx as default - { - col_s[0] = col[0]; - col_s[1] = col[1]; - col_s[2] = col[2]; - if (useRGBW) white_s = white; - bri_s = bri; - effectDefault = effectCurrent; - effectSpeedDefault = effectSpeed; - } else { - if (server.hasArg("CLDFR")) - { - int i = server.arg("CLDFR").toInt(); - if (i >= 0 && i <= 255) col_s[0] = i; - } - if (server.hasArg("CLDFG")) - { - int i = server.arg("CLDFG").toInt(); - if (i >= 0 && i <= 255) col_s[1] = i; - } - if (server.hasArg("CLDFB")) - { - int i = server.arg("CLDFB").toInt(); - if (i >= 0 && i <= 255) col_s[2] = i; - } - if (server.hasArg("CSECR")) - { - int i = server.arg("CSECR").toInt(); - if (i >= 0 && i <= 255) col_sec_s[0] = i; - } - if (server.hasArg("CSECG")) - { - int i = server.arg("CSECG").toInt(); - if (i >= 0 && i <= 255) col_sec_s[1] = i; - } - if (server.hasArg("CSECB")) - { - int i = server.arg("CSECB").toInt(); - if (i >= 0 && i <= 255) col_sec_s[2] = i; - } - if (server.hasArg("CSECW")) - { - int i = server.arg("CSECW").toInt(); - if (i >= 0 && i <= 255) white_sec_s = i; - } - if (server.hasArg("CLDFW")) - { - int i = server.arg("CLDFW").toInt(); - if (i >= 0 && i <= 255) + if (!server.arg("CPASS").indexOf('*') == 0) { - useRGBW = true; - white_s = i; - } else { - useRGBW = false; - white_s = 0; + DEBUG_PRINTLN("Setting pass"); + clientpass = server.arg("CPASS"); } } - if (server.hasArg("CLDFA")) + if (server.hasArg("CMDNS")) cmdns = server.arg("CMDNS"); + if (server.hasArg("APWTM")) { - int i = server.arg("CLDFA").toInt(); - if (i >= 0 && i <= 255) bri_s = i; + int i = server.arg("APWTM").toInt(); + if (i >= 0 && i <= 255) apWaitTimeSecs = i; } - if (server.hasArg("FXDEF")) + if (server.hasArg("APSSID")) apssid = server.arg("APSSID"); + aphide = server.hasArg("APHSSID"); + if (server.hasArg("APPASS")) { - int i = server.arg("FXDEF").toInt(); - if (i >= 0 && i <= 255) effectDefault = i; + if (!server.arg("APPASS").indexOf('*') == 0) appass = server.arg("APPASS"); } - if (server.hasArg("SXDEF")) + if (server.hasArg("APCHAN")) { - int i = server.arg("SXDEF").toInt(); - if (i >= 0 && i <= 255) effectSpeedDefault = i; + int chan = server.arg("APCHAN").toInt(); + if (chan > 0 && chan < 14) apchannel = chan; + } + if (server.hasArg("CSIP0")) + { + int i = server.arg("CSIP0").toInt(); + if (i >= 0 && i <= 255) staticip[0] = i; + } + if (server.hasArg("CSIP1")) + { + int i = server.arg("CSIP1").toInt(); + if (i >= 0 && i <= 255) staticip[1] = i; + } + if (server.hasArg("CSIP2")) + { + int i = server.arg("CSIP2").toInt(); + if (i >= 0 && i <= 255) staticip[2] = i; + } + if (server.hasArg("CSIP3")) + { + int i = server.arg("CSIP3").toInt(); + if (i >= 0 && i <= 255) staticip[3] = i; + } + if (server.hasArg("CSGW0")) + { + int i = server.arg("CSGW0").toInt(); + if (i >= 0 && i <= 255) staticgateway[0] = i; + } + if (server.hasArg("CSGW1")) + { + int i = server.arg("CSGW1").toInt(); + if (i >= 0 && i <= 255) staticgateway[1] = i; + } + if (server.hasArg("CSGW2")) + { + int i = server.arg("CSGW2").toInt(); + if (i >= 0 && i <= 255) staticgateway[2] = i; + } + if (server.hasArg("CSGW3")) + { + int i = server.arg("CSGW3").toInt(); + if (i >= 0 && i <= 255) staticgateway[3] = i; + } + if (server.hasArg("CSSN0")) + { + int i = server.arg("CSSN0").toInt(); + if (i >= 0 && i <= 255) staticsubnet[0] = i; + } + if (server.hasArg("CSSN1")) + { + int i = server.arg("CSSN1").toInt(); + if (i >= 0 && i <= 255) staticsubnet[1] = i; + } + if (server.hasArg("CSSN2")) + { + int i = server.arg("CSSN2").toInt(); + if (i >= 0 && i <= 255) staticsubnet[2] = i; + } + if (server.hasArg("CSSN3")) + { + int i = server.arg("CSSN3").toInt(); + if (i >= 0 && i <= 255) staticsubnet[3] = i; } } - turnOnAtBoot = server.hasArg("BOOTN"); - if (server.hasArg("BOOTP")) + + //LED SETTINGS + if (subPage == 2) { - int i = server.arg("BOOTP").toInt(); - if (i >= 0 && i <= 25) bootPreset = i; - } - useGammaCorrectionBri = server.hasArg("GCBRI"); - useGammaCorrectionRGB = server.hasArg("GCRGB"); - buttonEnabled = server.hasArg("BTNON"); - fadeTransition = server.hasArg("TFADE"); - sweepTransition = server.hasArg("TSWEE"); - sweepDirection = !server.hasArg("TSDIR"); - if (server.hasArg("TDLAY")) - { - int i = server.arg("TDLAY").toInt(); - if (i > 0){ - transitionDelay = i; + if (server.hasArg("LEDCN")) + { + int i = server.arg("LEDCN").toInt(); + if (i >= 0 && i <= LEDCOUNT) ledcount = i; + strip.setLedCount(ledcount); + } + if (server.hasArg("CBEOR")) //ignore settings and save current brightness, colors and fx as default + { + col_s[0] = col[0]; + col_s[1] = col[1]; + col_s[2] = col[2]; + if (useRGBW) white_s = white; + bri_s = bri; + effectDefault = effectCurrent; + effectSpeedDefault = effectSpeed; + } else { + if (server.hasArg("CLDFR")) + { + int i = server.arg("CLDFR").toInt(); + if (i >= 0 && i <= 255) col_s[0] = i; + } + if (server.hasArg("CLDFG")) + { + int i = server.arg("CLDFG").toInt(); + if (i >= 0 && i <= 255) col_s[1] = i; + } + if (server.hasArg("CLDFB")) + { + int i = server.arg("CLDFB").toInt(); + if (i >= 0 && i <= 255) col_s[2] = i; + } + if (server.hasArg("CSECR")) + { + int i = server.arg("CSECR").toInt(); + if (i >= 0 && i <= 255) col_sec_s[0] = i; + } + if (server.hasArg("CSECG")) + { + int i = server.arg("CSECG").toInt(); + if (i >= 0 && i <= 255) col_sec_s[1] = i; + } + if (server.hasArg("CSECB")) + { + int i = server.arg("CSECB").toInt(); + if (i >= 0 && i <= 255) col_sec_s[2] = i; + } + if (server.hasArg("CSECW")) + { + int i = server.arg("CSECW").toInt(); + if (i >= 0 && i <= 255) white_sec_s = i; + } + if (server.hasArg("CLDFW")) + { + int i = server.arg("CLDFW").toInt(); + if (i >= 0 && i <= 255) + { + useRGBW = true; + white_s = i; + } else { + useRGBW = false; + white_s = 0; + } + } + if (server.hasArg("CLDFA")) + { + int i = server.arg("CLDFA").toInt(); + if (i >= 0 && i <= 255) bri_s = i; + } + if (server.hasArg("FXDEF")) + { + int i = server.arg("FXDEF").toInt(); + if (i >= 0 && i <= 255) effectDefault = i; + } + if (server.hasArg("SXDEF")) + { + int i = server.arg("SXDEF").toInt(); + if (i >= 0 && i <= 255) effectSpeedDefault = i; + } + } + turnOnAtBoot = server.hasArg("BOOTN"); + if (server.hasArg("BOOTP")) + { + int i = server.arg("BOOTP").toInt(); + if (i >= 0 && i <= 25) bootPreset = i; + } + useGammaCorrectionBri = server.hasArg("GCBRI"); + useGammaCorrectionRGB = server.hasArg("GCRGB"); + buttonEnabled = server.hasArg("BTNON"); + fadeTransition = server.hasArg("TFADE"); + sweepTransition = server.hasArg("TSWEE"); + sweepDirection = !server.hasArg("TSDIR"); + if (server.hasArg("TDLAY")) + { + int i = server.arg("TDLAY").toInt(); + if (i > 0){ + transitionDelay = i; + } + } + if (server.hasArg("TLBRI")) + { + nightlightTargetBri = server.arg("TLBRI").toInt(); + } + if (server.hasArg("TLDUR")) + { + int i = server.arg("TLDUR").toInt(); + if (i > 0) nightlightDelayMins = i; + } + nightlightFade = server.hasArg("TLFDE"); + if (server.hasArg("OLDEF")) + { + int i = server.arg("OLDEF").toInt(); + if (i >= 0 && i <= 255) overlayDefault = i; + } + if (server.hasArg("WOFFS")) + { + int i = server.arg("WOFFS").toInt(); + if (i >= -255 && i <= 255) arlsOffset = i; + arlsSign = (i>=0)?true:false; + } + if (server.hasArg("NRBRI")) + { + int i = server.arg("NRBRI").toInt(); + if (i > 0) briMultiplier = i; } } - if (server.hasArg("TLBRI")) + + //UI + if (subPage == 3) { - bri_nl = server.arg("TLBRI").toInt(); + if (server.hasArg("DESC")) serverDescription = server.arg("DESC"); + useHSBDefault = server.hasArg("COLMD"); + useHSB = useHSBDefault; + if (server.hasArg("THEME")) currentTheme = server.arg("THEME").toInt(); + for(int i=0;i<5;i++) + { + if (server.hasArg(("CCOL"+i))) cssCol[i] = server.arg(("CCOL"+i)); + } + buildCssColorString(); } - if (server.hasArg("TLDUR")) + + //SYNC + if (subPage == 4) { - int i = server.arg("TLDUR").toInt(); - if (i > 0) nightlightDelayMins = i; + if (server.hasArg("NUDPP")) + { + udpPort = server.arg("NUDPP").toInt(); + } + receiveNotificationBrightness = server.hasArg("NRCBR"); + receiveNotificationColor = server.hasArg("NRCCL"); + receiveNotificationEffects = server.hasArg("NRCFX"); + receiveNotifications = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects); + notifyDirectDefault = server.hasArg("NSDIR"); + notifyDirect = notifyDirectDefault; + notifyButton = server.hasArg("NSBTN"); + alexaEnabled = server.hasArg("ALEXA"); + if (server.hasArg("AINVN")) alexaInvocationName = server.arg("AINVN"); + alexaNotify = server.hasArg("NSALX"); } - nightlightFade = server.hasArg("TLFDE"); - if (server.hasArg("NUDPP")) + + //TIME + if (subPage == 5) { - udpPort = server.arg("NUDPP").toInt(); + ntpEnabled = server.hasArg("NTPON"); } - receiveNotifications = server.hasArg("NRCVE"); - receiveNotificationsDefault = receiveNotifications; - if (server.hasArg("NRBRI")) - { - int i = server.arg("NRBRI").toInt(); - if (i > 0) bri_n = i; - } - notifyDirectDefault = server.hasArg("NSDIR"); - notifyDirect = notifyDirectDefault; - notifyButton = server.hasArg("NSBTN"); - alexaEnabled = server.hasArg("ALEXA"); - if (server.hasArg("AINVN")) alexaInvocationName = server.arg("AINVN"); - alexaNotify = server.hasArg("NSALX"); - ntpEnabled = server.hasArg("NTPON"); - if (server.hasArg("OLDEF")) - { - int i = server.arg("OLDEF").toInt(); - if (i >= 0 && i <= 255) overlayDefault = i; - } - if (server.hasArg("WOFFS")) - { - int i = server.arg("WOFFS").toInt(); - if (i >= -255 && i <= 255) arlsOffset = i; - arlsSign = (i>=0)?true:false; - } - if (server.hasArg("OPASS")) + + //SECURITY + if (subPage == 6) { + if (server.hasArg("RESET")) + { + clearEEPROM(); + serveMessage(200, "All Settings erased.", "Rebooting..."); + reset(); + } + + if (server.hasArg("OPASS")) + { + if (!otaLock) + { + if (server.arg("OPASS").length() > 0) + otapass = server.arg("OPASS"); + } else if (!server.hasArg("NOOTA")) + { + if (otapass.equals(server.arg("OPASS"))) + { + otaLock = false; + } + } + } + if (server.hasArg("NOOTA")) otaLock = true; if (!otaLock) { - if (server.arg("OPASS").length() > 0) - otapass = server.arg("OPASS"); - } else if (!server.hasArg("NOOTA")) - { - if (otapass.equals(server.arg("OPASS"))) - { - otaLock = false; - } + recoveryAPDisabled = server.hasArg("NORAP"); + aOtaEnabled = server.hasArg("AROTA"); } } - if (server.hasArg("NOOTA")) otaLock = true; - if (server.hasArg("NORAP")) { - if (!otaLock) recoveryAPDisabled = true; - } else { - recoveryAPDisabled = false; - } + saveSettingsToEEPROM(); } @@ -329,6 +371,7 @@ boolean handleSet(String req) if (pos > 0) { white = req.substring(pos + 3).toInt(); } + //set 2nd red value pos = req.indexOf("R2="); if (pos > 0) { @@ -349,6 +392,7 @@ boolean handleSet(String req) if (pos > 0) { white_sec = req.substring(pos + 3).toInt(); } + //set 2nd to white pos = req.indexOf("SW"); if (pos > 0) { @@ -398,6 +442,7 @@ boolean handleSet(String req) white = white_sec; white_sec = _temp[3]; } + //set current effect index pos = req.indexOf("FX="); if (pos > 0) { @@ -418,6 +463,17 @@ boolean handleSet(String req) effectUpdated = true; } } + //set effect intensity + pos = req.indexOf("IX="); + if (pos > 0) { + if (effectIntensity != req.substring(pos + 3).toInt()) + { + effectIntensity = req.substring(pos + 3).toInt(); + strip.setIntensity(effectIntensity); + effectUpdated = true; + } + } + //set default control mode (0 - RGB, 1 - HSB) pos = req.indexOf("MD="); if (pos > 0) { @@ -511,7 +567,7 @@ boolean handleSet(String req) //set nightlight target brightness pos = req.indexOf("NT="); if (pos > 0) { - bri_nl = req.substring(pos + 3).toInt(); + nightlightTargetBri = req.substring(pos + 3).toInt(); nightlightActive_old = false; //re-init } //toggle nightlight fade @@ -560,6 +616,7 @@ boolean handleSet(String req) countdownTime = req.substring(pos+3).toInt(); if (countdownTime - now() > 0) countdownOverTriggered = false; } + //set custom chase data bool _cc_updated = false; pos = req.indexOf("C0="); if (pos > 0) {cc_start = (req.substring(pos + 3).toInt()); _cc_updated = true;} diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino index 620010ba..09ce5d96 100644 --- a/wled00/wled05_init.ino +++ b/wled00/wled05_init.ino @@ -26,6 +26,7 @@ void wledInit() loadSettingsFromEEPROM(true); DEBUG_PRINT("CC: SSID: "); DEBUG_PRINT(clientssid); + buildCssColorString(); WiFi.disconnect(); //close old connections @@ -71,59 +72,108 @@ void wledInit() //SERVER INIT //settings page server.on("/settings", HTTP_GET, [](){ - if (!arlsTimeout) //do not serve while receiving realtime - { - String settingsBuffer = getSettings(); - server.setContentLength(strlen_P(PAGE_settings0) + strlen_P(PAGE_settings1) + settingsBuffer.length()); - server.send(200, "text/html", ""); - server.sendContent_P(PAGE_settings0); - server.sendContent(settingsBuffer); - server.sendContent_P(PAGE_settings1); - } else { - server.send(200, "text/plain", "The settings are not available while receiving real-time data."); - } + serveSettings(0); }); + server.on("/settings/wifi", HTTP_GET, [](){ + serveSettings(1); + }); + server.on("/settings/leds", HTTP_GET, [](){ + serveSettings(2); + }); + server.on("/settings/ui", HTTP_GET, [](){ + serveSettings(3); + }); + server.on("/settings/sync", HTTP_GET, [](){ + serveSettings(4); + }); + server.on("/settings/time", HTTP_GET, [](){ + serveSettings(5); + }); + server.on("/settings/sec", HTTP_GET, [](){ + serveSettings(6); + }); + server.on("/favicon.ico", HTTP_GET, [](){ if(!handleFileRead("/favicon.ico")) server.send(200, "image/x-icon", favicon); }); + server.on("/", HTTP_GET, [](){ - if (!initialBoot){ + if (!showWelcomePage){ if(!handleFileRead("/index.htm")) { serveIndex(); } }else{ if(!handleFileRead("/welcome.htm")) { - serveWelcomePage(); + serveSettings(255); } } }); - server.on("/sliders", HTTP_GET, serveIndex) - server.on("/welcome", HTTP_GET, serveWelcomePage) + + server.on("/sliders", HTTP_GET, serveIndex); + + server.on("/welcome", HTTP_GET, [](){ + serveSettings(255); + }); + server.on("/reset", HTTP_GET, [](){ - server.send(200, "text/plain", "Rebooting..."); + serveMessage(200,"Rebooting now...","(takes ~15 seconds)"); reset(); }); - server.on("/set-settings", HTTP_POST, [](){ - handleSettingsSet(); - if(!handleFileRead("/settingssaved.htm")) server.send(200, "text/html", PAGE_settingssaved); + + server.on("/settings/wifi", HTTP_POST, [](){ + handleSettingsSet(1); + serveMessage(200,"WiFi settings saved.","Rebooting now..."); + reset(); }); + + server.on("/settings/leds", HTTP_POST, [](){ + handleSettingsSet(2); + serveMessage(200,"LED settings saved.","",true); + }); + + server.on("/settings/ui", HTTP_POST, [](){ + handleSettingsSet(3); + serveMessage(200,"UI settings saved.","",true); + }); + + server.on("/settings/sync", HTTP_POST, [](){ + handleSettingsSet(4); + serveMessage(200,"Sync settings saved.","",true); + }); + + server.on("/settings/time", HTTP_POST, [](){ + handleSettingsSet(5); + serveMessage(200,"Time settings saved.","If you made changes to NTP, please reboot.",true); + }); + + server.on("/settings/sec", HTTP_POST, [](){ + handleSettingsSet(6); + serveMessage(200,"Security settings saved.","Rebooting now..."); + reset(); + }); + server.on("/version", HTTP_GET, [](){ server.send(200, "text/plain", (String)VERSION); }); + server.on("/uptime", HTTP_GET, [](){ server.send(200, "text/plain", (String)millis()); }); + server.on("/freeheap", HTTP_GET, [](){ server.send(200, "text/plain", (String)ESP.getFreeHeap()); }); + server.on("/power", HTTP_GET, [](){ String val = (String)(int)strip.getPowerEstimate(ledcount,strip.getColor(),strip.getBrightness()); val += "mA currently\nNotice: This is just an estimate which does not take into account several factors (like effects and wire resistance). It is NOT an accurate measurement!"; server.send(200, "text/plain", val); }); + server.on("/teapot", HTTP_GET, [](){ - server.send(418, "text/plain", "418. I'm a teapot. (Tangible Embedded Advanced Project Of Twinkling)"); + serveMessage(418, "418. I'm a teapot.","(Tangible Embedded Advanced Project Of Twinkling)"); }); + server.on("/build", HTTP_GET, [](){ String info = "hard-coded build info:\r\n\n"; #ifdef ARDUINO_ARCH_ESP32 @@ -183,30 +233,22 @@ void wledInit() server.on("/cleareeprom", HTTP_GET, clearEEPROM); //init ota page httpUpdater.setup(&server); - //init ArduinoOTA - ArduinoOTA.onStart([]() { - #ifndef ARDUINO_ARCH_ESP32 - wifi_set_sleep_type(NONE_SLEEP_T); - #endif - DEBUG_PRINTLN("Start ArduinoOTA"); - }); - ArduinoOTA.begin(); } else { server.on("/edit", HTTP_GET, [](){ - server.send(500, "text/plain", "OTA lock active"); + serveMessage(500, "Access Denied", txd); }); server.on("/down", HTTP_GET, [](){ - server.send(500, "text/plain", "OTA lock active"); + serveMessage(500, "Access Denied", txd); }); server.on("/cleareeprom", HTTP_GET, [](){ - server.send(500, "text/plain", "OTA lock active"); + serveMessage(500, "Access Denied", txd); }); server.on("/update", HTTP_GET, [](){ - server.send(500, "text/plain", "OTA lock active"); + serveMessage(500, "Access Denied", txd); }); server.on("/list", HTTP_GET, [](){ - server.send(500, "text/plain", "OTA lock active"); + serveMessage(500, "Access Denied", txd); }); } //called when the url is not defined here, ajax-in; get-settings @@ -216,7 +258,7 @@ void wledInit() DEBUG_PRINTLN("Body: " + server.arg(0)); if(!handleSet(server.uri())){ if(!handleAlexaApiCall(server.uri(),server.arg(0))) - server.send(404, "text/plain", "FileNotFound"); + server.send(404, "text/plain", "Not Found"); } }); //init Alexa hue emulation @@ -227,6 +269,18 @@ void wledInit() // Add service to MDNS MDNS.addService("http", "tcp", 80); + //init ArduinoOTA + if (aOtaEnabled) + { + ArduinoOTA.onStart([]() { + #ifndef ARDUINO_ARCH_ESP32 + wifi_set_sleep_type(NONE_SLEEP_T); + #endif + DEBUG_PRINTLN("Start ArduinoOTA"); + }); + ArduinoOTA.begin(); + } + // Initialize NeoPixel Strip strip.init(); strip.setLedCount(ledcount); @@ -278,16 +332,31 @@ void initCon() void buildCssColorString() { - cssColorString=":root{--aCol:"; + switch (currentTheme) + { + default: cssCol[0]="D9B310"; cssCol[1]="0B3C5D"; cssCol[2]="1D2731"; cssCol[3]="328CC1"; cssCol[4]="000"; break; //night + case 1: cssCol[0]="eee"; cssCol[1]="ddd"; cssCol[2]="b9b9b9"; cssCol[3]="049"; cssCol[4]="777"; break; //modern + case 2: cssCol[0]="abc"; cssCol[1]="fff"; cssCol[2]="ddd"; cssCol[3]="000"; cssCol[4]="0004"; break; //bright + case 3: cssCol[0]="c09f80"; cssCol[1]="d7cec7"; cssCol[2]="76323f"; cssCol[3]="888"; cssCol[4]="3334"; break; //wine + case 4: cssCol[0]="3cc47c"; cssCol[1]="828081"; cssCol[2]="d9a803"; cssCol[3]="1e392a"; cssCol[4]="000a"; break; //electric + case 5: cssCol[0]="57bc90"; cssCol[1]="a5a5af"; cssCol[2]="015249"; cssCol[3]="88c9d4"; cssCol[4]="0004"; break; //mint + case 6: cssCol[0]="f7c331"; cssCol[1]="dcc7aa"; cssCol[2]="6b7a8f"; cssCol[3]="f7882f"; cssCol[4]="0007"; break; //amber + case 7: cssCol[0]="fc3"; cssCol[1]="124"; cssCol[2]="334"; cssCol[3]="f1d"; cssCol[4]="f00"; break; //club + case 14: cssCol[0]="fc7"; cssCol[1]="49274a"; cssCol[2]="94618e"; cssCol[3]="f4decb"; cssCol[4]="0008"; break; //end + //case 15 do nothing since custom vals are already loaded + } + cssColorString="