diff --git a/tools/cdata.js b/tools/cdata.js index 201193f6f..de6a98f85 100644 --- a/tools/cdata.js +++ b/tools/cdata.js @@ -333,6 +333,18 @@ const char PAGE_settings_dmx[] PROGMEM = R"=====()====="; "function GetV() {var d=document;\n" ), }, + { + file: "settings_um.htm", + name: "PAGE_settings_um", + prepend: "=====(", + append: ")=====", + method: "plaintext", + filter: "html-minify", + mangle: (str) => + str + .replace(/\/gms, "") + .replace(/\.*\<\/style\>/gms, "%CSS%%SCSS%") + } ], "wled00/html_settings.h" ); diff --git a/usermods/Temperature/usermod_temperature.h b/usermods/Temperature/usermod_temperature.h index 6532680b3..2ca26dd42 100644 --- a/usermods/Temperature/usermod_temperature.h +++ b/usermods/Temperature/usermod_temperature.h @@ -173,45 +173,48 @@ class UsermodTemperature : public Usermod { /** * addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object). * Values in the state object may be modified by connected clients - * Add "pin_Temperature" to json state. This can be used to check which GPIO pin usermod uses. + * Add "_" to json state. This can be used to check which GPIO pin usermod uses. */ void addToJsonState(JsonObject &root) { - root[F("pin_Temperature")] = temperaturePin; - root[F("mode_Temperature")] = degC ? ("C") : ("F"); + //root[F("Temperature_pin")] = temperaturePin; + //root[F("Temperature_degC")] = degC ? ("C") : ("F"); } /** * readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object). * Values in the state object may be modified by connected clients - * Read "pin_Temperature" from json state and and change GPIO pin used. + * Read "_" from json state and and change settings (i.e. GPIO pin) used. */ void readFromJsonState(JsonObject &root) { - if (root[F("pin_Temperature")] != nullptr) { - int8_t pin = (int)root[F("pin_Temperature")]; - // deallocate pin and release memory - pinManager.deallocatePin(temperaturePin); - delete sensor; - delete oneWire; - // disable usermod - temperaturePin = -1; - disabled = true; - // check if pin is OK - if (pin>=0 && pinManager.allocatePin(pin,false)) { - // allocat memory - oneWire = new OneWire(pin); - sensor = new DallasTemperature(oneWire); - if (sensor) { - temperaturePin = pin; - sensor->begin(); - disabled = !sensor->getAddress(sensorDeviceAddress, 0); - } else { - pinManager.deallocatePin(pin); + if (root[F("Temperature_pin")] != nullptr) { + int8_t pin = (int)root[F("Temperature_pin")]; + if (pin != temperaturePin) { + // deallocate pin and release memory + delete sensor; + delete oneWire; + pinManager.deallocatePin(temperaturePin); + // disable usermod + temperaturePin = -1; + disabled = true; + // check if pin is OK + if (pin>=0 && pinManager.allocatePin(pin,false)) { + // allocat memory + oneWire = new OneWire(pin); + sensor = new DallasTemperature(oneWire); + if (sensor) { + temperaturePin = pin; + sensor->begin(); + disabled = !sensor->getAddress(sensorDeviceAddress, 0); + } else { + pinManager.deallocatePin(pin); + } } } } - if (root[F("mode_Temperature")] != nullptr) { - degC = (root[F("mode_Temperature")]==String(PSTR("C"))); + if (root[F("Temperature_degC")] != nullptr) { + String strDegC = root[F("Temperature_degC")]; // checkbox -> off or on + degC = (bool) (strDegC!="off"); // off is guaranteed to be present } } @@ -220,9 +223,9 @@ class UsermodTemperature : public Usermod { */ void addToConfig(JsonObject &root) { // we add JSON object: {"Temperature": {"pin": 0, "degC": true}} - JsonObject top = root.createNestedObject(F("Temperature")); - top[F("pin")] = temperaturePin; - top[F("degC")] = degC; + JsonObject top = root.createNestedObject(F("Temperature")); // usermodname + top["pin"] = temperaturePin; // usermodparam + top[F("degC")] = degC; // usermodparam } /** @@ -231,8 +234,8 @@ class UsermodTemperature : public Usermod { void readFromConfig(JsonObject &root) { // we look for JSON object: {"Temperature": {"pin": 0, "degC": true}} JsonObject top = root[F("Temperature")]; - if (!top.isNull() && top[F("pin")] != nullptr) { - temperaturePin = (int)top[F("pin")]; + if (!top.isNull() && top["pin"] != nullptr) { + temperaturePin = (int)top["pin"]; degC = top[F("degC")] != nullptr ? top[F("degC")] : true; } else { DEBUG_PRINTLN(F("No Temperature sensor config found. (Using defaults.)")); diff --git a/wled00/data/settings.htm b/wled00/data/settings.htm index 4d7eaaed2..b17648375 100644 --- a/wled00/data/settings.htm +++ b/wled00/data/settings.htm @@ -10,7 +10,7 @@ margin: 0; } html { - --h: 11.55vh; + --h: 10.55vh; } button { background: #333; @@ -18,7 +18,7 @@ font-family: Verdana, Helvetica, sans-serif; border: 0.3ch solid #333; display: inline-block; - font-size: 8vmin; + font-size: 6vmin; height: var(--h); width: 95%; margin-top: 2.4vh; @@ -41,6 +41,7 @@
+
\ No newline at end of file diff --git a/wled00/data/settings_leds.htm b/wled00/data/settings_leds.htm index e91e15095..618a2439b 100644 --- a/wled00/data/settings_leds.htm +++ b/wled00/data/settings_leds.htm @@ -163,6 +163,18 @@ var lc=d.getElementsByName("LC"+LCs[i].name.substring(2))[0]; lc.max=maxPB; } + if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4" || nm=="RL" || nm=="BT" || nm=="IR" || nm=="AX") + if (LCs[i].value!="" && LCs[i].value!="-1") { + var p = []; + if (d.um_p && Array.isArray(d.um_p)) for (k=0;ke==parseInt(LCs[i].value,10))) LCs[i].style.color="red"; else LCs[i].style.color="#fff"; + } } if (d.getElementById("LC").readOnly) d.getElementsByName("LC")[0].value = sLC; diff --git a/wled00/data/settings_um.htm b/wled00/data/settings_um.htm new file mode 100644 index 000000000..b9f3f9234 --- /dev/null +++ b/wled00/data/settings_um.htm @@ -0,0 +1,125 @@ + + + + + + UI Settings + + + + + +
+
+
+
+ +
+
+

Usermod Setup

+
Loading settings...
+
+
+ + + \ No newline at end of file diff --git a/wled00/html_settings.h b/wled00/html_settings.h index 9ad97fc96..d54a74cad 100644 --- a/wled00/html_settings.h +++ b/wled00/html_settings.h @@ -12,7 +12,7 @@ const char PAGE_settingsCss[] PROGMEM = R"=====(
%DMXMENU%
+ action="/settings/um">
)====="; @@ -72,7 +73,7 @@ Do not enable if WiFi is working correctly, increases power consumption.
LED Settings%CSS%%SCSS%
+

