From e90be757f254ec4bae362174d56c7bc604ed3681 Mon Sep 17 00:00:00 2001 From: Ewoud Date: Sat, 16 Mar 2024 09:54:27 +0100 Subject: [PATCH] Tune DNA effect, add phases, same on different sizes, use Speed_Flags pio.ini: set Speed_Flags LedEffects: tune DNA LedFixture and LedLeds and LedModEffects - rename ledsList with projections - replace auto with PhysMap - add mirrors (WIP) SysModModel: Coord3D/= : protect for /div0 --- platformio.ini | 23 ++++----- src/App/LedEffects.h | 16 +++++-- src/App/LedFixture.cpp | 35 +++++++++----- src/App/LedFixture.h | 2 +- src/App/LedLeds.cpp | 6 +-- src/App/LedLeds.h | 2 +- src/App/LedModEffects.h | 102 ++++++++++++++++++++-------------------- src/App/LedModFixture.h | 6 +-- src/Sys/SysModModel.h | 6 +-- 9 files changed, 108 insertions(+), 90 deletions(-) diff --git a/platformio.ini b/platformio.ini index 7dde1f7e..a570cf71 100644 --- a/platformio.ini +++ b/platformio.ini @@ -72,6 +72,15 @@ lib_deps = https://github.com/netmindz/WLED-sync#48cb28f11632b217f9ccd9f72149373919c28af5 ; sourceIP +[Speed_Flags] +build_flags = + -O2 ;; optimize for performance instead of size + ;-ffast-math ;; gives a few (2-5) percent speedup on ESP32-S3, but causes slight slowdown on classic ESP32 + -mtarget-align -free -fipa-pta ;; these are very useful, too + -fno-jump-tables -fno-tree-switch-conversion ;; needed + -freorder-blocks -Wwrite-strings -fstrict-volatile-bitfields ;; needed +build_unflags = + -Os ;; to disable standard optimization for size [env] framework = arduino @@ -81,8 +90,11 @@ board_build.partitions = tools/WLED_ESP32_4MB_256KB_FS.csv ;; 1.8MB firmware, board_build.filesystem = littlefs board_build.f_flash = 80000000L ; use full 80MHz speed for flash (default = 40Mhz) - this is a fixed override from the board specs applicable for all env!!! board_build.flash_mode = dio ; (dio = dual i/o; more compatible than qio = quad i/o) +build_unflags = + ${Speed_Flags.build_unflags} build_flags = ${starmod.build_flags} + ${Speed_Flags.build_flags} -DCONFIG_ASYNC_TCP_USE_WDT=0 -DLFS_THREADSAFE ;; enables use of semaphores in LittleFS driver ${STARMOD_APPMOD_LEDS.build_flags} @@ -96,16 +108,6 @@ lib_deps = ; ${STARMOD_USERMOD_HA.lib_deps} ${STARMOD_USERMOD_WLEDAUDIO.lib_deps} -[Speed_Flags] -build_flags = - -O2 ;; optimize for performance instead of size - ;-ffast-math ;; gives a few (2-5) percent speedup on ESP32-S3, but causes slight slowdown on classic ESP32 - -mtarget-align -free -fipa-pta ;; these are very useful, too - -fno-jump-tables -fno-tree-switch-conversion ;; needed - -freorder-blocks -Wwrite-strings -fstrict-volatile-bitfields ;; needed -build_unflags = - -Os ;; to disable standard optimization for size - [env:esp32dev] board = esp32dev ;https://github.com/platformio/platform-espressif32/blob/develop/boards/esp32dev.json @@ -114,7 +116,6 @@ platform = espressif32@6.5.0 ;using platformio/framework-arduinoespressif32 @ ~3 upload_speed = 1500000 build_flags = ${env.build_flags} - ; ${Speed_Flags.build_flags} -DCONFIG_IDF_TARGET_ESP32=1 -DARDUINO_USB_CDC_ON_BOOT=0 ;; Make sure that the right HardwareSerial driver is picked in arduino-esp32 (needed on "classic ESP32") diff --git a/src/App/LedEffects.h b/src/App/LedEffects.h index a967403a..5562a379 100644 --- a/src/App/LedEffects.h +++ b/src/App/LedEffects.h @@ -879,28 +879,34 @@ class Lines: public Effect { class DNA: public Effect { const char * name() {return "DNA";} unsigned8 dim() {return _2D;} - const char * tags() {return "💡";} + const char * tags() {return "💡💫";} void loop(Leds &leds) { - CRGBPalette16 pal = getPalette(); stackUnsigned8 speed = mdl->getValue("speed"); stackUnsigned8 blur = mdl->getValue("blur"); + stackUnsigned8 phases = mdl->getValue("phases"); leds.fadeToBlackBy(64); for (int i = 0; i < leds.size.x; i++) { - leds.setPixelColor(leds.XY(i, beatsin8(speed, 0, leds.size.y-1, 0, i*4 )), ColorFromPalette(pal, i*5+now/17, beatsin8(5, 55, 255, 0, i*10), LINEARBLEND)); - leds.setPixelColor(leds.XY(i, beatsin8(speed, 0, leds.size.y-1, 0, i*4+128)), ColorFromPalette(pal, i*5+128+now/17, beatsin8(5, 55, 255, 0, i*10+128), LINEARBLEND)); + //256 is a complete phase + // half a phase is dna is 128 + uint8_t phase = leds.size.x * i / 8; + //32: 4 * i + //16: 8 * i + phase = i * 127 / (leds.size.x-1) * phases / 64; + leds.setPixelColor(leds.XY(i, beatsin8(speed, 0, leds.size.y-1, 0, phase )), ColorFromPalette(pal, i*5+now/17, beatsin8(5, 55, 255, 0, i*10), LINEARBLEND)); + leds.setPixelColor(leds.XY(i, beatsin8(speed, 0, leds.size.y-1, 0, phase+128)), ColorFromPalette(pal, i*5+128+now/17, beatsin8(5, 55, 255, 0, i*10+128), LINEARBLEND)); } leds.blur2d(blur); - } void controls(JsonObject parentVar) { addPalette(parentVar, 4); ui->initSlider(parentVar, "speed", 16, 0, 32); ui->initSlider(parentVar, "blur", 128); + ui->initSlider(parentVar, "phases", 64); } }; // DNA diff --git a/src/App/LedFixture.cpp b/src/App/LedFixture.cpp index a335960b..900dee65 100644 --- a/src/App/LedFixture.cpp +++ b/src/App/LedFixture.cpp @@ -25,14 +25,14 @@ void Fixture::projectAndMap() { // reset leds stackUnsigned8 rowNr = 0; - for (Leds *leds: ledsList) { + for (Leds *leds: projections) { if (leds->doMap) { leds->fill_solid(CRGB::Black, true); //no blend - USER_PRINTF("Leds pre [%d] f:%d p:%d s:%d\n", rowNr, leds->fx, leds->projectionNr, ledsList.size()); + USER_PRINTF("Leds pre [%d] f:%d p:%d s:%d\n", rowNr, leds->fx, leds->projectionNr, projections.size()); leds->size = Coord3D{0,0,0}; //vectors really gone now? - for (auto map:leds->mappingTable) { + for (PhysMap &map:leds->mappingTable) { if (map.indexes) { map.indexes->clear(); delete map.indexes; @@ -78,7 +78,7 @@ void Fixture::projectAndMap() { // USER_PRINTF("led %d,%d,%d start %d,%d,%d end %d,%d,%d\n",x,y,z, startPos.x, startPos.y, startPos.z, endPos.x, endPos.y, endPos.z); stackUnsigned8 rowNr = 0; - for (Leds *leds: ledsList) { + for (Leds *leds: projections) { if (leds->doMap) { //add pixel in leds mappingtable //set start and endPos between bounderies of fixture @@ -107,12 +107,15 @@ void Fixture::projectAndMap() { else proCenter = Coord3D{0,0,0}; + Coord3D mirrors = Coord3D{0,0,0}; // no mirrors if (leds->projectionNr == p_Multiply || leds->projectionNr == p_Preset1) { Coord3D proMulti; proMulti = mdl->getValue("proMulti", rowNr); + //promultu 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; - pixelAdjusted = pixelAdjusted%sizeAdjusted; + mirrors = pixelAdjusted / sizeAdjusted; + pixelAdjusted = pixelAdjusted%sizeAdjusted; // pixel % size // USER_PRINTF("Multiply %d,%d,%d\n", leds->size.x, leds->size.y, leds->size.z); } @@ -127,7 +130,7 @@ void Fixture::projectAndMap() { Coord3D mapped; switch (leds->effectDimension) { - case _1D: //1DxD + case _1D: //effectDimension 1DxD if (leds->size == Coord3D{0,0,0}) { // first leds->size.x = sizeAdjusted.distance(proCenter); leds->size.y = 1; @@ -138,6 +141,11 @@ void Fixture::projectAndMap() { mapped.y = 0; mapped.z = 0; + //reversed + if (mirrors.x %2 != 0) mapped.x = leds->size.x - 1 - mapped.x; // x mirrored + if (mirrors.y %2 != 0) mapped.y = leds->size.y - 1 - mapped.y; // y mirrored + if (mirrors.z %2 != 0) mapped.z = leds->size.z - 1 - mapped.z; // z mirrored + indexV = leds->XYZNoSpin(mapped); break; case _2D: //effectDimension @@ -148,12 +156,15 @@ void Fixture::projectAndMap() { leds->size.y = sizeAdjusted.x * sizeAdjusted.y * sizeAdjusted.z / leds->size.x; leds->size.z = 1; } - mapped.x = (pixelAdjusted.x + pixelAdjusted.y + pixelAdjusted.z) % leds->size.x; - mapped.y = (pixelAdjusted.x + pixelAdjusted.y + pixelAdjusted.z) / leds->size.x; + mapped.x = (pixelAdjusted.x + pixelAdjusted.y + pixelAdjusted.z) % leds->size.x; // only one > 0 + mapped.y = (pixelAdjusted.x + pixelAdjusted.y + pixelAdjusted.z) / leds->size.x; // all rows next to each other mapped.z = 0; + if (mirrors.x %2 != 0) mapped.x = leds->size.x - 1 - mapped.x; // x mirrored + if (mirrors.y %2 != 0) mapped.y = leds->size.y - 1 - mapped.y; // y mirrored indexV = leds->XYZNoSpin(mapped); break; case _2D: //2D2D + //find the 2 axis if (leds->size == Coord3D{0,0,0}) { // first if (sizeAdjusted.x > 1) { leds->size.x = sizeAdjusted.x; @@ -304,7 +315,7 @@ void Fixture::projectAndMap() { } //if x,y,z between start and endpos } //leds->doMap rowNr++; - } //ledsList + } //projections indexP++; //also increase if no buffer created } //if 1D-3D pixel else { // end of leds array @@ -346,9 +357,9 @@ void Fixture::projectAndMap() { //after processing each led stackUnsigned8 rowNr = 0; - for (Leds *leds: ledsList) { + for (Leds *leds: projections) { if (leds->doMap) { - USER_PRINTF("Leds pre [%d] f:%d p:%d s:%d\n", rowNr, leds->fx, leds->projectionNr, ledsList.size()); + USER_PRINTF("Leds pre [%d] f:%d p:%d s:%d\n", rowNr, leds->fx, leds->projectionNr, projections.size()); stackUnsigned16 nrOfMappings = 0; stackUnsigned16 nrOfPixels = 0; @@ -373,7 +384,7 @@ void Fixture::projectAndMap() { //debug info + summary values stackUnsigned16 indexV = 0; - for (auto map:leds->mappingTable) { + for (PhysMap &map:leds->mappingTable) { if (map.indexes && map.indexes->size()) { // if (nrOfMappings < 10 || map.indexes->size() - indexV < 10) //first 10 and last 10 // if (nrOfMappings%(leds->nrOfLeds/10+1) == 0) diff --git a/src/App/LedFixture.h b/src/App/LedFixture.h index 11da9863..d5648147 100644 --- a/src/App/LedFixture.h +++ b/src/App/LedFixture.h @@ -43,7 +43,7 @@ class Fixture { unsigned8 fixtureNr = -1; Coord3D size = {8,8,1}; - std::vector ledsList; //virtual leds + std::vector projections; //virtual leds Coord3D head = {0,0,0}; diff --git a/src/App/LedLeds.cpp b/src/App/LedLeds.cpp index 7dca1c24..42c3a89a 100644 --- a/src/App/LedLeds.cpp +++ b/src/App/LedLeds.cpp @@ -59,7 +59,7 @@ void Leds::fadeToBlackBy(unsigned8 fadeBy) { if (projectionNr == p_None || projectionNr == p_Random) { fastled_fadeToBlackBy(fixture->ledsP, fixture->nrOfLeds, fadeBy); } else { - for (auto map:mappingTable) { + for (PhysMap &map:mappingTable) { if (map.indexes) for (forUnsigned16 indexP:*map.indexes) { CRGB oldValue = fixture->ledsP[indexP]; @@ -74,7 +74,7 @@ void Leds::fill_solid(const struct CRGB& color, bool noBlend) { if (projectionNr == p_None || projectionNr == p_Random) { fastled_fill_solid(fixture->ledsP, fixture->nrOfLeds, color); } else { - for (auto map:mappingTable) { + for (PhysMap &map:mappingTable) { if (map.indexes) for (forUnsigned16 indexP:*map.indexes) { fixture->ledsP[indexP] = noBlend?color:blend(color, fixture->ledsP[indexP], fixture->globalBlend); @@ -92,7 +92,7 @@ void Leds::fill_rainbow(unsigned8 initialhue, unsigned8 deltahue) { hsv.val = 255; hsv.sat = 240; - for (auto map:mappingTable) { + for (PhysMap &map:mappingTable) { if (map.indexes) for (forUnsigned16 indexP:*map.indexes) { fixture->ledsP[indexP] = blend(hsv, fixture->ledsP[indexP], fixture->globalBlend); diff --git a/src/App/LedLeds.h b/src/App/LedLeds.h index 6feb210c..93c997c3 100644 --- a/src/App/LedLeds.h +++ b/src/App/LedLeds.h @@ -195,7 +195,7 @@ class Leds { USER_PRINTF("Leds[%d] destructor\n", UINT8_MAX); fadeToBlackBy(100); doMap = true; // so loop is not running while deleting - for (auto map:mappingTable) { + for (PhysMap &map:mappingTable) { if (map.indexes) { map.indexes->clear(); delete map.indexes; diff --git a/src/App/LedModEffects.h b/src/App/LedModEffects.h index e56d97a0..edaacec0 100644 --- a/src/App/LedModEffects.h +++ b/src/App/LedModEffects.h @@ -65,21 +65,21 @@ class LedModEffects:public SysModule { ui->setComment(var, "List of effects"); return true; case f_AddRow: { - rowNr = fixture.ledsList.size(); + rowNr = fixture.projections.size(); USER_PRINTF("chFun addRow %s[%d]\n", mdl->varID(var), rowNr); web->getResponseObject()["addRow"]["rowNr"] = rowNr; - if (rowNr >= fixture.ledsList.size()) - fixture.ledsList.push_back(new Leds(fixture)); + if (rowNr >= fixture.projections.size()) + fixture.projections.push_back(new Leds(fixture)); return true; } case f_DelRow: { USER_PRINTF("chFun delrow %s[%d]\n", mdl->varID(var), rowNr); //tbd: fade to black - if (rowNr initSelect(tableVar, "fx", 0, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun case f_ValueFun: - for (forUnsigned8 rowNr = 0; rowNr < fixture.ledsList.size(); rowNr++) - mdl->setValue(var, fixture.ledsList[rowNr]->fx, rowNr); + for (forUnsigned8 rowNr = 0; rowNr < fixture.projections.size(); rowNr++) + mdl->setValue(var, fixture.projections[rowNr]->fx, rowNr); return true; case f_UIFun: { ui->setLabel(var, "Effect"); @@ -111,12 +111,12 @@ class LedModEffects:public SysModule { if (rowNr == UINT8_MAX) rowNr = 0; // in case fx without a rowNr //create a new leds instance if a new row is created - if (rowNr >= fixture.ledsList.size()) { - USER_PRINTF("ledslist fx[%d] changeFun %d %s\n", rowNr, fixture.ledsList.size(), mdl->findVar("fx")["value"].as().c_str()); - fixture.ledsList.push_back(new Leds(fixture)); + if (rowNr >= fixture.projections.size()) { + USER_PRINTF("projections fx[%d] changeFun %d %s\n", rowNr, fixture.projections.size(), mdl->findVar("fx")["value"].as().c_str()); + fixture.projections.push_back(new Leds(fixture)); } - if (rowNr < fixture.ledsList.size()) - effects.setEffect(*fixture.ledsList[rowNr], var, rowNr); + if (rowNr < fixture.projections.size()) + effects.setEffect(*fixture.projections[rowNr], var, rowNr); return true; default: return false; }}); @@ -124,8 +124,8 @@ class LedModEffects:public SysModule { currentVar = ui->initSelect(tableVar, "pro", 2, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun case f_ValueFun: - for (forUnsigned8 rowNr = 0; rowNr < fixture.ledsList.size(); rowNr++) - mdl->setValue(var, fixture.ledsList[rowNr]->projectionNr, rowNr); + for (forUnsigned8 rowNr = 0; rowNr < fixture.projections.size(); rowNr++) + mdl->setValue(var, fixture.projections[rowNr]->projectionNr, rowNr); return true; case f_UIFun: { ui->setLabel(var, "Projection"); @@ -147,11 +147,11 @@ class LedModEffects:public SysModule { if (rowNr == UINT8_MAX) rowNr = 0; // in case fx without a rowNr - if (rowNr < fixture.ledsList.size()) { - fixture.ledsList[rowNr]->doMap = true; + if (rowNr < fixture.projections.size()) { + fixture.projections[rowNr]->doMap = true; stackUnsigned8 proValue = mdl->getValue(var, rowNr); - fixture.ledsList[rowNr]->projectionNr = proValue; + fixture.projections[rowNr]->projectionNr = proValue; mdl->varPreDetails(var, rowNr); //set all positive var N orders to negative if (proValue == p_DistanceFromPoint || proValue == p_Preset1) { @@ -161,7 +161,7 @@ class LedModEffects:public SysModule { return true; case f_ChangeFun: //initiate projectAndMap - fixture.ledsList[rowNr]->doMap = true; + fixture.projections[rowNr]->doMap = true; fixture.doMap = true; // ui->setLabel(var, "Size"); return true; @@ -174,7 +174,7 @@ class LedModEffects:public SysModule { ui->setLabel(var, "Multiply"); return true; case f_ChangeFun: - fixture.ledsList[rowNr]->doMap = true; + fixture.projections[rowNr]->doMap = true; fixture.doMap = true; return true; default: return false; @@ -186,14 +186,14 @@ class LedModEffects:public SysModule { ui->setLabel(var, "Rotation speed"); return true; case f_ChangeFun: - fixture.ledsList[rowNr]->proRSpeed = mdl->getValue(var, rowNr); + fixture.projections[rowNr]->proRSpeed = mdl->getValue(var, rowNr); return true; default: return false; }}); } mdl->varPostDetails(var, rowNr); - USER_PRINTF("chFun pro[%d] <- %d (%d)\n", rowNr, proValue, fixture.ledsList.size()); + USER_PRINTF("chFun pro[%d] <- %d (%d)\n", rowNr, proValue, fixture.projections.size()); fixture.doMap = true; } @@ -204,9 +204,9 @@ class LedModEffects:public SysModule { ui->initCoord3D(tableVar, "fxStart", {0,0,0}, 0, NUM_LEDS_Max, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun case f_ValueFun: - for (forUnsigned8 rowNr = 0; rowNr < fixture.ledsList.size(); rowNr++) { - USER_PRINTF("fxStart[%d] valueFun %d,%d,%d\n", rowNr, fixture.ledsList[rowNr]->startPos.x, fixture.ledsList[rowNr]->startPos.y, fixture.ledsList[rowNr]->startPos.z); - mdl->setValue(var, fixture.ledsList[rowNr]->startPos, rowNr); + for (forUnsigned8 rowNr = 0; rowNr < fixture.projections.size(); rowNr++) { + USER_PRINTF("fxStart[%d] valueFun %d,%d,%d\n", rowNr, fixture.projections[rowNr]->startPos.x, fixture.projections[rowNr]->startPos.y, fixture.projections[rowNr]->startPos.z); + mdl->setValue(var, fixture.projections[rowNr]->startPos, rowNr); } return true; case f_UIFun: @@ -214,17 +214,17 @@ class LedModEffects:public SysModule { ui->setComment(var, "In pixels"); return true; case f_ChangeFun: - if (rowNr < fixture.ledsList.size()) { - fixture.ledsList[rowNr]->startPos = mdl->getValue(var, rowNr).as(); + if (rowNr < fixture.projections.size()) { + fixture.projections[rowNr]->startPos = mdl->getValue(var, rowNr).as(); - USER_PRINTF("fxStart[%d] chFun %d,%d,%d\n", rowNr, fixture.ledsList[rowNr]->startPos.x, fixture.ledsList[rowNr]->startPos.y, fixture.ledsList[rowNr]->startPos.z); + USER_PRINTF("fxStart[%d] chFun %d,%d,%d\n", rowNr, fixture.projections[rowNr]->startPos.x, fixture.projections[rowNr]->startPos.y, fixture.projections[rowNr]->startPos.z); - fixture.ledsList[rowNr]->fadeToBlackBy(); - fixture.ledsList[rowNr]->doMap = true; + fixture.projections[rowNr]->fadeToBlackBy(); + fixture.projections[rowNr]->doMap = true; fixture.doMap = true; } else { - USER_PRINTF("fxStart[%d] chfun rownr not in range > %d\n", rowNr, fixture.ledsList.size()); + USER_PRINTF("fxStart[%d] chfun rownr not in range > %d\n", rowNr, fixture.projections.size()); } return true; default: return false; @@ -232,9 +232,9 @@ class LedModEffects:public SysModule { ui->initCoord3D(tableVar, "fxEnd", {8,8,0}, 0, NUM_LEDS_Max, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun case f_ValueFun: - for (forUnsigned8 rowNr = 0; rowNr < fixture.ledsList.size(); rowNr++) { - USER_PRINTF("fxEnd[%d] valueFun %d,%d,%d\n", rowNr, fixture.ledsList[rowNr]->endPos.x, fixture.ledsList[rowNr]->endPos.y, fixture.ledsList[rowNr]->endPos.z); - mdl->setValue(var, fixture.ledsList[rowNr]->endPos, rowNr); + for (forUnsigned8 rowNr = 0; rowNr < fixture.projections.size(); rowNr++) { + USER_PRINTF("fxEnd[%d] valueFun %d,%d,%d\n", rowNr, fixture.projections[rowNr]->endPos.x, fixture.projections[rowNr]->endPos.y, fixture.projections[rowNr]->endPos.z); + mdl->setValue(var, fixture.projections[rowNr]->endPos, rowNr); } return true; case f_UIFun: @@ -242,17 +242,17 @@ class LedModEffects:public SysModule { ui->setComment(var, "In pixels"); return true; case f_ChangeFun: - if (rowNr < fixture.ledsList.size()) { - fixture.ledsList[rowNr]->endPos = mdl->getValue(var, rowNr).as(); + if (rowNr < fixture.projections.size()) { + fixture.projections[rowNr]->endPos = mdl->getValue(var, rowNr).as(); - USER_PRINTF("fxEnd[%d] chFun %d,%d,%d\n", rowNr, fixture.ledsList[rowNr]->endPos.x, fixture.ledsList[rowNr]->endPos.y, fixture.ledsList[rowNr]->endPos.z); + USER_PRINTF("fxEnd[%d] chFun %d,%d,%d\n", rowNr, fixture.projections[rowNr]->endPos.x, fixture.projections[rowNr]->endPos.y, fixture.projections[rowNr]->endPos.z); - fixture.ledsList[rowNr]->fadeToBlackBy(); - fixture.ledsList[rowNr]->doMap = true; + fixture.projections[rowNr]->fadeToBlackBy(); + fixture.projections[rowNr]->doMap = true; fixture.doMap = true; } else { - USER_PRINTF("fxEnd[%d] chfun rownr not in range > %d\n", rowNr, fixture.ledsList.size()); + USER_PRINTF("fxEnd[%d] chfun rownr not in range > %d\n", rowNr, fixture.projections.size()); } return true; default: return false; @@ -260,12 +260,12 @@ class LedModEffects:public SysModule { ui->initText(tableVar, "fxSize", nullptr, 32, true, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun case f_ValueFun: { - // for (std::vector::iterator leds=fixture.ledsList.begin(); leds!=fixture.ledsList.end(); ++leds) { + // for (std::vector::iterator leds=fixture.projections.begin(); leds!=fixture.projections.end(); ++leds) { stackUnsigned8 rowNr = 0; - for (Leds *leds: fixture.ledsList) { + for (Leds *leds: fixture.projections) { 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](of %d) = %s\n", rowNr, fixture.ledsList.size(), message); + USER_PRINTF("valueFun fxSize[%d](of %d) = %s\n", rowNr, fixture.projections.size(), message); mdl->setValue(var, JsonString(message, JsonString::Copied), rowNr); //rowNr rowNr++; } @@ -333,9 +333,9 @@ class LedModEffects:public SysModule { //for each programmed effect // run the next frame of the effect // vector iteration on classes is faster!!! (22 vs 30 fps !!!!) - // for (std::vector::iterator leds=fixture.ledsList.begin(); leds!=fixture.ledsList.end(); ++leds) { + // for (std::vector::iterator leds=fixture.projections.begin(); leds!=fixture.projections.end(); ++leds) { stackUnsigned8 rowNr = 0; - for (Leds *leds: fixture.ledsList) { + for (Leds *leds: fixture.projections) { if (!leds->doMap) { // don't run effect while remapping // 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 = rowNr++; @@ -368,9 +368,9 @@ class LedModEffects:public SysModule { const char * canvasData = var["canvasData"]; //0 - 494 - 140,150,0 USER_PRINTF("LedModEffects loop canvasData %s\n", canvasData); - //currently only leds[0] supported - if (fixture.ledsList.size()) { - fixture.ledsList[0]->fadeToBlackBy(); + uint8_t rowNr = 0; //currently only leds[0] supported + if (fixture.projections.size()) { + fixture.projections[rowNr]->fadeToBlackBy(); char * token = strtok((char *)canvasData, ":"); bool isStart = strcmp(token, "start") == 0; @@ -378,7 +378,7 @@ class LedModEffects:public SysModule { Coord3D midCoord; //placeHolder for mid - Coord3D *newCoord = isStart? &fixture.ledsList[0]->startPos: isEnd? &fixture.ledsList[0]->endPos : &midCoord; + Coord3D *newCoord = isStart? &fixture.projections[rowNr]->startPos: isEnd? &fixture.projections[rowNr]->endPos : &midCoord; if (newCoord) { token = strtok(NULL, ","); @@ -390,7 +390,7 @@ class LedModEffects:public SysModule { mdl->setValue(isStart?"fxStart":isEnd?"fxEnd":"proCenter", *newCoord, 0); //assuming row 0 for the moment - fixture.ledsList[0]->doMap = true; //recalc projection + fixture.projections[rowNr]->doMap = true; //recalc projection fixture.doMap = true; } @@ -410,7 +410,7 @@ class LedModEffects:public SysModule { if (fixture.doAllocPins) { unsigned pinNr = 0; - for (PinObject pinObject:pins->pinObjects) { + for (PinObject &pinObject:pins->pinObjects) { if (pins->isOwner(pinNr, "Leds")) { //if pin owned by leds, (assigned in projectAndMap) //dirty trick to decode nrOfLedsPerPin diff --git a/src/App/LedModFixture.h b/src/App/LedModFixture.h index a1f891ab..4adf4010 100644 --- a/src/App/LedModFixture.h +++ b/src/App/LedModFixture.h @@ -57,7 +57,7 @@ class LedModFixture:public SysModule { // ui->setComment(var, "Click to enlarge"); return true; case f_LoopFun: { - var["interval"] = max(eff->fixture.nrOfLeds * web->ws->count()/80, 16U)*10; //interval in ms * 10, not too fast //from cs to ms + var["interval"] = max(eff->fixture.nrOfLeds * web->ws->count()/200, 16U)*10; //interval in ms * 10, not too fast //from cs to ms web->sendDataWs([this](AsyncWebSocketMessageBuffer * wsBuf) { byte* buffer; @@ -104,8 +104,8 @@ class LedModFixture:public SysModule { eff->fixture.doAllocPins = true; //remap all leds - // for (std::vector::iterator leds=eff->fixture.ledsList.begin(); leds!=eff->fixture.ledsList.end(); ++leds) { - for (Leds *leds: eff->fixture.ledsList) { + // for (std::vector::iterator leds=eff->fixture.projections.begin(); leds!=eff->fixture.projections.end(); ++leds) { + for (Leds *leds: eff->fixture.projections) { leds->doMap = true; } diff --git a/src/Sys/SysModModel.h b/src/Sys/SysModModel.h index eb68fafa..269c8810 100644 --- a/src/Sys/SysModModel.h +++ b/src/Sys/SysModModel.h @@ -65,9 +65,9 @@ struct Coord3D { return *this; } Coord3D operator/=(Coord3D rhs) { - x /= rhs.x; - y /= rhs.y; - z /= rhs.z; + if (rhs.x) x /= rhs.x; + if (rhs.y) y /= rhs.y; + if (rhs.z) z /= rhs.z; return *this; } //Minus / delta (abs)