Skip to content

Commit

Permalink
str stuff - make Star a safer place + pidid bugfixes
Browse files Browse the repository at this point in the history
fixSize -> size
fixCount -> count

LedEffects: ScrollingTextEffect: check on existing text
LedLayer: drawText: check on existing text
  • Loading branch information
ewoudwijma committed Oct 3, 2024
1 parent 3a2bb2b commit 4887f3a
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 124 deletions.
4 changes: 2 additions & 2 deletions misc/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@
"value": 1,
"n": [
{
"id": "fixSize",
"id": "size",
"type": "coord3D",
"ro": true,
"max": 8192,
Expand All @@ -1112,7 +1112,7 @@
"p": 1073555848
},
{
"id": "fixCount",
"id": "count",
"type": "number",
"ro": true,
"pid": "fixture",
Expand Down
4 changes: 2 additions & 2 deletions misc/testOutput.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ class ScrollingTextEffect: public Effect {

// text might be nullified by selecting other effects and if effect is selected, controls are run afterwards
// tbd: this should be removed and fx.onChange (setEffect) must make sure this cannot happen!!
if (text && strlen(text)>0) {
if (text && strnlen(text, 2) > 0) {
leds.fadeToBlackBy();
leds.drawText(text, 0, 0, font, CRGB::Red, - (sys->now/25*speed/256)); //instead of call
}
Expand Down
8 changes: 4 additions & 4 deletions src/App/LedFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void Fixture::projectAndMap() {
if (doAllocPins) {
stackUnsigned8 pinNr = 0;
for (PinObject &pinObject: pinsM->pinObjects) {
if (strcmp(pinObject.owner, "Leds") == 0)
if (strncmp(pinObject.owner, "Leds", 5) == 0)
pinsM->deallocatePin(pinNr, "Leds");
pinNr++;
}
Expand Down Expand Up @@ -175,7 +175,7 @@ void Fixture::projectAndMap() {
ppf("pins extend leds %d: %s\n", currPin, details);
//tbd: more check

strncpy(pinsM->pinObjects[currPin].details, details, sizeof(PinObject::details)-1);
strlcpy(pinsM->pinObjects[currPin].details, details, sizeof(PinObject::details));
pinsM->pinsChanged = true;
}
}
Expand Down Expand Up @@ -264,8 +264,8 @@ void Fixture::projectAndMap() {
ppf("projectAndMap fixture P:%dx%dx%d -> %d\n", fixSize.x, fixSize.y, fixSize.z, nrOfLeds);
ppf("projectAndMap fixture.size = %d + l:(%d * %d) B\n", sizeof(Fixture) - NUM_LEDS_Max * sizeof(CRGB), NUM_LEDS_Max, sizeof(CRGB)); //56

mdl->setValue("Fixture", "fixSize", fixSize);
mdl->setValue("Fixture", "fixCount", nrOfLeds);
mdl->setValue("fixture", "size", fixSize);
mdl->setValue("fixture", "count", nrOfLeds);

//init pixelsToBlend
for (uint16_t i=0; i<nrOfLeds; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/App/LedLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ class LedsLayer {
}

void drawText(const char * text, int x = 0, int16_t y = 0, unsigned8 font = 0, CRGB col = CRGB::Red, unsigned16 shiftPixel = 0) {
const int numberOfChr = strlen(text); //Core 1 panic'ed (LoadProhibited). Exception was unhandled. - /builds/idf/crosstool-NG/.build/HOST-x86_64-apple-darwin12/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/strlen.S:82
const int numberOfChr = text?strnlen(text, 256):0; //max 256 charcters
for (int shiftChr = 0; shiftChr < numberOfChr; shiftChr++) {
drawCharacter(text[shiftChr], x, y, font, col, shiftPixel, shiftChr);
}
Expand Down
24 changes: 12 additions & 12 deletions src/App/LedModEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ class LedModEffects:public SysModule {
JsonArray options = ui->setOptions(var);
for (Effect *effect:effects) {
char buf[32] = "";
strcat(buf, effect->name());
strcat(buf, effect->dim()==_1D?"":effect->dim()==_2D?"":" 🧊");
strcat(buf, " ");
strcat(buf, effect->tags());
strlcat(buf, effect->name(), sizeof(buf));
strlcat(buf, effect->dim()==_1D?"":effect->dim()==_2D?"":" 🧊", sizeof(buf));
strlcat(buf, " ", sizeof(buf));
strlcat(buf, effect->tags(), sizeof(buf));
options.add(JsonString(buf, JsonString::Copied)); //copy!
}
return true; }
Expand All @@ -225,7 +225,7 @@ class LedModEffects:public SysModule {
//kill live script of moving to other effect
if (leds->fx < effects.size()) {
Effect* effect = effects[leds->fx];
if (strcmp(effect->name(), "Live Script") == 0) {
if (strncmp(effect->name(), "Live Script", 12) == 0) {
liveM->kill();
}
}
Expand Down Expand Up @@ -278,10 +278,10 @@ class LedModEffects:public SysModule {
JsonArray options = ui->setOptions(var);
for (Projection *projection:fixture.projections) {
char buf[32] = "";
strcat(buf, projection->name());
// strcat(buf, projection->dim()==_1D?" ┊":projection->dim()==_2D?" ▦":" 🧊");
strcat(buf, " ");
strcat(buf, projection->tags());
strlcat(buf, projection->name(), sizeof(buf));
// strlcat(buf, projection->dim()==_1D?" ┊":projection->dim()==_2D?" ▦":" 🧊");
strlcat(buf, " ", sizeof(buf));
strlcat(buf, projection->tags(), sizeof(buf));
options.add(JsonString(buf, JsonString::Copied)); //copy!
}
return true; }
Expand Down Expand Up @@ -554,8 +554,8 @@ class LedModEffects:public SysModule {
fixture.layers[rowNr]->fadeToBlackBy();

char * token = strtok((char *)canvasData, ":");
bool isStart = strcmp(token, "start") == 0;
bool isEnd = strcmp(token, "end") == 0;
bool isStart = strncmp(token, "start", 6) == 0;
bool isEnd = strncmp(token, "end", 4) == 0;

Coord3D midCoord; //placeHolder for mid

Expand Down Expand Up @@ -600,7 +600,7 @@ class LedModEffects:public SysModule {
if (pinsM->isOwner(pinNr, "Leds")) { //if pin owned by leds, (assigned in projectAndMap)
//dirty trick to decode nrOfLedsPerPin
char details[32];
strcpy(details, pinObject.details); //copy as strtok messes with the string
strlcpy(details, pinObject.details, sizeof(details)); //copy as strtok messes with the string
char * after = strtok((char *)details, "-");
if (after != NULL ) {
char * before;
Expand Down
11 changes: 2 additions & 9 deletions src/App/LedModFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ class LedModFixture:public SysModule {
parentVar = ui->initAppMod(parentVar, name, 1100);

JsonObject currentVar = ui->initCheckBox(parentVar, "on", true, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case onUI:
ui->setLabel(var, "On");
return true;
case onChange:
mdl->callVarOnChange(mdl->findVar("Fixture", "bri"), UINT8_MAX, true); //set brightness (init is true so bri value not send via udp)
return true;
Expand Down Expand Up @@ -170,16 +167,12 @@ class LedModFixture:public SysModule {
default: return false;
}}); //fixture

ui->initCoord3D(currentVar, "fixSize", &eff->fixture.fixSize, 0, NUM_LEDS_Max, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case onUI:
ui->setLabel(var, "Size");
return true;
ui->initCoord3D(currentVar, "size", &eff->fixture.fixSize, 0, NUM_LEDS_Max, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
default: return false;
}});

ui->initNumber(currentVar, "fixCount", &eff->fixture.nrOfLeds, 0, UINT16_MAX, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
ui->initNumber(currentVar, "count", &eff->fixture.nrOfLeds, 0, UINT16_MAX, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case onUI:
ui->setLabel(var, "Count");
web->addResponse(var, "comment", "Max %d", NUM_LEDS_Max, 0); //0 is to force format overload used
return true;
default: return false;
Expand Down
Loading

0 comments on commit 4887f3a

Please sign in to comment.