+

Usermod Setup

Loading settings...

)====="; + diff --git a/wled00/set.cpp b/wled00/set.cpp index 6c696cb68..005e568e9 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -32,7 +32,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) { //0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec 7: DMX - if (subPage <1 || subPage >7) return; + if (subPage <1 || subPage >8) return; //WIFI SETTINGS if (subPage == 1) @@ -408,6 +408,26 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) } #endif + //USERMODS + if (subPage == 8) + { + DynamicJsonDocument doc(JSON_BUFFER_SIZE); + JsonObject um = doc.createNestedObject(F("um")); + + size_t args = request->args(); + for (size_t i=0; iargName(i); + String value = request->arg(i); + + um.remove(name); // checkboxes get two fields (first is always "off", existence of second depends on checkmark and may be "on") + um[name] = value; + DEBUG_PRINT(name); + DEBUG_PRINT(" = "); + DEBUG_PRINTLN(value); + } + usermods.readFromJsonState(um); + } + if (subPage != 2 && (subPage != 6 || !doReboot)) serializeConfig(); //do not save if factory reset or LED settings (which are saved after LED re-init) if (subPage == 4) alexaInit(); } diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index 251c3cc7d..8808361c0 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -373,6 +373,7 @@ void serveSettings(AsyncWebServerRequest* request, bool post) #ifdef WLED_ENABLE_DMX // include only if DMX is enabled else if (url.indexOf("dmx") > 0) subPage = 7; #endif + else if (url.indexOf("um") > 0) subPage = 8; } else subPage = 255; //welcome page if (subPage == 1 && wifiLock && otaLock) @@ -394,6 +395,7 @@ void serveSettings(AsyncWebServerRequest* request, bool post) case 5: strcpy_P(s, PSTR("Time")); break; case 6: strcpy_P(s, PSTR("Security")); strcpy_P(s2, PSTR("Rebooting, please wait ~10 seconds...")); break; case 7: strcpy_P(s, PSTR("DMX")); break; + case 8: strcpy_P(s, PSTR("Usermods")); break; } strcat_P(s, PSTR(" settings saved.")); @@ -420,6 +422,7 @@ void serveSettings(AsyncWebServerRequest* request, bool post) case 5: request->send_P(200, "text/html", PAGE_settings_time, settingsProcessor); break; case 6: request->send_P(200, "text/html", PAGE_settings_sec , settingsProcessor); break; case 7: request->send_P(200, "text/html", PAGE_settings_dmx , settingsProcessor); break; + case 8: request->send_P(200, "text/html", PAGE_settings_um , settingsProcessor); break; case 255: request->send_P(200, "text/html", PAGE_welcome); break; default: request->send_P(200, "text/html", PAGE_settings , settingsProcessor); } diff --git a/wled00/xml.cpp b/wled00/xml.cpp index f9c83062e..6e3983438 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -274,9 +274,9 @@ void getSettingsJS(byte subPage, char* dest) } else if (!kv.value().isNull()) { // element is an JsonObject JsonObject obj = kv.value(); - if (obj[F("pin")] != nullptr) { + if (obj["pin"] != nullptr) { if (i++) oappend(SET_F(",")); - oappendi((int)obj[F("pin")]); + oappendi((int)obj["pin"]); } } }