diff --git a/wled00/FX.h b/wled00/FX.h index 430957803..4f2124ce5 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -727,8 +727,7 @@ class WS2812FX { // 96 bytes fixInvalidSegments(), setPixelColor(int n, uint32_t c), show(void), - setTargetFps(uint8_t fps), - deserializeMap(uint8_t n=0); + setTargetFps(uint8_t fps); void fill(uint32_t c) { for (int i = 0; i < _length; i++) setPixelColor(i, c); } // fill whole strip with color (inline) void addEffect(uint8_t id, mode_ptr mode_fn, const char *mode_name); // add effect to the list; defined in FX.cpp @@ -748,6 +747,7 @@ class WS2812FX { // 96 bytes hasCCTBus(void), // return true if the strip is being sent pixel updates isUpdating(void), + deserializeMap(uint8_t n=0), useLedsArray = false; inline bool isServicing(void) { return _isServicing; } diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 7745463b3..091d5eede 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -87,7 +87,7 @@ void WS2812FX::setUpMatrix() { // allowed values are: -1 (missing pixel/no LED attached), 0 (inactive/unused pixel), 1 (active/used pixel) char fileName[32]; strcpy_P(fileName, PSTR("/2d-gaps.json")); // reduce flash footprint bool isFile = WLED_FS.exists(fileName); - int gapSize = 0; + size_t gapSize = 0; int8_t *gapTable = nullptr; if (isFile && requestJSONBufferLock(20)) { @@ -108,6 +108,7 @@ void WS2812FX::setUpMatrix() { } } } + DEBUG_PRINTLN(F("Gaps loaded.")); releaseJSONBufferLock(); } @@ -147,7 +148,6 @@ void WS2812FX::setUpMatrix() { Segment::maxWidth = _length; Segment::maxHeight = 1; } - resetSegments(); } #else isMatrix = false; // no matter what config says diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index ee0e668b4..8b4b025bb 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -1417,7 +1417,7 @@ void WS2812FX::makeAutoSegments(bool forceReset) { } // do we have LEDs after the matrix? (ignore buses) if (autoSegments && _length > Segment::maxWidth*Segment::maxHeight /*&& getActiveSegmentsNum() == 2*/) { - if (_segments.size() == getLastActiveSegmentId()+1) + if (_segments.size() == getLastActiveSegmentId()+1U) _segments.push_back(Segment(Segment::maxWidth*Segment::maxHeight, _length)); else { size_t i = getLastActiveSegmentId() + 1; @@ -1484,6 +1484,7 @@ void WS2812FX::fixInvalidSegments() { } //true if all segments align with a bus, or if a segment covers the total length +//irrelevant in 2D set-up bool WS2812FX::checkSegmentAlignment() { bool aligned = false; for (segment &seg : _segments) { @@ -1583,7 +1584,7 @@ void WS2812FX::loadCustomPalettes() { } //load custom mapping table from JSON file (called from finalizeInit() or deserializeState()) -void WS2812FX::deserializeMap(uint8_t n) { +bool WS2812FX::deserializeMap(uint8_t n) { // 2D support creates its own ledmap (on the fly) if a ledmap.json exists it will overwrite built one. char fileName[32]; @@ -1599,19 +1600,19 @@ void WS2812FX::deserializeMap(uint8_t n) { delete[] customMappingTable; customMappingTable = nullptr; } - return; + return false; } - if (!requestJSONBufferLock(7)) return; - - DEBUG_PRINT(F("Reading LED map from ")); - DEBUG_PRINTLN(fileName); + if (!requestJSONBufferLock(7)) return false; if (!readObjectFromFile(fileName, nullptr, &doc)) { releaseJSONBufferLock(); - return; //if file does not exist just exit + return false; //if file does not exist just exit } + DEBUG_PRINT(F("Reading LED map from ")); + DEBUG_PRINTLN(fileName); + // erase old custom ledmap if (customMappingTable != nullptr) { customMappingSize = 0; @@ -1629,6 +1630,7 @@ void WS2812FX::deserializeMap(uint8_t n) { } releaseJSONBufferLock(); + return true; } diff --git a/wled00/set.cpp b/wled00/set.cpp index 6c776df21..2a4520e47 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -645,8 +645,6 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) if (subPage == 10) { strip.isMatrix = request->arg(F("SOMP")).toInt(); - // strip.panelH = MAX(1,MIN(128,request->arg(F("PH")).toInt())); - // strip.panelW = MAX(1,MIN(128,request->arg(F("PW")).toInt())); strip.panel.clear(); // release memory if allocated if (strip.isMatrix) { strip.panels = MAX(1,MIN(WLED_MAX_PANELS,request->arg(F("MPC")).toInt())); @@ -674,6 +672,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) strip.panel.push_back(p); } strip.setUpMatrix(); // will check limits + strip.makeAutoSegments(true); } else { Segment::maxWidth = strip.getLengthTotal(); Segment::maxHeight = 1; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 35894055e..4b4efa201 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -171,15 +171,14 @@ void WLED::loop() } delete busConfigs[i]; busConfigs[i] = nullptr; } - strip.finalizeInit(); - loadLedmap = 0; + strip.finalizeInit(); // also loads default ledmap if present if (aligned) strip.makeAutoSegments(); else strip.fixInvalidSegments(); yield(); serializeConfig(); } if (loadLedmap >= 0) { - strip.deserializeMap(loadLedmap); + if (!strip.deserializeMap(loadLedmap) && strip.isMatrix && loadLedmap == 0) strip.setUpMatrix(); loadLedmap = -1; }