Skip to content

Commit

Permalink
Console.log to UI + Minor changes
Browse files Browse the repository at this point in the history
index.js:
- add consolelog WIP
- bugfix mdlName.value exists

SysModModel:
- Coord3D overload functions: allow negative
- Coord3D.advance using step parameter

SysModPrint: pOut default Serial

SysModUI: callVarFun, change print
  • Loading branch information
ewoudwijma committed Apr 25, 2024
1 parent a976206 commit 1ff3511
Show file tree
Hide file tree
Showing 7 changed files with 1,255 additions and 1,224 deletions.
62 changes: 44 additions & 18 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ function onLoad() {
d.addEventListener("visibilitychange", handleVisibilityChange, false);
}

function consolelog() {
let logNode = gId("log");
let sep = "";
if (logNode) {
// console.log("conslog", theArgs);
for (var i = 0; i < arguments.length; i++) {
// console.log(arguments[i]);
if (Object.keys(arguments[i]))
logNode.value += sep + JSON.stringify(arguments[i]);
else
logNode.value += sep + arguments[i];
sep = " ";
// "WS receive createHTML " + module.id + "\n";
}
logNode.value += "\n";
// for (const arg of theArgs) {
// console.log(arg);
// }
logNode.scrollTop = logNode.scrollHeight;
}
else
console.log(arguments);
}

