Skip to content

Commit

Permalink
Tables bugfixing and improvements
Browse files Browse the repository at this point in the history
general
- add 'pseudo' VarObject functions (varID, varOrder)(WIP) (instead of JsonToChar)

index.js
- createHTML: create node also if rowNr > value length (WIP)
- genTableRowHTML: add setInstanceTableColumns

SysModFiles
- add fileList vector, push if filesChanged and use in columnValues
- use in delRow

SysModModel:
- cleanUpModel: remove values if table is readOnly
- add 'pseudo' VarObject functions (varID, varOrder)(WIP) (instead of JsonToChar)

SysModPins
- bug fixes: add rowNr, use ValueFun

SysModInstances
- bug fixes: add rowNr, use ValueFun
- allow update of one row only (rowNrL)
  • Loading branch information
ewowi committed Feb 19, 2024
1 parent 877de68 commit 03eb004
Show file tree
Hide file tree
Showing 18 changed files with 1,237 additions and 1,224 deletions.
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@
"mutex": "cpp",
"thread": "cpp",
"variant": "cpp",
"list": "cpp"
"list": "cpp",
"any": "cpp",
"codecvt": "cpp",
"csignal": "cpp",
"forward_list": "cpp",
"valarray": "cpp"
},
"cmake.configureOnOpen": false
}
9 changes: 6 additions & 3 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function createHTML(json, parentNode = null, rowNr = UINT8_MAX) {
let variable = json;

if (Array.isArray(variable.value) && rowNr != UINT8_MAX) {
if (rowNr >= variable.value.length || (rowNr < variable.value.length && variable.value[rowNr] == null)) {
if ((rowNr < variable.value.length && variable.value[rowNr] == null)) { //rowNr >= variable.value.length ||
// console.log("not showing this var as value is null", variable, rowNr);
return;
}
Expand Down Expand Up @@ -480,6 +480,8 @@ function genTableRowHTML(json, parentNode = null, rowNr = UINT8_MAX) {
trNode.appendChild(tdNode);
}
flushUIFunCommands();
if (variable.id == "insTbl")
setInstanceTableColumns();
}

//process json from server, json is assumed to be an object
Expand Down Expand Up @@ -576,7 +578,8 @@ function receiveData(json) {
let variable = findVar(key);

if (variable) {
// if (variable.id == "pinNr")
// if (variable.id == "vlLoopps" || variable.id == "flName" || variable.id == "insName")
// if (Array.isArray(variable.value))
// console.log("receiveData ", variable, value);
variable.fun = -2; // request processed

Expand Down Expand Up @@ -1239,7 +1242,7 @@ function setInstanceTableColumns() {
showHideColumn(columnNr, !isStageView);
}

gId("sma").parentNode.hidden = isStageView; //hide sync master label field and comment
if (gId("sma")) gId("sma").parentNode.hidden = isStageView; //hide sync master label field and comment
}

function changeHTMLView(value) {
Expand Down
28 changes: 14 additions & 14 deletions src/App/AppEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -1174,8 +1174,8 @@ class Effects {
sharedData.clear(); //make sure all values are 0

for (JsonObject var: var["n"].as<JsonArray>()) { //for all controls
if (var["o"].as<int>() >= 0) { //post init
var["o"] = -var["o"].as<int>(); // set all negative
if (mdl->varOrder(var) >= 0) { //post init
mdl->varOrder(var, -mdl->varOrder(var)); // set all negative
}
}

Expand All @@ -1189,23 +1189,23 @@ class Effects {

//check if post init added
bool postInit = false;
for (JsonObject childVar: var["n"].as<JsonArray>()) {
for (JsonObject childVar: mdl->varN(var)) {

if (childVar["o"].as<int>() >= 0) { //post init, just added,
if (mdl->varOrder(childVar) >= 0) { //post init, just added,
postInit = true;
break;
}
}
if (postInit) {
for (JsonObject childVar: var["n"].as<JsonArray>()) {
for (JsonObject childVar: mdl->varN(var)) {
if (childVar["value"].is<JsonArray>())
{
JsonArray valArray = childVar["value"].as<JsonArray>();
JsonArray valArray = childVar["value"];

if (childVar["o"].as<int>() < 0) { //if not updated
if (mdl->varOrder(childVar) < 0) { //if not updated
valArray[rowNr] = (char*)0; //null
// mdl->setValue(var, -99, rowNr); //set value -99
childVar["o"] = -childVar["o"].as<int>(); //make positive again
mdl->varOrder(childVar, -mdl->varOrder(childVar)); //make positive again
//if some values in array are not -99
}

Expand All @@ -1217,23 +1217,23 @@ class Effects {
}
if (allNull) {
print->printJson("remove allnulls", childVar);
var["n"].as<JsonArray>().remove(childVar);
mdl->varN(var).remove(childVar);
}
}

}
}

print->printJson("control", var);
// if (var["o"].as<int>() >= 0) { //post init
// var["o"] = -var["o"].as<int>(); //make positive again
// if (mdl->varOrder(var) >= 0) { //post init
// var["o"] = -mdl->varOrder(var); //make positive again
//set unused vars to inactive
// if (var["o"].as<int>() >=0)
// if (mdl->varOrder(var) >=0)
// mdl->setValue(var, UINT16_MAX, rowNr);
// }
// for (JsonObject var: var["n"].as<JsonArray>()) {
// if (var["o"].as<int>() <0)
// var["o"] = -var["o"].as<int>();
// if (mdl->varOrder(var) <0)
// var["o"] = -mdl->varOrder(var);
// }
//remove vars with all values -99

Expand Down
23 changes: 10 additions & 13 deletions src/App/AppFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@
break;
}

if (indexV != UINT16_MAX) { //can be nulled by inverse mapping
if (indexV > leds->nrOfLeds) {
USER_PRINTF("indexV too high %d>=%d (p:%d) p:%d,%d,%d\n", indexV, leds->nrOfLeds, indexP, pixel.x, pixel.y, pixel.z);
}
else if (indexV != UINT16_MAX) { //can be nulled by inverse mapping
//add physical tables if not present
if (indexV >= NUM_LEDS_Max / 2) {
USER_PRINTF("dev mapping add physMap %d>=%d/2 (V:%d) too big\n", indexV, NUM_LEDS_Max, leds->mappingTable.size());
Expand Down Expand Up @@ -307,20 +310,14 @@
leds->nrOfLeds = leds->mappingTable.size();

// uint16_t x=0; //indexV
// uint16_t y=0;
// // for (std::vector<std::vector<uint16_t>> ::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); ++physMap) {
// for (std::vector<uint16_t>physMap:leds->mappingTable) {
// if (physMap.size()) {
// USER_PRINTF("ledV %d mapping: firstLedP: %d #ledsP: %d", x, physMap[0], physMap.size());
// for (uint16_t indexP:physMap) {
// USER_PRINTF(" %d", indexP);
// y++;
// }
// for (std::vector<std::vector<uint16_t>>::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); ++physMap) {
// if (physMap->size()) {
// USER_PRINTF("ledV %d mapping: firstLedP: %d #ledsP: %d", x, physMap[0], physMap->size());
// for (uint16_t indexP:*physMap) {USER_PRINTF(" %d", indexP);}
// USER_PRINTF("\n");
// }
// else
// USER_PRINTF("ledV %d no mapping\n", x);

// // else
// // USER_PRINTF("ledV %d no mapping\n", x);
// x++;
// }
}
Expand Down
9 changes: 4 additions & 5 deletions src/App/AppModLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class AppModLeds:public SysModule {
return true;
case f_AddRow: {
rowNr = fixture.ledsList.size();
USER_PRINTF("chFun addRow %s[%d]\n", mdl->jsonToChar(var, "id"), rowNr);
USER_PRINTF("chFun addRow %s[%d]\n", mdl->varID(var), rowNr);

web->getResponseObject()["addRow"]["rowNr"] = rowNr;

Expand All @@ -81,7 +81,7 @@ class AppModLeds:public SysModule {
return true;
}
case f_DelRow: {
USER_PRINTF("chFun delrow %s[%d]\n", mdl->jsonToChar(var, "id"), rowNr);
USER_PRINTF("chFun delrow %s[%d]\n", mdl->varID(var), rowNr);
//tbd: fade to black
if (rowNr <fixture.ledsList.size()) {
fixture.ledsList.erase(fixture.ledsList.begin() + rowNr); //remove from leds
Expand Down Expand Up @@ -251,9 +251,8 @@ class AppModLeds:public SysModule {

// ui->stageVarChanged = true;
// //rebuild the table
for (JsonObject childVar: mdl->findVar("e131Tbl")["n"].as<JsonArray>()) {
ui->callVarFun(childVar, UINT8_MAX, f_UIFun);
}
for (JsonObject childVar: mdl->varN("e131Tbl"))
ui->callVarFun(childVar, UINT8_MAX, f_ValueFun);

// }
// else
Expand Down
73 changes: 45 additions & 28 deletions src/Sys/SysModFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// #include <FS.h>

bool SysModFiles::filesChanged = false;
bool SysModFiles::filesChanged = true; //init fileTbl

SysModFiles::SysModFiles() :SysModule("Files") {
if (!LittleFS.begin(true)) { //true: formatOnFail
Expand All @@ -35,54 +35,55 @@ void SysModFiles::setup() {

JsonObject tableVar = ui->initTable(parentVar, "fileTbl", nullptr, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case f_UIFun:
{
ui->setLabel(var, "Files");
ui->setComment(var, "List of files");
JsonArray rows = web->addResponseA(var["id"], "value"); //overwrite the value
dirToJson(rows);
return true;
}
case f_AddRow: {
USER_PRINTF("chFun addRow %s[%d] = %s\n", mdl->jsonToChar(var, "id"), rowNr, var["value"].as<String>().c_str());
case f_AddRow:
USER_PRINTF("chFun addRow %s[%d] = %s\n", mdl->varID(var), rowNr, var["value"].as<String>().c_str());
web->getResponseObject()["addRow"]["rowNr"] = rowNr;
//add a row with all defaults
return true;
}
case f_DelRow: {
USER_PRINTF("chFun delRow %s[%d] = %s\n", mdl->jsonToChar(var, "id"), rowNr, var["value"].as<String>().c_str());
if (rowNr != UINT8_MAX) {
// call uiFun of tbl to fill responseObject with files
ui->varFunctions[var["fun"]](var, UINT8_MAX, f_UIFun);
//trick to get the table values tbd: use column values
JsonObject responseObject = web->getResponseObject();
JsonArray row = responseObject["fileTbl"]["value"][rowNr];
if (!row.isNull()) {
const char * fileName = row[0]; //first column
print->printJson("delete file", row);
this->removeFiles(fileName, false);
}
case f_DelRow:
if (rowNr != UINT8_MAX && rowNr < fileList.size()) {
const char * fileName = fileList[rowNr].name;
USER_PRINTF("chFun delRow %s[%d] = %s %s\n", mdl->varID(var), rowNr, var["value"].as<String>().c_str(), fileName);
this->removeFiles(fileName, false);
}
print->printJson(" ", var);
return true;
}
default: return false;
}});

ui->initText(tableVar, "flName", nullptr, 32, true, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
ui->initText(tableVar, "flName", nullptr, 32, true, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case f_ValueFun:
for (uint8_t rowNr = 0; rowNr < fileList.size(); rowNr++)
mdl->setValue(var, JsonString(fileList[rowNr].name, JsonString::Copied), rowNr);
return true;
case f_UIFun:
ui->setLabel(var, "Name");
return true;
default: return false;
}});

ui->initNumber(tableVar, "flSize", UINT16_MAX, 0, UINT16_MAX, true, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
ui->initNumber(tableVar, "flSize", UINT16_MAX, 0, UINT16_MAX, true, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case f_ValueFun:
for (uint8_t rowNr = 0; rowNr < fileList.size(); rowNr++)
mdl->setValue(var, fileList[rowNr].size, rowNr);
return true;
case f_UIFun:
ui->setLabel(var, "Size (B)");
return true;
default: return false;
}});

ui->initURL(tableVar, "flLink", nullptr, true, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
ui->initURL(tableVar, "flLink", nullptr, true, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case f_ValueFun:
for (uint8_t rowNr = 0; rowNr < fileList.size(); rowNr++) {
char urlString[32] = "file/";
strncat(urlString, fileList[rowNr].name, sizeof(urlString)-1);
mdl->setValue(var, JsonString(urlString, JsonString::Copied), rowNr);
}
return true;
case f_UIFun:
ui->setLabel(var, "Show");
return true;
Expand All @@ -109,11 +110,27 @@ void SysModFiles::loop() {
// SysModule::loop();

if (filesChanged) {
ui->callVarFun(mdl->findVar("drsize"));
filesChanged = false;

// ui->processUiFun("fileTbl");
ui->callVarFun("fileTbl", UINT8_MAX, f_UIFun);
fileList.clear();

File root = LittleFS.open("/");
File file = root.openNextFile();

while (file) {
FileDetails details;
strcpy(details.name, file.name());
details.size = file.size();
fileList.push_back(details);
file.close();
file = root.openNextFile();
}
root.close();

ui->callVarFun(mdl->findVar("drsize"));

for (JsonObject childVar: mdl->varN("fileTbl"))
ui->callVarFun(childVar, UINT8_MAX, f_ValueFun);
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/Sys/SysModFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@
#include "SysModule.h"
#include "LittleFS.h"

struct FileDetails {
char name[32];
size_t size;
};

class SysModFiles: public SysModule {

public:

std::vector<FileDetails> fileList;

SysModFiles();
void setup();
void loop();
Expand Down Expand Up @@ -52,7 +60,7 @@ class SysModFiles: public SysModule {
bool readFile(const char * path);

private:
static bool filesChanged;// = false;
static bool filesChanged;

};

Expand Down
Loading

0 comments on commit 03eb004

Please sign in to comment.