Skip to content

Commit

Permalink
StarLight renaming and callVarFun to setValue
Browse files Browse the repository at this point in the history
indexjs: uifun to onUI

SysModFiles
- drSize not using onSetValue but default value and setValue

SysModModel: comment varToValues

SysModSystem:
- heap, psram, mainstack, tcpstack: not using onSetValue but default value and setValue
  • Loading branch information
ewoudwijma committed Jun 26, 2024
1 parent aea4b87 commit 7f54753
Show file tree
Hide file tree
Showing 17 changed files with 1,429 additions and 1,443 deletions.
2 changes: 1 addition & 1 deletion data/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
--comment-color: #598a43;
--font-size: 10px;
}
:root.starLeds {
:root.starlight {
--bg-color: linear-gradient(to bottom, #ffbe33 0%, #b60f62 100%);
--text-color: #030303;
--th-color: #b60f6281;
Expand Down
4 changes: 2 additions & 2 deletions data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h2><div id="serverName"></div></h2>
<span> | </span>
<label>Theme</label> <select name="theme-select" id="theme-select" onchange="setTheme(this)">
<option value="starbase">StarBase</option>
<option value="starleds">StarLeds</option>
<option value="starlight">StarLight</option>
<option value="wled">WLED</option>
<option value="grayeen">Grayeen</option>
<option value="dev">Dev</option>
Expand All @@ -85,7 +85,7 @@ <h2><div id="serverName"></div></h2>
</div>
<div id="connind">&#9790;</div>
<div id="modalView" class="modal"></div>
<p style="color:grey;"> © 2024 MoonModules ☾ - StarMod, StarBase and StarLeds is licensed under GPL-v3</p>
<p style="color:grey;"> © 2024 MoonModules ☾ - StarMod, StarBase and StarLight is licensed under GPL-v3</p>
<div id="canvasMenu" style="position:absolute;display:none"> <!--;background-color:#b60f62-->
<p><button id="canvasButton1"></button></p>
<p><button id="canvasButton2"></button></p>
Expand Down
20 changes: 10 additions & 10 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function makeWS() {
gId("vApp").value = appName(); //tbd: should be set by server

//send request for onUI
flushUIFunCommands();
flushOnUICommands();
}
else
console.log("html of module already generated", json);
Expand Down Expand Up @@ -544,7 +544,7 @@ function createHTML(json, parentNode = null, rowNr = UINT8_MAX) {
if (variable.fun >= 0) { //>=0 as element in var
onUICommands.push(variable.id);
if (onUICommands.length > 4) { //every 4 vars (to respect responseDoc size) check WS_EVT_DATA info
flushUIFunCommands();
flushOnUICommands();
}
variable.fun = -1; //requested
}
Expand Down Expand Up @@ -587,7 +587,7 @@ function genTableRowHTML(json, parentNode = null, rowNr = UINT8_MAX) {
tdNode.appendChild(buttonNode);
trNode.appendChild(tdNode);
}
flushUIFunCommands();
flushOnUICommands();
if (variable.id == "insTbl")
setInstanceTableColumns();
}
Expand Down Expand Up @@ -631,7 +631,7 @@ function receiveData(json) {
let variable = value.var;
let rowNr = value.rowNr == null?UINT8_MAX:value.rowNr;
let nodeId = variable.id + ((rowNr != UINT8_MAX)?"#" + rowNr:"");
//if var object with .n, create .n (e.g. see fx.onChange (setEffect) and fixtureGenChFun, tbd: )
//if var object with .n, create .n (e.g. see fx.onChange (setEffect) and fixtureGenonChange, tbd: )
ppf("receiveData details", key, variable.id, nodeId, rowNr);
if (gId(nodeId + "_n")) gId(nodeId + "_n").remove(); //remove old ndiv

Expand All @@ -646,7 +646,7 @@ function receiveData(json) {
gId(nodeId).parentNode.appendChild(ndivNode);
createHTML(modelVar.n, ndivNode, rowNr);
}
flushUIFunCommands(); //make sure onUIs of new elements are called
flushOnUICommands(); //make sure onUIs of new elements are called
}
else if (key == "addRow") { //update the row of a table
ppf("receiveData", key, value);
Expand Down Expand Up @@ -712,7 +712,7 @@ function receiveData(json) {

if (variable) {
let rowNr = value.rowNr == null?UINT8_MAX:value.rowNr;
// if (variable.id == "fxEnd" || variable.id == "fxSize" || variable.id == "point")
// if (variable.id == "ledsEnd" || variable.id == "ledsSize" || variable.id == "point")
// ppf("receiveData ", variable, value);
variable.fun = -2; // request processed

Expand Down Expand Up @@ -912,7 +912,7 @@ function changeHTML(variable, commandJson, rowNr = UINT8_MAX) {
newRowNr++;
}

flushUIFunCommands(); //make sure onUIs of new elements are called
flushOnUICommands(); //make sure onUIs of new elements are called

if (variable.id == "insTbl")
setInstanceTableColumns();
Expand Down Expand Up @@ -958,7 +958,7 @@ function changeHTML(variable, commandJson, rowNr = UINT8_MAX) {
changeHTML(variable, {"value":null, "chk":"column"}, newRowNr); //new row cell has no value
}

flushUIFunCommands(); //make sure onUIs of new elements are called
flushOnUICommands(); //make sure onUIs of new elements are called

}
else if (node.parentNode.parentNode.nodeName.toLocaleLowerCase() == "td" && Array.isArray(commandJson.value)) { //table column, called for each column cell!!!
Expand Down Expand Up @@ -1171,11 +1171,11 @@ function changeHTML(variable, commandJson, rowNr = UINT8_MAX) {
}
} //changeHTML

function flushUIFunCommands() {
function flushOnUICommands() {
if (onUICommands.length > 0) { //if something to flush
var command = {};
command.onUI = onUICommands; //ask to run onUI for vars (to add the options)
// console.log("flushUIFunCommands", command);
// console.log("flushOnUICommands", command);
requestJson(command);
onUICommands = [];
}
Expand Down
8 changes: 4 additions & 4 deletions data/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"max": 255,
"n": [
{
"id": "fxTbl",
"id": "ledsTbl",
"type": "table",
"ro": false,
"o": 14,
Expand Down Expand Up @@ -223,7 +223,7 @@
]
},
{
"id": "fxStart",
"id": "ledsStart",
"type": "coord3D",
"ro": false,
"o": 22,
Expand All @@ -237,7 +237,7 @@
]
},
{
"id": "fxEnd",
"id": "ledsEnd",
"type": "coord3D",
"ro": false,
"o": 23,
Expand All @@ -251,7 +251,7 @@
]
},
{
"id": "fxSize",
"id": "ledsSize",
"type": "text",
"ro": true,
"o": 24,
Expand Down
13 changes: 5 additions & 8 deletions src/Sys/SysModFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void SysModFiles::setup() {
case onDeleteRow:
if (rowNr != UINT8_MAX && rowNr < fileList.size()) {
const char * fileName = fileList[rowNr].name;
// ppf("chFun delRow %s[%d] = %s %s\n", mdl->varID(var), rowNr, var["value"].as<String>().c_str(), fileName);
// ppf("fileTbl delRow %s[%d] = %s %s\n", mdl->varID(var), rowNr, var["value"].as<String>().c_str(), fileName);
this->removeFiles(fileName, false);

// print->printVar(var);
Expand Down Expand Up @@ -94,10 +94,7 @@ void SysModFiles::setup() {
default: return false;
}});

ui->initProgress(parentVar, "drsize", UINT16_MAX, 0, files->totalBytes(), true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case onSetValue:
mdl->setValue(var, files->usedBytes());
return true;
ui->initProgress(parentVar, "drsize", files->usedBytes(), 0, files->totalBytes(), true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case onUI:
ui->setLabel(var, "FS Size");
return true;
Expand Down Expand Up @@ -131,15 +128,15 @@ void SysModFiles::loop() {
}
root.close();

ui->callVarFun("drsize");
mdl->setValue("drsize", files->usedBytes());

for (JsonObject childVar: mdl->varChildren("fileTbl"))
ui->callVarFun(childVar);
ui->callVarFun(childVar, UINT8_MAX, onSetValue); //set the value (WIP)
}
}

void SysModFiles::loop10s() {
ui->callVarFun("drsize");
mdl->setValue("drsize", files->usedBytes());
}

bool SysModFiles::remove(const char * path) {
Expand Down
24 changes: 12 additions & 12 deletions src/Sys/SysModInstances.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct SysData {
uint8_t timeSource; //29
uint32_t tokiTime; //30 in sec
uint16_t tokiMs; //34
byte type; //0=WLED, 1=StarBase, 2=StarLeds, 3=StarFork
byte type; //0=WLED, 1=StarBase, 2=StarLight, 3=StarFork
DMX dmx;
uint8_t macAddress[6]; // 48 bits WIP
};
Expand Down Expand Up @@ -176,7 +176,7 @@ class SysModInstances:public SysModule {
ui->initText(tableVar, "insType", nullptr, 16, true, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case onSetValue:
for (forUnsigned8 rowNrL = 0; rowNrL < instances.size() && (rowNr == UINT8_MAX || rowNrL == rowNr); rowNrL++)
mdl->setValue(var, (instances[rowNrL].sysData.type==0)?"WLED":(instances[rowNrL].sysData.type==1)?"StarBase":(instances[rowNrL].sysData.type==2)?"StarLeds":"StarFork", rowNrL);
mdl->setValue(var, (instances[rowNrL].sysData.type==0)?"WLED":(instances[rowNrL].sysData.type==1)?"StarBase":(instances[rowNrL].sysData.type==2)?"StarLight":"StarFork", rowNrL);
return true;
case onUI:
ui->setLabel(var, "Type");
Expand Down Expand Up @@ -260,10 +260,10 @@ class SysModInstances:public SysModule {
strcat(columnVarID, var["id"]);
JsonObject insVar; // = ui->cloneVar(var, columnVarID, [this, var](JsonObject insVar){});

//create a var of the same type. InitVar is not calling chFun which is good in this situation!
//create a var of the same type. InitVar is not calling onChange which is good in this situation!
insVar = ui->initVar(tableVar, columnVarID, var["type"], false, [this, var](JsonObject insVar, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case onSetValue:
//should not trigger chFun
//should not trigger onChange
for (forUnsigned8 rowNrL = 0; rowNrL < instances.size() && (rowNr == UINT8_MAX || rowNrL == rowNr); rowNrL++) {
// ppf("initVar dash %s[%d]\n", mdl->varID(insVar), rowNrL);
//do what setValue is doing except calling onChange
Expand Down Expand Up @@ -328,7 +328,7 @@ class SysModInstances:public SysModule {
instances.clear();

//not needed here as there is no connection
// ui->processUiFun("insTbl");
// ui->processOnUI("insTbl");

//udp off ??
}
Expand Down Expand Up @@ -464,7 +464,7 @@ class SysModInstances:public SysModule {

ppf("insTbl handleNotifications %d\n", notifierUdp.remoteIP()[3]);
for (JsonObject childVar: mdl->varChildren("insTbl"))
ui->callVarFun(childVar); //rowNr //instance - instances.begin()
ui->callVarFun(childVar, UINT8_MAX, onSetValue); //set the value (WIP) ); //rowNr //instance - instances.begin()

web->recvUDPCounter++;
web->recvUDPBytes+=packetSize;
Expand Down Expand Up @@ -558,7 +558,7 @@ class SysModInstances:public SysModule {
if (erased) {
ppf("insTbl remove inactive instances\n");
for (JsonObject childVar: mdl->varChildren("insTbl"))
ui->callVarFun(childVar); //no rowNr so all rows updated
ui->callVarFun(childVar, UINT8_MAX, onSetValue); //set the value (WIP)); //no rowNr so all rows updated

ui->callVarFun("ddpInst", UINT8_MAX, onUI); //rebuild options
ui->callVarFun("artInst", UINT8_MAX, onUI); //rebuild options
Expand Down Expand Up @@ -596,7 +596,7 @@ class SysModInstances:public SysModule {
#endif
starMessage.header.insId = localIP[3]; //WLED: used in map of instances as index!
starMessage.header.version = VERSION;
starMessage.sysData.type = (strcmp(_INIT(TOSTRING(APP)), "StarBase")==0)?1:(strcmp(_INIT(TOSTRING(APP)), "StarLeds")==0)?2:3; //1=StarBase,2=StarLeds, 3=StarFork
starMessage.sysData.type = (strcmp(_INIT(TOSTRING(APP)), "StarBase")==0)?1:(strcmp(_INIT(TOSTRING(APP)), "StarLight")==0)?2:3; //1=StarBase,2=StarLight, 3=StarFork
starMessage.sysData.upTime = millis()/1000;
starMessage.sysData.now = millis() + sys->timebase; //similar to now
starMessage.sysData.timeSource = sys->toki.getTimeSource();
Expand Down Expand Up @@ -721,7 +721,7 @@ class SysModInstances:public SysModule {
// ppf("macaddress %02X:%02X:%02X:%02X:%02X:%02X\n", instance.macAddress[0], instance.macAddress[1], instance.macAddress[2], instance.macAddress[3], instance.macAddress[4], instance.macAddress[5]);
}

if (udpStarMessage.sysData.type >= 1) {//StarBase, StarLeds and forks only
if (udpStarMessage.sysData.type >= 1) {//StarBase, StarLight and forks only
instance.sysData = udpStarMessage.sysData;

if (instance.ip != WiFi.localIP()) { //send from localIP will be done after updateInstance
Expand Down Expand Up @@ -796,7 +796,7 @@ class SysModInstances:public SysModule {
// ppf("updateInstance updRow\n");

for (JsonObject childVar: mdl->varChildren("insTbl"))
ui->callVarFun(childVar); //rowNr instance - instances.begin()
ui->callVarFun(childVar, UINT8_MAX, onSetValue); //set the value (WIP)); //rowNr instance - instances.begin()

//tbd: now done for all rows, should be done only for updated rows!
}
Expand All @@ -811,12 +811,12 @@ class SysModInstances:public SysModule {
ui->callVarFun("ddpInst", UINT8_MAX, onUI); //rebuild options
ui->callVarFun("artInst", UINT8_MAX, onUI); //rebuild options

// ui->processUiFun("insTbl");
// ui->processOnUI("insTbl");
//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: mdl->varChildren("insTbl")) {
ui->callVarFun(childVar); //no rowNr, update all
ui->callVarFun(childVar, UINT8_MAX, onSetValue); //set the value (WIP)); //no rowNr, update all
}
// }
// }
Expand Down
27 changes: 14 additions & 13 deletions src/Sys/SysModModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,20 @@ void SysModModel::findVars(const char * property, bool value, FindFun fun, JsonA
}
}

void SysModModel::varToValues(JsonObject var, JsonArray row) {

//add value for each child
// JsonArray row = rows.add<JsonArray>();
for (JsonObject childVar : var["n"].as<JsonArray>()) {
print->printJson("fxTbl childs", childVar);
row.add(childVar["value"]);

if (!childVar["n"].isNull()) {
varToValues(childVar, row.add<JsonArray>());
}
}
}
//currently not used
// void SysModModel::varToValues(JsonObject var, JsonArray row) {

// //add value for each child
// // JsonArray row = rows.add<JsonArray>();
// for (JsonObject childVar : var["n"].as<JsonArray>()) {
// print->printJson("varToValues childs", childVar);
// row.add(childVar["value"]);

// if (!childVar["n"].isNull()) {
// varToValues(childVar, row.add<JsonArray>());
// }
// }
// }

bool checkDash(JsonObject var) {
if (var["dash"])
Expand Down
4 changes: 2 additions & 2 deletions src/Sys/SysModModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ class SysModModel:public SysModule {
JsonObject findParentVar(const char * id, JsonObject parent = JsonObject());
void findVars(const char * id, bool value, FindFun fun, JsonArray parent = JsonArray());

//recursively add values in a variant
void varToValues(JsonObject var, JsonArray values);
//recursively add values in a variant, currently not used
// void varToValues(JsonObject var, JsonArray values);

//sends dash var change to udp (if init), sets pointer if pointer var and run onChange
bool callVarChangeFun(JsonObject var, unsigned8 rowNr = UINT8_MAX, bool init = false);
Expand Down
4 changes: 2 additions & 2 deletions src/Sys/SysModPins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void SysModPins::setup() {
case onChange: {
bool pinValue = var["value"];

ppf("chFun pin19 %s:=%d\n", mdl->varID(var), pinValue);
ppf("onChange pin19 %s:=%d\n", mdl->varID(var), pinValue);

// softhack007: writing these pins on S3/C3/S2 may cause major problems (crashes included)
digitalWrite(19, pinValue?HIGH:LOW);
Expand All @@ -125,7 +125,7 @@ void SysModPins::loop() {
pinsChanged = false;

for (JsonObject childVar: mdl->varChildren("pinTbl"))
ui->callVarFun(childVar);
ui->callVarFun(childVar, UINT8_MAX, onSetValue); //set the value (WIP)
}
}

Expand Down
Loading

0 comments on commit 7f54753

Please sign in to comment.