From 1c1b67e000170b43fe462a124d9d6e684cc9b3af Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Fri, 29 Dec 2023 23:07:29 +0100 Subject: [PATCH] Full per-port ABL implementation and bugfix. Update of BusManager class (static) --- usermods/quinled-an-penta/quinled-an-penta.h | 8 +- wled00/FX.h | 6 - wled00/FX_fcn.cpp | 46 +- wled00/bus_manager.cpp | 37 +- wled00/bus_manager.h | 48 +- wled00/button.cpp | 4 +- wled00/cfg.cpp | 26 +- wled00/data/settings_leds.htm | 64 +- wled00/html_settings.h | 1098 +++++++++--------- wled00/json.cpp | 4 +- wled00/set.cpp | 6 +- wled00/wled.cpp | 8 +- wled00/wled.h | 2 +- wled00/wled_eeprom.cpp | 2 +- wled00/xml.cpp | 21 +- 15 files changed, 702 insertions(+), 678 deletions(-) diff --git a/usermods/quinled-an-penta/quinled-an-penta.h b/usermods/quinled-an-penta/quinled-an-penta.h index 5153ee58a..10b784334 100644 --- a/usermods/quinled-an-penta/quinled-an-penta.h +++ b/usermods/quinled-an-penta/quinled-an-penta.h @@ -84,11 +84,11 @@ class QuinLEDAnPentaUsermod : public Usermod void getCurrentUsedLedPins() { for (int8_t lp = 0; lp <= 4; lp++) currentLedPins[lp] = 0; - byte numBusses = busses.getNumBusses(); + byte numBusses = BusManager::getNumBusses(); byte numUsedPins = 0; for (int8_t b = 0; b < numBusses; b++) { - Bus* curBus = busses.getBus(b); + Bus* curBus = BusManager::getBus(b); if (curBus != nullptr) { uint8_t pins[5] = {0, 0, 0, 0, 0}; currentBussesNumPins[b] = curBus->getPins(pins); @@ -104,11 +104,11 @@ class QuinLEDAnPentaUsermod : public Usermod void getCurrentLedcValues() { - byte numBusses = busses.getNumBusses(); + byte numBusses = BusManager::getNumBusses(); byte numLedc = 0; for (int8_t b = 0; b < numBusses; b++) { - Bus* curBus = busses.getBus(b); + Bus* curBus = BusManager::getBus(b); if (curBus != nullptr) { uint32_t curPixColor = curBus->getPixelColor(0); uint8_t _data[5] = {255, 255, 255, 255, 255}; diff --git a/wled00/FX.h b/wled00/FX.h index 3e1c7b238..b6eb58723 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -682,10 +682,7 @@ class WS2812FX { // 96 bytes WS2812FX() : paletteFade(0), paletteBlend(0), - milliampsPerLed(55), cctBlending(0), - ablMilliampsMax(ABL_MILLIAMPS_DEFAULT), - currentMilliamps(0), now(millis()), timebase(0), isMatrix(false), @@ -793,7 +790,6 @@ class WS2812FX { // 96 bytes uint8_t paletteBlend, - milliampsPerLed, cctBlending, getActiveSegmentsNum(void), getFirstSelectedSegId(void), @@ -811,8 +807,6 @@ class WS2812FX { // 96 bytes inline uint8_t getModeCount() { return _modeCount; } uint16_t - ablMilliampsMax, - currentMilliamps, getLengthPhysical(void), getLengthTotal(void), // will include virtual/nonexistent pixels in matrix getFps(); diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 796392fac..e9ab61054 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -900,8 +900,8 @@ void Segment::refreshLightCapabilities() { segStopIdx = stop; } - for (unsigned b = 0; b < busses.getNumBusses(); b++) { - Bus *bus = busses.getBus(b); + for (unsigned b = 0; b < BusManager::getNumBusses(); b++) { + Bus *bus = BusManager::getBus(b); if (bus == nullptr || bus->getLength()==0) break; if (!bus->isOk()) continue; if (bus->getStart() >= segStopIdx) continue; @@ -1086,7 +1086,7 @@ void WS2812FX::finalizeInit(void) { _hasWhiteChannel = _isOffRefreshRequired = false; //if busses failed to load, add default (fresh install, FS issue, ...) - if (busses.getNumBusses() == 0) { + if (BusManager::getNumBusses() == 0) { DEBUG_PRINTLN(F("No busses, init default")); const uint8_t defDataPins[] = {DATA_PINS}; const uint16_t defCounts[] = {PIXEL_COUNTS}; @@ -1099,13 +1099,13 @@ void WS2812FX::finalizeInit(void) { 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); - if (busses.add(defCfg) == -1) break; + if (BusManager::add(defCfg) == -1) break; } } _length = 0; - for (int i=0; igetStart() + bus->getLength() > MAX_LEDS) break; //RGBW mode is enabled if at least one of the strips is RGBW @@ -1162,7 +1162,7 @@ void WS2812FX::service() { _colors_t[1] = gamma32(seg.currentColor(1)); _colors_t[2] = gamma32(seg.currentColor(2)); seg.currentPalette(_currentPalette, seg.palette); // we need to pass reference - if (!cctFromRgb || correctWB) busses.setSegmentCCT(seg.currentBri(true), correctWB); + if (!cctFromRgb || correctWB) BusManager::setSegmentCCT(seg.currentBri(true), correctWB); // Effect blending // When two effects are being blended, each may have different segment data, this // data needs to be saved first and then restored before running previous mode. @@ -1193,7 +1193,7 @@ void WS2812FX::service() { _segment_index++; } _virtualSegmentLength = 0; - busses.setSegmentCCT(-1); + BusManager::setSegmentCCT(-1); _isServicing = false; _triggered = false; @@ -1212,13 +1212,13 @@ void WS2812FX::service() { void IRAM_ATTR WS2812FX::setPixelColor(unsigned i, uint32_t col) { if (i < customMappingSize) i = customMappingTable[i]; if (i >= _length) return; - busses.setPixelColor(i, col); + BusManager::setPixelColor(i, col); } uint32_t IRAM_ATTR WS2812FX::getPixelColor(uint16_t i) { if (i < customMappingSize) i = customMappingTable[i]; if (i >= _length) return 0; - return busses.getPixelColor(i); + return BusManager::getPixelColor(i); } void WS2812FX::show(void) { @@ -1229,7 +1229,7 @@ void WS2812FX::show(void) { // some buses send asynchronously and this method will return before // all of the data has been sent. // See https://github.com/Makuna/NeoPixelBus/wiki/ESP32-NeoMethods#neoesp32rmt-methods - busses.show(); + BusManager::show(); unsigned long showNow = millis(); size_t diff = showNow - _lastShow; @@ -1244,7 +1244,7 @@ void WS2812FX::show(void) { * On some hardware (ESP32), strip updates are done asynchronously. */ bool WS2812FX::isUpdating() { - return !busses.canAllShow(); + return !BusManager::canAllShow(); } /** @@ -1303,7 +1303,7 @@ void WS2812FX::setBrightness(uint8_t b, bool direct) { } // setting brightness with NeoPixelBusLg has no effect on already painted pixels, // so we need to force an update to existing buffer - busses.setBrightness(b); + BusManager::setBrightness(b); if (!direct) { unsigned long t = millis(); if (_segments[0].next_time > t + 22 && t - _lastShow > MIN_SHOW_DELAY) trigger(); //apply brightness change immediately if no refresh soon @@ -1359,8 +1359,8 @@ uint16_t WS2812FX::getLengthTotal(void) { uint16_t WS2812FX::getLengthPhysical(void) { uint16_t len = 0; - for (size_t b = 0; b < busses.getNumBusses(); b++) { - Bus *bus = busses.getBus(b); + for (size_t b = 0; b < BusManager::getNumBusses(); b++) { + Bus *bus = BusManager::getBus(b); if (bus->getType() >= TYPE_NET_DDP_RGB) continue; //exclude non-physical network busses len += bus->getLength(); } @@ -1371,8 +1371,8 @@ uint16_t WS2812FX::getLengthPhysical(void) { //returns if there is an RGBW bus (supports RGB and White, not only white) //not influenced by auto-white mode, also true if white slider does not affect output white channel bool WS2812FX::hasRGBWBus(void) { - for (size_t b = 0; b < busses.getNumBusses(); b++) { - Bus *bus = busses.getBus(b); + for (size_t b = 0; b < BusManager::getNumBusses(); b++) { + Bus *bus = BusManager::getBus(b); if (bus == nullptr || bus->getLength()==0) break; if (bus->hasRGB() && bus->hasWhite()) return true; } @@ -1381,8 +1381,8 @@ bool WS2812FX::hasRGBWBus(void) { bool WS2812FX::hasCCTBus(void) { if (cctFromRgb && !correctWB) return false; - for (size_t b = 0; b < busses.getNumBusses(); b++) { - Bus *bus = busses.getBus(b); + for (size_t b = 0; b < BusManager::getNumBusses(); b++) { + Bus *bus = BusManager::getBus(b); if (bus == nullptr || bus->getLength()==0) break; switch (bus->getType()) { case TYPE_ANALOG_5CH: @@ -1468,8 +1468,8 @@ void WS2812FX::makeAutoSegments(bool forceReset) { } #endif - for (size_t i = s; i < busses.getNumBusses(); i++) { - Bus* b = busses.getBus(i); + for (size_t i = s; i < BusManager::getNumBusses(); i++) { + Bus* b = BusManager::getBus(i); segStarts[s] = b->getStart(); segStops[s] = segStarts[s] + b->getLength(); @@ -1558,8 +1558,8 @@ void WS2812FX::fixInvalidSegments() { bool WS2812FX::checkSegmentAlignment() { bool aligned = false; for (segment &seg : _segments) { - for (unsigned b = 0; bgetStart() && seg.stop == bus->getStart() + bus->getLength()) aligned = true; } if (seg.start == 0 && seg.stop == _length) aligned = true; diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp index 013e906f4..0dcacc042 100644 --- a/wled00/bus_manager.cpp +++ b/wled00/bus_manager.cpp @@ -125,7 +125,7 @@ BusDigital::BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com) if (bc.type == TYPE_WS2812_1CH_X3) lenToCreate = NUM_ICS_WS2812_1CH_3X(bc.count); // only needs a third of "RGB" LEDs for NeoPixelBus _busPtr = PolyBus::create(_iType, _pins, lenToCreate + _skip, nr, _frequencykHz); _valid = (_busPtr != nullptr); - DEBUG_PRINTF("%successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u)\n", _valid?"S":"Uns", nr, bc.count, bc.type, _pins[0], _pins[1], _iType); + DEBUG_PRINTF("%successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u). mA=%d/%d\n", _valid?"S":"Uns", nr, bc.count, bc.type, _pins[0], _pins[1], _iType, _milliAmpsPerLed, _milliAmpsMax); } //fine tune power estimation constants for your setup @@ -150,7 +150,7 @@ uint8_t BusDigital::estimateCurrentAndLimitBri() { bool useWackyWS2815PowerModel = false; byte actualMilliampsPerLed = _milliAmpsPerLed; - if (_milliAmpsMax < MA_FOR_ESP || actualMilliampsPerLed == 0) { //0 mA per LED and too low numbers turn off calculation + if (_milliAmpsMax < MA_FOR_ESP/BusManager::getNumBusses() || actualMilliampsPerLed == 0) { //0 mA per LED and too low numbers turn off calculation return _bri; } @@ -159,7 +159,12 @@ uint8_t BusDigital::estimateCurrentAndLimitBri() { actualMilliampsPerLed = 12; // from testing an actual strip } - size_t powerBudget = (_milliAmpsMax - MA_FOR_ESP); //100mA for ESP power + size_t powerBudget = (_milliAmpsMax - MA_FOR_ESP/BusManager::getNumBusses()); //80/120mA for ESP power + if (powerBudget > getLength()) { //each LED uses about 1mA in standby, exclude that from power budget + powerBudget -= getLength(); + } else { + powerBudget = 0; + } uint32_t busPowerSum = 0; for (unsigned i = 0; i < getLength(); i++) { //sum up the usage of each LED @@ -178,29 +183,26 @@ uint8_t BusDigital::estimateCurrentAndLimitBri() { busPowerSum >>= 2; //same as /= 4 } - if (powerBudget > getLength()) { //each LED uses about 1mA in standby, exclude that from power budget - powerBudget -= getLength(); - } else { - powerBudget = 0; - } - // powerSum has all the values of channels summed (max would be getLength()*765 as white is excluded) so convert to milliAmps busPowerSum = (busPowerSum * actualMilliampsPerLed) / 765; + _milliAmpsTotal = busPowerSum * _bri / 255; uint8_t newBri = _bri; if (busPowerSum * _bri / 255 > powerBudget) { //scale brightness down to stay in current limit float scale = (float)(powerBudget * 255) / (float)(busPowerSum * _bri); - uint16_t scaleI = scale * 255; - uint8_t scaleB = (scaleI > 255) ? 255 : scaleI; + if (scale >= 1.0f) return _bri; + _milliAmpsTotal = ceilf((float)_milliAmpsTotal * scale); + uint8_t scaleB = min((int)(scale * 255), 255); newBri = unsigned(_bri * scaleB) / 256 + 1; } return newBri; } void BusDigital::show() { + _milliAmpsTotal = 0; if (!_valid) return; - uint8_t newBri = estimateCurrentAndLimitBri(); + uint8_t newBri = estimateCurrentAndLimitBri(); // will fill _milliAmpsTotal if (newBri < _bri) PolyBus::setBrightness(_busPtr, _iType, newBri); // limit brightness to stay within current limits if (_data) { // use _buffering this causes ~20% FPS drop @@ -646,9 +648,12 @@ void BusManager::removeAll() { } void BusManager::show() { + _milliAmpsUsed = 0; for (unsigned i = 0; i < numBusses; i++) { busses[i]->show(); + _milliAmpsUsed += busses[i]->getUsedCurrent(); } + if (_milliAmpsUsed) _milliAmpsUsed += MA_FOR_ESP; } void BusManager::setStatusPixel(uint32_t c) { @@ -714,3 +719,11 @@ uint16_t BusManager::getTotalLength() { int16_t Bus::_cct = -1; uint8_t Bus::_cctBlend = 0; uint8_t Bus::_gAWM = 255; + +uint16_t BusDigital::_milliAmpsTotal = 0; + +uint8_t BusManager::numBusses = 0; +Bus* BusManager::busses[WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES]; +ColorOrderMap BusManager::colorOrderMap = {}; +uint16_t BusManager::_milliAmpsUsed = 0; +uint16_t BusManager::_milliAmpsMax = ABL_MILLIAMPS_DEFAULT; \ No newline at end of file diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index 9d322749c..12fb81b39 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -137,6 +137,7 @@ class Bus { virtual uint8_t skippedLeds() { return 0; } virtual uint16_t getFrequency() { return 0U; } virtual uint16_t getLEDCurrent() { return 0; } + virtual uint16_t getUsedCurrent() { return 0; } virtual uint16_t getMaxCurrent() { return 0; } inline void setReversed(bool reversed) { _reversed = reversed; } inline uint16_t getStart() { return _start; } @@ -219,6 +220,7 @@ class BusDigital : public Bus { uint16_t getFrequency() { return _frequencykHz; } uint8_t estimateCurrentAndLimitBri(); uint16_t getLEDCurrent() { return _milliAmpsPerLed; } + uint16_t getUsedCurrent() { return _milliAmpsTotal; } uint16_t getMaxCurrent() { return _milliAmpsMax; } void reinit(); void cleanup(); @@ -233,7 +235,8 @@ class BusDigital : public Bus { uint16_t _milliAmpsMax; void * _busPtr; const ColorOrderMap &_colorOrderMap; - //bool _buffering; // temporary until we figure out why comparison "_data" causes severe FPS drop + + static uint16_t _milliAmpsTotal; // is overwitten/recalculated on each show() inline uint32_t restoreColorLossy(uint32_t c, uint8_t restoreBri) { if (restoreBri < 255) { @@ -314,39 +317,44 @@ class BusNetwork : public Bus { class BusManager { public: - BusManager() : numBusses(0) {}; + BusManager() {}; //utility to get the approx. memory usage of a given BusConfig static uint32_t memUsage(BusConfig &bc); + static uint16_t currentMilliamps(void) { return _milliAmpsUsed; } + static uint16_t ablMilliampsMax(void) { return _milliAmpsMax; } - int add(BusConfig &bc); + static int add(BusConfig &bc); //do not call this method from system context (network callback) - void removeAll(); + static void removeAll(); - void show(); - bool canAllShow(); - void setStatusPixel(uint32_t c); - void setPixelColor(uint16_t pix, uint32_t c); - void setBrightness(uint8_t b); - void setSegmentCCT(int16_t cct, bool allowWBCorrection = false); - uint32_t getPixelColor(uint16_t pix); + static void show(); + static bool canAllShow(); + static void setStatusPixel(uint32_t c); + static void setPixelColor(uint16_t pix, uint32_t c); + static void setBrightness(uint8_t b); + static void setSegmentCCT(int16_t cct, bool allowWBCorrection = false); + static void setMilliampsMax(uint16_t max) { _milliAmpsMax = max;} + static uint32_t getPixelColor(uint16_t pix); - Bus* getBus(uint8_t busNr); + static Bus* getBus(uint8_t busNr); //semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit()) - uint16_t getTotalLength(); - inline uint8_t getNumBusses() const { return numBusses; } + static uint16_t getTotalLength(); + static uint8_t getNumBusses() { return numBusses; } - inline void updateColorOrderMap(const ColorOrderMap &com) { memcpy(&colorOrderMap, &com, sizeof(ColorOrderMap)); } - inline const ColorOrderMap& getColorOrderMap() const { return colorOrderMap; } + static void updateColorOrderMap(const ColorOrderMap &com) { memcpy(&colorOrderMap, &com, sizeof(ColorOrderMap)); } + static const ColorOrderMap& getColorOrderMap() { return colorOrderMap; } private: - uint8_t numBusses; - Bus* busses[WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES]; - ColorOrderMap colorOrderMap; + static uint8_t numBusses; + static Bus* busses[WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES]; + static ColorOrderMap colorOrderMap; + static uint16_t _milliAmpsUsed; + static uint16_t _milliAmpsMax; - inline uint8_t getNumVirtualBusses() { + static uint8_t getNumVirtualBusses() { int j = 0; for (int i=0; igetType() >= TYPE_NET_DDP_RGB && busses[i]->getType() < 96) j++; return j; diff --git a/wled00/button.cpp b/wled00/button.cpp index f1487396a..b1e7f2a79 100644 --- a/wled00/button.cpp +++ b/wled00/button.cpp @@ -347,10 +347,10 @@ void handleButton() void esp32RMTInvertIdle() { bool idle_out; - for (uint8_t u = 0; u < busses.getNumBusses(); u++) + for (uint8_t u = 0; u < BusManager::getNumBusses(); u++) { if (u > 7) return; // only 8 RMT channels, TODO: ESP32 variants have less RMT channels - Bus *bus = busses.getBus(u); + Bus *bus = BusManager::getBus(u); if (!bus || bus->getLength()==0 || !IS_DIGITAL(bus->getType()) || IS_2PIN(bus->getType())) continue; //assumes that bus number to rmt channel mapping stays 1:1 rmt_channel_t ch = static_cast(u); diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 489793b24..4e2afb65f 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -87,8 +87,8 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { JsonObject hw_led = hw["led"]; uint16_t total = hw_led[F("total")] | strip.getLengthTotal(); - CJSON(strip.ablMilliampsMax, hw_led[F("maxpwr")]); - CJSON(strip.milliampsPerLed, hw_led[F("ledma")]); // no longer used + uint16_t ablMilliampsMax = hw_led[F("maxpwr")] | BusManager::ablMilliampsMax(); + BusManager::setMilliampsMax(ablMilliampsMax); Bus::setGlobalAWMode(hw_led[F("rgbwm")] | AW_GLOBAL_DISABLED); CJSON(correctWB, hw_led["cct"]); CJSON(cctFromRgb, hw_led[F("cr")]); @@ -138,7 +138,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { if (fromFS || !ins.isNull()) { uint8_t s = 0; // bus iterator - if (fromFS) busses.removeAll(); // can't safely manipulate busses directly in network callback + if (fromFS) BusManager::removeAll(); // can't safely manipulate busses directly in network callback uint32_t mem = 0, globalBufMem = 0; uint16_t maxlen = 0; bool busesChanged = false; @@ -164,8 +164,8 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { bool refresh = elm["ref"] | false; uint16_t freqkHz = elm[F("freq")] | 0; // will be in kHz for DotStar and Hz for PWM (not yet implemented fully) uint8_t AWmode = elm[F("rgbwm")] | RGBW_MODE_MANUAL_ONLY; - uint8_t maPerLed = elm[F("ledma")] | strip.milliampsPerLed; // replace with 55 when removing strip.milliampsPerLed - uint16_t maMax = elm[F("maxpwr")] | (strip.ablMilliampsMax * length) / total; // rough (incorrect?) per strip ABL calculation when no config exists + uint8_t maPerLed = elm[F("ledma")] | 55; + uint16_t maMax = elm[F("maxpwr")] | (ablMilliampsMax * length) / total; // rough (incorrect?) per strip ABL calculation when no config exists // To disable brightness limiter we either set output max current to 0 or single LED current to 0 (we choose output max current) if ((ledType > TYPE_TM1814 && ledType < TYPE_WS2801) || ledType >= TYPE_NET_DDP_RGB) { // analog and virtual maPerLed = 0; @@ -179,7 +179,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { maxlen = start + length; globalBufMem = maxlen * 4; } - if (mem + globalBufMem <= MAX_LED_MEMORY) if (busses.add(bc) == -1) break; // finalization will be done in WLED::beginStrip() + if (mem + globalBufMem <= MAX_LED_MEMORY) if (BusManager::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, freqkHz, useGlobalLedBuffer, maPerLed, maMax); @@ -190,7 +190,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { doInitBusses = busesChanged; // finalization done in beginStrip() } - if (hw_led["rev"]) busses.getBus(0)->setReversed(true); //set 0.11 global reversed setting for first bus + if (hw_led["rev"]) BusManager::getBus(0)->setReversed(true); //set 0.11 global reversed setting for first bus // read color order map configuration JsonArray hw_com = hw[F("com")]; @@ -205,7 +205,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { com.add(start, len, colorOrder); s++; } - busses.updateColorOrderMap(com); + BusManager::updateColorOrderMap(com); } // read multiple button configuration @@ -722,8 +722,8 @@ void serializeConfig() { JsonObject hw_led = hw.createNestedObject("led"); hw_led[F("total")] = strip.getLengthTotal(); //provided for compatibility on downgrade and per-output ABL - hw_led[F("maxpwr")] = strip.ablMilliampsMax; - hw_led[F("ledma")] = strip.milliampsPerLed; // no longer used + hw_led[F("maxpwr")] = BusManager::ablMilliampsMax(); + hw_led[F("ledma")] = 0; // no longer used hw_led["cct"] = correctWB; hw_led[F("cr")] = cctFromRgb; hw_led[F("cb")] = strip.cctBlending; @@ -753,8 +753,8 @@ void serializeConfig() { JsonArray hw_led_ins = hw_led.createNestedArray("ins"); - for (uint8_t s = 0; s < busses.getNumBusses(); s++) { - Bus *bus = busses.getBus(s); + for (uint8_t s = 0; s < BusManager::getNumBusses(); s++) { + Bus *bus = BusManager::getBus(s); if (!bus || bus->getLength()==0) break; JsonObject ins = hw_led_ins.createNestedObject(); ins["start"] = bus->getStart(); @@ -775,7 +775,7 @@ void serializeConfig() { } JsonArray hw_com = hw.createNestedArray(F("com")); - const ColorOrderMap& com = busses.getColorOrderMap(); + const ColorOrderMap& com = BusManager::getColorOrderMap(); for (uint8_t s = 0; s < com.count(); s++) { const ColorOrderMapEntry *entry = com.get(s); if (!entry) break; diff --git a/wled00/data/settings_leds.htm b/wled00/data/settings_leds.htm index 835b396fa..229c38327 100644 --- a/wled00/data/settings_leds.htm +++ b/wled00/data/settings_leds.htm @@ -107,30 +107,36 @@ e.preventDefault(); if (!pinsOK()) {e.stopPropagation();return false;} // Prevent form submission and contact with server if (bquot > 100) {var msg = "Too many LEDs for me to handle!"; if (maxM < 10000) msg += "\n\rConsider using an ESP32."; alert(msg);} + if (d.Sf.PPL.checked) d.Sf.MA.value = 0; // submit 0 as ABL (PPL will handle it) if (d.Sf.checkValidity()) d.Sf.submit(); //https://stackoverflow.com/q/37323914 } function enABL() { - var en = d.Sf["ABL"].checked; - d.Sf["MA"].min = en ? 250 : 0; + var en = d.Sf.ABL.checked; gId('abl').style.display = (en) ? 'inline':'none'; gId('psu2').style.display = (en) ? 'inline':'none'; - if (!en) d.Sf["PPL"].checked = false; + if (!en) d.Sf.PPL.checked = false; enPPL(); UI(); } function enPPL() { - const abl = d.Sf["ABL"].checked; - const en = d.Sf["PPL"].checked; - d.Sf["MA"].readonly = en; - gId("ppldis").style.display = en ? 'inline' : 'none'; + const abl = d.Sf.ABL.checked; + const ppl = d.Sf.PPL.checked; + let sumMA = 0; + d.Sf.MA.readonly = ppl; + d.Sf.MA.min = abl && !ppl ? 250 : 0; + gId("psuMA").style.display = ppl ? 'none' : 'inline'; + gId("ppldis").style.display = ppl ? 'inline' : 'none'; + // set PPL minimum value and clear actual PPL limit if ABL disabled d.Sf.querySelectorAll("#mLC input[name^=MA]").forEach((i,n)=>{ - gId("PSU"+n).style.display = en ? "inline" : "none"; + gId("PSU"+n).style.display = ppl ? "inline" : "none"; const t = parseInt(d.Sf["LT"+n].value); // LED type SELECT - i.min = en && !((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? 250 : 0; + i.min = ppl && !((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? 250 : 0; if (!abl) i.value = 0; + else if (ppl) sumMA += parseInt(i.value,10); }); + if (ppl) d.Sf.MA.value = sumMA; // populate UI ABL value if PPL used } function enLA(s,n) { @@ -141,10 +147,11 @@ } function setABL() { - d.Sf["ABL"].checked = false; + console.log(d.Sf.MA.value); + d.Sf.ABL.checked = parseInt(d.Sf.MA.value) > 0; // check if ABL is enabled (max mA entered per output) d.Sf.querySelectorAll("#mLC input[name^=MA]").forEach((i,n)=>{ - if (parseInt(i.value) > 0) d.Sf["ABL"].checked = true; + if (parseInt(i.value) > 0) d.Sf.ABL.checked = true; }); // select appropriate LED current d.Sf.querySelectorAll("#mLC select[name^=LAsel]").forEach((sel,n)=>{ @@ -190,8 +197,8 @@ let isRGBW = false, gRGBW = false, memu = 0; let sumMA = 0, busMA = 0; let sLC = 0, sPC = 0, sDI = 0, maxLC = 0; - const ablEN = d.Sf["ABL"].checked; - const pplEN = d.Sf["PPL"].checked; + const ablEN = d.Sf.ABL.checked; + const pplEN = d.Sf.PPL.checked; // enable/disable LED fields d.Sf.querySelectorAll("#mLC select[name^=LT]").forEach((s)=>{ @@ -244,7 +251,7 @@ gId("rev"+n).innerHTML = (t >= 40 && t < 48) ? "Inverted output":"Reversed (rotated 180°)"; // change reverse text for analog gId("psd"+n).innerHTML = (t >= 40 && t < 48) ? "Index:":"Start:"; // change analog start description if (ablEN && pplEN && !((t >= 80 && t < 96) || (t >= 40 && t < 48))) { - sumMA += parseInt(d.Sf["MA"+n].value); + sumMA += parseInt(d.Sf["MA"+n].value); // summarize PPL ABL limit (fields) } }); // display global white channel overrides @@ -269,11 +276,12 @@ if (s+c > sLC) sLC = s+c; //update total count if (c > maxLC) maxLC = c; //max per output if (t < 80) sPC += c; //virtual out busses do not count towards physical LEDs - if (!((t >= 80 && t < 96) || (t >= 40 && t < 48))) sDI += c; + //if (!((t >= 80 && t < 96) || (t >= 40 && t < 48))) sDI += c; if (!((t >= 80 && t < 96) || (t >= 40 && t < 48))) { + sDI += c; // summarize digital LED count let maPL = parseInt(d.Sf["LA"+n].value); if (maPL == 255) maPL = 12; - busMA += maPL*c; + busMA += maPL*c; // summarize maximum bus current (calculated) } } // increase led count return; @@ -316,14 +324,18 @@ else LC.style.color = d.ro_gpio.some((e)=>e==parseInt(LC.value)) ? "orange" : "#fff"; } }); + // distribute ABL current if not using PPL, otherwise sumMA contains summarized ABL limit d.Sf.querySelectorAll("#mLC input[name^=LC]").forEach((s,n)=>{ let c = parseInt(s.value,10); //get LED count - let t = parseInt(d.Sf["LT"+n].value); - if (ablEN) { - let v = Math.round(parseInt(d.Sf["MA"].value,10)*c/sDI); - if (!pplEN && !((t >= 80 && t < 96) || (t >= 40 && t < 48))) d.Sf["MA"+n].value = v; - } else d.Sf["MA"+n].value = 0; + let t = parseInt(d.Sf["LT"+n].value); //get LED type + if (!ablEN || (t >= 80 && t < 96) || (t >= 40 && t < 48)) { + // virtual and analog LEDs have no limiter + d.Sf["MA"+n].value = 0; + return; + } + if (!pplEN) d.Sf["MA"+n].value = Math.round(parseInt(d.Sf.MA.value,10)*c/sDI); }); + if (pplEN) d.Sf.MA.value = sumMA; // update global ABL if using PPL // update total led count gId("lc").textContent = sLC; gId("pc").textContent = (sLC == sPC) ? "":"(" + sPC + " physical)"; @@ -336,7 +348,6 @@ gId('ledwarning').style.color = (maxLC > Math.max(maxPB,800) || bquot > 100) ? 'red':'orange'; gId('wreason').innerHTML = (bquot > 80) ? "80% of max. LED memory" +(bquot>100 ? ` (ERROR: Using over ${maxM}B!)` : "") : "800 LEDs per output"; // calculate power - if (pplEN) d.Sf.MA.value = sumMA; gId('ampwarning').style.display = (parseInt(d.Sf.MA.value,10) > 7200) ? 'inline':'none'; var val = Math.ceil((100 + busMA)/500)/2; val = (val > 5) ? Math.ceil(val) : val; @@ -409,7 +420,7 @@ mA/LED:
-
PSU: mA
+
PSU: mA
Color Order: gId("+").style.display = (i0) ? "inline":"none"; - if (!init) UI(); + if (!init) { + enPPL(); + UI(); + } } function addCOM(start=0,len=1,co=0) { @@ -750,7 +764,7 @@ Length: mA
+
Maximum PSU Current: mA
Use per-output limiter: