Skip to content

Commit

Permalink
bugfix pidid char[64]
Browse files Browse the repository at this point in the history
ffFormat: use size, not size-1
pidid: use char 64 not 32
  • Loading branch information
ewoudwijma committed Oct 6, 2024
1 parent b173618 commit 91ed9df
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion misc/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@
"dash": true
},
{
"id": "bri",
"id": "brightness",
"type": "range",
"pid": "AppMod Demo",
"ro": false,
Expand Down
6 changes: 3 additions & 3 deletions misc/testOutput.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/App/AppModDemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AppModDemo: public SysModule {
currentVar["dash"] = true;

//logarithmic slider (10)
currentVar = ui->initSlider(parentVar, "bri", 10, 0, 255, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
currentVar = ui->initSlider(parentVar, "brightness", 10, 0, 255, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case onUI:
ui->setLabel(var, "Brightness");
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/Sys/SysModInstances.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct UDPStarMessage {
struct UDPWLEDSyncMessage { //see notify( in WLED
byte protocol; //0
byte callMode; //1
byte bri; //2
byte bri; //2 LEDs specific
byte rCol0; //3
byte gCol0; //4
byte bCol0; //5
Expand Down Expand Up @@ -415,7 +415,7 @@ class SysModInstances:public SysModule {
// Serial.printf("%d: %d\n", i, udpIn[i]);
// }

ppf(" %d %d p:%d\n", wledSyncMessage.bri, wledSyncMessage.mainsegMode, packetSize);
ppf(" %d %d p:%d\n", wledSyncMessage.bri, wledSyncMessage.mainsegMode, packetSize); //LEDs specific

InstanceInfo *instance = findInstance(notifierUdp.remoteIP()); //if not exist, created

Expand Down Expand Up @@ -454,7 +454,7 @@ class SysModInstances:public SysModule {
// }
// }

instance->jsonData["bri"] = wledSyncMessage.bri;
instance->jsonData["brightness"] = wledSyncMessage.bri; //LEDs specific
instance->jsonData["effect"] = wledSyncMessage.mainsegMode; //tbd: rowNr
instance->jsonData["pal"] = wledSyncMessage.palette; //tbd: rowNr

Expand Down
4 changes: 2 additions & 2 deletions src/Sys/SysModSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void SysModSystem::setup() {
default: return false;
}});

print->fFormat(chipInfo, sizeof(chipInfo)-1, "%s %s (%d.%d.%d) c#:%d %d mHz f:%d KB %d mHz %d", ESP.getChipModel(), ESP.getSdkVersion(), ESP_ARDUINO_VERSION_MAJOR, ESP_ARDUINO_VERSION_MINOR, ESP_ARDUINO_VERSION_PATCH, ESP.getChipCores(), ESP.getCpuFreqMHz(), ESP.getFlashChipSize()/1024, ESP.getFlashChipSpeed()/1000000, ESP.getFlashChipMode());
print->fFormat(chipInfo, sizeof(chipInfo), "%s %s (%d.%d.%d) c#:%d %d mHz f:%d KB %d mHz %d", ESP.getChipModel(), ESP.getSdkVersion(), ESP_ARDUINO_VERSION_MAJOR, ESP_ARDUINO_VERSION_MINOR, ESP_ARDUINO_VERSION_PATCH, ESP.getChipCores(), ESP.getCpuFreqMHz(), ESP.getFlashChipSize()/1024, ESP.getFlashChipSpeed()/1000000, ESP.getFlashChipMode());
ui->initText(parentVar, "chip", chipInfo, 16, true);

ui->initProgress(parentVar, "heap", (ESP.getHeapSize()-ESP.getFreeHeap()) / 1000, 0, ESP.getHeapSize()/1000, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
Expand Down Expand Up @@ -204,7 +204,7 @@ void SysModSystem::setup() {
// sscanf(__DATE__, "%s %d %d", version, &day, &year); // Mon dd yyyy
// month = (strnstr(month_names, version, 32)-month_names)/3+1;
// sscanf(__TIME__, "%d:%d:%d", &hour, &minute, &second); //hh:mm:ss
// print->fFormat(version, sizeof(version)-1, "%02d%02d%02d%02d", year-2000, month, day, hour);
// print->fFormat(version, sizeof(version), "%02d%02d%02d%02d", year-2000, month, day, hour);

// ppf("version %s %s %s %d:%d:%d\n", version, __DATE__, __TIME__, hour, minute, second);

Expand Down
4 changes: 2 additions & 2 deletions src/Sys/SysModUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void SysModUI::processJson(JsonVariant json) {
else
newValue = value["value"]; //use the value field

char pidid[32];
char pidid[64];
strlcpy(pidid, key, sizeof(pidid));
//check if we deal with multiple rows (from table type)
char * rowNrC = strtok(pidid, "#");
Expand All @@ -240,7 +240,7 @@ void SysModUI::processJson(JsonVariant json) {
}
stackUnsigned8 rowNr = rowNrC?atoi(rowNrC):UINT8_MAX;

char pid[32];
char pid[64];
strlcpy(pid, pidid, sizeof(pid));
char * id = strtok(pid, ".");
if (id != NULL ) {
Expand Down
16 changes: 8 additions & 8 deletions src/Sys/SysModUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,28 +414,28 @@ class SysModUI: public SysModule {
}
JsonArray setOptions(JsonObject var) {
JsonObject responseObject = web->getResponseObject();
char pidid[32];
print->fFormat(pidid, 32, "%s.%s", var["pid"].as<const char *>(), var["id"].as<const char *>());
char pidid[64];
print->fFormat(pidid, sizeof(pidid), "%s.%s", var["pid"].as<const char *>(), var["id"].as<const char *>());
return responseObject[pidid]["options"].to<JsonArray>();
}
//return the options from onUI (don't forget to clear responseObject)
JsonArray getOptions(JsonObject var) {
callVarFun(var, UINT8_MAX, onUI); //rebuild options
char pidid[32];
print->fFormat(pidid, 32, "%s.%s", var["pid"].as<const char *>(), var["id"].as<const char *>());
char pidid[64];
print->fFormat(pidid, sizeof(pidid), "%s.%s", var["pid"].as<const char *>(), var["id"].as<const char *>());
return web->getResponseObject()[pidid]["options"];
}
void clearOptions(JsonObject var) {
char pidid[32];
print->fFormat(pidid, 32, "%s.%s", var["pid"].as<const char *>(), var["id"].as<const char *>());
char pidid[64];
print->fFormat(pidid, sizeof(pidid), "%s.%s", var["pid"].as<const char *>(), var["id"].as<const char *>());
web->getResponseObject()[pidid].remove("options");
}

//find options text in a hierarchy of options
void findOptionsText(JsonObject var, uint8_t value, char * groupName, char * optionName) {
uint8_t startValue = 0;
char pidid[32];
print->fFormat(pidid, 32, "%s.%s", var["pid"].as<const char *>(), var["id"].as<const char *>());
char pidid[64];
print->fFormat(pidid, sizeof(pidid), "%s.%s", var["pid"].as<const char *>(), var["id"].as<const char *>());
bool optionsExisted = !web->getResponseObject()[pidid]["options"].isNull();
JsonString groupNameJS;
JsonString optionNameJS;
Expand Down
4 changes: 2 additions & 2 deletions src/Sys/SysModWeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ void SysModWeb::serveUpdate(WebRequest *request, const String& fileName, size_t
char message[64];
const char * name = mdl->getValue("System", "name");

print->fFormat(message, sizeof(message)-1, "Update of %s (...%d) %s", name, net->localIP()[3], success?"Successful":"Failed");
print->fFormat(message, sizeof(message), "Update of %s (...%d) %s", name, net->localIP()[3], success?"Successful":"Failed");

ppf("%s\n", message);
request->send(200, "text/plain", message);
Expand Down Expand Up @@ -702,7 +702,7 @@ void SysModWeb::serializeState(JsonObject root) {
deserializeJson(root, jsonState);

//tbd: //StarBase has no idea about leds so this should be led independent
root["bri"] = mdl->getValue("Fixture", "bri");
root["bri"] = mdl->getValue("Fixture", "brightness");
root["on"] = mdl->getValue("Fixture", "on").as<bool>();

}
Expand Down
6 changes: 3 additions & 3 deletions src/Sys/SysModWeb.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class SysModWeb:public SysModule {
//processJsonUrl handles requests send in javascript using fetch and from a browser or curl
//try this !!!: curl -X POST "http://192.168.121.196/json" -d '{"pin2":false}' -H "Content-Type: application/json"
//curl -X POST "http://4.3.2.1/json" -d '{"pin2":false}' -H "Content-Type: application/json"
//curl -X POST "http://4.3.2.1/json" -d '{"bri":20, "v":true}' -H "Content-Type: application/json"
//curl -X POST "http://4.3.2.1/json" -d '{"brightness":20, "v":true}' -H "Content-Type: application/json"
//curl -X POST "http://192.168.8.125/json" -d '{"effect":2}' -H "Content-Type: application/json"
//curl -X POST "http://192.168.8.152/json" -d '{"nrOfLeds":2000}' -H "Content-Type: application/json"

Expand All @@ -119,8 +119,8 @@ class SysModWeb:public SysModule {
void addResponse(JsonObject var, const char * key, Type value, unsigned8 rowNr = UINT8_MAX) {
JsonObject responseObject = getResponseObject();
// if (responseObject[id].isNull()) responseObject[id].to<JsonObject>();;
char pidid[32];
print->fFormat(pidid, 32, "%s.%s", var["pid"].as<const char *>(), var["id"].as<const char *>());
char pidid[64];
print->fFormat(pidid, sizeof(pidid), "%s.%s", var["pid"].as<const char *>(), var["id"].as<const char *>());
if (rowNr == UINT8_MAX)
responseObject[pidid][key] = value;
else {
Expand Down

0 comments on commit 91ed9df

Please sign in to comment.