From fbc639f369c65b2c221db1c63db7eb17e11e9f04 Mon Sep 17 00:00:00 2001 From: Ewoud Date: Thu, 18 Apr 2024 16:24:29 +0200 Subject: [PATCH] Refactor print output LedEffects: setEffect: printVar instead of printJson LedFixture: projectAndMap refactor print LedLeds: refactor print LedModEffects: refactor print + bugfix pinObject.details LedModFixture: refactor print --- src/App/LedEffects.h | 4 +++- src/App/LedFixture.cpp | 14 +++++++------- src/App/LedLeds.h | 8 ++++---- src/App/LedModEffects.h | 24 ++++++++++++------------ src/App/LedModFixture.h | 12 ++++-------- 5 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/App/LedEffects.h b/src/App/LedEffects.h index 3278e639..f00eb564 100644 --- a/src/App/LedEffects.h +++ b/src/App/LedEffects.h @@ -1626,7 +1626,9 @@ class Effects { effect->setup(leds); //if changed then run setup once (like call==0 in WLED) - print->printJson("control", var); + USER_PRINTF("control "); + print->printVar(var); + USER_PRINTF("\n"); if (effects[leds.fx]->dim() != leds.effectDimension) { leds.effectDimension = effects[leds.fx]->dim(); diff --git a/src/App/LedFixture.cpp b/src/App/LedFixture.cpp index 9741f941..20b2c186 100644 --- a/src/App/LedFixture.cpp +++ b/src/App/LedFixture.cpp @@ -29,7 +29,7 @@ void Fixture::projectAndMap() { 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, projections.size()); + USER_PRINTF("projectAndMap clear leds[%d] fx:%d pro:%d\n", rowNr, leds->fx, leds->projectionNr); leds->size = Coord3D{0,0,0}; //vectors really gone now? for (PhysMap &map:leds->mappingTable) { @@ -47,7 +47,7 @@ void Fixture::projectAndMap() { //deallocate all led pins if (doAllocPins) { stackUnsigned8 pinNr = 0; - for (PinObject pinObject: pins->pinObjects) { + for (PinObject &pinObject: pins->pinObjects) { if (strcmp(pinObject.owner, "Leds") == 0) pins->deallocatePin(pinNr, "Leds"); pinNr++; @@ -123,7 +123,7 @@ void Fixture::projectAndMap() { // USER_PRINTF("projectionNr p:%d f:%d s:%d, %d-%d-%d %d-%d-%d %d-%d-%d\n", projectionNr, effectDimension, projectionDimension, x, y, z, uint16CollectList[0], uint16CollectList[1], uint16CollectList[2], size.x, size.y, size.z); if (leds->size == Coord3D{0,0,0}) { // first - USER_PRINTF("leds[%d] first s:%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); + USER_PRINTF("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); } //calculate the indexV to add to current physical led to @@ -362,7 +362,7 @@ void Fixture::projectAndMap() { else {//allocate new pin //tbd: check if free print->fFormat(details, sizeof(details)-1, "%d-%d", prevIndexP, indexP - 1); //careful: LedModEffects:loop uses this to assign to FastLed - USER_PRINTF("pins %d: %s\n", currPin, details); + // USER_PRINTF("allocatePin %d: %s\n", currPin, details); pins->allocatePin(currPin, "Leds", details); } @@ -378,7 +378,7 @@ void Fixture::projectAndMap() { for (Leds *leds: projections) { if (leds->doMap) { - USER_PRINTF("Leds pre [%d] f:%d p:%d s:%d\n", rowNr, leds->fx, leds->projectionNr, projections.size()); + USER_PRINTF("projectAndMap post leds[%d] fx:%d pro:%d\n", rowNr, leds->fx, leds->projectionNr); stackUnsigned16 nrOfMappings = 0; stackUnsigned16 nrOfPixels = 0; @@ -427,7 +427,7 @@ void Fixture::projectAndMap() { } } - USER_PRINTF("projectAndMap [%d] V:%d x %d x %d -> %d (v:%d - p:%d)\n", rowNr, leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds, nrOfMappings, nrOfPixels); + USER_PRINTF("projectAndMap leds[%d] V:%d x %d x %d -> %d (v:%d - p:%d)\n", rowNr, leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds, nrOfMappings, nrOfPixels); // mdl->setValueV("fxSize", rowNr, "%d x %d x %d = %d", leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds); char buf[32]; @@ -442,7 +442,7 @@ void Fixture::projectAndMap() { rowNr++; } // leds - USER_PRINTF("projectAndMap P:%dx%dx%d -> %d\n", size.x, size.y, size.z, nrOfLeds); + USER_PRINTF("projectAndMap fixture P:%dx%dx%d -> %d\n", size.x, size.y, size.z, nrOfLeds); mdl->setValue("fixSize", size); mdl->setValue("fixCount", nrOfLeds); diff --git a/src/App/LedLeds.h b/src/App/LedLeds.h index 577e204e..b6ff412b 100644 --- a/src/App/LedLeds.h +++ b/src/App/LedLeds.h @@ -126,10 +126,10 @@ class SharedData { public: SharedData() { - USER_PRINTF("SharedData constructor %d %d\n", index, bytesAllocated); + // USER_PRINTF("SharedData constructor %d %d\n", index, bytesAllocated); } ~SharedData() { - USER_PRINTF("SharedData destructor WIP %d %d\n", index, bytesAllocated); + // USER_PRINTF("SharedData destructor WIP %d %d\n", index, bytesAllocated); // free(data); } @@ -212,12 +212,12 @@ class Leds { unsigned16 XYZ(unsigned16 x, unsigned16 y, unsigned16 z); Leds(Fixture &fixture) { - USER_PRINTF("Leds[%d] constructor %d\n", UINT8_MAX, sizeof(PhysMap)); + USER_PRINTF("Leds constructor (PhysMap:%d)\n", sizeof(PhysMap)); this->fixture = &fixture; } ~Leds() { - USER_PRINTF("Leds[%d] destructor\n", UINT8_MAX); + USER_PRINTF("Leds destructor\n"); fadeToBlackBy(100); doMap = true; // so loop is not running while deleting for (PhysMap &map:mappingTable) { diff --git a/src/App/LedModEffects.h b/src/App/LedModEffects.h index 3ca13146..9354d7d4 100644 --- a/src/App/LedModEffects.h +++ b/src/App/LedModEffects.h @@ -56,24 +56,22 @@ class LedModEffects:public SysModule { return true; case f_AddRow: { rowNr = fixture.projections.size(); - USER_PRINTF("chFun addRow %s[%d]\n", mdl->varID(var), rowNr); + // USER_PRINTF("chFun addRow %s[%d]\n", mdl->varID(var), rowNr); web->getResponseObject()["addRow"]["rowNr"] = rowNr; if (rowNr >= fixture.projections.size()) fixture.projections.push_back(new Leds(fixture)); - return true; - } + return true; } case f_DelRow: { - USER_PRINTF("chFun delrow %s[%d]\n", mdl->varID(var), rowNr); + // USER_PRINTF("chFun delrow %s[%d]\n", mdl->varID(var), rowNr); //tbd: fade to black if (rowNr varPostDetails(var, rowNr); - USER_PRINTF("chFun pro[%d] <- %d (%d)\n", rowNr, proValue, fixture.projections.size()); + // USER_PRINTF("chFun pro[%d] <- %d (%d)\n", rowNr, proValue, fixture.projections.size()); fixture.doMap = true; } @@ -282,10 +280,10 @@ class LedModEffects:public SysModule { case f_ValueFun: { // for (std::vector::iterator leds=fixture.projections.begin(); leds!=fixture.projections.end(); ++leds) { stackUnsigned8 rowNr = 0; - for (Leds *leds: fixture.projections) { + 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.projections.size(), message); + USER_PRINTF("valueFun fxSize[%d] = %s\n", rowNr, message); mdl->setValue(var, JsonString(message, JsonString::Copied), rowNr); //rowNr rowNr++; } @@ -430,11 +428,13 @@ 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 - char * after = strtok((char *)pinObject.details, "-"); + char details[32]; + strcpy(details, pinObject.details); //copy as strtok messes with the string + char * after = strtok((char *)details, "-"); if (after != NULL ) { char * before; before = after; @@ -442,7 +442,7 @@ class LedModEffects:public SysModule { stackUnsigned16 startLed = atoi(before); stackUnsigned16 nrOfLeds = atoi(after) - atoi(before) + 1; - USER_PRINTF("FastLED.addLeds new %d: %d-%d\n", pinNr, startLed, nrOfLeds); + USER_PRINTF("FastLED.addLeds new %d: %d-%d\n", pinNr, startLed, nrOfLeds-1); //commented pins: error: static assertion failed: Invalid pin specified switch (pinNr) { diff --git a/src/App/LedModFixture.h b/src/App/LedModFixture.h index 66461a17..2079ebe3 100644 --- a/src/App/LedModFixture.h +++ b/src/App/LedModFixture.h @@ -116,8 +116,7 @@ class LedModFixture:public SysModule { }}); currentVar = ui->initSelect(parentVar, "fixture", eff->fixture.fixtureNr, false ,[](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun - case f_UIFun: - { + case f_UIFun: { // ui->setComment(var, "Fixture to display effect on"); JsonArray options = ui->setOptions(var); files->dirToJson(options, true, "F_"); //only files containing F(ixture), alphabetically @@ -127,10 +126,8 @@ class LedModFixture:public SysModule { if (files->seqNrToName(fileName, var["value"])) { web->addResponse("pview", "file", JsonString(fileName, JsonString::Copied)); } - return true; - } - case f_ChangeFun: - { + return true; } + case f_ChangeFun: { eff->fixture.fixtureNr = var["value"]; eff->fixture.doMap = true; eff->fixture.doAllocPins = true; @@ -146,8 +143,7 @@ class LedModFixture:public SysModule { //send to pview a message to get file filename web->addResponse("pview", "file", JsonString(fileName, JsonString::Copied)); } - return true; - } + return true; } default: return false; }}); //fixture