Fixed canAllShow() and removeAll()
This commit is contained in:
		| @@ -24,6 +24,8 @@ | ||||
|   Modified for WLED | ||||
| */ | ||||
|  | ||||
| #include "wled.h" | ||||
|  | ||||
| #ifndef WS2812FX_h | ||||
| #define WS2812FX_h | ||||
|  | ||||
|   | ||||
| @@ -48,6 +48,7 @@ const uint16_t customMappingSize = sizeof(customMappingTable)/sizeof(uint16_t); | ||||
| #define PWM_INDEX 0 | ||||
| #endif | ||||
|  | ||||
| //do not call this method from system context (network callback) | ||||
| void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst) | ||||
| { | ||||
|   if (supportWhite == _useRgbw && countPixels == _length && _skipFirstMode == skipFirst) return; | ||||
| @@ -62,8 +63,11 @@ void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst) | ||||
|   } | ||||
|  | ||||
|   uint8_t pins[] = {2}; | ||||
|  | ||||
|   while (!busses->canAllShow()) yield(); | ||||
|   busses->removeAll(); | ||||
|   busses->add(supportWhite? TYPE_SK6812_RGBW : TYPE_WS2812_RGB, pins, 0, countPixels, COL_ORDER_GRB); | ||||
|    | ||||
|  | ||||
|   _segments[0].start = 0; | ||||
|   _segments[0].stop = _length; | ||||
|  | ||||
|   | ||||
| @@ -30,7 +30,7 @@ class Bus { | ||||
|   virtual void cleanup() {}; | ||||
|  | ||||
|   virtual ~Bus() { //throw the bus under the bus | ||||
|     cleanup(); | ||||
|     //Serial.println("Destructor!"); | ||||
|   } | ||||
|  | ||||
|   uint16_t getStart() { | ||||
| @@ -85,7 +85,7 @@ class BusDigital : public Bus { | ||||
|     _busPtr = PolyBus::create(_iType, _pins, _len); | ||||
|     _valid = (_busPtr != nullptr); | ||||
|     _colorOrder = colorOrder; | ||||
|     Serial.printf("Successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u)\n",nr, len, type, pins[0],pins[1],_iType); | ||||
|     //Serial.printf("Successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u)\n",nr, len, type, pins[0],pins[1],_iType); | ||||
|   }; | ||||
|  | ||||
|   void show() { | ||||
| @@ -127,6 +127,7 @@ class BusDigital : public Bus { | ||||
|   } | ||||
|  | ||||
|   void cleanup() { | ||||
|     //Serial.println("Digital Cleanup"); | ||||
|     PolyBus::cleanup(_busPtr, _iType); | ||||
|     _iType = I_NONE; | ||||
|     _valid = false; | ||||
| @@ -135,6 +136,10 @@ class BusDigital : public Bus { | ||||
|     pinManager.deallocatePin(_pins[1]); | ||||
|   } | ||||
|  | ||||
|   ~BusDigital() { | ||||
|     cleanup(); | ||||
|   } | ||||
|  | ||||
|   private:  | ||||
|   uint8_t _colorOrder = COL_ORDER_GRB; | ||||
|   uint8_t _pins[2] = {255, 255}; | ||||
| @@ -263,6 +268,7 @@ class BusManager { | ||||
|   } | ||||
|  | ||||
|   void removeAll() { | ||||
|     //Serial.println("Removing all."); | ||||
|     for (uint8_t i = 0; i < numBusses; i++) delete busses[i]; | ||||
|     numBusses = 0; | ||||
|   } | ||||
| @@ -278,7 +284,7 @@ class BusManager { | ||||
|     for (uint8_t i = 0; i < numBusses; i++) { | ||||
|       Bus* b = busses[i]; | ||||
|       uint16_t bstart = b->getStart(); | ||||
|       if (pix < bstart) continue; | ||||
|       if (pix < bstart || pix >= bstart + b->getLength()) continue; | ||||
|       busses[i]->setPixelColor(pix - bstart, c); | ||||
|     } | ||||
|   } | ||||
| @@ -301,7 +307,7 @@ class BusManager { | ||||
|  | ||||
|   bool canAllShow() { | ||||
|     for (uint8_t i = 0; i < numBusses; i++) { | ||||
|       if (busses[i]->canShow()) return false; | ||||
|       if (!busses[i]->canShow()) return false; | ||||
|     } | ||||
|     return true; | ||||
|   } | ||||
|   | ||||
| @@ -16,7 +16,7 @@ | ||||
| #ifdef ESP8266 | ||||
| #define WLED_MAX_BUSSES 2 | ||||
| #else | ||||
| #define WLED_MAX_BUSSES 8 | ||||
| #define WLED_MAX_BUSSES 7 | ||||
| #endif | ||||
|  | ||||
| //Usermod IDs | ||||
| @@ -175,7 +175,11 @@ | ||||
|  | ||||
| // maximum number of LEDs - more than 1500 LEDs (or 500 DMA "LEDPIN 3" driven ones) will cause a low memory condition on ESP8266 | ||||
| #ifndef MAX_LEDS | ||||
| #define MAX_LEDS 1500 | ||||
| #ifdef ESP8266 | ||||
| #define MAX_LEDS 1536 | ||||
| #else | ||||
| #define MAX_LEDS 8192 | ||||
| #endif | ||||
| #endif | ||||
|  | ||||
| #define MAX_LEDS_DMA 500 | ||||
|   | ||||
| @@ -331,9 +331,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) | ||||
|    | ||||
|   #endif | ||||
|   if (subPage != 6 || !doReboot) serializeConfig(); //do not save if factory reset | ||||
|   if (subPage == 2) { | ||||
|     strip.init(useRGBW,ledCount,skipFirstLed); | ||||
|   } | ||||
|   if (subPage == 2) doInitStrip = true; | ||||
|   if (subPage == 4) alexaInit(); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -195,10 +195,10 @@ void WLED::loop() | ||||
|     handleHue(); | ||||
|     handleBlynk(); | ||||
|  | ||||
|     /*if (presetToApply) { | ||||
|       applyPreset(presetToApply); | ||||
|       presetToApply = 0; | ||||
|     }*/ | ||||
|     if (doInitStrip) { | ||||
|       strip.init(useRGBW, ledCount, skipFirstLed); | ||||
|       doInitStrip = false; | ||||
|     } | ||||
|  | ||||
|     yield(); | ||||
|  | ||||
| @@ -267,13 +267,10 @@ void WLED::setup() | ||||
|   DEBUG_PRINTLN(ESP.getFreeHeap()); | ||||
|   registerUsermods(); | ||||
|  | ||||
|   //strip.init(EEPROM.read(372), ledCount, EEPROM.read(2204));        // init LEDs quickly | ||||
|   //strip.setBrightness(0); | ||||
|  | ||||
|   //DEBUG_PRINT(F("LEDs inited. heap usage ~")); | ||||
|   //DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap()); | ||||
|  | ||||
|  | ||||
|   bool fsinit = false; | ||||
|   DEBUGFS_PRINTLN(F("Mount FS")); | ||||
| #ifdef ARDUINO_ARCH_ESP32 | ||||
|   | ||||
| @@ -528,6 +528,7 @@ WLED_GLOBAL bool e131NewData _INIT(false); | ||||
|  | ||||
| // led fx library object | ||||
| WLED_GLOBAL WS2812FX strip _INIT(WS2812FX()); | ||||
| WLED_GLOBAL bool doInitStrip _INIT(false); | ||||
|  | ||||
| // Usermod manager | ||||
| WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager()); | ||||
|   | ||||
| @@ -254,13 +254,14 @@ void getSettingsJS(byte subPage, char* dest) | ||||
|   } | ||||
|  | ||||
|   if (subPage == 2) { | ||||
|     #ifdef ESP8266 | ||||
|     #if LEDPIN == 3 | ||||
|     oappend(SET_F("d.Sf.LC.max=500;")); | ||||
|     oappend(SET_F("d.Sf.LC.max=")); | ||||
|     #if defined(ESP8266) && LEDPIN == 3 | ||||
|     oappendi(MAX_LEDS_DMA); | ||||
|     #else | ||||
|     oappend(SET_F("d.Sf.LC.max=1500;")); | ||||
|     #endif | ||||
|     oappendi(MAX_LEDS); | ||||
|     #endif | ||||
|     oappend(";"); | ||||
|  | ||||
|     sappend('v',SET_F("LC"),ledCount); | ||||
|     sappend('v',SET_F("MA"),strip.ablMilliampsMax); | ||||
|     sappend('v',SET_F("LA"),strip.milliampsPerLed); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 cschwinne
					cschwinne