function makeWS() {
if (ws) return;
let url = (window.location.protocol == "https:"?"wss":"ws")+'://'+window.location.hostname+'/ws';
Expand Down Expand Up @@ -93,6 +117,7 @@ function makeWS() {
let module = json;
model.push((module)); //this is the model
console.log("WS receive createHTML", module);
consolelog("WS receive createHTML", module.id);
createHTML(module); //no parentNode

if (module.id == "System") {
Expand Down Expand Up @@ -231,7 +256,8 @@ function createHTML(json, parentNode = null, rowNr = UINT8_MAX) {

varNode = cE("div");
let mdlName = findVar("mdlName");
if (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 = findVar("mdlEnabled");
Expand Down Expand Up @@ -588,24 +614,24 @@ function receiveData(json) {

//special commands
if (key == "uiFun") {
console.log("receiveData no action", key, value); //should not happen anymore
consolelog("receiveData no action", key, value); //should not happen anymore
}
else if (key == "view") {
console.log("receiveData", key, value);
consolelog("receiveData", key, value);
changeHTMLView(value);
}
else if (key == "theme") {
console.log("receiveData", key, value);
consolelog("receiveData", key, value);
changeHTMLTheme(value);
}
else if (key == "canvasData") {
console.log("receiveData no action", key, value);
consolelog("receiveData no action", key, value);
} else if (key == "details") {
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 setEffect and fixtureGenChFun, tbd: )
console.log("receiveData details", key, variable, nodeId, rowNr);
consolelog("receiveData details", key, variable.id, nodeId, rowNr);
if (gId(nodeId + "_n")) gId(nodeId + "_n").remove(); //remove old ndiv

let modelVar = findVar(variable.id);
Expand All @@ -622,7 +648,7 @@ function receiveData(json) {
flushUIFunCommands(); //make sure uiFuns of new elements are called
}
else if (key == "addRow") { //update the row of a table
console.log("receiveData", key, value);
consolelog("receiveData", key, value);

if (value.id && value.rowNr != null) {
let tableId = value.id;
Expand All @@ -632,18 +658,18 @@ function receiveData(json) {
let tableNode = gId(tableId);
let tbodyNode = tableNode.querySelector("tbody");

console.log("addRow ", tableVar, tableNode, rowNr);
consolelog("addRow ", tableVar, tableNode, rowNr);

let newRowNr = tbodyNode.querySelectorAll("tr").length;

genTableRowHTML(tableVar, tableNode, newRowNr);
}
else
console.log("dev receiveData addRow no id and/or rowNr specified", key, value);
consolelog("dev receiveData addRow no id and/or rowNr specified", key, value);

} else if (key == "delRow") { //update the row of a table

console.log("receiveData", key, value);
consolelog("receiveData", key, value);
let tableId = value.id;
let tableVar = findVar(tableId);
let rowNr = value.rowNr;
Expand All @@ -656,7 +682,7 @@ function receiveData(json) {

varRemoveValuesForRow(tableVar, rowNr);

console.log("delRow ", tableVar, tableNode, rowNr);
consolelog("delRow ", tableVar, tableNode, rowNr);

} else if (key == "updRow") { //update the row of a table

Expand All @@ -665,19 +691,19 @@ function receiveData(json) {
let rowNr = value.rowNr;
let tableRow = value.value;

// console.log("receiveData updRow", key, tableId, rowNr, tableRow);
// console.log("updRow main", tableId, tableRows, tableNode, tableVar);
// consolelog("receiveData updRow", key, tableId, rowNr, tableRow);
// consolelog("updRow main", tableId, tableRows, tableNode, tableVar);

let colNr = 0;
for (let colVar of tableVar.n) {
let colValue = tableRow[colNr];
// console.log(" col", colNr, colVar, colValue);
// consolelog(" col", colNr, colVar, colValue);
changeHTML(colVar, {"value":colValue, "chk":"updRow"}, rowNr);
colNr++;
}

} else if (key == "sysInfo") { //update the row of a table
console.log("receiveData", key, value);
consolelog("receiveData", key, value);
sysInfo = value;
} else { //{variable:{label:value:options:comment:}}

Expand All @@ -686,19 +712,19 @@ function receiveData(json) {
if (variable) {
let rowNr = value.rowNr == null?UINT8_MAX:value.rowNr;
// if (variable.id == "fxEnd" || variable.id == "fxSize" || variable.id == "point")
// console.log("receiveData ", variable, value);
// consolelog("receiveData ", variable, value);
variable.fun = -2; // request processed

value.chk = "uiFun";
changeHTML(variable, value, rowNr); //changeHTML will find the rownumbers if needed
}
else
console.log("receiveData key is no variable", key, value);
consolelog("receiveData key is no variable", key, value);
}
} //for keys
} //isObject
else
console.log("receiveData no Object", object);
consolelog("receiveData no Object", object);
} //receiveData

//do something with an existing (variable) node, key is an existing node, json is what to do with it
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ build_flags =
${STARMOD_USERMOD_E131.build_flags}
; ${STARMOD_USERMOD_HA.build_flags}
-DAPP=StarMod
-DVERSION=24042319 ; Date and time (GMT!)
-DVERSION=24042519 ; Date and time (GMT!)
-DPIOENV=$PIOENV
lib_deps =
${starmod.lib_deps}
Expand Down
2 changes: 1 addition & 1 deletion src/App/AppModDemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AppModDemo: public SysModule {
ui->setLabel(var, "On");
return true;
case f_ChangeFun:
ui->callVarFun("bri", UINT8_MAX, f_ChangeFun); //set FastLed brightness
//implement on/off behaviour
return true;
default: return false;
}});
Expand Down
18 changes: 9 additions & 9 deletions src/Sys/SysModModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ struct Coord3D {
return result;
}
Coord3D operator+(Coord3D rhs) {
return Coord3D{unsigned16(x + rhs.x), unsigned16(y + rhs.y), unsigned16(z + rhs.z)};
return Coord3D{x + rhs.x, y + rhs.y, z + rhs.z};
}
Coord3D operator/(Coord3D rhs) {
return Coord3D{unsigned16(x / rhs.x), unsigned16(y / rhs.y), unsigned16(z / rhs.z)};
return Coord3D{x / rhs.x, y / rhs.y, z / rhs.z};
}
Coord3D operator%(Coord3D rhs) {
return Coord3D{unsigned16(x % rhs.x), unsigned16(y % rhs.y), unsigned16(z % rhs.z)};
return Coord3D{x % rhs.x, y % rhs.y, z % rhs.z};
}
Coord3D minimum(Coord3D rhs) {
return Coord3D{min(x, rhs.x), min(y, rhs.y), min(z, rhs.z)};
Expand All @@ -103,16 +103,16 @@ struct Coord3D {
return Coord3D{max(x, rhs.x), max(y, rhs.y), max(z, rhs.z)};
}
Coord3D operator*(unsigned8 rhs) {
return Coord3D{unsigned16(x * rhs), unsigned16(y * rhs), unsigned16(z * rhs)};
return Coord3D{x * rhs, y * rhs, z * rhs};
}
Coord3D operator/(unsigned8 rhs) {
return Coord3D{unsigned16(x / rhs), unsigned16(y / rhs), unsigned16(z / rhs)};
return Coord3D{x / rhs, y / rhs, z / rhs};
}
//move the coordinate one step closer to the goal, if difference in coordinates (used in GenFix)
Coord3D advance(Coord3D goal) {
if (x != goal.x) x += (x<goal.x)?1:-1;
if (y != goal.y) y += (y<goal.y)?1:-1;
if (z != goal.z) z += (z<goal.z)?1:-1;
Coord3D advance(Coord3D goal, uint8_t step) {
if (x != goal.x) x += (x<goal.x)?step:-step;
if (y != goal.y) y += (y<goal.y)?step:-step;
if (z != goal.z) z += (z<goal.z)?step:-step;
return *this;
}
unsigned distance(Coord3D rhs) {
Expand Down
4 changes: 2 additions & 2 deletions src/Sys/SysModPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ void SysModPrint::setup() {

parentVar = ui->initSysMod(parentVar, name, 2302);

//default to UI
ui->initSelect(parentVar, "pOut", 2, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
//default to Serial
ui->initSelect(parentVar, "pOut", 1, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
{
ui->setLabel(var, "Output");
Expand Down
6 changes: 2 additions & 4 deletions src/Sys/SysModUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,8 @@ class SysModUI: public SysModule {
// if (!var["value"].isNull() &&
if (funType != f_ValueFun) {
ppf("%sFun %s", funType==f_ValueFun?"val":funType==f_UIFun?"ui":funType==f_ChangeFun?"ch":funType==f_AddRow?"add":funType==f_DelRow?"del":"other", mdl->varID(var));
if (rowNr != UINT8_MAX)
ppf("[%d] = %s\n", rowNr, var["value"][rowNr].as<String>().c_str());
else
ppf(" = %s\n", var["value"].as<String>().c_str());
if (rowNr != UINT8_MAX) ppf("[%d]", rowNr);
ppf(" (%s)\n", var["value"].as<String>().c_str());
}
}
}
Expand Down
Loading

0 comments on commit 1ff3511

Please sign in to comment.