diff --git a/src/App/LedFixture.cpp b/src/App/LedFixture.cpp index da7571a4..faada4bb 100644 --- a/src/App/LedFixture.cpp +++ b/src/App/LedFixture.cpp @@ -86,6 +86,7 @@ void Fixture::projectAndMap() { //set start and endPos between bounderies of fixture Coord3D startPosAdjusted = (leds->startPos).minimum(fixSize - Coord3D{1,1,1}) * 10; Coord3D endPosAdjusted = (leds->endPos).minimum(fixSize - Coord3D{1,1,1}) * 10; + Coord3D midPosAdjusted = (leds->midPos).minimum(fixSize - Coord3D{1,1,1}); //not * 10 // mdl->setValue("fxStart", startPosAdjusted/10, rowNr); //rowNr // mdl->setValue("fxEnd", endPosAdjusted/10, rowNr); //rowNr @@ -108,9 +109,7 @@ void Fixture::projectAndMap() { mdl->getValueRowNr = rowNr; //run projection functions in the right rowNr context - Coord3D proCenter = mdl->getValue("proCenter", rowNr); - - if (projection) projection->adjustSizeAndPixel(sizeAdjusted, pixelAdjusted, proCenter); + if (projection) projection->adjustSizeAndPixel(sizeAdjusted, pixelAdjusted, midPosAdjusted); if (leds->size == Coord3D{0,0,0}) { // first ppf("projectAndMap first leds[%d] size:%d,%d,%d s:%d,%d,%d e:%d,%d,%d\n", rowNr, sizeAdjusted.x, sizeAdjusted.y, sizeAdjusted.z, startPosAdjusted.x, startPosAdjusted.y, startPosAdjusted.z, endPosAdjusted.x, endPosAdjusted.y, endPosAdjusted.z); @@ -123,7 +122,7 @@ void Fixture::projectAndMap() { switch (leds->effectDimension) { case _1D: //effectDimension 1DxD if (leds->size == Coord3D{0,0,0}) { // first - leds->size.x = sizeAdjusted.distance(proCenter); + leds->size.x = sizeAdjusted.distance(midPosAdjusted); leds->size.y = 1; leds->size.z = 1; } @@ -132,7 +131,7 @@ void Fixture::projectAndMap() { if (projection) projection->adjustMapped(mapped, sizeAdjusted, (pixel - startPosAdjusted)/10); - mapped.x = mapped.distance(proCenter); + mapped.x = mapped.distance(midPosAdjusted); mapped.y = 0; mapped.z = 0; diff --git a/src/App/LedFixture.h b/src/App/LedFixture.h index 9704ee85..9718f9f7 100644 --- a/src/App/LedFixture.h +++ b/src/App/LedFixture.h @@ -30,7 +30,7 @@ class Projection { virtual const char * tags() {return "";} // virtual uint8_t dim() {return _1D;}; - virtual void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &proCenter) {} + virtual void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) {} virtual void adjustMapped(Coord3D &mapped, Coord3D sizeAdjusted, Coord3D pixelAdjusted) {} diff --git a/src/App/LedLeds.h b/src/App/LedLeds.h index a585b927..8d01cbe3 100644 --- a/src/App/LedLeds.h +++ b/src/App/LedLeds.h @@ -271,6 +271,7 @@ class Leds { unsigned8 projectionDimension = -1; Coord3D startPos = {0,0,0}, endPos = {UINT16_MAX,UINT16_MAX,UINT16_MAX}; //default + Coord3D midPos = {0,0,0}; #ifdef STARBASE_USERMOD_MPU6050 bool proGyro = false; #endif diff --git a/src/App/LedModEffects.h b/src/App/LedModEffects.h index 875a263d..5b87b755 100644 --- a/src/App/LedModEffects.h +++ b/src/App/LedModEffects.h @@ -288,6 +288,34 @@ class LedModEffects:public SysModule { default: return false; }}); + ui->initCoord3D(tableVar, "fxMiddle", {0,0,0}, 0, NUM_LEDS_Max, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + case onSetValue: + for (forUnsigned8 rowNr = 0; rowNr < fixture.listOfLeds.size(); rowNr++) { + ppf("fxMiddle[%d] onSetValue %d,%d,%d\n", rowNr, fixture.listOfLeds[rowNr]->midPos.x, fixture.listOfLeds[rowNr]->midPos.y, fixture.listOfLeds[rowNr]->midPos.z); + mdl->setValue(var, fixture.listOfLeds[rowNr]->midPos, rowNr); + } + return true; + case onUI: + ui->setLabel(var, "Middle"); + ui->setComment(var, "In pixels"); + return true; + case onChange: + if (rowNr < fixture.listOfLeds.size()) { + fixture.listOfLeds[rowNr]->midPos = mdl->getValue(var, rowNr).as(); + + ppf("fxStart[%d] chFun %d,%d,%d\n", rowNr, fixture.listOfLeds[rowNr]->midPos.x, fixture.listOfLeds[rowNr]->midPos.y, fixture.listOfLeds[rowNr]->midPos.z); + + fixture.listOfLeds[rowNr]->fadeToBlackBy(); + fixture.listOfLeds[rowNr]->doMap = true; + fixture.doMap = true; + } + else { + ppf("fxStart[%d] chfun rownr not in range > %d\n", rowNr, fixture.listOfLeds.size()); + } + return true; + default: return false; + }}); + ui->initCoord3D(tableVar, "fxEnd", {8,8,0}, 0, NUM_LEDS_Max, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun case onSetValue: for (forUnsigned8 rowNr = 0; rowNr < fixture.listOfLeds.size(); rowNr++) { @@ -444,7 +472,7 @@ class LedModEffects:public SysModule { token = strtok(NULL, ","); if (token != NULL) newCoord->z = atoi(token) / 10; else newCoord->z = 0; - mdl->setValue(isStart?"fxStart":isEnd?"fxEnd":"proCenter", *newCoord, 0); //assuming row 0 for the moment + mdl->setValue(isStart?"fxStart":isEnd?"fxEnd":"fxMiddle", *newCoord, 0); //assuming row 0 for the moment fixture.listOfLeds[rowNr]->doMap = true; //recalc projection fixture.doMap = true; diff --git a/src/App/LedProjections.h b/src/App/LedProjections.h index e043023b..812cf1be 100644 --- a/src/App/LedProjections.h +++ b/src/App/LedProjections.h @@ -35,11 +35,11 @@ class MultiplyProjection: public Projection { public: //to use in Preset1Projection - void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &proCenter) { + void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { Coord3D proMulti = mdl->getValue("proMulti"); //, rowNr //promulti can be 0,0,0 but /= protects from /div0 sizeAdjusted /= proMulti; sizeAdjusted = sizeAdjusted.maximum(Coord3D{1,1,1}); //size min 1,1,1 - proCenter /= proMulti; + midPosAdjusted /= proMulti; pixelAdjusted = pixelAdjusted%sizeAdjusted; // pixel % size // ppf("Multiply %d,%d,%d\n", leds->size.x, leds->size.y, leds->size.z); } @@ -151,21 +151,21 @@ class DistanceFromPointProjection: public Projection { public: //to use in Preset1Projection void controls(Leds &leds, JsonObject parentVar) { - ui->initCoord3D(parentVar, "proCenter", {8,8,8}, 0, NUM_LEDS_Max, false, [&leds](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun - case onUI: - ui->setLabel(var, "Center"); - return true; - case onChange: - //initiate projectAndMap - ppf("proCenter %d %d\n", rowNr, leds.fixture->listOfLeds.size()); - if (rowNr < leds.fixture->listOfLeds.size()) { - leds.fixture->listOfLeds[rowNr]->doMap = true; //Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled. - leds.fixture->doMap = true; - } - // ui->setLabel(var, "Size"); - return true; - default: return false; - }}); + // ui->initCoord3D(parentVar, "proCenter", {8,8,8}, 0, NUM_LEDS_Max, false, [&leds](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + // case onUI: + // ui->setLabel(var, "Center"); + // return true; + // case onChange: + // //initiate projectAndMap + // ppf("proCenter %d %d\n", rowNr, leds.fixture->listOfLeds.size()); + // if (rowNr < leds.fixture->listOfLeds.size()) { + // leds.fixture->listOfLeds[rowNr]->doMap = true; //Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled. + // leds.fixture->doMap = true; + // } + // // ui->setLabel(var, "Size"); + // return true; + // default: return false; + // }}); } }; //DistanceFromPointProjection @@ -174,9 +174,9 @@ class Preset1Projection: public Projection { //uint8_t dim() {return _1D;} // every projection should work for all D const char * tags() {return "💫";} - void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &proCenter) { + void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { MultiplyProjection mp; - mp.adjustSizeAndPixel(sizeAdjusted, pixelAdjusted, proCenter); + mp.adjustSizeAndPixel(sizeAdjusted, pixelAdjusted, midPosAdjusted); } void adjustMapped(Coord3D &mapped, Coord3D sizeAdjusted, Coord3D pixelAdjusted) { @@ -259,7 +259,7 @@ class PinwheelProjection: public Projection { const char * name() {return "Pinwheel WIP";} const char * tags() {return "💡";} - void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &proCenter) { + void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { sizeAdjusted.x = mdl->getValue("Petals"); sizeAdjusted.y = 1; sizeAdjusted.z = 1;