Skip to content

Commit

Permalink
Add progress type (heap,stack,psram), simplify callCFAW and processJson
Browse files Browse the repository at this point in the history
index.js
- rowNr use UINT8_max
- add progress type

AppFixture
- fxSize including count
- fixture: chFun: no sendDataws needed

AppModFixtureGen
- matrix2D: add panels

AppModLeds
- fxStart/end: max NUM_LEDS_Max
- fxCount combined with fxSize

SysModModel
- rename setChFunAndWs to callChFunAndWs
- callChFunAndWs: simplify: direct call to addResponse
- setValueV: with rowNr parameter
- rename setValueUIOnly to setUIValueV

SysModSystem
- heap, psram, stack: change to progress type and add chFun setting ui value and comment, call callChFunAndWs to update (WIP)

SysModUI
- add initProgress
- initCoord3D: add rowNr
- processJson: void result, also support var:value and use simplify use of setValue and callChFunAndWs
- initVar: refactor type check
- processUiFun: simplify responseObject

SysModWeb:
- wsEvent: bugfix: add check on uiFun
- wsEvent: cleanupClients if buffer full (WIP)
  • Loading branch information
ewowi committed Feb 7, 2024
1 parent ae83838 commit cae2f8f
Show file tree
Hide file tree
Showing 19 changed files with 1,519 additions and 1,555 deletions.
49 changes: 27 additions & 22 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let jsonValues = {};
let uiFunCommands = [];
let model = []; //model.json (as send by the server), used by FindVar
let savedView = null;
const UINT8_MAX = 255;

function gId(c) {return d.getElementById(c);}
function cE(e) { return d.createElement(e); }
Expand Down Expand Up @@ -97,7 +98,7 @@ function makeWS() {
// console.log("WS receive update", json);
receiveData(json);
else
console.log("program error array not expected", json);
console.log("dev array not expected", json);
}
}
}
Expand Down Expand Up @@ -137,7 +138,7 @@ function linearToLogarithm(json, value) {
return Math.round(result);
}

