diff --git a/wled00/FX.h b/wled00/FX.h index 0fa30ee4..6c577a4b 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -859,7 +859,7 @@ class WS2812FX { // 96 bytes #endif void - setUpMatrix(bool reset = true), //WLEDMM: add reset option to switch on/off reset of customMappingTable + setUpMatrix(), setPixelColorXY(int x, int y, uint32_t c); // outsmart the compiler :) by correctly overloading diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index b0e425e8..946e0d22 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -34,15 +34,12 @@ // note: matrix may be comprised of multiple panels each with different orientation // but ledmap takes care of that. ledmap is constructed upon initialization // so matrix should disable regular ledmap processing -void WS2812FX::setUpMatrix(bool reset) { +void WS2812FX::setUpMatrix() { #ifndef WLED_DISABLE_2D // erase old ledmap, just in case. - if (reset) { //WLEDMM: add reset option to switch on/off reset of customMappingTable - if (customMappingTable != nullptr) delete[] customMappingTable; - customMappingTable = nullptr; - customMappingSize = 0; - loadedLedmap = 0; - } + if (customMappingTable != nullptr) delete[] customMappingTable; + customMappingTable = nullptr; + customMappingSize = 0; // isMatrix is set in cfg.cpp or set.cpp if (isMatrix) { @@ -59,30 +56,26 @@ void WS2812FX::setUpMatrix(bool reset) { } } - if (reset) { //WLEDMM: add reset option to switch on/off reset of customMappingTable - // safety check - if (Segment::maxWidth * Segment::maxHeight > MAX_LEDS || Segment::maxWidth <= 1 || Segment::maxHeight <= 1) { - DEBUG_PRINTF("2D Bounds error. %d x %d\n", Segment::maxWidth, Segment::maxHeight); - isMatrix = false; - Segment::maxWidth = _length; - Segment::maxHeight = 1; - panels = 0; - panel.clear(); // release memory allocated by panels - resetSegments(true); //WLEDMM bounds only - return; - } - - customMappingTable = new uint16_t[Segment::maxWidth * Segment::maxHeight]; + // safety check + if (Segment::maxWidth * Segment::maxHeight > MAX_LEDS || Segment::maxWidth <= 1 || Segment::maxHeight <= 1) { + DEBUG_PRINTF("2D Bounds error. %d x %d\n", Segment::maxWidth, Segment::maxHeight); + isMatrix = false; + Segment::maxWidth = _length; + Segment::maxHeight = 1; + panels = 0; + panel.clear(); // release memory allocated by panels + resetSegments(true); //WLEDMM bounds only + return; } + customMappingTable = new uint16_t[Segment::maxWidth * Segment::maxHeight]; + if (customMappingTable != nullptr) { - uint16_t customMappingSizeLedmap = customMappingSize; customMappingSize = Segment::maxWidth * Segment::maxHeight; - uint16_t *customMappingTableCombi = nullptr; //WLEDMM: Idea @Troy#2642 - if (customMappingSizeLedmap > 0) { //WLEDMM: @Troy#2642 : include ledmap = 0 as default ledmap - customMappingTableCombi = new uint16_t[customMappingSize]; - for (int i=0; i 0) { //WLEDMM: @Troy#2642 : include ledmap = 0 as default ledmap - if (index < customMappingSizeLedmap && customMappingTable[index] < customMappingSize) - customMappingTableCombi[customMappingTable[index]] = pix; //WLEDMM: allow for 2 transitions if reset = false (ledmap and logical to physical) - pix++; - } - else { - if (!gapTable || (gapTable && gapTable[index] > 0)) customMappingTable[index] = pix; // a useful pixel (otherwise -1 is retained) - if (!gapTable || (gapTable && gapTable[index] >= 0)) pix++; // not a missing pixel - } + if (!gapTable || (gapTable && gapTable[index] > 0)) customMappingTable[index] = pix; // a useful pixel (otherwise -1 is retained) + if (!gapTable || (gapTable && gapTable[index] >= 0)) pix++; // not a missing pixel } } } - if (customMappingSizeLedmap > 0) { //WLEDMM: @Troy#2642 : include ledmap = 0 as default ledmap - for (size_t i = 0; i < customMappingSize; i++) { - customMappingTable[i] = customMappingTableCombi[i]; - } - delete[] customMappingTableCombi; - } - // delete gap array as we no longer need it if (gapTable) delete[] gapTable; #ifdef WLED_DEBUG - DEBUG_PRINTF("Matrix ledmap: %d\n", loadedLedmap); + DEBUG_PRINTF("Matrix ledmap: \n"); for (uint16_t i=0; i 0) { - Serial.println("delete jVectorMap"); + USER_PRINTLN("delete jVectorMap"); for (size_t i=0; i0 && doc[F("height")]>0) { + panels = 1; + panel.clear(); + panel.reserve(1U); // pre-allocate memory for panels + Panel p; + p.bottomStart = p.rightStart = p.vertical = p.serpentine = false; + p.xOffset = p.yOffset = 0; + p.width = doc[F("width")]; + p.height = doc[F("height")]; + strip.panel.push_back(p); - //WLEDMM: support ledmap file properties width and height - if (doc[F("width")]>0 && doc[F("height")]>0) { - panels = 1; - panel.clear(); - panel.reserve(1U); // pre-allocate memory for panels - Panel p; - p.bottomStart = p.rightStart = p.vertical = p.serpentine = false; - p.xOffset = p.yOffset = 0; - p.width = doc[F("width")]; - p.height = doc[F("height")]; - strip.panel.push_back(p); + Segment::maxWidth = p.width; + Segment::maxHeight = p.height; - Segment::maxWidth = p.width; - Segment::maxHeight = p.height; - - makeAutoSegments(); + makeAutoSegments(); + } } - if (isMatrix) - customMappingSize = Segment::maxWidth * Segment::maxHeight; //as whole matrix will be stored in setUpMatrix - else -#endif - customMappingSize = map.size(); + customMappingSize = map.size(); customMappingTable = new uint16_t[customMappingSize]; - if (!doc[F("physical")]) { + // if (!doc[F("physical")]) { for (uint16_t i=0; i=0 mappings to customMappingTable - for (uint16_t i=0; i=0) - customMappingTable[map[i].as()] = i; - } + // } + // else { + // for (int i=0; i=0 mappings to customMappingTable + // for (uint16_t i=0; i=0) + // customMappingTable[map[i].as()] = i; + // } loadedLedmap = n; @@ -2126,11 +2116,7 @@ bool WS2812FX::deserializeMap(uint8_t n) { } DEBUG_PRINTLN(); #endif - - setUpMatrix(false); //WLEDMM: apply logical to physical mapping after the ledmap } - else - setUpMatrix(true); //WLEDMM: if no map then back to matrix default releaseJSONBufferLock(); return true; diff --git a/wled00/json.cpp b/wled00/json.cpp index 0e97a1fc..9aa726bc 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -649,7 +649,7 @@ void serializeState(JsonObject root, bool forPreset, bool includeBri, bool segme seg0["stop"] = 0; } } - root[F("ledmap")] = loadedLedmap; //WLEDMM ledmaps will be stored in json + root[F("ledmap")] = loadedLedmap; //WLEDMM ledmaps will be stored in json so dropdown can display it } // begin WLEDMM