From 95869eeb7029ba41b7e092adde9c0af5ffd449e2 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Sat, 31 Dec 2022 17:06:18 +0100 Subject: [PATCH] Allow more virtual buses. --- wled00/FX_fcn.cpp | 4 +- wled00/bus_manager.h | 47 +- wled00/cfg.cpp | 4 +- wled00/const.h | 19 + wled00/data/settings_leds.htm | 46 +- wled00/html_settings.h | 930 +++++++++++++++++----------------- wled00/set.cpp | 2 +- wled00/wled.cpp | 2 +- wled00/wled.h | 4 +- wled00/xml.cpp | 1 + 10 files changed, 551 insertions(+), 508 deletions(-) diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 5d6ac4ff..7310cdee 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -964,13 +964,13 @@ void WS2812FX::finalizeInit(void) const uint8_t defNumBusses = ((sizeof defDataPins) / (sizeof defDataPins[0])); const uint8_t defNumCounts = ((sizeof defCounts) / (sizeof defCounts[0])); uint16_t prevLen = 0; - for (uint8_t i = 0; i < defNumBusses && i < WLED_MAX_BUSSES; i++) { + for (uint8_t i = 0; i < defNumBusses && i < WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES; i++) { uint8_t defPin[] = {defDataPins[i]}; uint16_t start = prevLen; uint16_t count = defCounts[(i < defNumCounts) ? i : defNumCounts -1]; prevLen += count; BusConfig defCfg = BusConfig(DEFAULT_LED_TYPE, defPin, start, count, DEFAULT_LED_COLOR_ORDER, false, 0, RGBW_MODE_MANUAL_ONLY); - busses.add(defCfg); + if (busses.add(defCfg) == -1) break; } } diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index 5f604321..74f073e9 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -684,9 +684,24 @@ class BusManager { if (type == 44 || type == 45) return len*4; //RGBW return len*3; //RGB } - + +/* + int add(BusConfig &bc); + void removeAll(); //do not call this method from system context (network callback) + void setStatusPixel(uint32_t c); + void setPixelColor(uint16_t pix, uint32_t c, int16_t cct=-1); + void setBrightness(uint8_t b); + void setSegmentCCT(int16_t cct, bool allowWBCorrection = false); + uint32_t getPixelColor(uint16_t pix); + bool canAllShow(); + Bus* getBus(uint8_t busNr); + void show(); + uint16_t getTotalLength(); //semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit()) +*/ + // the following functions are inlined by compiler since they are defined within class definition + // they should be placed in cpp file instead int add(BusConfig &bc) { - if (numBusses >= WLED_MAX_BUSSES) return -1; + if (getNumBusses() - getNumVirtualBusses() >= WLED_MAX_BUSSES) return -1; if (bc.type >= TYPE_NET_DDP_RGB && bc.type < 96) { busses[numBusses] = new BusNetwork(bc); } else if (IS_DIGITAL(bc.type)) { @@ -714,11 +729,11 @@ class BusManager { } } - void setStatusPixel(uint32_t c) { + void setStatusPixel(uint32_t c) { for (uint8_t i = 0; i < numBusses; i++) { - busses[i]->setStatusPixel(c); - } - } + busses[i]->setStatusPixel(c); + } + } void IRAM_ATTR setPixelColor(uint16_t pix, uint32_t c, int16_t cct=-1) { for (uint8_t i = 0; i < numBusses; i++) { @@ -766,10 +781,6 @@ class BusManager { return busses[busNr]; } - inline uint8_t getNumBusses() { - return numBusses; - } - //semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit()) uint16_t getTotalLength() { uint16_t len = 0; @@ -777,17 +788,27 @@ class BusManager { return len; } - void updateColorOrderMap(const ColorOrderMap &com) { + inline void updateColorOrderMap(const ColorOrderMap &com) { memcpy(&colorOrderMap, &com, sizeof(ColorOrderMap)); } - const ColorOrderMap& getColorOrderMap() const { + inline const ColorOrderMap& getColorOrderMap() const { return colorOrderMap; } + inline uint8_t getNumBusses() { + return numBusses; + } + private: uint8_t numBusses = 0; - Bus* busses[WLED_MAX_BUSSES]; + Bus* busses[WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES]; ColorOrderMap colorOrderMap; + + inline uint8_t getNumVirtualBusses() { + int j = 0; + for (int i=0; igetType() >= TYPE_NET_DDP_RGB && busses[i]->getType() < 96) j++; + return j; + } }; #endif diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index d40b44f2..62362477 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -137,7 +137,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { uint32_t mem = 0; bool busesChanged = false; for (JsonObject elm : ins) { - if (s >= WLED_MAX_BUSSES) break; + if (s >= WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES) break; uint8_t pins[5] = {255, 255, 255, 255, 255}; JsonArray pinArr = elm["pin"]; if (pinArr.size() == 0) continue; @@ -161,7 +161,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { if (fromFS) { BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode); mem += BusManager::memUsage(bc); - if (mem <= MAX_LED_MEMORY && busses.getNumBusses() <= WLED_MAX_BUSSES) busses.add(bc); // finalization will be done in WLED::beginStrip() + if (mem <= MAX_LED_MEMORY) if (busses.add(bc) == -1) break; // finalization will be done in WLED::beginStrip() } else { if (busConfigs[s] != nullptr) delete busConfigs[s]; busConfigs[s] = new BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode); diff --git a/wled00/const.h b/wled00/const.h index 3d138ce6..6e80a697 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -25,25 +25,44 @@ #ifndef WLED_MAX_BUSSES #ifdef ESP8266 #define WLED_MAX_BUSSES 3 + #define WLED_MIN_VIRTUAL_BUSSES 2 #else #if defined(CONFIG_IDF_TARGET_ESP32C3) // 2 RMT, 6 LEDC, only has 1 I2S but NPB does not support it ATM #define WLED_MAX_BUSSES 3 // will allow 2 digital & 1 analog (or the other way around) + #define WLED_MIN_VIRTUAL_BUSSES 3 #elif defined(CONFIG_IDF_TARGET_ESP32S2) // 4 RMT, 8 LEDC, only has 1 I2S bus, supported in NPB #if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33 #define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog + #define WLED_MIN_VIRTUAL_BUSSES 4 #else #define WLED_MAX_BUSSES 7 // will allow 5 digital & 2 analog + #define WLED_MIN_VIRTUAL_BUSSES 3 #endif #elif defined(CONFIG_IDF_TARGET_ESP32S3) // 4 RMT, 8 LEDC, has 2 I2S but NPB does not support them ATM #define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog + #define WLED_MIN_VIRTUAL_BUSSES 4 #else #if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33 #define WLED_MAX_BUSSES 8 + #define WLED_MIN_VIRTUAL_BUSSES 2 #else #define WLED_MAX_BUSSES 10 + #define WLED_MIN_VIRTUAL_BUSSES 0 #endif #endif #endif +#else + #ifdef ESP8266 + #if WLED_MAX_BUSES > 5 + #error Maximum number of buses is 5. + #endif + #define WLED_MIN_VIRTUAL_BUSSES (5-WLED_MAX_BUSES) + #else + #if WLED_MAX_BUSES > 10 + #error Maximum number of buses is 10. + #endif + #define WLED_MIN_VIRTUAL_BUSSES (10-WLED_MAX_BUSES) + #endif #endif #ifndef WLED_MAX_BUTTONS diff --git a/wled00/data/settings_leds.htm b/wled00/data/settings_leds.htm index befcc9a6..20b8de8d 100644 --- a/wled00/data/settings_leds.htm +++ b/wled00/data/settings_leds.htm @@ -6,7 +6,7 @@ LED Settings