Skip to content

Commit

Permalink
newui updates, new ELS
Browse files Browse the repository at this point in the history
newui
- remove setDefaultValues
- css canvas 300x300
- modules.js: remove setDefaultValues

Pio.ini
- new ELS version

UserModLive
- refactor addExternalFunction and addExternalVariable
  • Loading branch information
ewowi committed Dec 27, 2024
1 parent 8717049 commit ed7d259
Show file tree
Hide file tree
Showing 9 changed files with 641 additions and 650 deletions.
2 changes: 1 addition & 1 deletion data/newui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Controller {
// every 10th second send binarydata
window.setInterval(function(){
let buffer = [0,1,2,3,4]
buffer[0] = Math.round(Math.random())
buffer[0] = Math.round(Math.random() * 2) //0, 1 or 2

// console.log(buffer)
// let buffer = new Uint8Array([0,1,2,3,4,5,6,7,8]);
Expand Down
9 changes: 2 additions & 7 deletions data/newui/mainnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ class MainNav {
</div>`
this.#createHTMLFun(this.#activeModuleJson, gId("Module.main"))
}
//done after innerHTML as it needs to find the nodes. tbd: createHTMLFun adds to dom directly
if (this.#setDefaultValuesFun) {
this.#setDefaultValuesFun(this.#activeModuleJson)
}

} //set activeModuleJson(moduleJson)

/**
Expand Down Expand Up @@ -174,11 +171,10 @@ class MainNav {
* Update the UI
*/
//updateUI is made after all modules have been fetched, how to adapt to add one module?
updateUI(moduleJson, createHTMLFun, setDefaultValuesFun) {
updateUI(moduleJson, createHTMLFun) {

//functions called when selecting a module
this.#createHTMLFun = createHTMLFun
this.#setDefaultValuesFun = setDefaultValuesFun

this.#updateMainMenu();
this.#updateSecondaryMenu();
Expand All @@ -201,5 +197,4 @@ class MainNav {

//stores the function to execute to display one module
#createHTMLFun = null;
#setDefaultValuesFun = null;
}
4 changes: 2 additions & 2 deletions data/newui/modules.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ textarea {
}

canvas {
width: 100%;
height: 100%;
width: 300;
height: 300;
border-radius: 12px;
border: 1px solid black;
background: transparent;
Expand Down
47 changes: 23 additions & 24 deletions data/newui/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,14 @@ class Modules {
return Math.abs(a.o) - Math.abs(b.o); //o is order nr (ignore negatives for the time being)
});

//all variables of module
//all child variables of module
for (let variable of moduleJson.n) {
let variableClass = varJsonToClass(variable);
variableClass.createHTML(gId(`m.${moduleJson.id}`))
}

gId(`m.${moduleJson.id}`).innerHTML += '<pre>' + JSON.stringify(moduleJson, null, 2) + '</pre>'
}

//done after innerHTML as it needs to find the nodes. tbd: createHTMLFun adds to dom directly
setDefaultValues(moduleJson) {
return;
// console.log("setDefaultValues", moduleJson)
controller.modules.walkThroughModel(function(parent, variable) { //this.walkThroughModel not working for some reason???

// if (Array.isArray(variable.value)) variable.value = variable.value[0] //temp hack to deal with table values

if (variable.value != null) {
let variableClass = varJsonToClass(variable);
variableClass.receiveData({"value":variable.value}); //receiveData knows how the value should be assigned to the node
}
}, moduleJson)
//show module.json (disabled for now)
// gId(`m.${moduleJson.id}`).innerHTML += '<pre>' + JSON.stringify(moduleJson, null, 2) + '</pre>'
}

//temporary to test issue above
Expand All @@ -64,7 +50,7 @@ class Modules {
this.model.push(moduleJson);

//updateUI is made after all modules have been fetched, how to adapt to add one module?
controller.mainNav.updateUI(moduleJson, this.createHTML, this.setDefaultValues); //moduleFun returns the html to show in the module panel of the UI
controller.mainNav.updateUI(moduleJson, this.createHTML); //moduleFun returns the html to show in the module panel of the UI
//still doesn't maker sense to call updateUI for every module ...
}

Expand All @@ -82,7 +68,7 @@ class Modules {
}
}

//loop through the model hierarchy and generateData data for each variable in the model
//loop through the model hierarchy and generateData data for each variable in the model (for Live Server)
generateData() {
this.walkThroughModel(function(parent, variable) {
if (parent) { //no need to send modules
Expand All @@ -101,6 +87,7 @@ class Modules {
return variable; //this stops the walkThrough
})
}

findParentVar(pid, id) {
// console.log("findVar", id, parent, model);
return this.walkThroughModel(function(parent, variable) {
Expand Down Expand Up @@ -284,7 +271,7 @@ class Variable {

//set the default value for this class
if (this.variable.value) {
console.log("init value", this.pidid(rowNr), this.variable.value)
// console.log("init value", this.pidid(rowNr), this.variable.value)
if (rowNr == UINT8_MAX)
this.receiveValue(this.variable.value)
else
Expand Down Expand Up @@ -384,16 +371,28 @@ class Variable {
}

if (properties.comment) {
console.log("receive comment for", this.pidid(), properties.comment)
// console.log("receive comment for", this.pidid(), properties.comment)
if (parentClass.variable.type != "table")
this.receiveComment(properties.comment)
else {
//place comment under th columns ...
}
}

if (properties.file)
this.receiveFile(properties.file)
if (properties.file) {
//not used ATM
let url;
if (window.location.href.includes("127.0.0.1"))
url = "/misc/" //get the files from the misc folder in the repo (Live Server)
else
url = `http://${window.location.hostname}/file/`

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);
});
}
} //if node
}

