Skip to content

Commit

Permalink
Refactor print output
Browse files Browse the repository at this point in the history
LedEffects: setEffect: printVar instead of printJson
LedFixture: projectAndMap refactor print
LedLeds: refactor print
LedModEffects: refactor print + bugfix pinObject.details
LedModFixture: refactor print
  • Loading branch information
ewoudwijma committed Apr 18, 2024
1 parent d8c2036 commit fbc639f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
4 changes: 3 additions & 1 deletion src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions src/App/LedFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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++;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/App/LedLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 12 additions & 12 deletions src/App/LedModEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fixture.projections.size()) {
Leds *leds = fixture.projections[rowNr];
fixture.projections.erase(fixture.projections.begin() + rowNr); //remove from vector
delete leds; //remove leds itself
}
return true;
}
return true; }
default: return false;
}});

Expand Down Expand Up @@ -213,7 +211,7 @@ class LedModEffects:public SysModule {
}
mdl->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;
}
Expand Down Expand Up @@ -282,10 +280,10 @@ class LedModEffects:public SysModule {
case f_ValueFun: {
// for (std::vector<Leds *>::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++;
}
Expand Down Expand Up @@ -430,19 +428,21 @@ 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;
after = strtok(NULL, " ");

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) {
Expand Down
12 changes: 4 additions & 8 deletions src/App/LedModFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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

Expand Down

0 comments on commit fbc639f

Please sign in to comment.