From 7b83b99ac928cf8e00a398b2728f6732affdae9b Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Sat, 27 Feb 2021 12:06:14 +0100 Subject: [PATCH] Fix for resetting segments. --- wled00/FX.h | 1 + wled00/FX_fcn.cpp | 29 +++++++++++++++++++---------- wled00/bus_manager.h | 6 ++++++ wled00/wled.cpp | 1 + wled00/wled.h | 2 +- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index 4cc7c80c..b03e5359 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -599,6 +599,7 @@ class WS2812FX { trigger(void), setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t grouping = 0, uint8_t spacing = 0), resetSegments(), + populateDefaultSegments(), setPixelColor(uint16_t n, uint32_t c), setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0), show(void), diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index f181b0b2..79551af8 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -67,17 +67,7 @@ void WS2812FX::finalizeInit(void) Bus *bus = busses.getBus(i); if (bus == nullptr) continue; _useRgbw |= bus->isRgbw(); - _segments[i].start = bus->getStart(); _length += bus->getLength(); - _segments[i].stop = _segments[i].start + bus->getLength(); - _segments[i].mode = DEFAULT_MODE; - _segments[i].colors[0] = DEFAULT_COLOR; - _segments[i].speed = DEFAULT_SPEED; - _segments[i].intensity = DEFAULT_INTENSITY; - _segments[i].grouping = 1; - _segments[i].setOption(SEG_OPTION_SELECTED, 1); - _segments[i].setOption(SEG_OPTION_ON, 1); - _segments[i].opacity = 255; } setBrightness(_brightness); @@ -583,6 +573,25 @@ void WS2812FX::resetSegments() { _segment_runtimes[0].reset(); } +void WS2812FX::populateDefaultSegments() { + uint16_t length = 0; + for (uint8_t i=0; igetStart(); + length += bus->getLength(); + _segments[i].stop = _segments[i].start + bus->getLength(); + _segments[i].mode = DEFAULT_MODE; + _segments[i].colors[0] = DEFAULT_COLOR; + _segments[i].speed = DEFAULT_SPEED; + _segments[i].intensity = DEFAULT_INTENSITY; + _segments[i].grouping = 1; + _segments[i].setOption(SEG_OPTION_SELECTED, 1); + _segments[i].setOption(SEG_OPTION_ON, 1); + _segments[i].opacity = 255; + } +} + //After this function is called, setPixelColor() will use that segment (offsets, grouping, ... will apply) void WS2812FX::setPixelSegment(uint8_t n) { diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index d911e612..b24ff49b 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -391,6 +391,12 @@ class BusManager { return numBusses; } + uint16_t getTotalLength() { + uint16_t len = 0; + for (uint8_t i=0; igetLength(); + return len; + } + static bool isRgbw(uint8_t type) { if (type == TYPE_SK6812_RGBW || type == TYPE_TM1814) return true; if (type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) return true; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 03214d12..32efed4b 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -394,6 +394,7 @@ void WLED::beginStrip() { // Initialize NeoPixel Strip and button strip.finalizeInit(); // busses created during deserializeConfig() + strip.populateDefaultSegments(); strip.setBrightness(0); strip.setShowCallback(handleOverlayDraw); diff --git a/wled00/wled.h b/wled00/wled.h index 547e9d53..2c61ae0b 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2102260 +#define VERSION 2102270 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG