Skip to content

Commit

Permalink
Fixture ProjectAndMap only per changed leds Object (doMap)
Browse files Browse the repository at this point in the history
AppEffects: setEffect:
- void result, fixture.doMap and leds.doMap

AppFixture && AppModFixture: projectAndMap
- check on leds->doMap

SysModModel:
- add operator+, absx, *, /
  • Loading branch information
ewowi committed Feb 18, 2024
1 parent 6f82e44 commit bc35ad5
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 59 deletions.
57 changes: 57 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,60 @@ build_flags =
; .pio/libdeps/esp32dev/home-assistant-integration/src/device-types/../utils/HANumeric.h:232:18: warning: class 'HANumeric' is implicitly friends with itself
; friend class HANumeric;





;AsyncJson.h


; In file included from src/Sys/SysModWeb.cpp:22:
; .pio/libdeps/lolin_d32/ESPAsyncWebServerAircoookie/src/AsyncJson.h:86:25: warning: 'DynamicJsonDocument' is deprecated: use JsonDocument instead [-Wdeprecated-declarations]
; DynamicJsonDocument _jsonBuffer;
; ^~~~~~~~~~~
; In file included from .pio/libdeps/lolin_d32/ArduinoJson/src/ArduinoJson.hpp:53,
; from .pio/libdeps/lolin_d32/ArduinoJson/src/ArduinoJson.h:9,
; from src/SysModule.h:23,
; from src/Sys/SysModWeb.h:13,
; from src/Sys/SysModWeb.cpp:12:
; .pio/libdeps/lolin_d32/ArduinoJson/src/ArduinoJson/compatibility.hpp:125:58: note: declared here
; class ARDUINOJSON_DEPRECATED("use JsonDocument instead") DynamicJsonDocument
; ^~~~~~~~~~~~~~~~~~~
; In file included from src/Sys/SysModWeb.cpp:22:
; .pio/libdeps/lolin_d32/ESPAsyncWebServerAircoookie/src/AsyncJson.h: In constructor 'AsyncJsonResponse::AsyncJsonResponse(bool, size_t)':
; .pio/libdeps/lolin_d32/ESPAsyncWebServerAircoookie/src/AsyncJson.h:108:47: warning: 'ArduinoJson::V703PB2::JsonArray ArduinoJson::V703PB2::JsonDocument::createNestedArray()' is deprecated: use add<JsonArray>() instead [-Wdeprecated-declarations]
; _root = _jsonBuffer.createNestedArray();
; ^
; In file included from .pio/libdeps/lolin_d32/ArduinoJson/src/ArduinoJson.hpp:33,
; from .pio/libdeps/lolin_d32/ArduinoJson/src/ArduinoJson.h:9,
; from src/SysModule.h:23,
; from src/Sys/SysModWeb.h:13,
; from src/Sys/SysModWeb.cpp:12:
; .pio/libdeps/lolin_d32/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp:298:13: note: declared here
; JsonArray createNestedArray() {
; ^~~~~~~~~~~~~~~~~
; In file included from src/Sys/SysModWeb.cpp:22:
; .pio/libdeps/lolin_d32/ESPAsyncWebServerAircoookie/src/AsyncJson.h:110:48: warning: 'ArduinoJson::V703PB2::JsonObject ArduinoJson::V703PB2::JsonDocument::createNestedObject()' is deprecated: use add<JsonObject>() instead [-Wdeprecated-declarations]
; _root = _jsonBuffer.createNestedObject();
; ^
; In file included from .pio/libdeps/lolin_d32/ArduinoJson/src/ArduinoJson.hpp:33,
; from .pio/libdeps/lolin_d32/ArduinoJson/src/ArduinoJson.h:9,
; from src/SysModule.h:23,
; from src/Sys/SysModWeb.h:13,
; from src/Sys/SysModWeb.cpp:12:
; .pio/libdeps/lolin_d32/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp:318:14: note: declared here
; JsonObject createNestedObject() {
; ^~~~~~~~~~~~~~~~~~
; In file included from src/Sys/SysModWeb.cpp:22:
; .pio/libdeps/lolin_d32/ESPAsyncWebServerAircoookie/src/AsyncJson.h: In member function 'virtual void AsyncCallbackJsonWebHandler::handleRequest(AsyncWebServerRequest*)':
; .pio/libdeps/lolin_d32/ESPAsyncWebServerAircoookie/src/AsyncJson.h:218:39: warning: 'DynamicJsonDocument' is deprecated: use JsonDocument instead [-Wdeprecated-declarations]
; DynamicJsonDocument jsonBuffer(this->maxJsonBufferSize);
; ^
; In file included from .pio/libdeps/lolin_d32/ArduinoJson/src/ArduinoJson.hpp:53,
; from .pio/libdeps/lolin_d32/ArduinoJson/src/ArduinoJson.h:9,
; from src/SysModule.h:23,
; from src/Sys/SysModWeb.h:13,
; from src/Sys/SysModWeb.cpp:12:
; .pio/libdeps/lolin_d32/ArduinoJson/src/ArduinoJson/compatibility.hpp:125:58: note: declared here
; class ARDUINOJSON_DEPRECATED("use JsonDocument instead") DynamicJsonDocument
; ^~~~~~~~~~~~~~~~~~~
67 changes: 34 additions & 33 deletions src/App/AppEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class DistortionWaves2D: public Effect {

void loop(Leds &leds) {

uint8_t speed = mdl->getValue("Speed", leds.rowNr).as<uint8_t>()/32;
uint8_t speed = mdl->getValue("speed", leds.rowNr).as<uint8_t>()/32;
uint8_t scale = mdl->getValue("scale", leds.rowNr).as<uint8_t>()/32;

uint8_t w = 2;
Expand Down Expand Up @@ -438,7 +438,7 @@ class DistortionWaves2D: public Effect {
}
}
void controls(JsonObject parentVar, Leds &leds) {
ui->initSlider(parentVar, "Speed", 128);
ui->initSlider(parentVar, "speed", 128);
ui->initSlider(parentVar, "scale", 128);
}
}; // DistortionWaves2D
Expand All @@ -460,7 +460,7 @@ 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 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);
Expand Down Expand Up @@ -510,7 +510,7 @@ class Octopus2D: public Effect {
}
void controls(JsonObject parentVar, Leds &leds) {
addPalette(parentVar, 4);
ui->initSlider(parentVar, "Speed", 128, 1, 255); //start with speed 1
ui->initSlider(parentVar, "speed", 128, 1, 255); //start with speed 1
ui->initSlider(parentVar, "Offset X", 128);
ui->initSlider(parentVar, "Offset Y", 128);
ui->initSlider(parentVar, "Legs", 4, 1, 8);
Expand All @@ -528,7 +528,7 @@ class Lissajous2D: public Effect {

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);
uint8_t speed = mdl->getValue("speed", leds.rowNr);
bool smooth = mdl->getValue("Smooth", leds.rowNr);
CRGBPalette16 pal = getPalette(leds.rowNr);

Expand Down Expand Up @@ -563,7 +563,7 @@ class Lissajous2D: public Effect {
addPalette(parentVar, 4);
ui->initSlider(parentVar, "X frequency", 64);
ui->initSlider(parentVar, "Fade rate", 128);
ui->initSlider(parentVar, "Speed", 128);
ui->initSlider(parentVar, "speed", 128);
ui->initCheckBox(parentVar, "Smooth", false);
}
}; // Lissajous2D
Expand Down Expand Up @@ -689,7 +689,7 @@ class ScrollingText2D: public Effect {
}

void loop(Leds &leds) {
uint8_t speed = mdl->getValue("Speed", leds.rowNr);
uint8_t speed = mdl->getValue("speed", leds.rowNr);
uint8_t font = mdl->getValue("font", leds.rowNr);
const char * text = mdl->getValue("text", leds.rowNr);

Expand All @@ -703,7 +703,7 @@ class ScrollingText2D: public Effect {
}
void controls(JsonObject parentVar, Leds &leds) {
ui->initText(parentVar, "text", "StarMod");
ui->initSlider(parentVar, "Speed", 128);
ui->initSlider(parentVar, "speed", 128);
ui->initSelect(parentVar, "font", 0, false, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case f_UIFun: {
JsonArray options = ui->setOptions(var);
Expand Down Expand Up @@ -1033,7 +1033,7 @@ class FreqMatrix:public Effect {
uint8_t *aux0 = sharedData.bind<uint8_t>();
if (!sharedData.allocated()) return;

uint8_t speed = mdl->getValue("Speed", leds.rowNr);
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);
Expand Down Expand Up @@ -1073,7 +1073,7 @@ class FreqMatrix:public Effect {
}

void controls(JsonObject parentVar, Leds &leds) {
ui->initSlider(parentVar, "Speed", 255);
ui->initSlider(parentVar, "speed", 255);
ui->initSlider(parentVar, "Sound effect", 128);
ui->initSlider(parentVar, "Low bin", 18);
ui->initSlider(parentVar, "High bin", 48);
Expand Down Expand Up @@ -1163,35 +1163,14 @@ class Effects {
EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
}

bool setEffect(Leds &leds, JsonObject var, uint8_t rowNr) {
bool doMap = false;
void setEffect(Leds &leds, JsonObject var, uint8_t rowNr) {

leds.fx = mdl->getValue(var, rowNr);

USER_PRINTF("setEffect fx[%d]: %d\n", rowNr, leds.fx);

if (leds.fx < effects.size()) {

//tbd: make property of effects
if (strstr(effects[leds.fx]->name(), "2D")) {
if (leds.effectDimension != 2) {
leds.effectDimension = 2;
doMap = true;
}
}
else if (strstr(effects[leds.fx]->name(), "3D")) {
if (leds.effectDimension != 3) {
leds.effectDimension = 3;
doMap = true;
}
}
else {
if (leds.effectDimension != 1) {
leds.effectDimension = 1;
doMap = true;
}
}

sharedData.clear(); //make sure all values are 0

for (JsonObject var: var["n"].as<JsonArray>()) { //for all controls
Expand Down Expand Up @@ -1258,9 +1237,31 @@ class Effects {
// }
//remove vars with all values -99

//tbd: make property of effects
if (strstr(effects[leds.fx]->name(), "2D")) {
if (leds.effectDimension != 2) {
leds.effectDimension = 2;
leds.doMap = true;
leds.fixture->doMap = true;
}
}
else if (strstr(effects[leds.fx]->name(), "3D")) {
if (leds.effectDimension != 3) {
leds.effectDimension = 3;
leds.doMap = true;
leds.fixture->doMap = true;
}
}
else {
if (leds.effectDimension != 1) {
leds.effectDimension = 1;
leds.doMap = true;
leds.fixture->doMap = true;
}
}

} // fx < size

return doMap;
}

};
16 changes: 10 additions & 6 deletions src/App/AppFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
if (files->seqNrToName(fileName, fixtureNr)) {
JsonRDWS jrdws(fileName); //open fileName for deserialize

for (std::vector<Leds>::iterator leds=ledsList.begin(); leds!=ledsList.end(); ++leds) {
for (std::vector<Leds>::iterator leds=ledsList.begin(); leds!=ledsList.end() && leds->doMap; ++leds) {
//vectors really gone now?
for (std::vector<std::vector<uint16_t>> ::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); ++physMap)
physMap->clear();
Expand Down Expand Up @@ -73,7 +73,7 @@
// for (Leds leds:ledsList) {
//vector iterator needed to get the pointer to leds as we need to update leds, also vector iteration on classes is faster!!!
//search: ^(?=.*\bfor\b)(?=.*\b:\b).*$
for (std::vector<Leds>::iterator leds=ledsList.begin(); leds!=ledsList.end(); ++leds) {
for (std::vector<Leds>::iterator leds=ledsList.begin(); leds!=ledsList.end() && leds->doMap; ++leds) {
Coord3D startPosAdjusted = (leds->startPos).minimum(size - Coord3D{1,1,1}) ;
Coord3D endPosAdjusted = (leds->endPos).minimum(size - Coord3D{1,1,1}) ;

Expand Down Expand Up @@ -230,7 +230,7 @@
if (indexV != UINT16_MAX) { //can be nulled by inverse mapping
//add physical tables if not present
if (indexV >= NUM_LEDS_Max / 2) {
USER_PRINTF("dev mapping add physMap %d>=%d (%d) too big %d\n", indexV, NUM_LEDS_Max, leds->mappingTable.size(), UINT16_MAX);
USER_PRINTF("dev mapping add physMap %d>=%d/2 (V:%d) too big\n", indexV, NUM_LEDS_Max, leds->mappingTable.size());
}
else {
//create new physMaps if needed
Expand Down Expand Up @@ -288,14 +288,15 @@
if (jrdws.deserialize(false)) { //this will call above function parameter for each led

uint8_t rowNr = 0;
for (std::vector<Leds>::iterator leds=ledsList.begin(); leds!=ledsList.end(); ++leds) {
for (std::vector<Leds>::iterator leds=ledsList.begin(); leds!=ledsList.end() && leds->doMap; ++leds) {
USER_PRINTF("leds loop %d %d\n", leds->rowNr, leds->fx);
if (leds->projectionNr <= p_Random) {
//defaults
leds->size = size;
leds->nrOfLeds = nrOfLeds;
}

if (leds->projectionNr > p_Random) {
else if (leds->projectionNr > p_Random) {

if (leds->mappingTable.size() < leds->size.x * leds->size.y * leds->size.z)
USER_PRINTF("mapping add extra physMap %d of %d %d,%d,%d\n", leds->mappingTable.size(), leds->size.x * leds->size.y * leds->size.z, leds->size.x, leds->size.y, leds->size.z);
Expand Down Expand Up @@ -326,11 +327,12 @@

USER_PRINTF("projectAndMap V:%dx%dx%d = %d\n", 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);
mdl->setValueV("fxSize", leds->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

rowNr++;
leds->doMap = false;
} // leds

USER_PRINTF("projectAndMap P:%dx%dx%d = %d\n", size.x, size.y, size.z, nrOfLeds);
Expand All @@ -342,4 +344,6 @@
} //if fileName
else
USER_PRINTF("projectAndMap: Filename for fixture %d not found\n", fixtureNr);

doMap = false;
}
2 changes: 2 additions & 0 deletions src/App/AppFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class Fixture {
//variables for json Scan
// uint16_t prevIndexP;
//track pins and leds

bool doMap = false;

//load fixture json file, parse it and depending on the projection, create a mapping for it
void projectAndMap();
Expand Down
2 changes: 2 additions & 0 deletions src/App/AppLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Leds {

uint16_t indexVLocal = 0; //set in operator[], used by operator=

bool doMap = false;

Leds(uint8_t rowNr, Fixture &fixture) {
USER_PRINTF("Leds[%d] constructor\n", rowNr);
this->rowNr = rowNr;
Expand Down
7 changes: 6 additions & 1 deletion src/App/AppModFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ class AppModFixture:public SysModule {
case f_ChangeFun:
{
lds->fixture.fixtureNr = var["value"];
lds->doMap = true;
lds->fixture.doMap = true;

//remap all leds
for (std::vector<Leds>::iterator leds=lds->fixture.ledsList.begin(); leds!=lds->fixture.ledsList.end(); ++leds) {
leds->doMap = true;
}

char fileName[32] = "";
if (files->seqNrToName(fileName, lds->fixture.fixtureNr)) {
Expand Down
Loading

0 comments on commit bc35ad5

Please sign in to comment.