From cc0f1be5d2421b7f996b6703533e1b957a20d779 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Sat, 22 May 2021 00:13:49 +0200 Subject: [PATCH] Bugfix saving PWM & button pins. --- wled00/FX_fcn.cpp | 5 ++++- wled00/bus_manager.h | 13 +++++------- wled00/cfg.cpp | 47 +++++++------------------------------------- wled00/set.cpp | 7 ++----- wled00/wled.h | 2 +- 5 files changed, 19 insertions(+), 55 deletions(-) diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index de53d8cc..dd11d77e 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -64,7 +64,7 @@ void WS2812FX::finalizeInit(void) { RESET_RUNTIME; - isRgbw = false; + isRgbw = isOffRefreshRequred = false; //if busses failed to load, add default (fresh install, FS issue, ...) if (busses.getNumBusses() == 0) { @@ -90,7 +90,10 @@ void WS2812FX::finalizeInit(void) Bus *bus = busses.getBus(i); if (bus == nullptr) continue; if (_length+bus->getLength() > MAX_LEDS) break; + //RGBW mode is enabled if at least one of the strips is RGBW isRgbw |= bus->isRgbw(); + //refresh is required to remain off if at least one of the strips requires the refresh. + isOffRefreshRequred |= BusManager::isOffRefreshRequred(bus->getType()); _length += bus->getLength(); } ledCount = _length; // or we can use busses.getTotalLength() diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index cfc3b5bf..b6f6b101 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -30,7 +30,7 @@ struct BusConfig { count = len; start = pstart; colorOrder = pcolorOrder; reversed = rev; skipAmount = skip; uint8_t nPins = 1; if (type > 47) nPins = 2; - else if (type > 41 && type < 46) nPins = NUM_PWM_PINS(type); + else if (type > 40 && type < 46) nPins = NUM_PWM_PINS(type); for (uint8_t i = 0; i < nPins; i++) pins[i] = ppins[i]; } }; @@ -222,14 +222,10 @@ class BusDigital : public Bus { class BusPwm : public Bus { public: BusPwm(BusConfig &bc) : Bus(bc.type, bc.start) { + _valid = false; if (!IS_PWM(bc.type)) return; uint8_t numPins = NUM_PWM_PINS(bc.type); - #ifdef WLED_DEBUG - Serial.print(F("Init: Number of pins=")); - Serial.println(numPins); - #endif - #ifdef ESP8266 analogWriteRange(255); //same range as one RGB channel analogWriteFreq(WLED_PWM_FREQ); @@ -243,8 +239,7 @@ class BusPwm : public Bus { for (uint8_t i = 0; i < numPins; i++) { _pins[i] = bc.pins[i]; if (!pinManager.allocatePin(_pins[i])) { - //deallocatePins(); return; - _pins[i] = 255; break; + _pins[i] = 255; return; } #ifdef ESP8266 pinMode(_pins[i], OUTPUT); @@ -280,10 +275,12 @@ class BusPwm : public Bus { //does no index check uint32_t getPixelColor(uint16_t pix) { + if (!_valid) return 0; return ((_data[3] << 24) | (_data[0] << 16) | (_data[1] << 8) | (_data[2])); } void show() { + if (!_valid) return; uint8_t numPins = NUM_PWM_PINS(_type); for (uint8_t i = 0; i < numPins; i++) { uint8_t scaled = (_data[i] * _bri) / 255; diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 5db70490..c9e0b13b 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -69,8 +69,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { noWifiSleep = !noWifiSleep; //int wifi_phy = doc[F("wifi")][F("phy")]; //force phy mode n? - DEBUG_PRINTLN(F(" Done network.")); - JsonObject hw = doc[F("hw")]; // initialize LED pins and lengths prior to other HW @@ -89,7 +87,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { if (fromFS || !ins.isNull()) { uint8_t s = 0; // bus iterator - strip.isRgbw = false; busses.removeAll(); uint32_t mem = 0; for (JsonObject elm : ins) { @@ -112,24 +109,17 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { uint8_t skipFirst = elm[F("skip")]; 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 - // if ((bool)elm[F("rgbw")]) SET_BIT(ledType,7); else UNSET_BIT(ledType,7); // hack bit 7 to indicate RGBW (as an override if necessary) - // strip.isRgbw |= (bool)elm[F("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); + //if ((bool)elm[F("rgbw")]) SET_BIT(ledType,7); else UNSET_BIT(ledType,7); // hack bit 7 to indicate RGBW (as an override if necessary) s++; lC += length; BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst); mem += BusManager::memUsage(bc); - DEBUG_PRINT(F(" Adding bus no. ")); - DEBUG_PRINTLN(busses.getNumBusses()); if (mem <= MAX_LED_MEMORY && busses.getNumBusses() <= WLED_MAX_BUSSES) busses.add(bc); // finalization will be done in WLED::beginStrip() } + // finalization done in beginStrip() //strip.finalizeInit(); } if (lC > ledCount) ledCount = lC; // fix incorrect total length (honour analog setup) - DEBUG_PRINTLN(F(" Done LEDs.")); // read multiple button configuration JsonArray hw_btn_ins = hw[F("btn")][F("ins")]; @@ -138,13 +128,11 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { for (JsonObject btn : hw_btn_ins) { CJSON(buttonType[s], btn["type"]); int8_t pin = btn[F("pin")][0] | -1; - if (pin > -1) { - if (pinManager.allocatePin(pin,false)) { - btnPin[s] = pin; - pinMode(btnPin[s], INPUT_PULLUP); - } else { - btnPin[s] = -1; - } + if (pin > -1 && pinManager.allocatePin(pin,false)) { + btnPin[s] = pin; + pinMode(btnPin[s], INPUT_PULLUP); + } else { + btnPin[s] = -1; } JsonArray hw_btn_ins_0_macros = btn[F("macros")]; CJSON(macroButton[s], hw_btn_ins_0_macros[0]); @@ -172,26 +160,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { } } CJSON(touchThreshold,hw[F("btn")][F("tt")]); - DEBUG_PRINTLN(F(" Done buttons.")); -/* - JsonObject hw_btn_ins_0 = hw[F("btn")][F("ins")][0]; - CJSON(buttonType, hw_btn_ins_0["type"]); - int hw_btn_pin = hw_btn_ins_0[F("pin")][0] | -2; //-2 = not present in doc, keep current. -1 = disable - if (hw_btn_pin > -1) { - if (pinManager.allocatePin(hw_btn_pin,false)) { - btnPin = hw_btn_pin; - pinMode(btnPin, INPUT_PULLUP); - } else { - btnPin = -1; - } - } - - JsonArray hw_btn_ins_0_macros = hw_btn_ins_0[F("macros")]; - CJSON(macroButton, hw_btn_ins_0_macros[0]); - CJSON(macroLongPress,hw_btn_ins_0_macros[1]); - CJSON(macroDoublePress, hw_btn_ins_0_macros[2]); -*/ #ifndef WLED_DISABLE_INFRARED int hw_ir_pin = hw["ir"]["pin"] | -2; // 4 if (hw_ir_pin > -2) { @@ -217,7 +186,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { if (relay.containsKey("rev")) { rlyMde = !relay["rev"]; } - DEBUG_PRINTLN(F(" Done HW.")); //int hw_status_pin = hw[F("status")]["pin"]; // -1 @@ -570,7 +538,6 @@ void serializeConfig() { // additional buttons for (uint8_t i=1; i=0 && pinManager.isPinAllocated(btnPin[s])) pinManager.deallocatePin(btnPin[s]); - strip.isRgbw = false; uint8_t colorOrder, type, skip; uint16_t length, start; uint8_t pins[5] = {255, 255, 255, 255, 255}; @@ -98,7 +97,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) char ls[4] = "LS"; ls[2] = 48+s; ls[3] = 0; //strip start LED char cv[4] = "CV"; cv[2] = 48+s; cv[3] = 0; //strip reverse char sl[4] = "SL"; sl[2] = 48+s; sl[3] = 0; //skip 1st LED -// char ew[4] = "EW"; ew[2] = 48+s; ew[3] = 0; //strip RGBW override + //char ew[4] = "EW"; ew[2] = 48+s; ew[3] = 0; //strip RGBW override if (!request->hasArg(lp)) { DEBUG_PRINTLN(F("No data.")); break; } @@ -108,9 +107,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) pins[i] = (request->arg(lp).length() > 0) ? request->arg(lp).toInt() : 255; } type = request->arg(lt).toInt(); -// if (request->hasArg(ew)) SET_BIT(type,7); else UNSET_BIT(type,7); // hack bit 7 to indicate RGBW (as a LED type override if necessary) -// strip.isRgbw = strip.isRgbw || request->hasArg(ew); - strip.isRgbw = strip.isRgbw || Bus::isRgbw(type); + //if (request->hasArg(ew)) SET_BIT(type,7); else UNSET_BIT(type,7); // hack bit 7 to indicate RGBW (as a LED type override if necessary) skip = request->hasArg(sl) ? LED_SKIP_AMOUNT : 0; colorOrder = request->arg(co).toInt(); diff --git a/wled00/wled.h b/wled00/wled.h index d306d69f..37ac4e15 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2105211 +#define VERSION 2105212 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG