From c24ab1b21d42d7e9e95b2173dc89d96ee2181f1c Mon Sep 17 00:00:00 2001 From: Christian Schwinne Date: Sat, 11 Sep 2021 01:17:42 +0200 Subject: [PATCH] Auto create segments setting (#2183) --- CHANGELOG.md | 7 +++++ platformio.ini | 4 +-- wled00/FX_fcn.cpp | 49 +++++++++++++++++++++++++---------- wled00/cfg.cpp | 2 ++ wled00/data/settings_leds.htm | 4 ++- wled00/html_settings.h | 3 ++- wled00/hue.cpp | 2 +- wled00/mqtt.cpp | 18 ++++++------- wled00/set.cpp | 4 ++- wled00/wled.h | 7 ++++- wled00/xml.cpp | 1 + 11 files changed, 71 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 219549ad..19bf7186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ### Builds after release 0.12.0 +#### Build 2109100 + +- Added an auto create segments per bus setting +- Added 15 new palettes from SR branch (PR #2134) +- Fixed segment runtime not reset on FX change via HTTP API +- Changed AsyncTCP dependency to pbolduc fork v1.2.0 + #### Build 2108250 - Added Sync groups (PR #2150) diff --git a/platformio.ini b/platformio.ini index b969322a..6ca479ff 100644 --- a/platformio.ini +++ b/platformio.ini @@ -210,7 +210,7 @@ build_flags = -g lib_deps = ${env.lib_deps} makuna/NeoPixelBus @ 2.6.7 - https://github.com/pbolduc/AsyncTCP.git + https://github.com/pbolduc/AsyncTCP.git @ 1.2.0 [esp32s2] build_flags = -g @@ -224,7 +224,7 @@ build_flags = -g lib_deps = ${env.lib_deps} makuna/NeoPixelBus @ 2.6.7 - https://github.com/pbolduc/AsyncTCP.git + https://github.com/pbolduc/AsyncTCP.git @ 1.2.0 # ------------------------------------------------------------------------------ # WLED BUILDS diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 4113ab72..43cb4846 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -98,24 +98,25 @@ void WS2812FX::finalizeInit(uint16_t countPixels) setBrightness(_brightness); //TODO make sure segments are only refreshed when bus config actually changed (new settings page) - //make one segment per bus uint8_t s = 0; for (uint8_t i = 0; i < busses.getNumBusses(); i++) { Bus* b = busses.getBus(i); - segStarts[s] = b->getStart(); - segStops[s] = segStarts[s] + b->getLength(); + if (autoSegments) { //make one segment per bus + segStarts[s] = b->getStart(); + segStops[s] = segStarts[s] + b->getLength(); - //check for overlap with previous segments - for (uint8_t j = 0; j < s; j++) { - if (segStops[j] > segStarts[s] && segStarts[j] < segStops[s]) { - //segments overlap, merge - segStarts[j] = min(segStarts[s],segStarts[j]); - segStops [j] = max(segStops [s],segStops [j]); segStops[s] = 0; - s--; + //check for overlap with previous segments + for (uint8_t j = 0; j < s; j++) { + if (segStops[j] > segStarts[s] && segStarts[j] < segStops[s]) { + //segments overlap, merge + segStarts[j] = min(segStarts[s],segStarts[j]); + segStops [j] = max(segStops [s],segStops [j]); segStops[s] = 0; + s--; + } } + s++; } - s++; #ifdef ESP8266 if ((!IS_DIGITAL(b->getType()) || IS_2PIN(b->getType()))) continue; @@ -126,9 +127,29 @@ void WS2812FX::finalizeInit(uint16_t countPixels) #endif } - for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) { - _segments[i].start = segStarts[i]; - _segments[i].stop = segStops [i]; + if (autoSegments) { + for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) { + _segments[i].start = segStarts[i]; + _segments[i].stop = segStops [i]; + } + } else { + //expand the main seg to the entire length, but only if there are no other segments + uint8_t mainSeg = getMainSegmentId(); + bool isMultipleSegs = false; + for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) + { + if (i != mainSeg && _segments[i].isActive()) isMultipleSegs = true; + } + if (!isMultipleSegs) { + _segments[mainSeg].start = 0; _segments[mainSeg].stop = _length; + } else { + //there are multiple segments, leave them, but prune length to total + for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) + { + if (_segments[i].start > _length) _segments[i].stop = 0; + if (_segments[i].stop > _length) _segments[i].stop = _length; + } + } } } diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index b345a873..18048649 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -202,6 +202,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { JsonObject light = doc[F("light")]; CJSON(briMultiplier, light[F("scale-bri")]); CJSON(strip.paletteBlend, light[F("pal-mode")]); + CJSON(autoSegments, light[F("aseg")]); float light_gc_bri = light["gc"]["bri"]; float light_gc_col = light["gc"]["col"]; // 2.8 @@ -565,6 +566,7 @@ void serializeConfig() { JsonObject light = doc.createNestedObject(F("light")); light[F("scale-bri")] = briMultiplier; light[F("pal-mode")] = strip.paletteBlend; + light[F("aseg")] = autoSegments; JsonObject light_gc = light.createNestedObject("gc"); light_gc["bri"] = (strip.gammaCorrectBri) ? 2.8 : 1.0; diff --git a/wled00/data/settings_leds.htm b/wled00/data/settings_leds.htm index 2dfb6ab2..ae6a37f5 100644 --- a/wled00/data/settings_leds.htm +++ b/wled00/data/settings_leds.htm @@ -369,7 +369,9 @@ Reverse (rotated 180°):
+ + Make a segment for each output:
+
Touch threshold:
IR pin:  

Touch threshold:
IR pin: