Merge branch 'json-mapping' into mdev

This commit is contained in:
Ewowi
2022-09-08 11:38:45 +02:00
3 changed files with 35 additions and 31 deletions

View File

@@ -368,7 +368,7 @@ typedef struct Segment {
byte* data; byte* data;
CRGB* leds; CRGB* leds;
static CRGB *_globalLeds; static CRGB *_globalLeds;
void *jMapC; //WLEDSR jMap void *jMap; //WLEDSR jMap
private: private:
union { union {
@@ -478,8 +478,6 @@ 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();
} }
@@ -535,7 +533,7 @@ typedef struct Segment {
CRGBPalette16 &currentPalette(CRGBPalette16 &tgt, uint8_t paletteID); CRGBPalette16 &currentPalette(CRGBPalette16 &tgt, uint8_t paletteID);
// 1D strip // 1D strip
uint16_t virtualLength(void); //WLEDSR jMap: without const uint16_t virtualLength(void) 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
@@ -562,7 +560,7 @@ 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 createjMap(); //WLEDSR jMap
void deletejMap(); //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[])

View File

@@ -437,14 +437,14 @@ class JMapC {
} }
} }
uint16_t length() { uint16_t length() {
initjMapDoc(); updatejMapDoc();
if (jMapDoc) if (jMapDoc)
return jMapDoc->size(); return jMapDoc->size();
else else
return SEGMENT.virtualWidth() * SEGMENT.virtualHeight(); //pixels return SEGMENT.virtualWidth() * SEGMENT.virtualHeight(); //pixels
} }
void setPixelColor(uint16_t i, uint32_t col) { void setPixelColor(uint16_t i, uint32_t col) {
initjMapDoc(); updatejMapDoc();
if (jMapDoc) { if (jMapDoc) {
if (i==0) { if (i==0) {
SEGMENT.fadeToBlackBy(10); //as not all pixels used SEGMENT.fadeToBlackBy(10); //as not all pixels used
@@ -463,7 +463,7 @@ class JMapC {
} }
} }
uint32_t getPixelColor(uint16_t i) { uint32_t getPixelColor(uint16_t i) {
initjMapDoc(); updatejMapDoc();
if (jMapDoc) { if (jMapDoc) {
JsonArray outerArray = jMapDoc->as<JsonArray>(); JsonArray outerArray = jMapDoc->as<JsonArray>();
if (outerArray[i][0].is<JsonArray>()) if (outerArray[i][0].is<JsonArray>())
@@ -476,14 +476,15 @@ class JMapC {
private: private:
DynamicJsonDocument *jMapDoc = nullptr; DynamicJsonDocument *jMapDoc = nullptr;
uint8_t scale; uint8_t scale;
void initjMapDoc() { void updatejMapDoc() {
// if (jMapDoc && SEGMENT.name == nullptr) { if (jMapDoc && SEGMENT.name == nullptr) {
// Serial.println("Delete jMapDoc"); Serial.println("Delete jMapDoc");
// delete jMapDoc; jMapDoc = nullptr; delete jMapDoc; jMapDoc = nullptr;
// } }
if (!jMapDoc && SEGMENT.name != nullptr) {
if (!jMapDoc && SEGMENT.name != nullptr && SEGMENT.map1D2D == M12_jMap) {
Serial.println("Create jMapDoc"); Serial.println("Create jMapDoc");
jMapDoc = new DynamicJsonDocument(4*4096); jMapDoc = new DynamicJsonDocument(5*4096);
} }
if (jMapDoc && SEGMENT.name != nullptr && strcmp(SEGMENT.name, previousSegmentName) != 0) { if (jMapDoc && SEGMENT.name != nullptr && strcmp(SEGMENT.name, previousSegmentName) != 0) {
@@ -499,7 +500,7 @@ class JMapC {
if (err) if (err)
{ {
Serial.printf("deserializeJson() of parseTree failed with code %s\n", err.c_str()); 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 delete[] SEGMENT.name; SEGMENT.name = nullptr; //need to clear the name as otherwise continuously loaded
return; return;
} }
//get the width and height of the jMap //get the width and height of the jMap
@@ -526,29 +527,28 @@ class JMapC {
// serializeJson(*jMapDoc, Serial); Serial.println(); // serializeJson(*jMapDoc, Serial); Serial.println();
strcpy(previousSegmentName, SEGMENT.name); strcpy(previousSegmentName, SEGMENT.name);
} }
} //initjMapDoc } //updatejMapDoc
}; //class JMapC }; //class JMapC
//WLEDSR jMap //WLEDSR jMap
void * Segment::getjMap() { void Segment::createjMap() {
if (!jMapC) { if (!jMap) {
Serial.println("getjMap"); Serial.println("createjMap");
jMapC = new JMapC(); jMap = new JMapC();
} }
return jMapC;
} }
//WLEDSR jMap //WLEDSR jMap
void Segment::deletejMap() { void Segment::deletejMap() {
//Should be called from ~Segment but causes crash (and ~Segment is called quite often...) //Should be called from ~Segment but causes crash (and ~Segment is called quite often...)
if (jMapC) { if (jMap) {
Serial.println("deletejMap"); Serial.println("deletejMap");
delete (JMapC *)jMapC; jMapC = nullptr; delete (JMapC *)jMap; jMap = nullptr;
} }
} }
// 1D strip // 1D strip
uint16_t Segment::virtualLength() { //WLEDSR jMap: without const uint16_t Segment::virtualLength() const {
#ifndef WLED_DISABLE_2D #ifndef WLED_DISABLE_2D
if (is2D()) { if (is2D()) {
uint16_t vW = virtualWidth(); uint16_t vW = virtualWidth();
@@ -563,8 +563,8 @@ uint16_t Segment::virtualLength() { //WLEDSR jMap: without const
vLen = max(vW,vH); // get the longest dimension vLen = max(vW,vH); // get the longest dimension
break; break;
case M12_jMap: //WLEDSR jMap case M12_jMap: //WLEDSR jMap
JMapC *jMapC = (JMapC *)getjMap(); if (jMap)
vLen = jMapC->length(); vLen = ((JMapC *)jMap)->length();
break; break;
} }
return vLen; return vLen;
@@ -609,8 +609,8 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t 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 case M12_jMap: //WLEDSR jMap
JMapC *jMapC = (JMapC *)getjMap(); if (jMap)
jMapC->setPixelColor(i, col); ((JMapC *)jMap)->setPixelColor(i, col);
break; break;
} }
return; return;
@@ -719,8 +719,8 @@ uint32_t Segment::getPixelColor(int i)
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 case M12_jMap: //WLEDSR jMap
JMapC *jMapC = (JMapC *)getjMap(); if (jMap)
return jMapC->getPixelColor(i); return ((JMapC *)jMap)->getPixelColor(i);
break; break;
} }
return 0; return 0;

View File

@@ -82,6 +82,12 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
uint8_t soundSim = elem["ssim"] | seg.soundSim; uint8_t soundSim = elem["ssim"] | seg.soundSim;
uint8_t map1D2D = elem["mp12"] | seg.map1D2D; uint8_t map1D2D = elem["mp12"] | seg.map1D2D;
//WLEDSR jMap
if (map1D2D == M12_jMap && !seg.jMap)
seg.createjMap();
if (map1D2D != M12_jMap && seg.jMap)
seg.deletejMap();
if ((spc>0 && spc!=seg.spacing) || seg.map1D2D!=map1D2D) seg.fill(BLACK); // clear spacing gaps if ((spc>0 && spc!=seg.spacing) || seg.map1D2D!=map1D2D) seg.fill(BLACK); // clear spacing gaps
seg.map1D2D = constrain(map1D2D, 0, 7); seg.map1D2D = constrain(map1D2D, 0, 7);