Expand Down Expand Up @@ -472,7 +471,7 @@ class CheckboxVariable extends Variable {
let node = gId(this.pidid(rowNr))

if (node && value != null) {
console.log("rv2", this.pidid(rowNr), value)
// console.log("rv2", this.pidid(rowNr), value)
// console.log("CheckboxVariable receiveValue", this.pidid(rowNr), value)
node.checked = value
node.indeterminate = (value == -1); //tbd: gen -1
Expand Down
3 changes: 2 additions & 1 deletion misc/F_Panel2x2-16x16.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"height": 32,
"depth": 1,
"ledSize": 5,
"shape": 0,
"ledShape": 0,
"ledFactor": 10,
"outputs": [
{
"pin": 2,
Expand Down
1 change: 1 addition & 0 deletions misc/misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cp ./tools/* ../../ewowi/StarBase/tools
cp ./misc/* ../../ewowi/StarBase/misc
cp ./data/* ../../ewowi/StarBase/data
cp ./data/newui/* ../../ewowi/StarBase/data/newui
cp ./data/svelte/* ../../ewowi/StarBase/data/svelte
cp ./platformio.ini ../../ewowi/StarBase
cp ./src/* ../../ewowi/StarBase/src

Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ build_flags =
-D STARBASE_USERMOD_LIVE
-D EXTPRINTF=ppf ;redirect Live Script prints to StarBase print
lib_deps =
https://github.com/ewowi/ESPLiveScript.git#7bcd5bf ; v3.1 ;ewowi repo adds some proposed PR's and makes sure we don't have unexpected updates
https://github.com/ewowi/ESPLiveScript.git#3f57cc2 ; v3.1 ;ewowi repo adds some proposed PR's and makes sure we don't have unexpected updates

[STARBASE]
build_flags =
Expand Down
12 changes: 6 additions & 6 deletions src/User/UserModLive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,13 @@ static float _time(float j) {
}

void UserModLive::addExternalVal(string result, string name, void * ptr) {
if (findLink(name, externalType::value) == -1) //allready added earlier
addExternal(name, externalType::value, ptr);
scScript += "external " + result + " " + name + ";\n";
if (findLink(name, externalType::value) == -1) //not allready added earlier
addExternalVariable(name, result, "", ptr);
}

void UserModLive::addExternalFun(string result, string name, string parameters, void * ptr) {
if (findLink(name, externalType::function) == -1) //allready added earlier
addExternal(name, externalType::function, ptr);
scScript += "external " + result + " " + name + parameters + ";\n";
if (findLink(name, externalType::function) == -1) //not allready added earlier
addExternalFunction(name, result, parameters, ptr);
}

// void UserModLive::addExternalFun(string name, std::function<void(int)> fun) {
Expand Down Expand Up @@ -365,6 +363,7 @@ static float _time(float j) {

if (post) scScript += post;

//print the script
size_t scripLines = 0;
size_t lastIndex = 0;
for (size_t i = 0; i < scScript.length(); i++)
Expand All @@ -375,6 +374,7 @@ static float _time(float j) {
lastIndex = i + 1;
}
}
ppf("\n");

ppf("Before parsing of %s\n", fileName);
ppf("Heap %s:%d f:%d / t:%d (l:%d) B [%d %d]\n", __FUNCTION__, __LINE__, ESP.getFreeHeap(), ESP.getHeapSize(), ESP.getMaxAllocHeap(), esp_get_free_heap_size(), esp_get_free_internal_heap_size());
Expand Down
Loading

0 comments on commit ed7d259

Please sign in to comment.