Skip to content

Commit

Permalink
Merge pull request #60 from ewowi/dev
Browse files Browse the repository at this point in the history
ELS latest, add pub sub, add presets, StarString, cpuTime
  • Loading branch information
ewowi authored Dec 8, 2024
2 parents f71bfe8 + 8823da5 commit b48faab
Show file tree
Hide file tree
Showing 26 changed files with 620 additions and 240 deletions.
2 changes: 1 addition & 1 deletion misc/misc.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Release steps
- update dates in files
- check all lib_deps on right version
- clean and build to check latest versions (before github actions fail on this)
- clean and build to check latest versions (before github actions fail on this) - (remove .pio and rebuild)

WebHook to MM discord
https://discord.com/api/webhooks/1229821142479536179/UeO3ryPqUyHABYTAuGtHZK6t7yghM0ZETN0LUYpg32KBleGhm-zvaYDzkyYjiqaVqt0T/github
Expand Down
4 changes: 2 additions & 2 deletions misc/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@
"fun": 74
},
{
"id": "fps1",
"id": "fpsCycles",
"type": "text",
"pid": "LiveScripts",
"ro": true,
Expand All @@ -961,7 +961,7 @@
"value": "0 /s"
},
{
"id": "fps2",
"id": "fpsFrame",
"type": "text",
"pid": "LiveScripts",
"ro": true,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"zlib": "^1.0.5"
},
"engines": {
"node": ">=20.0.0"
"node": ">=21.0.0"
}
}
7 changes: 4 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ build_flags =
-D STARBASE_USERMOD_LIVE
-D EXTPRINTF=ppf ;redirect Live Script prints to StarBase print
lib_deps =
https://github.com/ewowi/ESPLiveScript.git#main ;1.2.0. ewowi repo adds some proposed PR's and makes sure we don't have unexpected updates
https://github.com/ewowi/ESPLiveScript.git#d62bf25 ; v3.1 ;ewowi repo adds some proposed PR's and makes sure we don't have unexpected updates

[STARBASE]
build_flags =
-D APP=StarBase
-D PIOENV=$PIOENV
-D VERSION=24112412 ; Date and time (GMT!), update at every commit!!
-D VERSION=24120809 ; Date and time (GMT!), update at every commit!!
-D LFS_THREADSAFE ; enables use of semaphores in LittleFS driver
-D STARBASE_DEVMODE
-mtext-section-literals ;otherwise [UserModLive::setup()]+0xa17): dangerous relocation: l32r: literal target out of range (try using text-section-literals)
Expand Down Expand Up @@ -156,7 +156,8 @@ lib_deps =

