From e51f7bfbff034d82e98239f3b7ef11b01b24729e Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Thu, 9 Feb 2023 20:15:55 +0100 Subject: [PATCH] LED matrix gaps. --- wled00/FX_2Dfcn.cpp | 36 ++++++++++++++++++++++++++++++++++-- wled00/FX_fcn.cpp | 7 ++++--- wled00/cfg.cpp | 2 -- wled00/set.cpp | 2 +- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index ad7f3a10f..3ec12a42d 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -71,6 +71,9 @@ void WS2812FX::setUpMatrix() { customMappingTable = new uint16_t[Segment::maxWidth * Segment::maxHeight]; if (customMappingTable != nullptr) { + int gapSize = 0; + int8_t *gapTable = nullptr; + customMappingSize = Segment::maxWidth * Segment::maxHeight; // fill with empty in case we don't fill the entire matrix @@ -78,21 +81,50 @@ void WS2812FX::setUpMatrix() { customMappingTable[i] = (uint16_t)-1; } + char fileName[32]; + strcpy_P(fileName, PSTR("/ledgap.json")); + bool isFile = WLED_FS.exists(fileName); + + if (isFile && requestJSONBufferLock(20)) { + DEBUG_PRINT(F("Reading LED gap from ")); + DEBUG_PRINTLN(fileName); + + if (readObjectFromFile(fileName, nullptr, &doc)) { + // the array is similar to ledmap, except it has only 3 values: + // -1 ... missing pixel (do not increase pixel count) + // 0 ... inactive pixel (it does count, but should be mapped out) + // 1 ... active pixel + JsonArray map = doc.as(); + gapSize = map.size(); + if (!map.isNull() && gapSize >= customMappingSize) { // not an empty map + gapTable = new int8_t[gapSize]; + for (size_t i = 0; i < gapSize; i++) { + gapTable[i] = constrain(map[i], -1, 1); + } + } + } + releaseJSONBufferLock(); + } + uint16_t x, y, pix=0; //pixel for (size_t pan = 0; pan < panel.size(); pan++) { Panel &p = panel[pan]; uint16_t h = p.vertical ? p.height : p.width; uint16_t v = p.vertical ? p.width : p.height; for (size_t j = 0; j < v; j++){ - for(size_t i = 0; i < h; i++, pix++) { + for(size_t i = 0; i < h; i++) { y = (p.vertical?p.rightStart:p.bottomStart) ? v-j-1 : j; x = (p.vertical?p.bottomStart:p.rightStart) ? h-i-1 : i; x = p.serpentine && j%2 ? h-x-1 : x; - customMappingTable[(p.yOffset + (p.vertical?x:y)) * Segment::maxWidth + p.xOffset + (p.vertical?y:x)] = pix; + size_t index = (p.yOffset + (p.vertical?x:y)) * Segment::maxWidth + p.xOffset + (p.vertical?y:x); + if (!gapTable || (gapTable && gapTable[index] > 0)) customMappingTable[index] = pix; + if (!gapTable || (gapTable && gapTable[index] >= 0)) pix++; } } } + if (gapTable) delete[] gapTable; + #ifdef WLED_DEBUG DEBUG_PRINT(F("Matrix ledmap:")); for (uint16_t i=0; iarg(pO).toInt(); strip.panel.push_back(p); } + strip.setUpMatrix(); // will check limits } else { Segment::maxWidth = strip.getLengthTotal(); Segment::maxHeight = 1; } - strip.setUpMatrix(); // will check limits } #endif