diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d0d4cbf8..5c04cdae8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,36 @@ ### Builds after release 0.12.0 +#### Build 2105171 + +- Always copy MQTT payloads to prevent non-0-terminated strings +- Updated ArduinoJson to 6.18.0 +- Added experimental support for `{"on":"t"}` to toggle on/off state via JSON + +#### Build 2105120 + +- Fixed possibility of non-0-terminated MQTT payloads +- Fixed two warnings regarding integer comparison + +#### Build 2105112 + +- Usermod settings page no usermods message +- Lowered min speed for Drip effect + +#### Build 2105111 + +- Fixed various Codacy code style and logic issues + +#### Build 2105110 + +- Added Usermod settings page and configurable usermods (PR #1951) +- Added experimental `/json/cfg` endpoint for changing settings from JSON (see #1944, not part of official API) + +#### Build 2105070 + +- Fixed not turning on after pressing "Off" on IR remote twice (#1950) +- Fixed OTA update file selection from Android app (TODO: file type verification in JS, since android can't deal with accept='.bin' attribute) + #### Build 2104220 - Version bump to 0.12.1-b1 "Hikari" diff --git a/platformio.ini b/platformio.ini index 217d90c06..dca72f055 100644 --- a/platformio.ini +++ b/platformio.ini @@ -114,9 +114,6 @@ build_unflags = # enables all features for travis CI build_flags_all_features = - -D WLED_USE_ANALOG_LED - -D WLED_USE_H801 - -D WLED_ENABLE_5CH_LEDS -D WLED_ENABLE_ADALIGHT -D WLED_ENABLE_DMX -D WLED_ENABLE_MQTT @@ -289,7 +286,7 @@ platform = ${common.platform_wled_default} platform_packages = ${common.platform_packages} board_build.ldscript = ${common.ldscript_1m128k} build_unflags = ${common.build_unflags} -build_flags = ${common.build_flags_esp8266} -D WLED_DISABLE_OTA -D WLED_USE_ANALOG_LEDS +build_flags = ${common.build_flags_esp8266} -D WLED_DISABLE_OTA [env:esp8285_4CH_H801] board = esp8285 @@ -297,7 +294,7 @@ platform = ${common.platform_wled_default} platform_packages = ${common.platform_packages} board_build.ldscript = ${common.ldscript_1m128k} build_unflags = ${common.build_unflags} -build_flags = ${common.build_flags_esp8266} -D WLED_DISABLE_OTA -D WLED_USE_ANALOG_LEDS -D WLED_USE_H801 +build_flags = ${common.build_flags_esp8266} -D WLED_DISABLE_OTA [env:esp8285_5CH_H801] board = esp8285 @@ -305,7 +302,7 @@ platform = ${common.platform_wled_default} platform_packages = ${common.platform_packages} board_build.ldscript = ${common.ldscript_1m128k} build_unflags = ${common.build_unflags} -build_flags = ${common.build_flags_esp8266} -D WLED_DISABLE_OTA -D WLED_USE_ANALOG_LEDS -D WLED_USE_H801 -D WLED_ENABLE_5CH_LEDS +build_flags = ${common.build_flags_esp8266} -D WLED_DISABLE_OTA [env:d1_mini_5CH_Shojo_PCB] board = d1_mini @@ -313,7 +310,7 @@ platform = ${common.platform_wled_default} platform_packages = ${common.platform_packages} board_build.ldscript = ${common.ldscript_4m1m} build_unflags = ${common.build_unflags} -build_flags = ${common.build_flags_esp8266} -D WLED_USE_ANALOG_LEDS -D WLED_USE_SHOJO_PCB -D WLED_ENABLE_5CH_LEDS +build_flags = ${common.build_flags_esp8266} -D WLED_USE_SHOJO_PCB # ------------------------------------------------------------------------------ # DEVELOPMENT BOARDS @@ -405,6 +402,7 @@ build_flags = ${common.build_flags_esp32} ${common.debug_flags} ${common.build_f # ------------------------------------------------------------------------------ # codm pixel controller board configurations +# codm-controller-0.6 can also be used for the TYWE3S controller # ------------------------------------------------------------------------------ [env:codm-controller-0.6] diff --git a/platformio_override.ini.sample b/platformio_override.ini.sample index c9dab5487..7df8ce8d5 100644 --- a/platformio_override.ini.sample +++ b/platformio_override.ini.sample @@ -39,12 +39,8 @@ build_flags = ${common.build_flags_esp8266} ; PIN defines for 2 wire LEDs -D CLKPIN=0 -D DATAPIN=2 -; to drive analog LED strips (aka 5050), uncomment the following -; PWM pins 5,12,13,15 are used with Magic Home LED Controller (default) - -D WLED_USE_ANALOG_LEDS -; for the H801 controller (PINs 15,13,12,14 (W2 = 04)) uncomment this -; -D WLED_USE_H801 -; for the BW-LT11 controller (PINs 12,4,14,5 ) uncomment this -; -D WLED_USE_BWLT11 -; and to enable channel 5 for RGBW-CT led strips this -; -D WLED_USE_5CH_LEDS +; to drive analog LED strips (aka 5050) hardware configuration is no longer necessary +; configure the settings in the UI as follows (hard): +; for the Magic Home LED Controller use PWM pins 5,12,13,15 +; for the H801 controller use PINs 15,13,12,14 (W2 = 04) +; for the BW-LT11 controller use PINs 12,4,14,5 diff --git a/tools/cdata.js b/tools/cdata.js index de6a98f85..8a9048435 100644 --- a/tools/cdata.js +++ b/tools/cdata.js @@ -344,6 +344,10 @@ const char PAGE_settings_dmx[] PROGMEM = R"=====()====="; str .replace(/\/gms, "") .replace(/\.*\<\/style\>/gms, "%CSS%%SCSS%") + .replace( + /function GetV().*\<\/script\>/gms, + "function GetV() {var d=document;\n" + ), } ], "wled00/html_settings.h" diff --git a/tools/fps_test.htm b/tools/fps_test.htm new file mode 100644 index 000000000..5858e8ad5 --- /dev/null +++ b/tools/fps_test.htm @@ -0,0 +1,232 @@ + + + + WLED frame rate test tool + + + + +