function createHTML(json, parentNode = null, rowNr = -1) {
function createHTML(json, parentNode = null, rowNr = UINT8_MAX) {

// console.log("createHTML", json, parentNode);
if (Array.isArray(json)) {
Expand All @@ -153,9 +154,9 @@ function createHTML(json, parentNode = null, rowNr = -1) {
else { // json is variable
let variable = json;

if (Array.isArray(variable.value) && rowNr != -1) {
if (Array.isArray(variable.value) && rowNr != UINT8_MAX) {
if (rowNr < variable.value.length && variable.value[rowNr] == null) {
console.log("not showing this var as value is null", variable, rowNr);
// console.log("not showing this var as value is null", variable, rowNr);
return;
}
}
Expand All @@ -167,7 +168,7 @@ function createHTML(json, parentNode = null, rowNr = -1) {
}
let parentNodeType = parentNode.nodeName.toLocaleLowerCase();

let isPartOfTableRow = (rowNr != -1);
let isPartOfTableRow = (rowNr != UINT8_MAX);

// if (!variable || !variable.id) {
// console.log("genHTML no variable and id", variable, parentNode); //tbd: caused by more data then columns in table...
Expand Down Expand Up @@ -317,7 +318,7 @@ function createHTML(json, parentNode = null, rowNr = -1) {
varNode = cE("input");
varNode.type = variable.type;
varNode.disabled = variable.ro;
varNode.value = initCap(variable.id); //initial label
varNode.value = initCap(variable.id); //initial label, button.value is the label shown on the button
varNode.addEventListener('click', (event) => {console.log(variable.type + " click", event.target);sendValue(event.target);});
} else if (variable.type == "range") {
varNode = cE("input");
Expand Down Expand Up @@ -364,6 +365,10 @@ function createHTML(json, parentNode = null, rowNr = -1) {
zNode.addEventListener('change', (event) => {console.log(variable.type + " change", event.target.parentNode);sendValue(event.target.parentNode);});
varNode.appendChild(zNode);
}
} else if (variable.type == "progress") {
varNode = cE("progress");
varNode.min = variable.min?variable.min:0; //if not specified then unsigned value (min=0)
if (variable.max) varNode.max = variable.max;
} else {
//input types: text, search, tel, url, email, and password.

Expand Down Expand Up @@ -447,7 +452,7 @@ function createHTML(json, parentNode = null, rowNr = -1) {
} //not an array but variable
}

function genTableRowHTML(json, parentNode = null, rowNr = -1) {
function genTableRowHTML(json, parentNode = null, rowNr = UINT8_MAX) {
let variable = json;
let tbodyNode = parentNode.querySelector("tbody");
// console.log("genTableRowHTML", parentNode.id, rowNr, tbodyNode.querySelectorAll("tr").length);
Expand Down Expand Up @@ -508,8 +513,8 @@ function receiveData(json) {
}
else if (key == "details") {
let variable = value.var;
let rowNr = value.rowNr == null?-1:value.rowNr;
let nodeId = variable.id + ((rowNr != -1)?"#" + rowNr:"");
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);
if (gId(nodeId + "_n")) gId(nodeId + "_n").remove(); //remove old ndiv
Expand All @@ -533,7 +538,7 @@ function receiveData(json) {
// console.log("updRow main", tableId, tableRows, tableNode, tableVar);

let rowFound = false;
let rowNr = -1;
let rowNr = UINT8_MAX;
for (let nodeRowNr = 1, rowNode; rowNode = tableNode.rows[nodeRowNr]; nodeRowNr++) { //<table> rows starting with header row
rowNr = nodeRowNr - 1;
// console.log(" noderow", rowNr, rowNode);
Expand Down Expand Up @@ -593,28 +598,28 @@ function receiveData(json) {
} //receiveData

//do something with an existing (variable) node, key is an existing node, json is what to do with it
function changeHTML(variable, commandJson, rowNr = -1) {
function changeHTML(variable, commandJson, rowNr = UINT8_MAX) {

let node = null;

if (rowNr != -1) node = gId(variable.id + "#" + rowNr);
if (rowNr != UINT8_MAX) node = gId(variable.id + "#" + rowNr);
else node = gId(variable.id);

if (!node) {
//we should find all nodes, it's a bit if a trick just checking for node0 (what if deleted): tbd: improve
let rowNodes = document.querySelectorAll(`${variable.type}[id*="${variable.id}#"]`); //find nodes from the right class with id + #nr
for (let subNode of rowNodes) {
let rowNr = parseInt(subNode.id.substring(variable.id.length + 1));
console.log("changeHTML found row nodes !", variable, subNode, commandJson, rowNr);
// console.log("changeHTML found row nodes !", variable, subNode, commandJson, rowNr);
changeHTML(variable, commandJson, rowNr); //recursive call of all nodes
}
if (rowNodes.length == 0)
console.log("dev changeHTML no node !", variable, node, commandJson, rowNr);
// if (rowNodes.length == 0) //can happen e.g. fixture parameters
// console.log("changeHTML no node !", variable, node, commandJson, rowNr);
return;
}

let nodeType = node.nodeName.toLocaleLowerCase();
let isPartOfTableRow = (rowNr != -1);
let isPartOfTableRow = (rowNr != UINT8_MAX);

if (commandJson.hasOwnProperty("label")) {
if (nodeType == "th") //table header
Expand Down Expand Up @@ -747,7 +752,7 @@ function changeHTML(variable, commandJson, rowNr = -1) {
let trNodes = tableNode.querySelector('tbody').querySelectorAll("tr");
let tableVar = findVar(tableNode.id); //tbd: table in table
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 == -1)?JSON.stringify(commandJson.value):commandJson.value[rowNr], commandJson.chk, rowNr);
// console.log("changeHTML th column", node.id, (rowNr == UINT8_MAX)?JSON.stringify(commandJson.value):commandJson.value[rowNr], commandJson.chk, rowNr);

let max = Math.max(valueLength, trNodes.length);
for (let newRowNr = 0; newRowNr<max;newRowNr++) {
Expand All @@ -773,9 +778,9 @@ function changeHTML(variable, commandJson, rowNr = -1) {

}
else if (node.parentNode.parentNode.nodeName.toLocaleLowerCase() == "td" && Array.isArray(commandJson.value)) { //table column, called for each column cell!!!
// console.log("changeHTML value array", node.parentNode.parentNode.nodeName.toLocaleLowerCase(), node.id, (rowNr == -1)?JSON.stringify(commandJson.value):commandJson.value[rowNr], commandJson.chk, rowNr);
// console.log("changeHTML value array", node.parentNode.parentNode.nodeName.toLocaleLowerCase(), node.id, (rowNr == UINT8_MAX)?JSON.stringify(commandJson.value):commandJson.value[rowNr], commandJson.chk, rowNr);

if (rowNr == -1) {
if (rowNr == UINT8_MAX) {
console.log("changeHTML value array should not happen when no rowNr", variable, node, commandJson, rowNr);
let newRowNr = 0;
for (let val of commandJson.value) {
Expand Down Expand Up @@ -848,7 +853,7 @@ function changeHTML(variable, commandJson, rowNr = -1) {
console.log(" value coord3D value not object[x,y,z]", commandJson.value);
}
else {//inputs or select
if (Array.isArray(commandJson.value) && rowNr != -1)
if (Array.isArray(commandJson.value) && rowNr != UINT8_MAX)
node.value = commandJson.value[rowNr];
else
node.value = commandJson.value;
Expand All @@ -863,7 +868,7 @@ function changeHTML(variable, commandJson, rowNr = -1) {

//value assignments depending on different situations

if ((variable.value == null || !Array.isArray(variable.value)) && !Array.isArray(commandJson.value) && rowNr == -1) {
if ((variable.value == null || !Array.isArray(variable.value)) && !Array.isArray(commandJson.value) && rowNr == UINT8_MAX) {
//no arrays and rowNr. normal situation
if (variable.value != commandJson.value)
variable.value = commandJson.value;
Expand All @@ -888,7 +893,7 @@ function changeHTML(variable, commandJson, rowNr = -1) {
variable.value[rowNr] = commandJson.value;
}
}
else if (!Array.isArray(variable.value) && !Array.isArray(commandJson.value) && rowNr != -1) {
else if (!Array.isArray(variable.value) && !Array.isArray(commandJson.value) && rowNr != UINT8_MAX) {
if (variable.value != commandJson.value) {
console.log("chHTML column with one value for all rows", variable.id, node.id, variable.value, commandJson.value, rowNr);
variable.value = commandJson.value;
Expand Down
12 changes: 1 addition & 11 deletions src/App/AppEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ class GEQEffect:public Effect {
if (e131mod->isEnabled) {
e131mod->patchChannel(3, "fadeOut", 255); // TODO: add constant for name
e131mod->patchChannel(4, "ripple", 255);
ui->processUiFun("e131Tbl");
ui->processUiFun("e131Tbl"); // sends data to ws...
}

#endif
Expand Down Expand Up @@ -1090,16 +1090,6 @@ class Effects {
// }
//remove vars with all values -99

JsonDocument *responseDoc = web->getResponseDoc();
responseDoc->clear(); //needed for deserializeJson?
JsonObject responseObject = responseDoc->to<JsonObject>();

responseObject["details"]["var"] = var;
responseObject["details"]["rowNr"] = rowNr;

print->printJson("var", responseObject);
web->sendDataWs(responseObject); //always send, also when no children, to remove them from ui

} // fx < size

return doMap;
Expand Down
5 changes: 3 additions & 2 deletions src/App/AppFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@

if (pixel >= startPosAdjusted && pixel <= endPosAdjusted) {

// to display ScrollingText on one side of a cube (WIP)
if (fixtureDimension == 3 && endPosAdjusted.z == 0)
fixtureDimension = _2D;

Expand Down Expand Up @@ -319,8 +320,8 @@
}

USER_PRINTF("projectAndMap V:%dx%dx%d V:%dx%dx%d and V:%d P:%d\n", leds->size.x, leds->size.y, leds->size.z, size.x, size.y, size.z, leds->nrOfLeds, nrOfLeds);
mdl->setValue("fxSize", leds->size, rowNr);
mdl->setValue("fxCount", leds->nrOfLeds, rowNr);

mdl->setValueV("fxSize", rowNr, "%d x %d x %d = %d", leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds);

USER_PRINTF("leds[%d].size = %d + %d\n", leds->rowNr, sizeof(Leds), leds->mappingTable.size()); //44

Expand Down
1 change: 1 addition & 0 deletions src/App/AppLeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ CRGB Leds::getPixelColor(uint16_t indexV) {
return CRGB::Black;
}
else if (!mappingTable[indexV].size()) //if no physMap // Core 1 panic'ed (LoadProhibited). Exception was unhandled. - std::vector<unsigned short, std::allocator<unsigned short> >::size()
// by blurrows CRGB cur = getPixelColor(XY(i,row));?
{
USER_PRINTF(" dev gPC P:%d >= %d", mappingTable[indexV][0], NUM_LEDS_Max);
return CRGB::Black;
Expand Down
8 changes: 1 addition & 7 deletions src/App/AppModFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,11 @@ class AppModFixture:public SysModule {
char fileName[32] = "";
if (files->seqNrToName(fileName, lds->fixture.fixtureNr)) {
//send to pview a message to get file filename
JsonDocument *responseDoc = web->getResponseDoc();
responseDoc->clear(); //needed for deserializeJson?
JsonVariant responseVariant = responseDoc->as<JsonVariant>();

web->addResponse("pview", "file", JsonString(fileName, JsonString::Copied));
web->sendDataWs(responseVariant);
print->printJson("fixture chFun send ws done", responseVariant); //during server startup this is not send to a client, so client refresh should also trigger this
}
}); //fixture

ui->initCoord3D(parentVar, "fixSize", lds->fixture.size, 0, UINT16_MAX, true, [this](JsonObject var) { //uiFun
ui->initCoord3D(parentVar, "fixSize", lds->fixture.size, UINT8_MAX, 0, UINT16_MAX, true, [this](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "Size");
// web->addResponse(var["id"], "value", fixture.size);
});
Expand Down
60 changes: 29 additions & 31 deletions src/App/AppModFixtureGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class GenFix {
}

void write2D(uint16_t x, uint16_t y) {
if (x>UINT16_MAX/2 || y>UINT8_MAX/2) USER_PRINTF("write2D coord too high %d,%d\n",x, y);
if (x>UINT16_MAX/2 || y>UINT16_MAX/2) USER_PRINTF("write2D coord too high %d,%d\n",x, y);

f.printf("%s[%d,%d]", pixelSep, x, y);
width = max(width, x);
Expand Down Expand Up @@ -176,31 +176,33 @@ class GenFix {
closePin();
}

void matrix2D (uint16_t startX, uint16_t startY, uint16_t width, uint16_t height) {
void matrix2D (uint16_t startX, uint16_t startY, uint8_t panels, uint16_t width, uint16_t height) {

openPin();

//qad setup of serpentine, should be done better!
bool serpentine = mdl->getValue("serpentine");

if (serpentine) {
for (uint8_t y = 0; y<height; y++) { //1cm distance between leds
if (y%2==0)
for (uint8_t panel=0; panel < panels; panel++) {
if (serpentine) {
for (uint8_t y = 0; y<height; y++) { //1cm distance between leds
if (y%2==0)
for (uint16_t x = 0; x<width ; x++) {
write2D(x*10+startX,y*10+startY);
}
else
for (int x = width-1; x>=0 ; x--) {
write2D(x*10+startX,y*10+startY);
}
}
}
else {
for (uint8_t y = 0; y<height; y++) //1cm distance between leds
for (uint16_t x = 0; x<width ; x++) {
write2D(x*10+startX,y*10+startY);
}
else
for (int x = width-1; x>=0 ; x--) {
write2D(x*10+startX,y*10+startY);
}
}
}
else {
for (uint8_t y = 0; y<height; y++) //1cm distance between leds
for (uint16_t x = 0; x<width ; x++) {
write2D(x*10+startX,y*10+startY);
}
}

closePin();
}
Expand Down Expand Up @@ -554,6 +556,8 @@ class AppModFixtureGen:public SysModule {
select.add("3DGeodesicDome WIP"); //12
}, [this](JsonObject var, uint8_t) { //chFun
fixtureGenChFun(var);

web->addResponse("details", "var", var);
}); //fixtureGen

ui->initText(parentVar, "pinList", "16", UINT8_MAX, 32, false, [](JsonObject var) { //uiFun
Expand All @@ -563,6 +567,9 @@ class AppModFixtureGen:public SysModule {
ui->initButton(parentVar, "generate", nullptr, false, [](JsonObject var) { //uiFun
}, [this](JsonObject var, uint8_t) { //chFun
generateChFun(var);

//reload fixture select
ui->processUiFun("fixture"); //in AppModFixture sends data to ws...
});

}
Expand Down Expand Up @@ -613,6 +620,8 @@ class AppModFixtureGen:public SysModule {
ui->initNumber(parentVar, "nrOfRings", 24, 1, 360);
}
else if (value == f_2DMatrix) {
ui->initNumber(parentVar, "panels", 1, 1, 255);

ui->initNumber(parentVar, "width", 8, 1, 255);

ui->initNumber(parentVar, "height", 8, 1, 255);
Expand Down Expand Up @@ -645,15 +654,6 @@ class AppModFixtureGen:public SysModule {
ui->initNumber(parentVar, "width", 24, 1, 16);
}

JsonDocument *responseDoc = web->getResponseDoc();
responseDoc->clear(); //needed for deserializeJson?
JsonObject responseObject = responseDoc->to<JsonObject>();

responseObject["details"] = parentVar;

print->printJson("parentVar", responseObject);
web->sendDataWs(responseObject); //always send, also when no children, to remove them from ui

}

void generateChFun(JsonObject var) {
Expand All @@ -673,12 +673,13 @@ class AppModFixtureGen:public SysModule {
genFix.closeHeader();

} else if (fix == f_2DMatrix) {
uint16_t panels = mdl->getValue("panels");
uint16_t width = mdl->getValue("width");
uint16_t height = mdl->getValue("height");

genFix.openHeader("2DMatrix%d%d", width, height);
genFix.openHeader("2DMatrix%dx%d%d", panels, width, height);

genFix.matrix2D(0, 0, width, height);
genFix.matrix2D(0, 0, panels, width, height);

genFix.closeHeader();

Expand Down Expand Up @@ -712,9 +713,9 @@ class AppModFixtureGen:public SysModule {

genFix.rings241(0, 0);

genFix.matrix2D(190, 0, 8, 8);
genFix.matrix2D(190, 0, 1, 8, 8);

genFix.matrix2D(0, 190, 50, 6);
genFix.matrix2D(0, 190, 1, 50, 6);

genFix.ring2D(190, 85, 48);

Expand Down Expand Up @@ -816,9 +817,6 @@ class AppModFixtureGen:public SysModule {
}

files->filesChange();

//reload fixture select
ui->processUiFun("fixture");
}

// File openFile(const char * name) {
Expand Down
Loading

0 comments on commit cae2f8f

Please sign in to comment.