Skip to content

Commit 059118c

Browse files
committed
onUpdate for deleted rows, Nodes specify their type(s), Nodes on/off
Server ===== - Module: compareRecursive: onUpdate for deleted rows - Fixtures: Panel: add snake, run setup, hasFixDef - Animations: remove type and error. onUpdate: refactor nodes and on - Nodes: LiveScript: add WLED type controls, compile: analyze script on setup, loop, addPixel, modifyPixel - Nodes.h add hasSetup, hasLoop, hasModifier, hasFixDef - PhysicalLayer: check on Node.hasModifier and Node.on
1 parent d8535e4 commit 059118c

File tree

14 files changed

+13922
-13799
lines changed

14 files changed

+13922
-13799
lines changed

interface/src/lib/components/moonbase/ObjectArray.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@
135135
class="btn btn-primary text-primary-content btn-md absolute -top-14 right-0"
136136
onclick={() => {
137137
addItem(property.name);
138-
onChange();
139-
138+
140139
//add the new item to the data
141140
data[property.name].push(dataEditable);
141+
onChange();
142142
showEditor = true;
143143
}}
144144
>
@@ -171,7 +171,7 @@
171171
<div>
172172
<div class="font-bold">{getTimeAgo(data[property.name][index][propertyN.name], currentTime)}</div>
173173
</div>
174-
{:else if propertyN.type != "array" && propertyN.type != "password"}
174+
{:else if propertyN.type != "array" && propertyN.type != "controls" && propertyN.type != "password"}
175175
<div>
176176
<div class="font-bold">{data[property.name][index][propertyN.name]}</div>
177177
</div>

lib/framework/WWWData.h

Lines changed: 13690 additions & 13686 deletions
Large diffs are not rendered by default.

