Create expand to json mapping
- add M12_jMap and use in vL, sPC and gPC - add void *jMapC, getjMap and deletejMap to Segment! - remove const from virtualLength as we assign jMapC - add JMapC class
This commit is contained in:
11
wled00/FX.h
11
wled00/FX.h
@@ -341,7 +341,8 @@ typedef enum mapping1D2D {
|
|||||||
M12_Pixels = 0,
|
M12_Pixels = 0,
|
||||||
M12_pBar = 1,
|
M12_pBar = 1,
|
||||||
M12_pArc = 2,
|
M12_pArc = 2,
|
||||||
M12_pCorner = 3
|
M12_pCorner = 3,
|
||||||
|
M12_jMap = 4 //WLEDSR jMap
|
||||||
} mapping1D2D_t;
|
} mapping1D2D_t;
|
||||||
|
|
||||||
// segment, 72 bytes
|
// segment, 72 bytes
|
||||||
@@ -395,6 +396,7 @@ typedef struct Segment {
|
|||||||
byte* data;
|
byte* data;
|
||||||
CRGB* leds;
|
CRGB* leds;
|
||||||
static CRGB *_globalLeds;
|
static CRGB *_globalLeds;
|
||||||
|
void *jMapC; //WLEDSR jMap
|
||||||
|
|
||||||
private:
|
private:
|
||||||
union {
|
union {
|
||||||
@@ -468,6 +470,7 @@ typedef struct Segment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Segment(uint16_t sStartX, uint16_t sStopX, uint16_t sStartY, uint16_t sStopY) : Segment(sStartX, sStopX) {
|
Segment(uint16_t sStartX, uint16_t sStopX, uint16_t sStartY, uint16_t sStopY) : Segment(sStartX, sStopX) {
|
||||||
|
Serial.println("Segment"); //WLEDSR jMap
|
||||||
startY = sStartY;
|
startY = sStartY;
|
||||||
stopY = sStopY;
|
stopY = sStopY;
|
||||||
}
|
}
|
||||||
@@ -486,6 +489,8 @@ typedef struct Segment {
|
|||||||
if (!Segment::_globalLeds && leds) free(leds);
|
if (!Segment::_globalLeds && leds) free(leds);
|
||||||
if (name) delete[] name;
|
if (name) delete[] name;
|
||||||
if (_t) delete _t;
|
if (_t) delete _t;
|
||||||
|
Serial.println("~Segment"); //WLEDSR jMap
|
||||||
|
// deletejMap();
|
||||||
deallocateData();
|
deallocateData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -541,7 +546,7 @@ typedef struct Segment {
|
|||||||
CRGBPalette16 ¤tPalette(CRGBPalette16 &tgt, uint8_t paletteID);
|
CRGBPalette16 ¤tPalette(CRGBPalette16 &tgt, uint8_t paletteID);
|
||||||
|
|
||||||
// 1D strip
|
// 1D strip
|
||||||
uint16_t virtualLength(void) const;
|
uint16_t virtualLength(void); //WLEDSR jMap: without const
|
||||||
void setPixelColor(int n, uint32_t c); // set relative pixel within segment with color
|
void setPixelColor(int n, uint32_t c); // set relative pixel within segment with color
|
||||||
void setPixelColor(int n, byte r, byte g, byte b, byte w = 0) { setPixelColor(n, RGBW32(r,g,b,w)); } // automatically inline
|
void setPixelColor(int n, byte r, byte g, byte b, byte w = 0) { setPixelColor(n, RGBW32(r,g,b,w)); } // automatically inline
|
||||||
void setPixelColor(int n, CRGB c) { setPixelColor(n, RGBW32(c.r,c.g,c.b,0)); } // automatically inline
|
void setPixelColor(int n, CRGB c) { setPixelColor(n, RGBW32(c.r,c.g,c.b,0)); } // automatically inline
|
||||||
@@ -568,6 +573,8 @@ typedef struct Segment {
|
|||||||
uint16_t virtualWidth(void) const;
|
uint16_t virtualWidth(void) const;
|
||||||
uint16_t virtualHeight(void) const;
|
uint16_t virtualHeight(void) const;
|
||||||
uint16_t nrOfVStrips(void) const;
|
uint16_t nrOfVStrips(void) const;
|
||||||
|
void *getjMap(); //WLEDSR jMap
|
||||||
|
void deletejMap(); //WLEDSR jMap
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
uint16_t XY(uint16_t x, uint16_t y); // support function to get relative index within segment (for leds[])
|
uint16_t XY(uint16_t x, uint16_t y); // support function to get relative index within segment (for leds[])
|
||||||
void setPixelColorXY(int x, int y, uint32_t c); // set relative pixel within segment with color
|
void setPixelColorXY(int x, int y, uint32_t c); // set relative pixel within segment with color
|
||||||
|
|||||||
@@ -420,8 +420,130 @@ uint16_t Segment::nrOfVStrips() const {
|
|||||||
return vLen;
|
return vLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WLEDSR jMap
|
||||||
|
class JMapC {
|
||||||
|
public:
|
||||||
|
char previousSegmentName[50] = "";
|
||||||
|
|
||||||
|
~JMapC() {
|
||||||
|
Serial.println("~JMapC");
|
||||||
|
if (jMapDoc) {
|
||||||
|
delete jMapDoc; jMapDoc = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uint16_t length() {
|
||||||
|
initjMapDoc();
|
||||||
|
if (jMapDoc)
|
||||||
|
return jMapDoc->size();
|
||||||
|
else
|
||||||
|
return SEGMENT.virtualWidth() * SEGMENT.virtualHeight(); //pixels
|
||||||
|
}
|
||||||
|
void setPixelColor(uint16_t i, uint32_t col) {
|
||||||
|
initjMapDoc();
|
||||||
|
if (jMapDoc) {
|
||||||
|
if (i==0) {
|
||||||
|
SEGMENT.fadeToBlackBy(10); //as not all pixels used
|
||||||
|
}
|
||||||
|
//get itH element of jMap and use x and y to sPCXY call (or multiple calls if tuples)
|
||||||
|
JsonArray outerArray = jMapDoc->as<JsonArray>();
|
||||||
|
if (outerArray[i][0].is<JsonArray>()){
|
||||||
|
for (JsonVariant innerElement: outerArray[i].as<JsonArray>()) {
|
||||||
|
SEGMENT.setPixelColorXY(innerElement[0].as<uint16_t>() * scale, innerElement[1].as<uint16_t>() * scale, col);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SEGMENT.setPixelColorXY(outerArray[i][0].as<uint16_t>() * scale, outerArray[i][1].as<uint16_t>() * scale, col);
|
||||||
|
// SEGMENT.drawLine(outerArray[i][0].as<uint16_t>()*scale, outerArray[i-1][0].as<uint16_t>()*scale, outerArray[i-1][0].as<uint16_t>()*scale, outerArray[i][1].as<uint16_t>()*scale, col);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uint32_t getPixelColor(uint16_t i) {
|
||||||
|
initjMapDoc();
|
||||||
|
if (jMapDoc) {
|
||||||
|
JsonArray outerArray = jMapDoc->as<JsonArray>();
|
||||||
|
if (outerArray[i][0].is<JsonArray>())
|
||||||
|
return SEGMENT.getPixelColorXY(outerArray[i][0][0].as<uint16_t>() * scale, outerArray[i][0][1].as<uint16_t>() * scale);
|
||||||
|
else
|
||||||
|
return SEGMENT.getPixelColorXY(outerArray[i][0].as<uint16_t>() * scale, outerArray[i][1].as<uint16_t>() * scale);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
DynamicJsonDocument *jMapDoc = nullptr;
|
||||||
|
uint8_t scale;
|
||||||
|
void initjMapDoc() {
|
||||||
|
// if (jMapDoc && SEGMENT.name == nullptr) {
|
||||||
|
// Serial.println("Delete jMapDoc");
|
||||||
|
// delete jMapDoc; jMapDoc = nullptr;
|
||||||
|
// }
|
||||||
|
if (!jMapDoc && SEGMENT.name != nullptr) {
|
||||||
|
Serial.println("Create jMapDoc");
|
||||||
|
jMapDoc = new DynamicJsonDocument(4*4096);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jMapDoc && SEGMENT.name != nullptr && strcmp(SEGMENT.name, previousSegmentName) != 0) {
|
||||||
|
Serial.println("New name");
|
||||||
|
char jMapFileName[50];
|
||||||
|
strcpy(jMapFileName, "/");
|
||||||
|
strcat(jMapFileName, SEGMENT.name);
|
||||||
|
strcat(jMapFileName, ".jmap");
|
||||||
|
File jMapFile;
|
||||||
|
jMapFile = LITTLEFS.open(jMapFileName, "r");
|
||||||
|
|
||||||
|
DeserializationError err = deserializeJson(*jMapDoc, jMapFile);
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
Serial.printf("deserializeJson() of parseTree failed with code %s\n", err.c_str());
|
||||||
|
SEGMENT.name = nullptr; //need to clear the name as otherwise continuously loaded
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//get the width and height of the jMap
|
||||||
|
uint8_t maxWidth = 0;
|
||||||
|
uint8_t maxHeight = 0;
|
||||||
|
JsonArray outerArray = jMapDoc->as<JsonArray>();
|
||||||
|
for (JsonVariant outerElement: outerArray) {
|
||||||
|
if (outerElement[0].is<JsonArray>()){
|
||||||
|
for (JsonVariant innerElement: outerElement.as<JsonArray>()) {
|
||||||
|
maxWidth = MAX(maxWidth, innerElement[0].as<uint16_t>());
|
||||||
|
maxHeight = MAX(maxHeight, innerElement[1].as<uint16_t>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
maxWidth = MAX(maxWidth, outerElement[0].as<uint16_t>());
|
||||||
|
maxHeight = MAX(maxHeight, outerElement[1].as<uint16_t>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maxWidth++; maxHeight++;
|
||||||
|
scale = MIN(SEGMENT.virtualWidth() / maxWidth, SEGMENT.virtualHeight() / maxHeight);
|
||||||
|
|
||||||
|
Serial.printf("jMapDoc %u / %u%% (%u %u %u)\n", (unsigned int)jMapDoc->memoryUsage(), 100 * jMapDoc->memoryUsage() / jMapDoc->capacity(), (unsigned int)jMapDoc->size(), jMapDoc->overflowed(), (unsigned int)jMapDoc->nesting());
|
||||||
|
Serial.println(scale);
|
||||||
|
// serializeJson(*jMapDoc, Serial); Serial.println();
|
||||||
|
strcpy(previousSegmentName, SEGMENT.name);
|
||||||
|
}
|
||||||
|
} //initjMapDoc
|
||||||
|
}; //class JMapC
|
||||||
|
|
||||||
|
//WLEDSR jMap
|
||||||
|
void * Segment::getjMap() {
|
||||||
|
if (!jMapC) {
|
||||||
|
Serial.println("getjMap");
|
||||||
|
jMapC = new JMapC();
|
||||||
|
}
|
||||||
|
return jMapC;
|
||||||
|
}
|
||||||
|
|
||||||
|
//WLEDSR jMap
|
||||||
|
void Segment::deletejMap() {
|
||||||
|
//Should be called from ~Segment but causes crash (and ~Segment is called quite often...)
|
||||||
|
if (jMapC) {
|
||||||
|
Serial.println("deletejMap");
|
||||||
|
delete (JMapC *)jMapC; jMapC = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 1D strip
|
// 1D strip
|
||||||
uint16_t Segment::virtualLength() const {
|
uint16_t Segment::virtualLength() { //WLEDSR jMap: without const
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
if (is2D()) {
|
if (is2D()) {
|
||||||
uint16_t vW = virtualWidth();
|
uint16_t vW = virtualWidth();
|
||||||
@@ -435,6 +557,10 @@ uint16_t Segment::virtualLength() const {
|
|||||||
case M12_pArc:
|
case M12_pArc:
|
||||||
vLen = max(vW,vH); // get the longest dimension
|
vLen = max(vW,vH); // get the longest dimension
|
||||||
break;
|
break;
|
||||||
|
case M12_jMap: //WLEDSR jMap
|
||||||
|
JMapC *jMapC = (JMapC *)getjMap();
|
||||||
|
vLen = jMapC->length();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return vLen;
|
return vLen;
|
||||||
}
|
}
|
||||||
@@ -484,6 +610,10 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col)
|
|||||||
for (int x = 0; x <= i; x++) setPixelColorXY(x, i, col);
|
for (int x = 0; x <= i; x++) setPixelColorXY(x, i, col);
|
||||||
for (int y = 0; y < i; y++) setPixelColorXY(i, y, col);
|
for (int y = 0; y < i; y++) setPixelColorXY(i, y, col);
|
||||||
break;
|
break;
|
||||||
|
case M12_jMap: //WLEDSR jMap
|
||||||
|
JMapC *jMapC = (JMapC *)getjMap();
|
||||||
|
jMapC->setPixelColor(i, col);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (strip.isMatrix && (width()==1 || height()==1)) { // TODO remove this hack
|
} else if (strip.isMatrix && (width()==1 || height()==1)) { // TODO remove this hack
|
||||||
@@ -590,6 +720,10 @@ uint32_t Segment::getPixelColor(int i)
|
|||||||
// use longest dimension
|
// use longest dimension
|
||||||
return vW>vH ? getPixelColorXY(i, 0) : getPixelColorXY(0, i);
|
return vW>vH ? getPixelColorXY(i, 0) : getPixelColorXY(0, i);
|
||||||
break;
|
break;
|
||||||
|
case M12_jMap: //WLEDSR jMap
|
||||||
|
JMapC *jMapC = (JMapC *)getjMap();
|
||||||
|
return jMapC->getPixelColor(i);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -713,12 +713,14 @@ function populateSegments(s)
|
|||||||
rvYck = `<label class="check revchkl">Reverse<input type="checkbox" id="seg${i}rY" onchange="setRevY(${i})" ${inst.rY?"checked":""}><span class="checkmark"></span></label>`;
|
rvYck = `<label class="check revchkl">Reverse<input type="checkbox" id="seg${i}rY" onchange="setRevY(${i})" ${inst.rY?"checked":""}><span class="checkmark"></span></label>`;
|
||||||
miYck = `<label class="check revchkl">Mirror<input type="checkbox" id="seg${i}mY" onchange="setMiY(${i})" ${inst.mY?"checked":""}><span class="checkmark"></span></label>`;
|
miYck = `<label class="check revchkl">Mirror<input type="checkbox" id="seg${i}mY" onchange="setMiY(${i})" ${inst.mY?"checked":""}><span class="checkmark"></span></label>`;
|
||||||
}
|
}
|
||||||
|
// WLEDSR: jMap
|
||||||
let map2D = `<div id="seg${i}map2D" data-map="map2D" class="lbl-s hide">Expand 1D FX<br>
|
let map2D = `<div id="seg${i}map2D" data-map="map2D" class="lbl-s hide">Expand 1D FX<br>
|
||||||
<div class="sel-p"><select class="sel-p" id="seg${i}mp12" onchange="setMp12(${i})">
|
<div class="sel-p"><select class="sel-p" id="seg${i}mp12" onchange="setMp12(${i})">
|
||||||
<option value="0" ${inst.mp12==0?' selected':''}>Pixels</option>
|
<option value="0" ${inst.mp12==0?' selected':''}>Pixels</option>
|
||||||
<option value="1" ${inst.mp12==1?' selected':''}>Bar</option>
|
<option value="1" ${inst.mp12==1?' selected':''}>Bar</option>
|
||||||
<option value="2" ${inst.mp12==2?' selected':''}>Arc</option>
|
<option value="2" ${inst.mp12==2?' selected':''}>Arc</option>
|
||||||
<option value="3" ${inst.mp12==3?' selected':''}>Corner</option>
|
<option value="3" ${inst.mp12==3?' selected':''}>Corner</option>
|
||||||
|
<option value="4" ${inst.mp12==4?' selected':''}>jMap</option>
|
||||||
</select></div>
|
</select></div>
|
||||||
</div>`;
|
</div>`;
|
||||||
let sndSim = `<div data-snd="ssim" class="lbl-s hide">Sound sim<br>
|
let sndSim = `<div data-snd="ssim" class="lbl-s hide">Sound sim<br>
|
||||||
|
|||||||
3743
wled00/html_ui.h
3743
wled00/html_ui.h
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user