Starship monitoring dashboard

+ (or rather just a WLED frame rate tester lol)

+ IP:
+ Time per effect: s
+ Effects to test: + + + + +
+ Extra JSON:
+ +
+ LEDs: -, Seg: -, Bri: -
+ FPS min: -, max: -, avg: -

+
+

+ + + + + \ No newline at end of file diff --git a/wled00/data/jsontest.htm b/tools/json_test.htm similarity index 100% rename from wled00/data/jsontest.htm rename to tools/json_test.htm diff --git a/usermods/PIR_sensor_switch/readme.md b/usermods/PIR_sensor_switch/readme.md index d6ea0fb0b..9b17c3ad0 100644 --- a/usermods/PIR_sensor_switch/readme.md +++ b/usermods/PIR_sensor_switch/readme.md @@ -9,9 +9,7 @@ The LED strip is switched [using a relay](https://github.com/Aircoookie/WLED/wik ## Webinterface -The info page in the web interface shows the items below -- the remaining time of the off timer. -**I recommend to deactivate the sensor before an OTA update and activate it again afterwards**. +The info page in the web interface shows the remaining time of the off timer. ## Sensor connection @@ -63,7 +61,10 @@ void registerUsermods() ## API to enable/disable the PIR sensor from outside. For example from another usermod. -To query or change the PIR sensor state the methods `bool PIRsensorEnabled()` and `void EnablePIRsensor(bool enable)` are available. +To query or change the PIR sensor state the methods `bool PIRsensorEnabled()` and `void EnablePIRsensor(bool enable)` are available. + +When the PIR sensor state changes an MQTT message is broadcasted with topic `wled/deviceMAC/motion` and message `on` or `off`. +Usermod can also be configured to just send MQTT message and not change WLED state using settings page as well as responding to motion only during nighttime (assuming NTP and lattitude/longitude are set to determine sunrise/sunset times). ### There are two options to get access to the usermod instance: diff --git a/usermods/Temperature/readme.md b/usermods/Temperature/readme.md index 8f200662a..ac2823c3f 100644 --- a/usermods/Temperature/readme.md +++ b/usermods/Temperature/readme.md @@ -3,7 +3,7 @@ Based on the excellent `QuinLED_Dig_Uno_Temp_MQTT` by srg74 and 400killer! This usermod will read from an attached DS18B20 temperature sensor (as available on the QuinLED Dig-Uno) The temperature is displayed both in the Info section of the web UI as well as published to the `/temperature` MQTT topic if enabled. -This usermod will be expanded with support for different sensor types in the future. +This usermod may be expanded with support for different sensor types in the future. If temperature sensor is not detected during boot, this usermod will be disabled. @@ -16,18 +16,19 @@ Copy the example `platformio_override.ini` to the root directory. This file sho * `USERMOD_DALLASTEMPERATURE` - define this to have this user mod included wled00\usermods_list.cpp * `USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT` - the number of milliseconds after boot to take first measurement, defaults to 20 seconds -All parameters can be configured at runtime using Usermods settings page. +All parameters can be configured at runtime using Usermods settings page, including pin, selection to display temerature in degrees Celsius or Farenheit mand measurement interval. ## Project link * [QuinLED-Dig-Uno](https://quinled.info/2018/09/15/quinled-dig-uno/) - Project link +* [Srg74-WLED-Wemos-shield](https://github.com/srg74/WLED-wemos-shield) - another great DIY WLED board ### PlatformIO requirements If you are using `platformio_override.ini`, you should be able to refresh the task list and see your custom task, for example `env:d1_mini_usermod_dallas_temperature_C`. -If you are not using `platformio_override.ini`, you might have to uncomment `DallasTemperature@~3.8.0`,`OneWire@~2.3.5 under` `[common]` section in `platformio.ini`: +If you are not using `platformio_override.ini`, you might have to uncomment `OneWire@~2.3.5 under` `[common]` section in `platformio.ini`: ```ini # platformio.ini @@ -41,8 +42,7 @@ default_envs = d1_mini ... lib_deps = ... - #For Dallas sensor uncomment following 2 lines - DallasTemperature@~3.8.0 + #For Dallas sensor uncomment following line OneWire@~2.3.5 ... ``` diff --git a/wled00/.vs/wled00/v15/.suo b/wled00/.vs/wled00/v15/.suo deleted file mode 100644 index 5bbdedd72..000000000 Binary files a/wled00/.vs/wled00/v15/.suo and /dev/null differ diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 6b0a0c90b..4d2f2185c 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -34,7 +34,7 @@ */ uint16_t WS2812FX::mode_static(void) { fill(SEGCOLOR(0)); - return (SEGMENT.getOption(SEG_OPTION_TRANSITIONAL)) ? FRAMETIME : 380; //update faster if in transition + return (SEGMENT.getOption(SEG_OPTION_TRANSITIONAL)) ? FRAMETIME : 350; //update faster if in transition } @@ -1436,8 +1436,8 @@ uint16_t WS2812FX::mode_tricolor_fade(void) } byte stp = prog; // % 256 - uint32_t color = 0; for(uint16_t i = 0; i < SEGLEN; i++) { + uint32_t color; if (stage == 2) { color = color_blend(color_from_palette(i, true, PALETTE_SOLID_WRAP, 2), color2, stp); } else if (stage == 1) { @@ -3050,7 +3050,7 @@ uint16_t WS2812FX::mode_drip(void) numDrops = 1 + (SEGMENT.intensity >> 6); // 255>>6 = 3 - float gravity = -0.001 - (SEGMENT.speed/50000.0); + float gravity = -0.0005 - (SEGMENT.speed/50000.0); gravity *= SEGLEN; int sourcedrop = 12; diff --git a/wled00/FX.h b/wled00/FX.h index ffb8b868c..e8416d5d3 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -612,6 +612,7 @@ class WS2812FX { bool isRgbw = false, + isOffRefreshRequred = false, //periodic refresh is required for the strip to remain off. gammaCorrectBri = false, gammaCorrectCol = true, applyToAllSelected = true, diff --git a/wled00/__vm/.wled00.vsarduino.h b/wled00/__vm/.wled00.vsarduino.h deleted file mode 100644 index 2a9ef40a4..000000000 --- a/wled00/__vm/.wled00.vsarduino.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - Editor: https://www.visualmicro.com/ - This file is for intellisense purpose only. - Visual micro (and the arduino ide) ignore this code during compilation. This code is automatically maintained by visualmicro, manual changes to this file will be overwritten - The contents of the _vm sub folder can be deleted prior to publishing a project - All non-arduino files created by visual micro and all visual studio project or solution files can be freely deleted and are not required to compile a sketch (do not delete your own code!). - Note: debugger breakpoints are stored in '.sln' or '.asln' files, knowledge of last uploaded breakpoints is stored in the upload.vmps.xml file. Both files are required to continue a previous debug session without needing to compile and upload again - - Hardware: ESP32 Dev Module, Platform=esp32, Package=esp32 -*/ - -#if defined(_VMICRO_INTELLISENSE) - -#ifndef _VSARDUINO_H_ -#define _VSARDUINO_H_ -#define __ESP32_esp32__ -#define __ESP32_ESP32__ -#define ESP_PLATFORM -#define HAVE_CONFIG_H -#define GCC_NOT_5_2_0 0 -#define WITH_POSIX -#define F_CPU 240000000L -#define ARDUINO 108011 -#define ARDUINO_ESP32_DEV -#define ARDUINO_ARCH_ESP32 -#define ESP32 -#define CORE_DEBUG_LEVEL 0 -#define __cplusplus 201103L - -#define _Pragma(x) -#undef __cplusplus -#define __cplusplus 201103L - -#define __STDC__ -#define __ARM__ -#define __arm__ -#define __inline__ -#define __asm__(...) -#define __extension__ -#define __ATTR_PURE__ -#define __ATTR_CONST__ -#define __volatile__ - -#define __ASM -#define __INLINE -#define __attribute__(noinline) - -//#define _STD_BEGIN -//#define EMIT -#define WARNING -#define _Lockit -#define __CLR_OR_THIS_CALL -#define C4005 -#define _NEW - -typedef bool _Bool; -typedef int _read; -typedef int _seek; -typedef int _write; -typedef int _close; -typedef int __cleanup; - -//#define inline - -#define __builtin_clz -#define __builtin_clzl -#define __builtin_clzll -#define __builtin_labs -#define __builtin_va_list -typedef int __gnuc_va_list; - -#define __ATOMIC_ACQ_REL - -#define __CHAR_BIT__ -#define _EXFUN() - -typedef unsigned char byte; -extern "C" void __cxa_pure_virtual() {;} - -typedef long __INTPTR_TYPE__ ; -typedef long __UINTPTR_TYPE__ ; -typedef long __SIZE_TYPE__ ; -typedef long __PTRDIFF_TYPE__; - -typedef long pthread_t; -typedef long pthread_key_t; -typedef long pthread_once_t; -typedef long pthread_mutex_t; -typedef long pthread_mutex_t; -typedef long pthread_cond_t; - - - -#include "arduino.h" -#include - -#define interrupts() sei() -#define noInterrupts() cli() - -#define ESP_LOGI(tag, ...) - -#include "wled00.ino" -#include "wled01_eeprom.ino" -#include "wled02_xml.ino" -#include "wled03_set.ino" -#include "wled04_file.ino" -#include "wled05_init.ino" -#include "wled06_usermod.ino" -#include "wled07_notify.ino" -#include "wled08_led.ino" -#include "wled09_button.ino" -#include "wled10_ntp.ino" -#include "wled11_ol.ino" -#include "wled12_alexa.ino" -#include "wled13_cronixie.ino" -#include "wled14_colors.ino" -#include "wled15_hue.ino" -#include "wled16_blynk.ino" -#include "wled17_mqtt.ino" -#include "wled18_server.ino" -#include "wled19_json.ino" -#include "wled20_ir.ino" -#endif -#endif diff --git a/wled00/__vm/Compile.vmps.xml b/wled00/__vm/Compile.vmps.xml deleted file mode 100644 index 6390398ed..000000000 --- a/wled00/__vm/Compile.vmps.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/wled00/__vm/Configuration.Release.vmps.xml b/wled00/__vm/Configuration.Release.vmps.xml deleted file mode 100644 index bcbca636a..000000000 --- a/wled00/__vm/Configuration.Release.vmps.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index 070121f2b..cfc3b5bf9 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -63,7 +63,7 @@ class Bus { return _start; } - void setStart(uint16_t start) { + inline void setStart(uint16_t start) { _start = start; } @@ -81,7 +81,7 @@ class Bus { return false; } - virtual uint8_t skipFirstLed() { + virtual uint8_t skippedLeds() { return 0; } @@ -184,10 +184,10 @@ class BusDigital : public Bus { } inline bool isRgbw() { - return _rgbw; + return (_rgbw || _type == TYPE_SK6812_RGBW || _type == TYPE_TM1814); } - inline uint8_t skipFirstLed() { + inline uint8_t skippedLeds() { return _skip; } @@ -451,6 +451,11 @@ class BusManager { return Bus::isRgbw(type); } + //Return true if the strip requires a refresh to stay off. + static bool isOffRefreshRequred(uint8_t type) { + return type == TYPE_TM1814; + } + private: uint8_t numBusses = 0; Bus* busses[WLED_MAX_BUSSES]; diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 6af7a86e4..39a9b177b 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -12,24 +12,7 @@ void getStringFromJson(char* dest, const char* src, size_t len) { if (src != nullptr) strlcpy(dest, src, len); } -void deserializeConfig() { - bool fromeep = false; - bool success = deserializeConfigSec(); - if (!success) { //if file does not exist, try reading from EEPROM - deEEPSettings(); - fromeep = true; - } - - DynamicJsonDocument doc(JSON_BUFFER_SIZE); - - DEBUG_PRINTLN(F("Reading settings from /cfg.json...")); - - success = readObjectFromFile("/cfg.json", nullptr, &doc); - if (!success) { //if file does not exist, try reading from EEPROM - if (!fromeep) deEEPSettings(); - return; - } - +bool deserializeConfig(JsonObject doc, bool fromFS) { //int rev_major = doc["rev"][0]; // 1 //int rev_minor = doc["rev"][1]; // 0 @@ -103,52 +86,61 @@ void deserializeConfig() { CJSON(strip.rgbwMode, hw_led[F("rgbwm")]); JsonArray ins = hw_led["ins"]; - uint8_t s = 0; // bus iterator - strip.isRgbw = false; - busses.removeAll(); - uint32_t mem = 0; - for (JsonObject elm : ins) { - if (s >= WLED_MAX_BUSSES) break; - uint8_t pins[5] = {255, 255, 255, 255, 255}; - JsonArray pinArr = elm["pin"]; - if (pinArr.size() == 0) continue; - uint8_t i = 0; - for (int p : pinArr) { - pins[i++] = p; - if (i>4) break; - } - uint16_t length = elm[F("len")]; - if (length==0 || length+lC > MAX_LEDS) continue; // zero length or we reached max. number of LEDs, just stop - uint16_t start = elm[F("start")] | 0; - if (start >= lC+length) continue; // something is very wrong :) - uint8_t colorOrder = elm[F("order")]; - uint8_t skipFirst = elm[F("skip")]; - uint8_t ledType = elm["type"] | TYPE_WS2812_RGB; - bool reversed = elm["rev"]; - //RGBW mode is enabled if at least one of the strips is RGBW -// if ((bool)elm[F("rgbw")]) SET_BIT(ledType,7); else UNSET_BIT(ledType,7); // hack bit 7 to indicate RGBW (as an override if necessary) -// strip.isRgbw |= (bool)elm[F("rgbw")]; - strip.isRgbw = (strip.isRgbw || Bus::isRgbw(ledType)); - s++; - lC += length; - BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst); - mem += BusManager::memUsage(bc); - DEBUG_PRINT(F(" Adding bus no. ")); - DEBUG_PRINTLN(busses.getNumBusses()); - if (mem <= MAX_LED_MEMORY && busses.getNumBusses() <= WLED_MAX_BUSSES) busses.add(bc); // finalization will be done in WLED::beginStrip() + if (fromFS || !ins.isNull()) { + uint8_t s = 0; // bus iterator + strip.isRgbw = false; + busses.removeAll(); + uint32_t mem = 0; + for (JsonObject elm : ins) { + if (s >= WLED_MAX_BUSSES) break; + uint8_t pins[5] = {255, 255, 255, 255, 255}; + JsonArray pinArr = elm["pin"]; + if (pinArr.size() == 0) continue; + pins[0] = pinArr[0]; + uint8_t i = 0; + for (int p : pinArr) { + pins[i++] = p; + if (i>4) break; + } + + uint16_t length = elm[F("len")]; + if (length==0 || length+lC > MAX_LEDS) continue; // zero length or we reached max. number of LEDs, just stop + uint16_t start = elm[F("start")] | 0; + if (start >= lC+length) continue; // something is very wrong :) + uint8_t colorOrder = elm[F("order")]; + uint8_t skipFirst = elm[F("skip")]; + uint8_t ledType = elm["type"] | TYPE_WS2812_RGB; + bool reversed = elm["rev"]; + //RGBW mode is enabled if at least one of the strips is RGBW + // if ((bool)elm[F("rgbw")]) SET_BIT(ledType,7); else UNSET_BIT(ledType,7); // hack bit 7 to indicate RGBW (as an override if necessary) + // strip.isRgbw |= (bool)elm[F("rgbw")]; + strip.isRgbw = (strip.isRgbw || BusManager::isRgbw(ledType)); + //refresh is required to remain off if at least one of the strips requires the refresh. + strip.isOffRefreshRequred |= BusManager::isOffRefreshRequred(ledType); + s++; + lC += length; + BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst); + mem += BusManager::memUsage(bc); + DEBUG_PRINT(F(" Adding bus no. ")); + DEBUG_PRINTLN(busses.getNumBusses()); + if (mem <= MAX_LED_MEMORY && busses.getNumBusses() <= WLED_MAX_BUSSES) busses.add(bc); // finalization will be done in WLED::beginStrip() + } + //strip.finalizeInit(); } if (lC > ledCount) ledCount = lC; // fix incorrect total length (honour analog setup) DEBUG_PRINTLN(F(" Done LEDs.")); JsonObject hw_btn_ins_0 = hw[F("btn")][F("ins")][0]; CJSON(buttonType, hw_btn_ins_0["type"]); - int hw_btn_pin = hw_btn_ins_0["pin"][0]; - if (pinManager.allocatePin(hw_btn_pin,false)) { - btnPin = hw_btn_pin; - pinMode(btnPin, INPUT_PULLUP); - } else { - btnPin = -1; + int hw_btn_pin = hw_btn_ins_0[F("pin")][0] | -2; //-2 = not present in doc, keep current. -1 = disable + if (hw_btn_pin > -2) { + if (pinManager.allocatePin(hw_btn_pin,false)) { + btnPin = hw_btn_pin; + pinMode(btnPin, INPUT_PULLUP); + } else { + btnPin = -1; + } } JsonArray hw_btn_ins_0_macros = hw_btn_ins_0[F("macros")]; @@ -156,25 +148,27 @@ void deserializeConfig() { CJSON(macroLongPress,hw_btn_ins_0_macros[1]); CJSON(macroDoublePress, hw_btn_ins_0_macros[2]); - //int hw_btn_ins_0_type = hw_btn_ins_0["type"]; // 0 - #ifndef WLED_DISABLE_INFRARED - int hw_ir_pin = hw["ir"]["pin"] | -1; // 4 - if (pinManager.allocatePin(hw_ir_pin,false)) { - irPin = hw_ir_pin; - } else { - irPin = -1; + int hw_ir_pin = hw["ir"]["pin"] | -2; // 4 + if (hw_ir_pin > -2) { + if (pinManager.allocatePin(hw_ir_pin,false)) { + irPin = hw_ir_pin; + } else { + irPin = -1; + } } #endif CJSON(irEnabled, hw["ir"]["type"]); JsonObject relay = hw[F("relay")]; - int hw_relay_pin = relay["pin"] | -1; - if (hw_relay_pin>=0 && pinManager.allocatePin(hw_relay_pin,true)) { - rlyPin = hw_relay_pin; - pinMode(rlyPin, OUTPUT); - } else { - rlyPin = -1; + int hw_relay_pin = relay["pin"] | -2; + if (hw_relay_pin > -2) { + if (pinManager.allocatePin(hw_relay_pin,true)) { + rlyPin = hw_relay_pin; + pinMode(rlyPin, OUTPUT); + } else { + rlyPin = -1; + } } if (relay.containsKey("rev")) { rlyMde = !relay["rev"]; @@ -202,8 +196,9 @@ void deserializeConfig() { JsonObject light_nl = light["nl"]; CJSON(nightlightMode, light_nl[F("mode")]); - CJSON(nightlightDelayMinsDefault, light_nl["dur"]); - nightlightDelayMins = nightlightDelayMinsDefault; + byte prev = nightlightDelayMinsDefault; + CJSON(nightlightDelayMinsDefault, light_nl[F("dur")]); + if (nightlightDelayMinsDefault != prev) nightlightDelayMins = nightlightDelayMinsDefault; CJSON(nightlightTargetBri, light_nl[F("tbri")]); CJSON(macroNl, light_nl[F("macro")]); @@ -231,12 +226,14 @@ void deserializeConfig() { JsonObject if_sync_recv = if_sync["recv"]; CJSON(receiveNotificationBrightness, if_sync_recv["bri"]); CJSON(receiveNotificationColor, if_sync_recv["col"]); - CJSON(receiveNotificationEffects, if_sync_recv["fx"]); + CJSON(receiveNotificationEffects, if_sync_recv[F("fx")]); + //! following line might be a problem if called after boot receiveNotifications = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects); JsonObject if_sync_send = if_sync["send"]; + prev = notifyDirectDefault; CJSON(notifyDirectDefault, if_sync_send[F("dir")]); - notifyDirect = notifyDirectDefault; + if (notifyDirectDefault != prev) notifyDirect = notifyDirectDefault; CJSON(notifyButton, if_sync_send[F("btn")]); CJSON(notifyAlexa, if_sync_send[F("va")]); CJSON(notifyHue, if_sync_send[F("hue")]); @@ -321,9 +318,10 @@ void deserializeConfig() { CJSON(latitude, if_ntp[F("lt")]); JsonObject ol = doc[F("ol")]; + prev = overlayDefault; CJSON(overlayDefault ,ol[F("clock")]); // 0 CJSON(countdownMode, ol[F("cntdwn")]); - overlayCurrent = overlayDefault; + if (prev != overlayDefault) overlayCurrent = overlayDefault; CJSON(overlayMin, ol["min"]); CJSON(overlayMax, ol[F("max")]); @@ -398,7 +396,32 @@ void deserializeConfig() { DEBUG_PRINTLN(F("Starting usermod config.")); JsonObject usermods_settings = doc["um"]; - usermods.readFromConfig(usermods_settings); + if (!usermods_settings.isNull()) usermods.readFromConfig(usermods_settings); + + if (fromFS) return false; + doReboot = doc[F("rb")] | doReboot; + return (doc["sv"] | true); +} + +void deserializeConfigFromFS() { + bool fromeep = false; + bool success = deserializeConfigSec(); + if (!success) { //if file does not exist, try reading from EEPROM + deEEPSettings(); + fromeep = true; + } + + DynamicJsonDocument doc(JSON_BUFFER_SIZE); + + DEBUG_PRINTLN(F("Reading settings from /cfg.json...")); + + success = readObjectFromFile("/cfg.json", nullptr, &doc); + if (!success) { //if file does not exist, try reading from EEPROM + if (!fromeep) deEEPSettings(); + return; + } + + deserializeConfig(doc.as(), true); } void serializeConfig() { @@ -480,8 +503,8 @@ void serializeConfig() { uint8_t nPins = bus->getPins(pins); for (uint8_t i = 0; i < nPins; i++) ins_pin.add(pins[i]); ins[F("order")] = bus->getColorOrder(); - ins["rev"] = bus->reversed; - ins[F("skip")] = bus->skipFirstLed(); + ins["rev"] = bus->reversed; + ins[F("skip")] = bus->skippedLeds(); ins["type"] = bus->getType(); ins[F("rgbw")] = bus->isRgbw(); } diff --git a/wled00/data/settings.htm b/wled00/data/settings.htm index b17648375..516a63afa 100644 --- a/wled00/data/settings.htm +++ b/wled00/data/settings.htm @@ -10,18 +10,18 @@ margin: 0; } html { - --h: 10.55vh; + --h: 10.2vh; } button { background: #333; color: #fff; font-family: Verdana, Helvetica, sans-serif; - border: 0.3ch solid #333; display: inline-block; + border: 1px solid #333; font-size: 6vmin; height: var(--h); width: 95%; - margin-top: 2.4vh; + margin-top: 2vh; }
)====="; // Autogenerated from wled00/data/settings_um.htm, do not edit!! const char PAGE_settings_um[] PROGMEM = R"=====(UI Settings%CSS%%SCSS%
Usermod Settings")); }