From 5da47636cfbb13f12bbeedb8363cb9a8f65e645f Mon Sep 17 00:00:00 2001 From: cschwinne Date: Fri, 9 Jul 2021 16:25:23 +0200 Subject: [PATCH] Busses extend total configured LEDs if required (closes #2056 ) Fixed extra button pins defaulting to 0 on first boot --- CHANGELOG.md | 5 +++++ wled00/bus_manager.h | 12 +++++++++++ wled00/cfg.cpp | 51 +++++++++++++++++--------------------------- wled00/wled.cpp | 17 +++++++++++---- wled00/wled.h | 2 +- 5 files changed, 51 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 403c4b81..29f3b024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ### Builds after release 0.12.0 +#### Build 2107090 + +- Busses extend total configured LEDs if required +- Fixed extra button pins defaulting to 0 on first boot + #### Build 2107080 - Made Peek use the main websocket connection instead of opening a second one diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index 3517288c..530cae32 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -27,6 +27,18 @@ struct BusConfig { else if (type > 40 && type < 46) nPins = NUM_PWM_PINS(type); for (uint8_t i = 0; i < nPins; i++) pins[i] = ppins[i]; } + + //validates start and length and extends total if needed + bool adjustBounds(uint16_t& total) { + if (!count) count = 1; + if (count > MAX_LEDS_PER_BUS) count = MAX_LEDS_PER_BUS; + if (start >= MAX_LEDS) return false; + //limit length of strip if it would exceed total permissible LEDs + if (start + count > MAX_LEDS) count = MAX_LEDS - start; + //extend total count accordingly + if (start + count > total) total = start + count; + return true; + } }; //parent class of BusDigital and BusPwm diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 827439e3..d4cce2f3 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -85,6 +85,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { if (fromFS || !ins.isNull()) { uint8_t s = 0; //bus iterator strip.isRgbw = false; + strip.isOffRefreshRequred = false; busses.removeAll(); uint32_t mem = 0; for (JsonObject elm : ins) { @@ -99,25 +100,23 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { if (i>4) break; } - uint16_t length = elm[F("len")]; - if (length==0) continue; + uint16_t length = elm[F("len")] | 1; uint8_t colorOrder = (int)elm[F("order")]; - //only use skip from the first strip (this shouldn't have been in ins obj. but remains here for compatibility) uint8_t skipFirst = elm[F("skip")]; uint16_t start = elm[F("start")] | 0; - if (start >= ledCount) continue; - //limit length of strip if it would exceed total configured LEDs - if (start + length > ledCount) length = ledCount - start; 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 - 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++; + BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst); - mem += busses.memUsage(bc); - if (mem <= MAX_LED_MEMORY) busses.add(bc); + if (bc.adjustBounds(ledCount)) { + //RGBW mode is enabled if at least one of the strips is 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++; + mem += busses.memUsage(bc); + if (mem <= MAX_LED_MEMORY) busses.add(bc); + } } strip.finalizeInit(ledCount); } @@ -153,7 +152,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { } } else { // new install/missing configuration (button 0 has defaults) - if (fromFS) + if (fromFS) for (uint8_t s=1; stype)) strip.isRgbw = true; - strip.isRgbw = (strip.isRgbw || BusManager::isRgbw(busConfigs[i]->type)); + + if (busConfigs[i]->adjustBounds(ledCount)) { + mem += busses.memUsage(*busConfigs[i]); + if (mem <= MAX_LED_MEMORY) { + busses.add(*busConfigs[i]); + //RGBW mode is enabled if at least one of the strips is RGBW + strip.isRgbw = (strip.isRgbw || BusManager::isRgbw(busConfigs[i]->type)); + //refresh is required to remain off if at least one of the strips requires the refresh. + strip.isOffRefreshRequred |= BusManager::isOffRefreshRequred(busConfigs[i]->type); + } + } delete busConfigs[i]; busConfigs[i] = nullptr; } strip.finalizeInit(ledCount); @@ -284,6 +291,8 @@ void WLED::setup() pinManager.allocatePin(2); #endif + for (uint8_t i=1; i