diff --git a/src/App/AppEffects.h b/src/App/AppEffects.h index 32d6f9dc..1972e145 100644 --- a/src/App/AppEffects.h +++ b/src/App/AppEffects.h @@ -1,7 +1,7 @@ /* @title StarMod @file AppEffects.h - @date 20240226 + @date 20240227 @repo https://github.com/ewowi/StarMod @Authors https://github.com/ewowi/StarMod/commits/main @Copyright © 2024 Github StarMod Commit Authors @@ -32,7 +32,7 @@ class Effect { virtual void controls(JsonObject parentVar, Leds &leds) {} void addPalette(JsonObject parentVar, uint8_t value) { - //currentVar["value"][parentRowNr] will be set to value parameter + //currentVar["value"][contextRowNr] will be set to value parameter JsonObject currentVar = ui->initSelect(parentVar, "pal", value, false, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun case f_UIFun: { ui->setLabel(var, "Palette"); @@ -45,16 +45,15 @@ class Effect { options.add("RainbowStripeColors"); options.add("PartyColors"); options.add("HeatColors"); - return true; - } + return true; } default: return false; }}); //tbd: check if memory is freed! currentVar["stage"] = true; } - CRGBPalette16 getPalette(uint8_t rowNr) { - switch (mdl->getValue("pal", rowNr).as()) { + CRGBPalette16 getPalette() { + switch (mdl->getValue("pal").as()) { case 0: return CloudColors_p; break; case 1: return LavaColors_p; break; case 2: return OceanColors_p; break; @@ -74,9 +73,10 @@ class SolidEffect: public Effect { return "Solid 1D"; } void loop(Leds &leds) { - uint8_t red = mdl->getValue("Red", leds.rowNr); - uint8_t green = mdl->getValue("Green", leds.rowNr); - uint8_t blue = mdl->getValue("Blue", leds.rowNr); + uint8_t red = mdl->getValue("Red"); + uint8_t green = mdl->getValue("Green"); + uint8_t blue = mdl->getValue("Blue"); + CRGB color = CRGB(red, green, blue); leds.fill_solid(color); } @@ -124,7 +124,7 @@ class SinelonEffect: public Effect { void loop(Leds &leds) { // a colored dot sweeping back and forth, with fading trails leds.fadeToBlackBy(20); - int pos = beatsin16( mdl->getValue("BPM", leds.rowNr).as(), 0, leds.nrOfLeds-1 ); + int pos = beatsin16( mdl->getValue("BPM").as(), 0, leds.nrOfLeds-1 ); leds[pos] = leds.getPixelColor(pos) + CHSV( gHue, 255, 192); } void controls(JsonObject parentVar, Leds &leds) { @@ -140,9 +140,9 @@ class RunningEffect: public Effect { } void loop(Leds &leds) { // a colored dot sweeping back and forth, with fading trails - leds.fadeToBlackBy(mdl->getValue("fade", leds.rowNr).as()); //physical leds - int pos = map(beat16( mdl->getValue("BPM", leds.rowNr).as()), 0, uint16_t(-1), 0, leds.nrOfLeds-1 ); //instead of call%leds.nrOfLeds - // int pos2 = map(beat16( mdl->getValue("BPM", leds.rowNr).as(), 1000), 0, uint16_t(-1), 0, leds.nrOfLeds-1 ); //one second later + leds.fadeToBlackBy(mdl->getValue("fade").as()); //physical leds + int pos = map(beat16( mdl->getValue("BPM").as()), 0, uint16_t(-1), 0, leds.nrOfLeds-1 ); //instead of call%leds.nrOfLeds + // int pos2 = map(beat16( mdl->getValue("BPM").as(), 1000), 0, uint16_t(-1), 0, leds.nrOfLeds-1 ); //one second later leds[pos] = CHSV( gHue, 255, 192); //make sure the right physical leds get their value // leds[leds.nrOfLeds -1 - pos2] = CHSV( gHue, 255, 192); //make sure the right physical leds get their value } @@ -178,7 +178,7 @@ class BPMEffect: public Effect { } void loop(Leds &leds) { - CRGBPalette16 pal = getPalette(leds.rowNr); + CRGBPalette16 pal = getPalette(); // colored stripes pulsing at a defined Beats-Per-Minute (BPM) uint8_t BeatsPerMinute = 62; @@ -214,7 +214,7 @@ class Ripples3DEffect: public Effect { return "Ripples 3D"; } void loop(Leds &leds) { - uint8_t interval = mdl->getValue("interval", leds.rowNr); + uint8_t interval = mdl->getValue("interval"); float ripple_interval = 1.3 * (interval/128.0); @@ -283,9 +283,9 @@ class Frizzles2D: public Effect { void loop(Leds &leds) { leds.fadeToBlackBy(16); - uint16_t bpm = mdl->getValue("BPM", leds.rowNr); - uint16_t intensity = mdl->getValue("intensity", leds.rowNr); - CRGBPalette16 pal = getPalette(leds.rowNr); + uint16_t bpm = mdl->getValue("BPM"); + uint16_t intensity = mdl->getValue("intensity"); + CRGBPalette16 pal = getPalette(); for (size_t i = 8; i > 0; i--) { Coord3D pos = {0,0,0}; @@ -294,7 +294,7 @@ class Frizzles2D: public Effect { CRGB color = ColorFromPalette(pal, beatsin8(12, 0, 255), 255); leds[pos] = color; } - leds.blur2d(mdl->getValue("blur", leds.rowNr)); + leds.blur2d(mdl->getValue("blur")); } void controls(JsonObject parentVar, Leds &leds) { @@ -315,14 +315,14 @@ class Lines2D: public Effect { leds.fadeToBlackBy(100); Coord3D pos = {0,0,0}; - if (mdl->getValue("Vertical", leds.rowNr).as()) { - pos.x = map(beat16( mdl->getValue("BPM", leds.rowNr).as()), 0, uint16_t(-1), 0, leds.size.x-1 ); //instead of call%width + if (mdl->getValue("Vertical").as()) { + pos.x = map(beat16( mdl->getValue("BPM").as()), 0, uint16_t(-1), 0, leds.size.x-1 ); //instead of call%width for (pos.y = 0; pos.y < leds.size.y; pos.y++) { leds[pos] = CHSV( gHue, 255, 192); } } else { - pos.y = map(beat16( mdl->getValue("BPM", leds.rowNr).as()), 0, uint16_t(-1), 0, leds.size.y-1 ); //instead of call%height + pos.y = map(beat16( mdl->getValue("BPM").as()), 0, uint16_t(-1), 0, leds.size.y-1 ); //instead of call%height for (pos.x = 0; pos.x < leds.size.x; pos.x++) { leds[pos] = CHSV( gHue, 255, 192); } @@ -348,8 +348,8 @@ class DistortionWaves2D: public Effect { void loop(Leds &leds) { - uint8_t speed = mdl->getValue("speed", leds.rowNr).as()/32; - uint8_t scale = mdl->getValue("scale", leds.rowNr).as()/32; + uint8_t speed = mdl->getValue("speed").as()/32; + uint8_t scale = mdl->getValue("scale").as()/32; uint8_t w = 2; @@ -412,11 +412,14 @@ class Octopus2D: public Effect { const uint8_t mapp = 180 / max(leds.size.x,leds.size.y); - uint8_t speed = mdl->getValue("speed", leds.rowNr); - uint8_t offsetX = mdl->getValue("Offset X", leds.rowNr); - uint8_t offsetY = mdl->getValue("Offset Y", leds.rowNr); - uint8_t legs = mdl->getValue("Legs", leds.rowNr); - CRGBPalette16 pal = getPalette(leds.rowNr); + // uint8_t *speed2 = leds.sharedData.bind(speed2); + // // USER_PRINTF(" %d:%d", speed2, *speed2); + + uint8_t speed = mdl->getValue("speed"); + uint8_t offsetX = mdl->getValue("Offset X"); + uint8_t offsetY = mdl->getValue("Offset Y"); + uint8_t legs = mdl->getValue("Legs"); + CRGBPalette16 pal = getPalette(); map_t *rMap = leds.sharedData.bind(rMap, leds.size.x * leds.size.y); //array uint8_t *offsX = leds.sharedData.bind(offsX); @@ -444,7 +447,7 @@ class Octopus2D: public Effect { } } - *step = now * speed / 32 / 10;//mdl->getValue("realFps", leds.rowNr).as(); // WLEDMM 40fps + *step = now * speed / 32 / 10;//mdl->getValue("realFps").as(); // WLEDMM 40fps for (pos.x = 0; pos.x < leds.size.x; pos.x++) { for (pos.y = 0; pos.y < leds.size.y; pos.y++) { @@ -459,8 +462,25 @@ class Octopus2D: public Effect { } } void controls(JsonObject parentVar, Leds &leds) { + + //bind the variables to sharedData... + // uint8_t *speed2 = leds.sharedData.bind(speed2); + // USER_PRINTF("(bind %d) %d %d\n", speed2, leds.sharedData.index, leds.sharedData.bytesAllocated); + // USER_PRINTF("bind %d->%d %d\n", index, newIndex, bytesAllocated); + + //if changeValue then update the linked variable... + addPalette(parentVar, 4); - ui->initSlider(parentVar, "speed", 128, 1, 255); //start with speed 1 + + ui->initSlider(parentVar, "speed", 128, 1, 255); + // , false, [leds](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun + // case f_ChangeFun: { + // uint8_t *speed2 = leds.sharedData.data+0; + // USER_PRINTF("%s[%d] chFun = %s (bind %d)\n", mdl->varID(var), rowNr, var["value"].as().c_str(), speed2); + // *speed2 = var["value"][rowNr]; + // return true; } + // default: return false; + // }}); ui->initSlider(parentVar, "Offset X", 128); ui->initSlider(parentVar, "Offset Y", 128); ui->initSlider(parentVar, "Legs", 4, 1, 8); @@ -476,11 +496,11 @@ class Lissajous2D: public Effect { void loop(Leds &leds) { - uint8_t freqX = mdl->getValue("X frequency", leds.rowNr); - uint8_t fadeRate = mdl->getValue("Fade rate", leds.rowNr); - uint8_t speed = mdl->getValue("speed", leds.rowNr); - bool smooth = mdl->getValue("Smooth", leds.rowNr); - CRGBPalette16 pal = getPalette(leds.rowNr); + uint8_t freqX = mdl->getValue("X frequency"); + uint8_t fadeRate = mdl->getValue("Fade rate"); + uint8_t speed = mdl->getValue("speed"); + bool smooth = mdl->getValue("Smooth"); + CRGBPalette16 pal = getPalette(); leds.fadeToBlackBy(fadeRate); @@ -536,9 +556,9 @@ class BouncingBalls1D: public Effect { } void loop(Leds &leds) { - uint8_t grav = mdl->getValue("gravity", leds.rowNr); - uint8_t numBalls = mdl->getValue("balls", leds.rowNr); - CRGBPalette16 pal = getPalette(leds.rowNr); + uint8_t grav = mdl->getValue("gravity"); + uint8_t numBalls = mdl->getValue("balls"); + CRGBPalette16 pal = getPalette(); Ball *balls = leds.sharedData.bind(balls, maxNumBalls); //array @@ -635,9 +655,9 @@ class ScrollingText2D: public Effect { } void loop(Leds &leds) { - uint8_t speed = mdl->getValue("speed", leds.rowNr); - uint8_t font = mdl->getValue("font", leds.rowNr); - const char * text = mdl->getValue("text", leds.rowNr); + uint8_t speed = mdl->getValue("speed"); + uint8_t font = mdl->getValue("font"); + const char * text = mdl->getValue("text"); // text might be nullified by selecting other effects and if effect is selected, controls are run afterwards // tbd: this should be removed and setEffect must make sure this cannot happen!! @@ -673,12 +693,12 @@ class Waverly2D: public Effect { } void loop(Leds &leds) { - CRGBPalette16 pal = getPalette(leds.rowNr); - uint8_t amplification = mdl->getValue("Amplification", leds.rowNr); - uint8_t sensitivity = mdl->getValue("Sensitivity", leds.rowNr); - bool noClouds = mdl->getValue("No Clouds", leds.rowNr); - // bool soundPressure = mdl->getValue("Sound Pressure", leds.rowNr); - // bool agcDebug = mdl->getValue("AGC debug", leds.rowNr); + CRGBPalette16 pal = getPalette(); + uint8_t amplification = mdl->getValue("Amplification"); + uint8_t sensitivity = mdl->getValue("Sensitivity"); + bool noClouds = mdl->getValue("No Clouds"); + // bool soundPressure = mdl->getValue("Sound Pressure"); + // bool agcDebug = mdl->getValue("AGC debug"); leds.fadeToBlackBy(amplification); // if (agcDebug && soundPressure) soundPressure = false; // only one of the two at any time @@ -730,10 +750,10 @@ class PopCorn1D: public Effect { } void loop(Leds &leds) { - CRGBPalette16 pal = getPalette(leds.rowNr); - uint8_t speed = mdl->getValue("speed", leds.rowNr); - uint8_t intensity = mdl->getValue("intensity", leds.rowNr); - bool useaudio = mdl->getValue("useaudio", leds.rowNr); + CRGBPalette16 pal = getPalette(); + uint8_t speed = mdl->getValue("speed"); + uint8_t intensity = mdl->getValue("intensity"); + bool useaudio = mdl->getValue("useaudio"); Spark *popcorn = leds.sharedData.bind(popcorn, maxNumPopcorn); //array @@ -820,11 +840,11 @@ class GEQEffect:public Effect { uint8_t samplePeak = *(uint8_t*)um_data->u_data[3]; #endif - uint8_t fadeOut = mdl->getValue("fadeOut", leds.rowNr); - uint8_t ripple = mdl->getValue("ripple", leds.rowNr); - bool colorBars = mdl->getValue("colorBars", leds.rowNr); - bool smoothBars = mdl->getValue("smoothBars", leds.rowNr); - CRGBPalette16 pal = getPalette(leds.rowNr); + uint8_t fadeOut = mdl->getValue("fadeOut"); + uint8_t ripple = mdl->getValue("ripple"); + bool colorBars = mdl->getValue("colorBars"); + bool smoothBars = mdl->getValue("smoothBars"); + CRGBPalette16 pal = getPalette(); bool rippleTime = false; if (now - *step >= (256U - ripple)) { @@ -923,11 +943,11 @@ class AudioRings:public RingEffect { } void loop(Leds &leds) { - CRGBPalette16 pal = getPalette(leds.rowNr); + CRGBPalette16 pal = getPalette(); for (int i = 0; i < 7; i++) { // 7 rings uint8_t val; - if(mdl->getValue("inWards", leds.rowNr).as()) { + if(mdl->getValue("inWards").as()) { val = wledAudioMod->fftResults[(i*2)]; } else { @@ -975,11 +995,11 @@ class FreqMatrix:public Effect { uint8_t *aux0 = leds.sharedData.bind(aux0); - uint8_t speed = mdl->getValue("speed", leds.rowNr); - uint8_t fx = mdl->getValue("Sound effect", leds.rowNr); - uint8_t lowBin = mdl->getValue("Low bin", leds.rowNr); - uint8_t highBin = mdl->getValue("High bin", leds.rowNr); - uint8_t sensitivity10 = mdl->getValue("Sensivity", leds.rowNr); + uint8_t speed = mdl->getValue("speed"); + uint8_t fx = mdl->getValue("Sound effect"); + uint8_t lowBin = mdl->getValue("Low bin"); + uint8_t highBin = mdl->getValue("High bin"); + uint8_t sensitivity10 = mdl->getValue("Sensivity"); uint8_t secondHand = (speed < 255) ? (micros()/(256-speed)/500 % 16) : 0; if((speed > 254) || (*aux0 != secondHand)) { // WLEDMM allow run run at full speed @@ -1120,9 +1140,11 @@ class Effects { Effect* effect = effects[leds.fx]; - ui->parentRowNr = rowNr; + mdl->contextRowNr = rowNr; + // effect->loop(leds); //do a loop to set sharedData right + // leds.sharedData.loop(); effect->controls(var, leds); //new controls have positive order (var["o"]) - ui->parentRowNr = UINT8_MAX; + mdl->contextRowNr = UINT8_MAX; effect->setup(leds); //if changed then run setup once (like call==0 in WLED) diff --git a/src/App/AppFixture.cpp b/src/App/AppFixture.cpp index f3ee282b..e51c463f 100644 --- a/src/App/AppFixture.cpp +++ b/src/App/AppFixture.cpp @@ -1,7 +1,7 @@ /* @title StarMod @file AppFixture.cpp - @date 20240226 + @date 20240227 @repo https://github.com/ewowi/StarMod @Authors https://github.com/ewowi/StarMod/commits/main @Copyright © 2024 Github StarMod Commit Authors @@ -12,7 +12,7 @@ #include "AppFixture.h" #include "../Sys/SysModFiles.h" -#include "../Sys/SysJsonRDWS.h" +#include "../Sys/SysStarModJson.h" #include "../Sys/SysModPins.h" Coord3D map1Dto2D(Coord3D in) { @@ -36,7 +36,7 @@ Coord3D map2Dto2D(Coord3D in) { char fileName[32] = ""; if (files->seqNrToName(fileName, fixtureNr)) { - JsonRDWS jrdws(fileName); //open fileName for deserialize + StarModJson starModJson(fileName); //open fileName for deserialize for (std::vector::iterator leds=ledsList.begin(); leds!=ledsList.end() && leds->doMap; ++leds) { //vectors really gone now? @@ -59,14 +59,14 @@ Coord3D map2Dto2D(Coord3D in) { bool first = true; //what to deserialize - jrdws.lookFor("width", &size.x); - jrdws.lookFor("height", &size.y); - jrdws.lookFor("depth", &size.z); - jrdws.lookFor("nrOfLeds", &nrOfLeds); - jrdws.lookFor("pin", &currPin); + starModJson.lookFor("width", &size.x); + starModJson.lookFor("height", &size.y); + starModJson.lookFor("depth", &size.z); + starModJson.lookFor("nrOfLeds", &nrOfLeds); + starModJson.lookFor("pin", &currPin); //lookFor leds array and for each item in array call lambdo to make a projection - jrdws.lookFor("leds", [this, &prevIndexP, &indexP, &currPin, &first](std::vector uint16CollectList) { //this will be called for each tuple of coordinates! + starModJson.lookFor("leds", [this, &prevIndexP, &indexP, &currPin, &first](std::vector uint16CollectList) { //this will be called for each tuple of coordinates! // USER_PRINTF("funList "); // for (uint16_t num:uint16CollectList) // USER_PRINTF(" %d", num); @@ -354,13 +354,13 @@ Coord3D map2Dto2D(Coord3D in) { prevIndexP = indexP; } - }); //jrdws.lookFor("leds" (create the right type, otherwise crash) + }); //starModJson.lookFor("leds" (create the right type, otherwise crash) - if (jrdws.deserialize(false)) { //this will call above function parameter for each led + if (starModJson.deserialize(false)) { //this will call above function parameter for each led uint8_t rowNr = 0; for (std::vector::iterator leds=ledsList.begin(); leds!=ledsList.end() && leds->doMap; ++leds) { - USER_PRINTF("leds loop %d %d\n", leds->rowNr, leds->fx); + USER_PRINTF("leds loop %d %d\n", leds - ledsList.begin(), leds->fx); uint16_t nrOfMappings = 0; uint16_t nrOfPixels = 0; @@ -404,9 +404,9 @@ Coord3D map2Dto2D(Coord3D in) { USER_PRINTF("projectAndMap [%d] V:%d x %d x %d = %d (%d-%d)\n", rowNr, leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds, nrOfMappings, nrOfPixels); - mdl->setValueV("fxSize", leds->rowNr, "%d x %d x %d = %d", leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds); + mdl->setValueV("fxSize", rowNr, "%d x %d x %d = %d", leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds); - USER_PRINTF("leds[%d].size = %d + %d\n", leds->rowNr, sizeof(Leds), leds->mappingTable.size()); //44 + USER_PRINTF("leds[%d].size = %d + %d\n", rowNr, sizeof(Leds), leds->mappingTable.size()); //44 rowNr++; leds->doMap = false; diff --git a/src/App/AppLeds.h b/src/App/AppLeds.h index 462103cf..504bf55b 100644 --- a/src/App/AppLeds.h +++ b/src/App/AppLeds.h @@ -1,7 +1,7 @@ /* @title StarMod @file AppLeds.h - @date 20240226 + @date 20240227 @repo https://github.com/ewowi/StarMod @Authors https://github.com/ewowi/StarMod/commits/main @Copyright © 2024 Github StarMod Commit Authors @@ -34,12 +34,14 @@ class Fixture; //forward //StarMod implementation of segment.data class SharedData { + private: byte *data; uint16_t index = 0; uint16_t bytesAllocated = 0; public: + SharedData() { USER_PRINTF("SharedData constructor %d %d\n", index, bytesAllocated); } @@ -50,6 +52,7 @@ class SharedData { void clear() { memset(data, 0, bytesAllocated); + index = 0; } void loop() { @@ -63,7 +66,7 @@ class SharedData { size_t newSize = bytesAllocated + (1 + ( newIndex - bytesAllocated)/1024) * 1024; // add a multitude of 1024 bytes USER_PRINTF("bind add more %d->%d %d->%d\n", index, newIndex, bytesAllocated, newSize); if (bytesAllocated == 0) - data = (byte*) malloc(newSize); //start bytesAllocated 100 bytes + data = (byte*) malloc(newSize); else data = (byte*)realloc(data, newSize); bytesAllocated = newSize; @@ -82,8 +85,6 @@ class Leds { public: - uint8_t rowNr = 0; - Fixture *fixture; uint16_t nrOfLeds = 64; //amount of virtual leds (calculated by projection) @@ -113,16 +114,16 @@ class Leds { bool doMap = false; - Leds(uint8_t rowNr, Fixture &fixture) { - USER_PRINTF("Leds[%d] constructor\n", rowNr); - this->rowNr = rowNr; + Leds(Fixture &fixture) { + USER_PRINTF("Leds[%d] constructor\n", UINT8_MAX); + // this->rowNr = rowNr; this->fixture = &fixture; - this->fx = 13; - this->projectionNr = 2; + // this->fx = 13; + // this->projectionNr = 2; } ~Leds() { - USER_PRINTF("Leds[%d] destructor\n", rowNr); + USER_PRINTF("Leds[%d] destructor\n", UINT8_MAX); fadeToBlackBy(100); for (std::vector> ::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) physMap->clear(); diff --git a/src/App/AppModLeds.h b/src/App/AppModLeds.h index cff51b52..227895e6 100644 --- a/src/App/AppModLeds.h +++ b/src/App/AppModLeds.h @@ -1,7 +1,7 @@ /* @title StarMod @file AppModLeds.h - @date 20240226 + @date 20240227 @repo https://github.com/ewowi/StarMod @Authors https://github.com/ewowi/StarMod/commits/main @Copyright © 2024 Github StarMod Commit Authors @@ -74,7 +74,7 @@ class AppModLeds:public SysModule { web->getResponseObject()["addRow"]["rowNr"] = rowNr; if (rowNr >= fixture.ledsList.size()) - fixture.ledsList.push_back(Leds(fixture.ledsList.size(), fixture)); + fixture.ledsList.push_back(Leds(fixture)); return true; } case f_DelRow: { @@ -107,7 +107,7 @@ class AppModLeds:public SysModule { //create a new leds instance if a new row is created if (rowNr >= fixture.ledsList.size()) { USER_PRINTF("ledslist fx changeFun %d %s", fixture.ledsList.size(), mdl->findVar("fx")["value"].as().c_str()); - fixture.ledsList.push_back(Leds(fixture.ledsList.size(), fixture)); + fixture.ledsList.push_back(Leds(fixture)); } effects.setEffect(fixture.ledsList[rowNr], var, rowNr); @@ -227,7 +227,7 @@ class AppModLeds:public SysModule { for (std::vector::iterator leds=fixture.ledsList.begin(); leds!=fixture.ledsList.end(); ++leds) { char message[32]; print->fFormat(message, sizeof(message)-1, "%d x %d x %d = %d", leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds); - USER_PRINTF("valueFun fxSize[%d]([%d 0f %d]) = %s\n", leds - fixture.ledsList.begin(), fixture.ledsList[leds - fixture.ledsList.begin()].rowNr, fixture.ledsList.size(), message); + USER_PRINTF("valueFun fxSize[%d]([%d 0f %d]) = %s\n", leds - fixture.ledsList.begin(), leds - fixture.ledsList.begin(), fixture.ledsList.size(), message); mdl->setValue(var, JsonString(message, JsonString::Copied), leds - fixture.ledsList.begin()); //rowNr } return true; @@ -296,7 +296,9 @@ class AppModLeds:public SysModule { // vector iteration on classes is faster!!! (22 vs 30 fps !!!!) for (std::vector::iterator leds=fixture.ledsList.begin(); leds!=fixture.ledsList.end(); ++leds) { // USER_PRINTF(" %d %d,%d,%d - %d,%d,%d (%d,%d,%d)", leds->fx, leds->startPos.x, leds->startPos.y, leds->startPos.z, leds->endPos.x, leds->endPos.y, leds->endPos.z, leds->size.x, leds->size.y, leds->size.z ); + mdl->contextRowNr = leds - fixture.ledsList.begin();// rowNr; effects.loop(*leds); + mdl->contextRowNr = UINT8_MAX; } FastLED.show(); diff --git a/src/Sys/SysModFiles.cpp b/src/Sys/SysModFiles.cpp index ba3a6801..6b059b2e 100644 --- a/src/Sys/SysModFiles.cpp +++ b/src/Sys/SysModFiles.cpp @@ -236,7 +236,7 @@ bool SysModFiles::readObjectFromFile(const char* path, JsonDocument* dest) { } } -//candidate for deletion as taken over by JsonRDWS +//candidate for deletion as taken over by StarModJson // bool SysModFiles::writeObjectToFile(const char* path, JsonDocument* dest) { // File f = open(path, "w"); // if (f) { diff --git a/src/Sys/SysModFiles.h b/src/Sys/SysModFiles.h index f06994c1..f3422343 100644 --- a/src/Sys/SysModFiles.h +++ b/src/Sys/SysModFiles.h @@ -51,7 +51,7 @@ class SysModFiles: public SysModule { //write json into file //name is copied from WLED but better to call it readJsonFrom file - //candidate for deletion as taken over by JsonRDWS + //candidate for deletion as taken over by StarModJson // bool writeObjectToFile(const char* path, JsonDocument* dest); //remove files meeting filter condition, if no filter, all, if reverse then all but filter diff --git a/src/Sys/SysModModel.cpp b/src/Sys/SysModModel.cpp index 45ec9394..d75f1107 100644 --- a/src/Sys/SysModModel.cpp +++ b/src/Sys/SysModModel.cpp @@ -12,11 +12,12 @@ #include "SysModModel.h" #include "SysModule.h" #include "SysModFiles.h" -#include "SysJsonRDWS.h" +#include "SysStarModJson.h" #include "SysModUI.h" JsonDocument * SysModModel::model = nullptr; JsonObject SysModModel::modelParentVar; +uint8_t SysModModel::contextRowNr = UINT8_MAX; SysModModel::SysModModel() :SysModule("Model") { model = new JsonDocument(&allocator); @@ -87,9 +88,9 @@ void SysModModel::setup() { cleanUpModel(JsonObject(), false, true);//remove if var["o"] is negative (not cleanedUp) and remove ro values - JsonRDWS jrdws("/model.json", "w"); //open fileName for deserialize - jrdws.addExclusion("fun"); - jrdws.writeJsonDocToFile(model); + StarModJson starModJson("/model.json", "w"); //open fileName for deserialize + starModJson.addExclusion("fun"); + starModJson.writeJsonDocToFile(model); // print->printJson("Write model", *model); //this shows the model before exclusion diff --git a/src/Sys/SysModModel.h b/src/Sys/SysModModel.h index 84a9eec5..6dc82351 100644 --- a/src/Sys/SysModModel.h +++ b/src/Sys/SysModModel.h @@ -1,7 +1,7 @@ /* @title StarMod @file SysModModel.h - @date 20240226 + @date 20240227 @repo https://github.com/ewowi/StarMod @Authors https://github.com/ewowi/StarMod/commits/main @Copyright © 2024 Github StarMod Commit Authors @@ -160,6 +160,8 @@ class SysModModel:public SysModule { bool doWriteModel = false; + static uint8_t contextRowNr; + SysModModel(); void setup(); void loop(); @@ -290,6 +292,7 @@ class SysModModel:public SysModule { JsonVariant getValue(JsonObject var, uint8_t rowNr = UINT8_MAX) { if (var["value"].is()) { JsonArray valueArray = var["value"].as(); + if (rowNr == UINT8_MAX) rowNr = contextRowNr; if (rowNr != UINT8_MAX && rowNr < valueArray.size()) return valueArray[rowNr]; else if (valueArray.size()) diff --git a/src/Sys/SysModUI.cpp b/src/Sys/SysModUI.cpp index fd953d88..8f086832 100644 --- a/src/Sys/SysModUI.cpp +++ b/src/Sys/SysModUI.cpp @@ -18,7 +18,6 @@ std::vector SysModUI::varFunctions; std::vector SysModUI::loopFunctions; int SysModUI::varCounter = 1; //start with 1 so it can be negative, see var["o"] bool SysModUI::stageVarChanged = false; -uint8_t SysModUI::parentRowNr = UINT8_MAX; SysModUI::SysModUI() :SysModule("UI") { }; diff --git a/src/Sys/SysModUI.h b/src/Sys/SysModUI.h index a3ecd617..3971e788 100644 --- a/src/Sys/SysModUI.h +++ b/src/Sys/SysModUI.h @@ -1,7 +1,7 @@ /* @title StarMod @file SysModUI.h - @date 20240226 + @date 20240227 @repo https://github.com/ewowi/StarMod @Authors https://github.com/ewowi/StarMod/commits/main @Copyright © 2024 Github StarMod Commit Authors @@ -60,8 +60,6 @@ class SysModUI:public SysModule { static bool stageVarChanged;// = false; //tbd: move mechanism to UserModInstances as there it will be used static std::vector varFunctions; //static because of static functions callChangeFun, processJson... - static uint8_t parentRowNr; - SysModUI(); //serve index.htm @@ -127,10 +125,16 @@ class SysModUI:public SysModule { return initVarAndUpdate(parent, id, "button", false, 0, 0, readOnly, varFun); } + //int value ? JsonObject initSelect(JsonObject parent, const char * id, int value = UINT16_MAX, bool readOnly = false, VarFun varFun = nullptr) { return initVarAndUpdate(parent, id, "select", value, 0, 0, readOnly, varFun); } + //WIP + JsonObject initSelect(JsonObject parent, const char * id, uint8_t * value = nullptr, bool readOnly = false, VarFun varFun = nullptr) { + return initVarAndUpdate(parent, id, "select", value, 0, 0, readOnly, varFun); + } + JsonObject initTextArea(JsonObject parent, const char * id, const char * value = nullptr, bool readOnly = false, VarFun varFun = nullptr) { return initVarAndUpdate(parent, id, "textarea", value, 0, 0, readOnly, varFun); } @@ -139,16 +143,21 @@ class SysModUI:public SysModule { return initVarAndUpdate(parent, id, "url", value, 0, 0, readOnly, varFun); } + //WIP + template + JsonObject initVarAndUpdate(JsonObject parent, const char * id, const char * type, Type * value, int min = 0, int max = 255, bool readOnly = true, VarFun varFun = nullptr) { + // JsonObject var = initVar(parent, id, type, readOnly, varFun); + JsonObject var = initVarAndUpdate(parent, id, type, *value, min, max, readOnly, varFun); + // var["p"] = (const char *)value; //store pointer! + return var; + } + template JsonObject initVarAndUpdate(JsonObject parent, const char * id, const char * type, Type value, int min = 0, int max = 255, bool readOnly = true, VarFun varFun = nullptr) { JsonObject var = initVar(parent, id, type, readOnly, varFun); if (min) var["min"] = min; if (max && max != UINT16_MAX) var["max"] = max; - if (parentRowNr != UINT8_MAX) { - USER_PRINTF("parentRowNr %s: %d for %s\n", mdl->varID(parent), parentRowNr, mdl->varID(var)); - } - bool valueNeedsUpdate = false; if (strcmp(type, "button") != 0) { //button never gets a value if (var["value"].isNull()) { @@ -156,10 +165,10 @@ class SysModUI:public SysModule { // print->printJson("initVarAndUpdate varFun value is null", var); } else if (var["value"].is()) { JsonArray valueArray = var["value"].as(); - if (parentRowNr != UINT8_MAX) { // if var in table - if (parentRowNr >= valueArray.size()) + if (mdl->contextRowNr != UINT8_MAX) { // if var in table + if (mdl->contextRowNr >= valueArray.size()) valueNeedsUpdate = true; - else if (valueArray[parentRowNr].isNull()) + else if (valueArray[mdl->contextRowNr].isNull()) valueNeedsUpdate = true; } } @@ -168,13 +177,13 @@ class SysModUI:public SysModule { if (valueNeedsUpdate) { bool valueFunExists = false; if (varFun) { - valueFunExists = varFun(var, parentRowNr, f_ValueFun); + valueFunExists = varFun(var, mdl->contextRowNr, f_ValueFun); } if (!valueFunExists) { //setValue provided (if not null) if (mdl->varRO(var) && !mdls->isConnected) { - mdl->setValueNoROCheck(var, value, parentRowNr); //does changefun if needed, if var in table, update the table row + mdl->setValueNoROCheck(var, value, mdl->contextRowNr); //does changefun if needed, if var in table, update the table row } else - mdl->setValue(var, value, parentRowNr); //does changefun if needed, if var in table, update the table row + mdl->setValue(var, value, mdl->contextRowNr); //does changefun if needed, if var in table, update the table row } } else { //do changeFun on existing value @@ -196,9 +205,6 @@ class SysModUI:public SysModule { } } - if (parentRowNr != UINT8_MAX) - print->printJson("gravity var", web->getResponseObject()); - return var; } diff --git a/src/Sys/SysJsonRDWS.h b/src/Sys/SysStarModJson.h similarity index 92% rename from src/Sys/SysJsonRDWS.h rename to src/Sys/SysStarModJson.h index 86267d8b..449243a1 100644 --- a/src/Sys/SysJsonRDWS.h +++ b/src/Sys/SysStarModJson.h @@ -1,6 +1,6 @@ /* @title StarMod - @file SysJsonRDWS.h + @file SysStarModJson.h @date 20240114 @repo https://github.com/ewowi/StarMod @Authors https://github.com/ewowi/StarMod/commits/main @@ -12,19 +12,19 @@ //Lazy Json Read Deserialize Write Serialize (write / serialize not implemented yet) //ArduinoJson won't work on very large fixture.json, this does //only support what is currently needed: read / deserialize uint8/16/char var elements (arrays not yet) -class JsonRDWS { +class StarModJson { public: - JsonRDWS(const char * path, const char * mode = "r") { - USER_PRINTF("JsonRDWS constructing %s %s\n", path, mode); + StarModJson(const char * path, const char * mode = "r") { + USER_PRINTF("StarModJson constructing %s %s\n", path, mode); f = files->open(path, mode); if (!f) - USER_PRINTF("JsonRDWS open %s for %s failed", path, mode); + USER_PRINTF("StarModJson open %s for %s failed", path, mode); } - ~JsonRDWS() { - USER_PRINTF("JsonRDWS destructing\n"); + ~StarModJson() { + USER_PRINTF("StarModJson destructing\n"); f.close(); } @@ -71,9 +71,9 @@ class JsonRDWS { while (f.available() && (!foundAll || !lazy)) next(); if (foundAll) - USER_PRINTF("JsonRDWS found all what it was looking for %d >= %d\n", foundCounter, varDetails.size()); + USER_PRINTF("StarModJson found all what it was looking for %d >= %d\n", foundCounter, varDetails.size()); else - USER_PRINTF("JsonRDWS Not all vars looked for where found %d < %d\n", foundCounter, varDetails.size()); + USER_PRINTF("StarModJson Not all vars looked for where found %d < %d\n", foundCounter, varDetails.size()); f.close(); return foundAll; } @@ -221,7 +221,7 @@ class JsonRDWS { for (std::vector::iterator vd=varDetails.begin(); vd!=varDetails.end(); ++vd) { // USER_PRINTF("check %s %s %s\n", vd->id, varId, value); if (strcmp(vd->id, varId)==0) { - // USER_PRINTF("JsonRDWS found %s:%s %d %s %d %d\n", varId, vd->type, vd->index, value?value:"", uint16CollectList.size(), funList.size()); + // USER_PRINTF("StarModJson found %s:%s %d %s %d %d\n", varId, vd->type, vd->index, value?value:"", uint16CollectList.size(), funList.size()); if (strcmp(vd->type, "uint8") ==0 && value) *uint8List[vd->index] = atoi(value); if (strcmp(vd->type, "uint16") ==0 && value) *uint16List[vd->index] = atoi(value); if (strcmp(vd->type, "char") ==0 && value) strncpy(charList[vd->index], value, 31); //assuming size 32-1 here @@ -278,7 +278,7 @@ class JsonRDWS { f.print("null"); } else - USER_PRINTF("dev JsonRDWS write %s not supported\n", variant.as().c_str()); + USER_PRINTF("dev StarModJson write %s not supported\n", variant.as().c_str()); } }; \ No newline at end of file diff --git a/src/testOutput.txt b/src/testOutput.txt index d8294b30..4b0dc4b9 100644 --- a/src/testOutput.txt +++ b/src/testOutput.txt @@ -133,10 +133,10 @@ initVarAndUpdate valueFun mdlSuccess count:17 setValue var mdlSuccess[0] value null not array, creating initVarAndUpdate chFun init mdlEnabled v:[true,true,true,true,true,true,true,true,true,false,false,true,true,true,true,true,true] seqNrToName: 2DMatrix3232.json 9640 -JsonRDWS constructing /2DMatrix3232.json r +StarModJson constructing /2DMatrix3232.json r pins 16: 0-1023 allocatePin 16 Leds 0-1023 -JsonRDWS found all what it was looking for 1030 >= 6 +StarModJson found all what it was looking for 1030 >= 6 projectAndMap P:32x32x1 V:15x15x1 and P:1024 V:225 Coord3D toJson 15,15,1 -> {"x":15,"y":15,"z":1} setValue changed fxSize ->{"x":15,"y":15,"z":1} @@ -146,7 +146,7 @@ Coord3D toJson 32,32,1 -> {"x":32,"y":32,"z":1} setValue changed fixSize ->{"x":32,"y":32,"z":1} callChangeFun fixSize unknown type for {"x":32,"y":32,"z":1} setValue changed fixCount ->1024 -JsonRDWS destructing +StarModJson destructing FastLED.addLeds new 16: 0-1024 lastReconnectAttempt == 0 Access point disabled (init).