From 3107943af81ae5b64267e83b36726d2e2e397f88 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Fri, 2 Oct 2020 12:30:17 +0200 Subject: [PATCH] Fixed interaction of `T` and `NL` HTTP API commands (#1214) --- CHANGELOG.md | 5 +++++ wled00/json.cpp | 2 +- wled00/led.cpp | 2 +- wled00/set.cpp | 25 ++++++++++++------------- wled00/wled.cpp | 2 +- wled00/wled.h | 2 +- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6652af1a2..9acec9914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ### Development versions after the 0.10.2 release +#### Build 2010020 + +- Fixed interaction of `T` and `NL` HTTP API commands (#1214) +- Fixed an issue where Sunrise mode nightlight does not activate if toggled on simultaneously + #### Build 2009291 - Fixed MQTT bootloop (no F() macro, #1199) diff --git a/wled00/json.cpp b/wled00/json.cpp index d8d07ed84..62c6a334d 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -180,7 +180,7 @@ bool deserializeState(JsonObject root) if (tr >= 2) presetCycleTime = tr; JsonObject nl = root[F("nl")]; - nightlightActive = nl["on"] | nightlightActive; + nightlightActive = nl["on"] | nightlightActive; nightlightDelayMins = nl[F("dur")] | nightlightDelayMins; nightlightMode = nl[F("fade")] | nightlightMode; //deprecated nightlightMode = nl[F("mode")] | nightlightMode; diff --git a/wled00/led.cpp b/wled00/led.cpp index 7b359faee..395cd8493 100644 --- a/wled00/led.cpp +++ b/wled00/led.cpp @@ -134,7 +134,7 @@ void colorUpdated(int callMode) if (bri > 0) briLast = bri; //deactivate nightlight if target brightness is reached - if (bri == nightlightTargetBri && callMode != NOTIFIER_CALL_MODE_NO_NOTIFY) nightlightActive = false; + if (bri == nightlightTargetBri && callMode != NOTIFIER_CALL_MODE_NO_NOTIFY && nightlightMode != NL_MODE_SUN) nightlightActive = false; if (fadeTransition) { diff --git a/wled00/set.cpp b/wled00/set.cpp index 02e6493a6..f87ea9338 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -613,6 +613,18 @@ bool handleSet(AsyncWebServerRequest *request, const String& req) pos = req.indexOf(F("RD=")); if (pos > 0) receiveDirect = (req.charAt(pos+3) != '0'); + //main toggle on/off (parse before nightlight, #1214) + pos = req.indexOf(F("&T=")); + if (pos > 0) { + nightlightActive = false; //always disable nightlight when toggling + switch (getNumVal(&req, pos)) + { + case 0: if (bri != 0){briLast = bri; bri = 0;} break; //off, only if it was previously on + case 1: if (bri == 0) bri = briLast; break; //on, only if it was previously off + default: toggleOnOff(); //toggle + } + } + //toggle nightlight mode bool aNlDef = false; if (req.indexOf(F("&ND")) > 0) aNlDef = true; @@ -622,7 +634,6 @@ bool handleSet(AsyncWebServerRequest *request, const String& req) if (req.charAt(pos+3) == '0') { nightlightActive = false; - bri = briT; } else { nightlightActive = true; if (!aNlDef) nightlightDelayMins = getNumVal(&req, pos); @@ -664,18 +675,6 @@ bool handleSet(AsyncWebServerRequest *request, const String& req) pos = req.indexOf(F("TT=")); if (pos > 0) transitionDelay = getNumVal(&req, pos); - //main toggle on/off - pos = req.indexOf(F("&T=")); - if (pos > 0) { - nightlightActive = false; //always disable nightlight when toggling - switch (getNumVal(&req, pos)) - { - case 0: if (bri != 0){briLast = bri; bri = 0;} break; //off, only if it was previously on - case 1: if (bri == 0) bri = briLast; break; //on, only if it was previously off - default: toggleOnOff(); //toggle - } - } - //Segment reverse pos = req.indexOf(F("RV=")); if (pos > 0) strip.getSegment(main).setOption(SEG_OPTION_REVERSED, req.charAt(pos+3) != '0'); diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 1185ae4e3..fb8823650 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -29,7 +29,7 @@ void WLED::reset() bool oappendi(int i) { char s[11]; - sprintf(s, "%ld", i); + sprintf(s, "%d", i); return oappend(s); } diff --git a/wled00/wled.h b/wled00/wled.h index 932d89822..c587c88e7 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2009291 +#define VERSION 2010020 // ESP8266-01 (blue) got too little storage space to work with all features of WLED. To use it, you must use ESP8266 Arduino Core v2.4.2 and the setting 512K(No SPIFFS).