src/MoonBase/Module.cpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,48 @@ bool ModuleState::compareRecursive(JsonString parent, JsonVariant stateData, Jso
6767
JsonVariant newValue = newData[key.c_str()];
6868
if (!newValue.isNull() && stateValue != newValue) { //if value changed, don't update if not defined in newValue
6969

70-
if (depth != UINT8_MAX) {
70+
if (depth != UINT8_MAX) { //depth starts with '-1' (no depth)
7171
updatedItem.parent[depth] = parent.c_str();
7272
updatedItem.index[depth] = index;
7373
}
74+
for (int i = uint8_t(depth + 1); i < 2; i++) { // reset deeper levels when coming back from recursion
75+
updatedItem.parent[i] = "";
76+
updatedItem.index[i] = UINT8_MAX;
77+
}
7478

7579
if (stateValue.is<JsonArray>() || newValue.is<JsonArray>()) { // if the property is an array
7680
if (stateValue.isNull()) {stateData[key.c_str()].to<JsonArray>(); stateValue = stateData[key.c_str()];} // if old value is null, set to empty array
77-
JsonArray oldArray = stateValue.as<JsonArray>();
81+
JsonArray stateArray = stateValue.as<JsonArray>();
7882
JsonArray newArray = newValue.as<JsonArray>();
83+
84+
// ESP_LOGD(TAG, "compare %s[%d] %s = %s -> %s", parent.c_str(), index, key.c_str(), stateValue.as<String>().c_str(), newValue.as<String>().c_str());
7985

80-
for (int i = 0; i < max(oldArray.size(), newArray.size()); i++) { //compare each item in the array
81-
if (oldArray.size() < newArray.size()) oldArray.add<JsonObject>(); //add new row
82-
changed = compareRecursive(key, oldArray[i], newArray[i], updatedItem, depth+1, i) || changed;
83-
if (oldArray.size() > newArray.size()) oldArray.remove(i); //remove old row
86+
for (int i = 0; i < max(stateArray.size(), newArray.size()); i++) { //compare each item in the array
87+
if (i >= stateArray.size()) { //newArray has added a row
88+
ESP_LOGD(TAG, "add %s%s[%d] d: %d", parent.c_str(), key.c_str(), i, depth);
89+
stateArray.add<JsonObject>(); //add new row
90+
changed = compareRecursive(key, stateArray[i], newArray[i], updatedItem, depth+1, i) || changed;
91+
} else if (i >= newArray.size()) { //newArray has deleted a row
92+
ESP_LOGD(TAG, "remove %s.%s[%d] d: %d", parent.c_str(), key.c_str(), i, depth);
93+
// newArray.add<JsonObject>(); //add dummy row
94+
changed = true; //compareRecursive(key, stateArray[i], newArray[i], updatedItem, depth+1, i) || changed;
95+
//set all the values to null
96+
// UpdatedItem updatedItem; //create local updatedItem
97+
updatedItem.parent[(uint8_t)(depth+1)] = key.c_str();
98+
updatedItem.index[(uint8_t)(depth+1)] = i;
99+
for (JsonPair property : stateArray[i].as<JsonObject>()) {
100+
ESP_LOGD(TAG, " remove %s[%d] %s %s", key.c_str(), i, property.key().c_str(), property.value().as<String>().c_str());
101+
// newArray[i][property.key()] = nullptr; // Initialize the keys in newArray so comparerecusive can compare them
102+
updatedItem.name = property.key().c_str();
103+
updatedItem.oldValue = property.value().as<String>();
104+
updatedItem.value = JsonVariant(); // Assign an empty JsonVariant
105+
stateArray[i].remove(property.key()); //remove the property from the state row so onUpdate see it as empty
106+
if (onUpdate) onUpdate(updatedItem);
107+
108+
}
109+
stateArray.remove(i); //remove the state row entirely
110+
} else //row already exists
111+
changed = compareRecursive(key, stateArray[i], newArray[i], updatedItem, depth+1, i) || changed;
84112
}
85113
} else { // if property is key/value
86114
changed = true;

src/MoonBase/ModuleDemo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ModuleDemo : public Module
7070

7171
void onUpdate(UpdatedItem &updatedItem) override
7272
{
73-
ESP_LOGD(TAG, "no handle for %s.%s[%d] = %s -> %s", updatedItem.parent[0]?updatedItem.parent[0]:"", updatedItem.name, updatedItem.index[0], updatedItem.oldValue.c_str(), updatedItem.value.as<String>().c_str());
73+
ESP_LOGD(TAG, "no handle for %s[%d]%s[%d].%s = %s -> %s", updatedItem.parent[0]?updatedItem.parent[0]:"---", updatedItem.index[0], updatedItem.parent[1]?updatedItem.parent[1]:"---", updatedItem.index[1], updatedItem.name, updatedItem.oldValue.c_str(), updatedItem.value.as<String>().c_str());
7474
}
7575

7676
void loop1s() {

src/MoonBase/ModuleInstances.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ModuleInstances : public Module
6464

6565
void onUpdate(UpdatedItem &updatedItem) override
6666
{
67-
ESP_LOGD(TAG, "no handle for %s.%s[%d] = %s -> %s", updatedItem.parent[0]?updatedItem.parent[0]:"", updatedItem.name, updatedItem.index[0], updatedItem.oldValue.c_str(), updatedItem.value.as<String>().c_str());
67+
ESP_LOGD(TAG, "no handle for %s[%d]%s[%d].%s = %s -> %s", updatedItem.parent[0]?updatedItem.parent[0]:"---", updatedItem.index[0], updatedItem.parent[1]?updatedItem.parent[1]:"---", updatedItem.index[1], updatedItem.name, updatedItem.oldValue.c_str(), updatedItem.value.as<String>().c_str());
6868
}
6969

7070
void loop1s() {

src/MoonLight/Effects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,4 @@ class LissajousEffect: public Node {
211211
layerV->setPixelColor(locn, ColorFromPalette(palette, millis()/100+i, 255));
212212
}
213213
}
214-
};
214+
};

src/MoonLight/Fixtures.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,27 @@
1010
**/
1111

1212
class Panel16fixture: public Node {
13-
const char * name() override {return "Panel16";}
13+
const char * name() override {return "Panel🚥";}
1414

1515
uint8_t width = 16;
1616
uint8_t height = 16;
17+
bool snake = true;
1718

1819
void getControls(JsonArray controls) override {
20+
hasFixDef = true;
1921
JsonObject control;
20-
control = controls.add<JsonObject>(); control["name"] = "width"; control["type"] = "range"; control["default"] = 16; control["value"] = width;
21-
control = controls.add<JsonObject>(); control["name"] = "height"; control["type"] = "range"; control["default"] = 16; control["value"] = height;
22+
control = controls.add<JsonObject>(); control["name"] = "width"; control["type"] = "range"; control["default"] = 16; control["max"] = 32; control["value"] = width;
23+
control = controls.add<JsonObject>(); control["name"] = "height"; control["type"] = "range"; control["default"] = 16; control["max"] = 32; control["value"] = height;
24+
control = controls.add<JsonObject>(); control["name"] = "snake"; control["type"] = "checkbox"; control["default"] = true; control["value"] = snake;
2225
}
2326

2427
void setControl(JsonObject control) override {
2528
ESP_LOGD(TAG, "%s = %s", control["name"].as<String>().c_str(), control["value"].as<String>().c_str());
26-
if (control["width"] == "bpm") width = control["value"];
27-
if (control["height"] == "bpm") height = control["value"];
29+
if (control["name"] == "width") width = control["value"];
30+
if (control["name"] == "height") height = control["value"];
31+
if (control["name"] == "snake") snake = control["value"];
32+
//if changed run setup
33+
setup();
2834
}
2935

3036
void setup() override {
@@ -33,7 +39,7 @@ class Panel16fixture: public Node {
3339
layerV->layerP->addPixelsPre();
3440
for (int x = 0; x<width; x++) {
3541
for (int y = 0; y<height; y++) {
36-
layerV->layerP->addPixel({x, (x%2)?y:height-1-y, 0});
42+
layerV->layerP->addPixel({x, (x%2 || !snake)?y:height-1-y, 0});
3743
}
3844
}
3945
layerV->layerP->addPixelsPost();

src/MoonLight/Modifiers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class MultiplyModifier: public Node {
1717
Coord3D originalSize;
1818

1919
void modifyPixelsPre() override {
20+
hasModifier = true;
21+
2022
layerV->size = (layerV->size + proMulti - Coord3D({1,1,1})) / proMulti; // Round up
2123
originalSize = layerV->size;
2224
ESP_LOGD(TAG, "multiply %d %d %d", layerV->size.x, layerV->size.y, layerV->size.z);
@@ -43,6 +45,7 @@ class MirrorModifier: public Node {
4345
Coord3D originalSize;
4446

4547
void getControls(JsonArray controls) override {
48+
hasModifier = true;
4649
JsonObject control;
4750
control = controls.add<JsonObject>(); control["name"] = "mirrorX"; control["type"] = "checkbox"; control["default"] = true; control["value"] = mirrorX;
4851
control = controls.add<JsonObject>(); control["name"] = "mirrorY"; control["type"] = "checkbox"; control["default"] = false; control["value"] = mirrorY;
@@ -81,6 +84,7 @@ class PinwheelModifier: public Node {
8184
uint8_t zTwist = 0;
8285

8386
void getControls(JsonArray controls) override {
87+
hasModifier = true;
8488
JsonObject control;
8589
control = controls.add<JsonObject>(); control["name"] = "petals"; control["type"] = "range"; control["default"] = 60; control["value"] = petals;
8690
control = controls.add<JsonObject>(); control["name"] = "swirlVal"; control["type"] = "range"; control["default"] = 30; control["value"] = swirlVal;

0 commit comments

Comments
 (0)