; https://github.com/platformio/platform-espressif32/issues/1360
; https://community.platformio.org/t/support-esp32-wrover-module/17717
; note: flasghing to new board goes wrong, try first without ICVD then with and without etc until it works (witchcraft)
; note: flashing to new board goes wrong, try first without ICVD then with and without etc until it works (witchcraft)
; Guru Meditation Error: Core 0 panic'ed (Cache disabled but cached memory region accessed).
[env:esp-wrover-kit]
board = esp-wrover-kit ; esp-wrover-kit ;https://github.com/platformio/platform-espressif32/blob/develop/boards/esp-wrover-kit.json
; recommended to pin to a platform version, see https://github.com/platformio/platform-espressif32/releases
Expand Down
40 changes: 19 additions & 21 deletions src/Sys/SysModFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void SysModFiles::setup() {
// for (size_t rowNr = 0; rowNr < fileList.size(); rowNr++) {
// char urlString[32] = "file/";
// strlcat(urlString, fileList[rowNr].name, sizeof(urlString));
// variable.setValue(JsonString(urlString, JsonString::Copied), rowNr);
// variable.setValue(JsonString(urlString), rowNr);
// }
// return true;
// default: return false;
Expand Down Expand Up @@ -118,8 +118,8 @@ void SysModFiles::loop20ms() {

uint8_t rowNrL = 0;
for (VectorString name: fileNames) {
mdl->setValue("files", "name", JsonString(name.s, JsonString::Copied), rowNrL);
mdl->setValue("files", "edit", JsonString(name.s, JsonString::Copied), rowNrL);
mdl->setValue("files", "name", JsonString(name.s), rowNrL);
mdl->setValue("files", "edit", JsonString(name.s), rowNrL);
rowNrL++;
}
rowNrL = 0; for (uint16_t size: fileSizes) mdl->setValue("files", "size", size, rowNrL++);
Expand Down Expand Up @@ -158,15 +158,15 @@ void SysModFiles::dirToJson(JsonArray array, bool nameOnly, const char * filter)

if (filter == nullptr || strnstr(file.name(), filter, 32) != nullptr) {
if (nameOnly) {
array.add(JsonString(file.name(), JsonString::Copied));
array.add(JsonString(file.name()));
}
else {
JsonArray row = array.add<JsonArray>();
row.add(JsonString(file.name(), JsonString::Copied));
row.add(JsonString(file.name()));
row.add(file.size());
char urlString[32] = "file/";
strlcat(urlString, file.name(), sizeof(urlString));
row.add(JsonString(urlString, JsonString::Copied));
row.add(JsonString(urlString));
}
// ppf("FILE: %s %d\n", file.name(), file.size());
}
Expand Down Expand Up @@ -233,7 +233,7 @@ bool SysModFiles::nameToSeqNr(const char * fileName, size_t *seqNr, const char *

bool SysModFiles::readObjectFromFile(const char* path, JsonDocument* dest) {
// if (doCloseFile) closeFile();
File f = open(path, "r");
File f = open(path, FILE_READ);
if (!f) {
ppf("File %s open not successful\n", path);
return false;
Expand All @@ -253,20 +253,18 @@ bool SysModFiles::readObjectFromFile(const char* path, JsonDocument* dest) {
}
}

//candidate for deletion as taken over by StarJson
// bool SysModFiles::writeObjectToFile(const char* path, JsonDocument* dest) {
// File f = open(path, "w");
// if (f) {
// print->println(" success");
// serializeJson(*dest, f);
// f.close();
// filesChanged = true;
// return true;
// } else {
// print->println(" fail");
// return false;
// }
// }
bool SysModFiles::writeObjectToFile(const char* path, JsonDocument* dest) {
File f = open(path, FILE_WRITE);
if (f) {
serializeJson(*dest, f);
f.close();
filesChanged = true;
return true;
} else {
ppf("File %s open not successful\n", path);
return false;
}
}

void SysModFiles::removeFiles(const char * filter, bool reverse) {
File root = LittleFS.open("/");
Expand Down
3 changes: 1 addition & 2 deletions src/Sys/SysModFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class SysModFiles: public SysModule {

//write json into file
//name is copied from WLED but better to call it readJsonFrom file
//candidate for deletion as taken over by StarJson
// bool writeObjectToFile(const char* path, JsonDocument* dest);
bool writeObjectToFile(const char* path, JsonDocument* dest);

//remove files meeting filter condition, if no filter, all, if reverse then all but filter
void removeFiles(const char * filter = nullptr, bool reverse = false);
Expand Down
37 changes: 20 additions & 17 deletions src/Sys/SysModInstances.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class SysModInstances:public SysModule {
ui->initText(tableVar, "name", nullptr, 32, false, [this](EventArguments) { switch (eventType) {
case onSetValue:
for (size_t rowNrL = 0; rowNrL < instances.size() && (rowNr == UINT8_MAX || rowNrL == rowNr); rowNrL++)
variable.setValue(JsonString(instances[rowNrL].name, JsonString::Copied), rowNrL);
variable.setValue(JsonString(instances[rowNrL].name), rowNrL);
return true;
// comment this out for the time being as causes corrupted instance names
// case onChange:
Expand All @@ -135,7 +135,7 @@ class SysModInstances:public SysModule {
for (size_t rowNrL = 0; rowNrL < instances.size() && (rowNr == UINT8_MAX || rowNrL == rowNr); rowNrL++) {
char urlString[32] = "http://";
strlcat(urlString, instances[rowNrL].ip.toString().c_str(), sizeof(urlString));
variable.setValue(JsonString(urlString, JsonString::Copied), rowNrL);
variable.setValue(JsonString(urlString), rowNrL);
}
return true;
default: return false;
Expand All @@ -152,7 +152,7 @@ class SysModInstances:public SysModule {
ui->initText(tableVar, "IP", nullptr, 16, true, [this](EventArguments) { switch (eventType) {
case onSetValue:
for (size_t rowNrL = 0; rowNrL < instances.size() && (rowNr == UINT8_MAX || rowNrL == rowNr); rowNrL++)
variable.setValue(JsonString(instances[rowNrL].ip.toString().c_str(), JsonString::Copied), rowNrL);
variable.setValue(JsonString(instances[rowNrL].ip.toString().c_str()), rowNrL);
return true;
default: return false;
}});
Expand Down Expand Up @@ -233,24 +233,27 @@ class SysModInstances:public SysModule {
//extract the variable from insVariable.id()
char pid[32]; strlcpy(pid, insVariable.id() + 3, sizeof(pid)); //+3 : remove ins
char * id = strtok(pid, "_"); if (id != nullptr ) {strlcpy(pid, id, sizeof(pid)); id = strtok(nullptr, "_");} //split pid and id
Variable variable = Variable(mdl->findVar(pid, id));
Variable variable = Variable(pid, id);
switch (eventType) { //varEvent
case onSetValue:
//should not trigger onChange
for (size_t rowNrL = 0; rowNrL < instances.size() && (rowNr == UINT8_MAX || rowNrL == rowNr); rowNrL++) {
// ppf("initVar dash %s[%d]\n", variable.id(), rowNrL);
//do what setValue is doing except calling onChange
// insVar["value"][rowNrL] = instances[rowNrL].jsonData[variable.id()]; //only int values...

web->addResponse(insVariable.var, "value", instances[rowNrL].jsonData[variable.id()], rowNrL); // error: passing 'const Variable' as 'this' argument discards qualifiers
JsonVariant value = instances[rowNrL].jsonData[variable.id()];
web->addResponse(insVariable.var, "value", value, rowNrL); // error: passing 'const Variable' as 'this' argument discards qualifiers

// mdl->setValue(insVariable.var, instances[rowNrL].jsonData[variable.id()], rowNr);
//send to ws?
}
return true;
case onUI:
// call onUI of the base variable for the new variable
mdl->varEvents[variable.var["fun"]](insVariable, rowNr, onUI);
if (variable.var["fun"].as<uint8_t>() != UINT8_MAX)
mdl->varEvents[variable.var["fun"]](insVariable, rowNr, onUI);
else
insVariable.publish(onUI, rowNr); //is insVariable subscribed ???
return true;
case onChange: {
//do not set this initially!!!
Expand Down Expand Up @@ -436,7 +439,7 @@ class SysModInstances:public SysModule {
// Serial.println();

ppf("instances handleNotifications %d\n", notifierUdp.remoteIP()[3]);
for (JsonObject childVar: Variable(mdl->findVar("Instances", "instances")).children())
for (JsonObject childVar: Variable("Instances", "instances").children())
Variable(childVar).triggerEvent(onSetValue); //set the value (WIP) ); //rowNr //instance - instances.begin()

web->recvUDPCounter++;
Expand Down Expand Up @@ -508,7 +511,7 @@ class SysModInstances:public SysModule {
if (!message["id"].isNull() && !message["value"].isNull()) {
ppf("handleNotifications i:%d json message %.*s l:%d\n", instanceUDP.remoteIP()[3], packetSize, buffer, packetSize);

Variable(mdl->findVar(message["pid"].as<const char *>(), message["id"].as<const char *>())).setValueJV(message["value"]);
Variable(message["pid"].as<const char *>(), message["id"].as<const char *>()).setValueJV(message["value"]);
}
}
}
Expand Down Expand Up @@ -537,13 +540,13 @@ class SysModInstances:public SysModule {
}
if (erased) {
ppf("instances remove inactive instances\n");
for (JsonObject childVar: Variable(mdl->findVar("Instances", "instances")).children())
for (JsonObject childVar: Variable("Instances", "instances").children())
Variable(childVar).triggerEvent(onSetValue); //set the value (WIP)); //no rowNr so all rows updated

//tbd: pubsub mechanism
//LEDs specific
Variable(mdl->findVar("DDP", "instance")).triggerEvent(onUI); //rebuild options
// Variable(mdl->findVar("Artnet", "artInst")).triggerEvent(onUI); //rebuild options
Variable("DDP", "instance").triggerEvent(onUI); //rebuild options
// Variable("Artnet", "artInst").triggerEvent(onUI); //rebuild options
}
}

Expand Down Expand Up @@ -783,7 +786,7 @@ class SysModInstances:public SysModule {
id = strtok(nullptr, "."); //the rest after .
}

Variable(mdl->findVar(pid, id)).setValueJV(pair.value());
Variable(pid, id).setValueJV(pair.value());
}
instance.jsonData = newData; // deepcopy: https://github.com/bblanchon/ArduinoJson/issues/1023
// ppf("updateInstance json ip:%d", instance.ip[3]);
Expand All @@ -810,7 +813,7 @@ class SysModInstances:public SysModule {

// ppf("updateInstance updRow\n");

for (JsonObject childVar: Variable(mdl->findVar("Instances", "instances")).children())
for (JsonObject childVar: Variable("Instances", "instances").children())
Variable(childVar).triggerEvent(onSetValue); //set the value (WIP)); //rowNr instance - instances.begin()

//tbd: now done for all rows, should be done only for updated rows!
Expand All @@ -825,14 +828,14 @@ class SysModInstances:public SysModule {

//tbd: pubsub mechanism
//LEDs specific
Variable(mdl->findVar("DDP", "instance")).triggerEvent(onUI); //rebuild options
// Variable(mdl->findVar(Artnet", "artInst")).triggerEvent(onUI); //rebuild options
Variable("DDP", "instance").triggerEvent(onUI); //rebuild options
// Variable(Artnet", "artInst").triggerEvent(onUI); //rebuild options

// ui->processOnUI("instances");
//run though it sorted to find the right rowNr
// for (std::vector<InstanceInfo>::iterator instance=instances.begin(); instance!=instances.end(); ++instance) {
// if (instance->ip == messageIP) {
for (JsonObject childVar: Variable(mdl->findVar("Instances", "instances")).children()) {
for (JsonObject childVar: Variable("Instances", "instances").children()) {
Variable(childVar).triggerEvent(onSetValue); //set the value (WIP)); //no rowNr, update all
}
// }
Expand Down
Loading

0 comments on commit b48faab

Please sign in to comment.