From 660de0b4e573d8364ee4e4cd044e330dda71fc1f Mon Sep 17 00:00:00 2001 From: cschwinne Date: Thu, 24 Jun 2021 02:29:14 +0200 Subject: [PATCH] Auto-create segments based on configured busses --- tools/WLED_ESP32_16MB.csv | 6 ++++ usermods/EXAMPLE_v2/usermod_v2_example.h | 4 ++- wled00/FX.h | 2 +- wled00/FX_fcn.cpp | 41 +++++++++++++++++++----- wled00/wled.h | 2 +- 5 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 tools/WLED_ESP32_16MB.csv diff --git a/tools/WLED_ESP32_16MB.csv b/tools/WLED_ESP32_16MB.csv new file mode 100644 index 00000000..de78209d --- /dev/null +++ b/tools/WLED_ESP32_16MB.csv @@ -0,0 +1,6 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x200000, +app1, app, ota_1, 0x210000,0x200000, +spiffs, data, spiffs, 0x410000,0xBE0000, \ No newline at end of file diff --git a/usermods/EXAMPLE_v2/usermod_v2_example.h b/usermods/EXAMPLE_v2/usermod_v2_example.h index ef68e907..db582a24 100644 --- a/usermods/EXAMPLE_v2/usermod_v2_example.h +++ b/usermods/EXAMPLE_v2/usermod_v2_example.h @@ -137,7 +137,9 @@ class MyExampleUsermod : public Usermod { void readFromConfig(JsonObject& root) { JsonObject top = root["top"]; - userVar0 = top["great"] | 42; //The value right of the pipe "|" is the default value in case your setting was not present in cfg.json (e.g. first boot) + if (!top.isNull()) { + userVar0 = top["great"] | 42; //The value right of the pipe "|" is the default value in case your setting was not present in cfg.json (e.g. first boot) + } } diff --git a/wled00/FX.h b/wled00/FX.h index 77638aed..541c8e4a 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -801,7 +801,7 @@ class WS2812FX { CRGBPalette16 currentPalette; CRGBPalette16 targetPalette; - uint16_t _length, _lengthRaw, _virtualSegmentLength; + uint16_t _length, _virtualSegmentLength; uint16_t _rand16seed; uint8_t _brightness; uint16_t _usedSegmentData = 0; diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 075988cd..81f9f689 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -60,12 +60,15 @@ #define DEFAULT_LED_TYPE TYPE_WS2812_RGB #endif +#if MAX_NUM_SEGMENTS < WLED_MAX_BUSSES + #error "Max segments must be at least max number of busses!" +#endif + //do not call this method from system context (network callback) void WS2812FX::finalizeInit(uint16_t countPixels) { RESET_RUNTIME; _length = countPixels; - _lengthRaw = _length; //if busses failed to load, add default (FS issue...) if (busses.getNumBusses() == 0) { @@ -77,7 +80,7 @@ void WS2812FX::finalizeInit(uint16_t countPixels) for (uint8_t i = 0; i < defNumBusses; i++) { uint8_t defPin[] = {defDataPins[i]}; uint16_t start = prevLen; - uint16_t count = _lengthRaw; + uint16_t count = _length; if (defNumBusses > 1 && defNumCounts) { count = defCounts[(i < defNumCounts) ? i : defNumCounts -1]; } @@ -89,22 +92,44 @@ void WS2812FX::finalizeInit(uint16_t countPixels) deserializeMap(); - //make segment 0 cover the entire strip - _segments[0].start = 0; - _segments[0].stop = _length; + uint16_t segStarts[MAX_NUM_SEGMENTS] = {0}; + uint16_t segStops [MAX_NUM_SEGMENTS] = {0}; setBrightness(_brightness); - #ifdef ESP8266 + //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(); + + //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++; + + #ifdef ESP8266 if ((!IS_DIGITAL(b->getType()) || IS_2PIN(b->getType()))) continue; uint8_t pins[5]; b->getPins(pins); BusDigital* bd = static_cast(b); if (pins[0] == 3) bd->reinit(); + #endif + } + + for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) { + _segments[i].start = segStarts[i]; + _segments[i].stop = segStops [i]; } - #endif } void WS2812FX::service() { @@ -503,7 +528,7 @@ uint32_t WS2812FX::getPixelColor(uint16_t i) if (i < customMappingSize) i = customMappingTable[i]; - if (i >= _lengthRaw) return 0; + if (i >= _length) return 0; return busses.getPixelColor(i); } diff --git a/wled00/wled.h b/wled00/wled.h index a04a9d61..b562f452 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2106200 +#define VERSION 2106240 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG