Skip to content

Commit

Permalink
identify variables by pid and id
Browse files Browse the repository at this point in the history
findVar(pid,id)
- index.js
- newui/index.js
- newui/modules.js

SysModFiles
- setValue(pid,id)

SysModInstances
- findVar(pid,id)
- getValue(pid,id)
- callVarFun(pid, id)
- sendMessageUDP(pid, id)
- updateInstance: split pid, id

SysModModel
- do not exclude pid in model.json save
- remove findVar(id)
- Variable: add pid()
- setValueJV: use var
- setValue, getValue: add pid

SysModNetwork
- ethOn: default false
- ethConfig: default olimex
- getValue(pid,id)
- setValue(pid,id)

SysModSystem
- setValue(pid,id)
- heap, psram, stacks: use onLoop1s

SysModUI
- callVarFun add pid
- callVarFun: support VectorString pointers
- initVar: use pid , no differentParents check
- findVar(pid,id)
- processJson; split pid and id

SysModWeb
- findVar(pid,id)
- setValue(pid,id)
- getValue(pid,id)

UserModE131
- findVar(pid,id)
- add pid to varToWatch
  • Loading branch information
ewoudwijma committed Oct 1, 2024
1 parent bf11ce0 commit dc4f940
Show file tree
Hide file tree
Showing 23 changed files with 2,081 additions and 2,089 deletions.
65 changes: 29 additions & 36 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,18 @@ async function fetchModel() {
}

class Modules {
findVar(id, parent = model) {
// console.log("findVar", id, parent, model);
//temp: if pid.id, then search for id
let ids = id.split(".")
if (ids[1])
id = ids[1]

let foundVar = null;
findVar(pid, id, parent = model) {
for (var variable of parent) {
if (foundVar == null) {
if (variable.id == id)
foundVar = variable;
else if (variable.n)
foundVar = this.findVar(id, variable.n); //recursive
if (variable.pid == pid && variable.id == id)
return variable;
else if (variable.n) {
let foundVar = this.findVar(pid, id, variable.n); //recursive
if (foundVar) return foundVar
}
}
return foundVar;
if (parent == model)
console.log("dev findVar not found", pid, id)
return null;
}

}
Expand Down Expand Up @@ -297,12 +292,7 @@ function createHTML(json, parentNode = null, rowNr = UINT8_MAX) {
let ndivNeeded = true; //for details ("n"), module and table do not need an extra div for details

let labelNode = cE("label");
let parentVar = controller.modules.findVar(variable.pid);
if (parentVar && variable.id != parentVar.id && parentVar.id && variable.id.substring(0, parentVar.id.length) == parentVar.id) { // if parent id is beginning of the name of the child id then remove that part
labelNode.innerText = initCap(variable.id.substring(parentVar.id.length)); // the default when not overridden by onUI
}
else
labelNode.innerText = initCap(variable.id); // the default when not overridden by onUI
labelNode.innerText = initCap(variable.id); // the default when not overridden by onUI

divNode = cE("div");
divNode.id = variable.pid + "." + variable.id + (rowNr != UINT8_MAX?"#" + rowNr:"") + "_d";
Expand All @@ -316,12 +306,12 @@ function createHTML(json, parentNode = null, rowNr = UINT8_MAX) {
ndivNeeded = false;

varNode = cE("div");
let mdlName = controller.modules.findVar("mdlTbl.mdlName");
let mdlName = controller.modules.findVar("mdlTbl", "mdlName");
if (mdlName && mdlName.value) { //sometimes value not set yet
// console.log("createModule", variable, mdlName);
let index = mdlName.value.indexOf(variable.id); //find this module
if (index != -1) {
let mdlEnabled = controller.modules.findVar("mdlEnabled");
let mdlEnabled = controller.modules.findVar("mdlTbl", "mdlEnabled");
if (mdlEnabled)
varNode.hidden = !mdlEnabled.value[index]; //hidden if not enabled
}
Expand Down Expand Up @@ -756,10 +746,10 @@ function receiveData(json) {
let rowNr = value.rowNr == null?UINT8_MAX:value.rowNr;
let nodeId = variable.pid + "." + variable.id + ((rowNr != UINT8_MAX)?"#" + rowNr:"");
//if var object with .n, create .n (e.g. see fx.onChange (setEffect) and fixtureGenonChange, tbd: )
ppf("receiveData details", key, variable.id, nodeId, rowNr);
ppf("receiveData", key, variable.pid, variable.id, nodeId, rowNr);
if (gId(nodeId + "_n")) gId(nodeId + "_n").remove(); //remove old ndiv

let modelVar = controller.modules.findVar(variable.pid + "." + variable.id);
let modelVar = controller.modules.findVar(variable.pid, variable.id);
modelVar.n = variable.n;

//create new ndiv
Expand All @@ -776,10 +766,9 @@ function receiveData(json) {
ppf("receiveData", key, value); //e.g. "onAdd" {"id":"ArtNet.anTbl","rowNr":255}

if (value.id && value.rowNr != null) {
let tableId = value.id;
let tableId = value.pid + "." + value.id;
let rowNr = value.rowNr;

let tableVar = controller.modules.findVar(tableId);
let tableVar = controller.modules.findVar(value.pid, value.id);
let tableNode = gId(tableId);
let tbodyNode = tableNode.querySelector("tbody");

Expand All @@ -795,8 +784,8 @@ function receiveData(json) {
} else if (key == "onDelete") { //update the row of a table
ppf("receiveData", key, value); //e.g. "onDelete" {"id":"ArtNet.anTbl","rowNr":255}

let tableId = value.id;
let tableVar = controller.modules.findVar(tableId);
let tableId = value.pid + "." + value.id;
let tableVar = controller.modules.findVar(value.pid, value.id);
let rowNr = value.rowNr;

//delete the row here as well...
Expand All @@ -812,7 +801,8 @@ function receiveData(json) {
} else if (key == "updRow") { //update the row of a table

let tableId = value.id;
let tableVar = controller.modules.findVar(tableId); //TBD!!!
let pidid = tableId.split(".")
let tableVar = controller.modules.findVar(pidid[0], pidid[1]);
let rowNr = value.rowNr;
let tableRow = value.value;

Expand All @@ -832,7 +822,8 @@ function receiveData(json) {
sysInfo = value;
} else { //{variable:{label:value:options:comment:}}

let variable = controller.modules.findVar(key);
let pidid = key.split(".")
let variable = controller.modules.findVar(pidid[0], pidid[1]);

if (variable) {
let rowNr = value.rowNr == null?UINT8_MAX:value.rowNr;
Expand Down Expand Up @@ -1048,7 +1039,8 @@ function changeHTML(variable, commandJson, rowNr = UINT8_MAX) {

let tableNode = node.parentNode.parentNode.parentNode;
let trNodes = tableNode.querySelector('tbody').querySelectorAll("tr");
let tableVar = controller.modules.findVar(tableNode.id); //tbd: table in table
let pidid = tableNode.id.split(".")
let tableVar = controller.modules.findVar(pidid[0], pidid[1]);
let valueLength = Array.isArray(commandJson.value)?commandJson.value.length:1; //tbd: use table nr of rows (not saved yet)
// console.log("changeHTML th column", node.id, (rowNr == UINT8_MAX)?JSON.stringify(commandJson.value):commandJson.value[rowNr], commandJson.chk, rowNr);

Expand All @@ -1059,7 +1051,7 @@ function changeHTML(variable, commandJson, rowNr = UINT8_MAX) {
newValue = commandJson.value[newRowNr];
//hide/show disabled/enabled modules
if (variable.id == "mdlEnabled") {
let nameVar = controller.modules.findVar("mdlTbl.mdlName");
let nameVar = controller.modules.findVar("mdlTbl", "mdlName");
let mdlNode = nameVar.value?gId("m."+nameVar.value[newRowNr]):null; //Live Server Mode: no value
// console.log("mdlEnabled", variable, node, newValue, newRowNr, nameVar, mdlNode);
if (mdlNode) {
Expand Down Expand Up @@ -1354,7 +1346,7 @@ function requestJson(command) {
function sendValue(varNode) {
let varId;
if (varNode.id == "saveModel" || varNode.id == "bSave") {
varId = "saveModel";
varId = "Model.saveModel";
gId("bSave").value = "Save";
gId("bSave").disabled = true;
}
Expand Down Expand Up @@ -1646,15 +1638,16 @@ function changeHTMLView(viewName) {
else {
for (let moduleNode of divNode.childNodes) {
if (moduleNode.className) {
if (viewName=="vSetup" && controller.modules.findVar(moduleNode.id).s) // show all module with setup variable (s) set to true
let pidid = moduleNode.id.split(".")
if (viewName=="vSetup" && controller.modules.findVar(pidid[0], pidid[1]).s) // show all module with setup variable (s) set to true
found = true;
if (viewName=="vApp" && moduleNode.className == "appmod")
found = true;
if (viewName=="vSys" && moduleNode.className == "sysmod")
found = true;
if (viewName=="vUser" && moduleNode.className == "usermod")
found = true;
if (viewName=="vDash" && moduleNode.id == "Instances")
if (viewName=="vDash" && moduleNode.id == "m.Instances")
found = true;
}
// console.log(mdlColumnNode, moduleNode, moduleNode.className);
Expand Down
6 changes: 3 additions & 3 deletions data/newui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ class Controller {
}

receiveData(json) {
console.log("receiveData", json)
// console.log("receiveData", json)
if (isObject(json)) {
for (let key of Object.keys(json)) {
let value = json[key] //contains pid.id

let variable = this.modules.findVar(key);
let pidid = key.split(".")
let variable = this.modules.findVar(pidid[0], pidid[1]);
if (variable) {
let variableClass = varJsonToClass(variable);
variableClass.receiveData(value)
Expand Down
20 changes: 3 additions & 17 deletions data/newui/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,7 @@ class Modules {
}

//finds a var with id in the model, if found returns it
findVar(id) {
//temp: if pid.id, then search for id
let ids = id.split(".")
if (ids[1])
id = ids[1]
// console.log("findVar", id, parent, model);
return this.walkThroughModel(function(variable){
if (variable.id == id) //found variable
return variable; //this stops the walkThrough
})
}

//finds a var with id in the model, if found returns it
findVarP(pid, id) {
findVar(pid, id) {
// console.log("findVar", id, parent, model);
return this.walkThroughModel(function(variable){
if (variable.pid == pid, variable.id == id) //found variable
Expand Down Expand Up @@ -255,7 +242,7 @@ class Variable {

//ask server for onUI
let command = {};
command.onUI = [this.variable.id];
command.onUI = [this.variable.pid + "." + this.variable.id];
controller.requestJson(command); // this can be done here because of the async nature of requestJson, better is to do it after innerHTML+=...

if (this.variable.n) {
Expand Down Expand Up @@ -300,8 +287,7 @@ class Variable {
else
url = `http://${window.location.hostname}/file/`

fetchAndExecute(url, properties.file, this.node.id, function(id, text) { //send node.id as parameter
let variable = controller.modules.findVar(id)
fetchAndExecute(url, properties.file, this.variable, function(variable, text) {
variable.file = JSON.parse(text); //assuming it is json, should we call this file?
variable.file.new = true;
console.log("receiveData file fetched", variable.id, variable.file);
Expand Down
1 change: 1 addition & 0 deletions misc/misc.txt
Original file line number Diff line number Diff line change
@@ -1,6 +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)

WebHook to MM discord
https://discord.com/api/webhooks/1229821142479536179/UeO3ryPqUyHABYTAuGtHZK6t7yghM0ZETN0LUYpg32KBleGhm-zvaYDzkyYjiqaVqt0T/github
Expand Down
5 changes: 3 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ build_flags =
;-D CONFIG_ASYNC_TCP_TASK_STACK_SIZE ; 8192*2 here as default !!!
lib_deps =
https://github.com/MoonModules/ESPAsyncWebServer.git @ 3.2.2 ; + queueLength (see https://github.com/esphome/ESPAsyncWebServer/pull/38)
; https://github.com/mathieucarbou/ESPAsyncWebServer.git @ 3.3.5 ; WIP...

; ESPAsyncWebServer AirCoookie v2.0.7 version (2.2.1 is latest)
; [ESPAsyncWebServer]
Expand Down Expand Up @@ -75,7 +76,7 @@ lib_deps =
build_flags =
-D APP=StarBase
-D PIOENV=$PIOENV
-D VERSION=24093015 ; Date and time (GMT!), update at every commit!!
-D VERSION=24100118 ; 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 All @@ -89,7 +90,7 @@ build_flags =
${STARBASE_USERMOD_LIVE.build_flags} ;+222.204 bytes 11.7%
lib_deps =
${ESPAsyncWebServer.lib_deps} ;alternatively PsychicHttp
https://github.com/bblanchon/ArduinoJson.git # 7.2.0
https://github.com/bblanchon/ArduinoJson.git @ 7.2.0 ;force latest
; https://github.com/Jason2866/ESP32_Show_Info.git
;optional:
${STARBASE_USERMOD_E131.lib_deps}
Expand Down
12 changes: 6 additions & 6 deletions src/Sys/SysModFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,21 @@ void SysModFiles::loop20ms() {
}
root.close();

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

uint8_t rowNrL = 0;
for (VectorString name: fileNames) {
mdl->setValue("flName", JsonString(name.s, JsonString::Copied), rowNrL);
mdl->setValue("flEdit", JsonString(name.s, JsonString::Copied), rowNrL);
mdl->setValue("fileTbl", "flName", JsonString(name.s, JsonString::Copied), rowNrL);
mdl->setValue("fileTbl", "flEdit", JsonString(name.s, JsonString::Copied), rowNrL);
rowNrL++;
}
rowNrL = 0; for (uint16_t size: fileSizes) mdl->setValue("flSize", size, rowNrL++);
rowNrL = 0; for (uint16_t time: fileTimes) mdl->setValue("flTime", time, rowNrL++);
rowNrL = 0; for (uint16_t size: fileSizes) mdl->setValue("fileTbl", "flSize", size, rowNrL++);
rowNrL = 0; for (uint16_t time: fileTimes) mdl->setValue("fileTbl", "flTime", time, rowNrL++);
}
}

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

bool SysModFiles::remove(const char * path) {
Expand Down
Loading

0 comments on commit dc4f940

Please sign in to comment.