From f7e297160fabab83861100992c892d8267c3d519 Mon Sep 17 00:00:00 2001 From: Ewoud Date: Wed, 1 Mar 2023 17:00:49 +0100 Subject: [PATCH] ledmap file properties: width, length, physical and segment resize --- wled00/FX_fcn.cpp | 24 +- wled00/data/index.js | 10 +- wled00/html_ui.h | 1576 +++++++++++++++++++++--------------------- wled00/wled.h | 2 +- 4 files changed, 812 insertions(+), 800 deletions(-) diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 2dfd0573..601857a2 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -2019,8 +2019,6 @@ void WS2812FX::loadCustomPalettes() { 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. - bool isPhysicalMap = false; - char fileName[32]; //WLEDMM: als support segment name ledmaps bool isFile = false;; @@ -2035,7 +2033,6 @@ bool WS2812FX::deserializeMap(uint8_t n) { if (n == 10 + segment_index && !isFile && seg.name != nullptr) { sprintf_P(fileName, PSTR("/lm%s.json"), seg.name); isFile = WLED_FS.exists(fileName); - isPhysicalMap = seg.name[0] == 'P'; } if (isFile) break; segment_index++; @@ -2080,6 +2077,25 @@ bool WS2812FX::deserializeMap(uint8_t n) { if (!map.isNull() && map.size()) { // not an empty map //WLEDMM: if isMatrix then customMap size is whole matrix #ifndef WLED_DISABLE_2D + + //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; + + makeAutoSegments(); + } + if (isMatrix) customMappingSize = Segment::maxWidth * Segment::maxHeight; //as whole matrix will be stored in setUpMatrix else @@ -2087,7 +2103,7 @@ bool WS2812FX::deserializeMap(uint8_t n) { customMappingSize = map.size(); customMappingTable = new uint16_t[customMappingSize]; - if (!isPhysicalMap) { + if (!doc[F("physical")]) { for (uint16_t i=0; i=0 && ctx) { //WLEDMM: @Troy#2642 : include ledmap = 0 as default ledmap // console.log("Before fetch ledmap ", lastinfo.ledmap); var fileName; - let isPhysicalMap = false; if (ledmapNr==0) fileName = "ledmap.json"; //0 is ledmap.json, not ledmap0.json else if (ledmapNr<10) fileName = "ledmap"+ledmapNr+".json"; - else { + else fileName = ledmapFileNames[ledmapNr-10]; - isPhysicalMap = fileName.charAt(2) == "P"; - } - fetchAndExecute((loc?`http://${locip}`:'.') + "/", fileName , function(text) { + + fetchAndExecute((loc?`http://${locip}`:'.') + "/", fileName , function(text) { var ledmapJson = JSON.parse(text); var counter = 0; var noMap = []; @@ -1341,7 +1339,7 @@ function drawSegmentView() { var colorArray = ["yellow", "green", "magenta", "orange"]; var customMappingTable = []; - if (!isPhysicalMap) { + if (!ledmapJson["physical"]) { customMappingTable = ledmapJson["map"]; } else { for (let i=0;i