From 40e82166bc62a7c39ab97a54aa29f03de12bbfec Mon Sep 17 00:00:00 2001 From: Ewoud Date: Fri, 10 Feb 2023 16:26:35 +0100 Subject: [PATCH] Ledmap persistent/consistent and showing in segment graph +small changes pio.ini: remove ping pong clock from _all ce.js: change on error handling liveviewws2D: add colorAdjust json.cpp: ledmaps will be stored in json/info settings_2D: fieldChange at loadJS FX_(2D)fcn.cpp: - loadedLedmap default 0 (default) - loadedLedmap active then only use if index { // if (callback) setTimeout(callback,99); diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 78b86187..d8d7fd45 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -41,7 +41,7 @@ void WS2812FX::setUpMatrix(bool reset) { if (customMappingTable != nullptr) delete[] customMappingTable; customMappingTable = nullptr; customMappingSize = 0; - loadedLedmap = -1; + loadedLedmap = 0; } // isMatrix is set in cfg.cpp or set.cpp @@ -76,17 +76,12 @@ void WS2812FX::setUpMatrix(bool reset) { } if (customMappingTable != nullptr) { + uint16_t customMappingSizeLedmap = customMappingSize; customMappingSize = Segment::maxWidth * Segment::maxHeight; - // fill with empty in case we don't fill the entire matrix - if (loadedLedmap <= 0) //WLEDMM: only if no ledmap - for (size_t i = 0; i< customMappingSize; i++) { - customMappingTable[i] = (uint16_t)-1; - } - - uint16_t *customMappingTableLedMap = nullptr; //WLEDMM: Idea @Troy#2642 + uint16_t *customMappingTableCombi = nullptr; //WLEDMM: Idea @Troy#2642 if (loadedLedmap > 0) - customMappingTableLedMap = new uint16_t[customMappingSize]; + customMappingTableCombi = new uint16_t[customMappingSize]; uint16_t x, y, pix=0; //pixel for (size_t pan = 0; pan < panel.size(); pan++) { @@ -98,23 +93,28 @@ void WS2812FX::setUpMatrix(bool reset) { 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; - if (loadedLedmap > 0) - customMappingTableLedMap[customMappingTable[(p.yOffset + (p.vertical?x:y)) * Segment::maxWidth + p.xOffset + (p.vertical?y:x)]] = pix; //WLEDMM: allow for 2 transitions if reset = false (ledmap and logical to physical) + uint16_t index = (p.yOffset + (p.vertical?x:y)) * Segment::maxWidth + p.xOffset + (p.vertical?y:x); + if (loadedLedmap > 0) { + if (index < customMappingSizeLedmap) + customMappingTableCombi[customMappingTable[index]] = pix; //WLEDMM: allow for 2 transitions if reset = false (ledmap and logical to physical) + else + customMappingTableCombi[index] = pix; + } else - customMappingTable[(p.yOffset + (p.vertical?x:y)) * Segment::maxWidth + p.xOffset + (p.vertical?y:x)] = pix; //WLEDMM: allow for 2 transitions if reset = false (ledmap and logical to physical) + customMappingTable[index] = pix; } } } if (loadedLedmap > 0) { for (size_t i = 0; i < customMappingSize; i++) { - customMappingTable[i] = customMappingTableLedMap[i]; + customMappingTable[i] = customMappingTableCombi[i]; } - delete[] customMappingTableLedMap; + delete[] customMappingTableCombi; } #ifdef WLED_DEBUG - DEBUG_PRINT(F("Matrix ledmap:")); + DEBUG_PRINTF("Matrix ledmap: %d\n", loadedLedmap); for (uint16_t i=0; i 1) ? "block":"none"; // rsbtn parent if (Array.isArray(li.maps) && li.maps.length>0) { //WLEDMM >0 instead of 1 to show also first ledmap. Attention: WLED AC has isM check, in MM Matrices are supported so do not check on isM - let cont = `Ledmap: `; //WLEDMM remove + for (const k of (li.maps||[])) cont += ``; //WLEDMM set ledmap selected cont += ""; gId("ledmap").innerHTML = cont; gId("ledmap").classList.remove('hide'); @@ -1146,20 +1146,20 @@ function updateLen(s) if (isM && start >= mw*mh) out += " [strip]"; gId(`seg${s}len`).innerHTML = out; - if (isM) draw(); //WLEDMM + if (isM) drawSegments(); //WLEDMM draw new segment graphic if something changes in a segment } -function draw() { +//WLEDMM +function drawSegments() { if (!ctx) { console.log("init", window.innerWidth); //WLEDMM: add canvas, initialize and set UI var canvas = gId("canvas"); canvas.hidden = false; - // c.width = window.innerWidth > 800?300:300; //Mobile gets 400, pc 800 - // c.height = c.width; ctx = canvas.getContext('2d'); } + ctx.canvas.width = ctx.canvas.parentElement.offsetWidth > 800?800:300; //Mobile and non pc mode gets 300, pc 800 //calc max height and width var maxWidth = 0; @@ -1185,7 +1185,8 @@ function draw() { ctx.strokeStyle="yellow"; ctx.strokeRect(0, 0, ctx.canvas.width, ctx.canvas.height); // add space between panels - var colorArray = ["red", "green", "blue", "magenta", "orange", "yellow"]; + var colorArray = [[255,0,0], [0,255,0], [0,0,255], [255,0,255], [255,165,0], [255,255,0]]; + // ["red", "green", "blue", "magenta", "orange", "yellow"]; for (let p=0; p= width() || yY >= height()) continue; // we have reached one dimension's end - ctx.fillStyle = colorArray[p%colorArray.length]; + ctx.fillStyle = rgbToString(colorArray[p%colorArray.length], counter/ph/pw); ctx.beginPath(); ctx.arc(topLeftX + ppL/2 + xX*ppL, topLeftY + ppL/2 + yY * ppL, ppL*0.4, 0, 2 * Math.PI); ctx.fill(); + counter++; } } } + } ctx.font = '40px Arial'; ctx.fillStyle = "orange"; @@ -1280,6 +1290,23 @@ function draw() { } // for each segment gId("MD").innerHTML = "☾ W*H=LC: " + maxWidth + " x " + maxHeight + " = " + maxWidth * maxHeight; + + //draw the ledmap + if (lastinfo.ledmap>0 && ctx) { + // console.log("Before fetch ledmap ", lastinfo.ledmap); + fetchAndExecute((loc?`http://${locip}`:'.') + "/", "ledmap"+lastinfo.ledmap+".json" , function(text) { + ledmapJson = JSON.parse(text); + var counter = 0; + for (let i=0;i { + if (!res.ok) { + showToast("File " + name + " not found", true); + return ""; + } + console.log("res", res); + return res.text(); + }) + .then(text => { + console.log("text", text); + callback(text); + }) + .catch(function (error) { + showToast("Error getting " + name, true); + console.log(error); + }) + .finally(() => { + console.log("finally"); + // if (callback) setTimeout(callback,99); + }); +} + +//WLEDMM: utility function to save file to FS (used in savePresetsGen) function uploadFileWithText(name, text) { var req = new XMLHttpRequest(); @@ -3086,6 +3142,9 @@ function togglePcMode(fromB = false) sCol('--bh', gId('bot').clientHeight + "px"); _C.style.width = (pcMode)?'100%':'400%'; lastw = wW; + //WLEDMM + gId("canvas").width = gId("canvas").parentElement.offsetWidth > 800?800:300; //WLEDMM Mobile and non pc mode gets 300, pc 800 + drawSegments(); //WLEDMM } function mergeDeep(target, ...sources) diff --git a/wled00/data/liveviewws2D.htm b/wled00/data/liveviewws2D.htm index 585a6bc8..2ace097b 100644 --- a/wled00/data/liveviewws2D.htm +++ b/wled00/data/liveviewws2D.htm @@ -50,8 +50,9 @@ let lOf = Math.floor((c.width - pPL*mW)/2); //left offeset (to center matrix) var i = 6; ctx.clearRect(0, 0, c.width, c.height); //WLEDMM + function colorAdjust(color) {return 55+150*color/255;} //WLEDMM in range 55 - 205 for (y=0.5;y