Ledmap refactors
Refactor ledmap in index.js and FX_fcn.cpp (remove physical) WS2812FX::setPixelColor and gPC: check index after ledmap applied
This commit is contained in:
@@ -1505,15 +1505,15 @@ void WS2812FX::service() {
|
||||
|
||||
void IRAM_ATTR WS2812FX::setPixelColor(int i, uint32_t col)
|
||||
{
|
||||
if (i >= _length) return;
|
||||
if (i < customMappingSize) i = customMappingTable[i];
|
||||
if (i >= _length) return; //WLEDMM: check after mapping
|
||||
busses.setPixelColor(i, col);
|
||||
}
|
||||
|
||||
uint32_t WS2812FX::getPixelColor(uint16_t i)
|
||||
{
|
||||
if (i >= _length) return 0;
|
||||
if (i < customMappingSize) i = customMappingTable[i];
|
||||
if (i >= _length) return 0; //WLEDMM: check after mapping
|
||||
return busses.getPixelColor(i);
|
||||
}
|
||||
|
||||
@@ -2040,13 +2040,14 @@ bool WS2812FX::deserializeMap(uint8_t n) {
|
||||
}
|
||||
|
||||
if (!isFile) {
|
||||
//WLEDMM: disable temporary!!!
|
||||
// erase custom mapping if selecting nonexistent ledmap.json (n==0)
|
||||
// if (!isMatrix && !n && customMappingTable != nullptr) {
|
||||
// customMappingSize = 0;
|
||||
// delete[] customMappingTable;
|
||||
// customMappingTable = nullptr;
|
||||
// }
|
||||
//WLEDM: doubt this is necessary as return false causes setupMatrix to deal with this
|
||||
if (!isMatrix && !n && customMappingTable != nullptr) {
|
||||
customMappingSize = 0;
|
||||
delete[] customMappingTable;
|
||||
customMappingTable = nullptr;
|
||||
loadedLedmap = 0; //WLEDMM
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2070,41 +2071,29 @@ bool WS2812FX::deserializeMap(uint8_t n) {
|
||||
|
||||
JsonArray map = doc[F("map")];
|
||||
if (!map.isNull() && map.size()) { // not an empty map
|
||||
if (doc[F("physical")]) {
|
||||
//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);
|
||||
//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();
|
||||
}
|
||||
|
||||
customMappingSize = map.size();
|
||||
customMappingTable = new uint16_t[customMappingSize];
|
||||
|
||||
// if (!doc[F("physical")]) {
|
||||
for (uint16_t i=0; i<MIN(customMappingSize, map.size()); i++)
|
||||
customMappingTable[i] = (uint16_t) (map[i]<0 ? 0xFFFFU : map[i]);
|
||||
// }
|
||||
// else {
|
||||
// for (int i=0; i<customMappingSize;i++) customMappingTable[i] = (uint16_t)0xFFFFU; //WLEDMM: init with no show
|
||||
// //assign all >=0 mappings to customMappingTable
|
||||
// for (uint16_t i=0; i<map.size(); i++)
|
||||
// if (map[i]>=0)
|
||||
// customMappingTable[map[i].as<uint16_t>()] = i;
|
||||
// }
|
||||
|
||||
for (uint16_t i=0; i<MIN(customMappingSize, map.size()); i++)
|
||||
customMappingTable[i] = (uint16_t) (map[i]<0 ? 0xFFFFU : map[i]);
|
||||
|
||||
loadedLedmap = n;
|
||||
|
||||
|
||||
@@ -710,7 +710,8 @@ function populateSegments(s)
|
||||
let li = lastinfo;
|
||||
segCount = 0; lowestUnused = 0; lSeg = 0;
|
||||
|
||||
ledmapFileNames = [];
|
||||
ledmapNr = s.ledmap; //WLEDMM
|
||||
ledmapFileNames = []; //WLEDMM
|
||||
|
||||
for (var inst of (s.seg||[])) {
|
||||
segCount++;
|
||||
@@ -833,7 +834,7 @@ function populateSegments(s)
|
||||
resetUtil(noNewSegs);
|
||||
if (gId('selall')) gId('selall').checked = true;
|
||||
for (var i = 0; i <= lSeg; i++) {
|
||||
updateLen(i, false);
|
||||
updateLen(i, false); //WLEDMM: no draw
|
||||
updateTrail(gId(`seg${i}bri`));
|
||||
gId(`segr${i}`).style.display = "none";
|
||||
if (!gId(`seg${i}sel`).checked && gId('selall')) gId('selall').checked = false; // uncheck if at least one is unselected.
|
||||
@@ -1322,7 +1323,6 @@ function drawSegmentView() {
|
||||
|
||||
//draw the ledmap
|
||||
if (ledmapNr>=0 && ctx) { //WLEDMM: @Troy#2642 : include ledmap = 0 as default ledmap
|
||||
// console.log("Before fetch ledmap ", lastinfo.ledmap);
|
||||
var fileName;
|
||||
if (ledmapNr==0)
|
||||
fileName = "ledmap.json"; //0 is ledmap.json, not ledmap0.json
|
||||
@@ -1331,7 +1331,7 @@ function drawSegmentView() {
|
||||
else
|
||||
fileName = ledmapFileNames[ledmapNr-10];
|
||||
|
||||
fetchAndExecute((loc?`http://${locip}`:'.') + "/", fileName , function(text) {
|
||||
fetchAndExecute((loc?`http://${locip}`:'.') + "/", fileName , function(text) {
|
||||
var ledmapJson = JSON.parse(text);
|
||||
var counter = 0;
|
||||
var noMap = [];
|
||||
@@ -1339,13 +1339,9 @@ function drawSegmentView() {
|
||||
var colorArray = ["yellow", "green", "magenta", "orange"];
|
||||
|
||||
var customMappingTable = [];
|
||||
if (!ledmapJson["physical"]) {
|
||||
customMappingTable = ledmapJson["map"];
|
||||
} else {
|
||||
for (let i=0;i<maxWidth * maxHeight;i++) customMappingTable.push(-1); //init with noshow
|
||||
for (let i=0;i<maxWidth * maxHeight;i++)
|
||||
if (ledmapJson["map"][i]>=0) customMappingTable[ledmapJson["map"][i]] = i;
|
||||
}
|
||||
for (let i=0;i<maxWidth * maxHeight;i++) customMappingTable.push(-1); //init with noshow
|
||||
for (let i=0;i<maxWidth * maxHeight;i++)
|
||||
if (ledmapJson["map"][i]>=0) customMappingTable[ledmapJson["map"][i]] = i;
|
||||
|
||||
for (let i=0;i<customMappingTable.length;i++) {
|
||||
let mapIndex = customMappingTable[i];
|
||||
@@ -1576,8 +1572,6 @@ function readState(s,command=false)
|
||||
tr = s.transition;
|
||||
gId('tt').value = tr/10;
|
||||
|
||||
ledmapNr = s.ledmap; //WLEDMM
|
||||
|
||||
populateSegments(s);
|
||||
var selc=0;
|
||||
var sellvl=0; // 0: selc is invalid, 1: selc is mainseg, 2: selc is first selected
|
||||
|
||||
2098
wled00/html_ui.h
2098
wled00/html_ui.h
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user