Skip to content

Commit d8535e4

Browse files
committed
Node controls: MultiInput UI widgets, Node.on, setControl
UI == - MultiInput: range: default 0-255, default value as tooltip - ObjectArray: support control type (name, type, value -> type as UI widget) Server ===== - pio.ini: FastLED 3.9.16 - Nodes, Effects, Modifiers, Fixtures: setControls->setControl, getControls: add default, add node.on - Animations: add nodes.on, onUpdate: restructure Nodes, add on, setControl
1 parent 2de8ecf commit d8535e4

File tree

12 files changed

+14533
-13486
lines changed

12 files changed

+14533
-13486
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,20 @@
8282
<!-- range colors: https://daisyui.com/components/range/ -->
8383
<input
8484
type="range"
85-
min={property.min}
86-
max={property.max}
85+
min={property.min?property.min:0}
86+
max={property.max?property.max:255}
8787
step={step}
8888
class={"range " + (disabled == false ? (property.color=="Red"?"range-error":(property.color=="Green"?"range-success":"range-primary")) : "range-secondary")}
8989
{disabled}
90+
title={property.default}
9091
bind:value={value}
9192
on:change={onChange}
9293
/>
9394
{#if hasNumber}
9495
<input
9596
type="number"
96-
min={property.min}
97-
max={property.max}
97+
min={property.min?property.min:0}
98+
max={property.max?property.max:255}
9899
step={step}
99100
class="input input-bordered"
100101
style="height: 2rem; width: 5rem"

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import MultiInput from '$lib/components/moonbase/MultiInput.svelte';
2626
import ObjectArray from '$lib/components/moonbase/ObjectArray.svelte';
2727
import {initCap, getTimeAgo} from '$lib/stores/moonbase_utilities';
28+
import { fromJSON } from 'postcss';
2829
2930
let { property, data = $bindable(), definition, onChange, changeOnInput} = $props();
3031
@@ -177,7 +178,7 @@
177178
{/if}
178179
{/each}
179180
{#each property.n as propertyN}
180-
{#if propertyN.type == "array"}
181+
{#if propertyN.type == "array" || propertyN.type == "controls"}
181182
<div>
182183
<div class="font-bold">↓{nrofDetails(index, propertyN)}</div>
183184
</div>
@@ -211,13 +212,17 @@
211212
{#if showEditor && property.name == propertyEditable && data[property.name] && data[property.name].length}
212213
<div class="divider my-0"></div>
213214
{#each property.n as propertyN}
214-
{#if propertyN.type != "array"}
215+
{#if propertyN.type == "array"}
216+
<label for="{propertyN.name}">{propertyN.name}</label>
217+
<ObjectArray property={propertyN} bind:data={dataEditable} definition={localDefinition} onChange={onChange} changeOnInput={changeOnInput}></ObjectArray>
218+
{:else if propertyN.type == "controls"}
219+
{#each dataEditable[propertyN.name] as control}
220+
<MultiInput property={control} bind:value={control.value} onChange={onChange} changeOnInput={changeOnInput}></MultiInput>
221+
{/each}
222+
{:else}
215223
<div>
216224
<MultiInput property={propertyN} bind:value={dataEditable[propertyN.name]} onChange={onChange} changeOnInput={changeOnInput}></MultiInput>
217225
</div>
218-
{:else if propertyN.type == "array"}
219-
<label for="{propertyN.name}">{propertyN.name}</label>
220-
<ObjectArray property={propertyN} bind:data={dataEditable} definition={localDefinition} onChange={onChange} changeOnInput={changeOnInput}></ObjectArray>
221226
{/if}
222227
{/each}
223228
{/if}

lib/framework/WWWData.h

Lines changed: 14376 additions & 13345 deletions
Large diffs are not rendered by default.

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extra_configs =
2020
build_flags =
2121
-D HTTPD_STACK_SIZE=16384 ;8192 ; default 4096 but not enough for more complex read and update
2222
lib_deps =
23-
https://github.com/FastLED/FastLED.git ; Comment if FT_MOONLIGHT=0
23+
https://github.com/FastLED/FastLED.git#3.9.16 ; Comment if FT_MOONLIGHT=0
2424
https://github.com/hpwit/ESPLiveScript.git#39e9409 ; 1.3.2 / v4.2 15-02-2025 ; Comment if FT_LIVESCRIPT=0
2525

2626
[env]

src/MoonBase/ModuleDemo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ModuleDemo : public Module
3838
values.add("Offline");
3939
values.add("Signal Strength");
4040
values.add("Priority");
41-
property = root.add<JsonObject>(); property["name"] = "brightness"; property["type"] = "range"; property["min"] = 0; property["max"] = 255; property["default"] = 10;
41+
property = root.add<JsonObject>(); property["name"] = "brightness"; property["type"] = "range"; property["default"] = 10;
4242
property = root.add<JsonObject>(); property["name"] = "millis"; property["type"] = "number"; property["ro"] = true;
4343

4444
property = root.add<JsonObject>(); property["name"] = "savedNetworks"; property["type"] = "array"; details = property["n"].to<JsonArray>();

src/MoonLight/Effects.h

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ class SinelonEffect: public Node {
4545

4646
void getControls(JsonArray controls) override {
4747
JsonObject control;
48-
control = controls.add<JsonObject>(); control["name"] = "BPM"; control["type"] = "Range"; control["value"] = bpm;
48+
control = controls.add<JsonObject>(); control["name"] = "bpm"; control["type"] = "range"; control["default"] = 60; control["value"] = bpm;
4949
}
5050

51-
void setControls(JsonArray controls) override {
52-
ESP_LOGD(TAG, "%s", controls[0].as<String>().c_str());
53-
bpm = controls[0]["value"];
51+
void setControl(JsonObject control) override {
52+
ESP_LOGD(TAG, "%s = %s", control["name"].as<String>().c_str(), control["value"].as<String>().c_str());
53+
if (control["name"] == "bpm") bpm = control["value"];
5454
}
5555

5656
const char * name() override {return "Sinelon";}
@@ -89,12 +89,12 @@ class SinusEffect: public Node {
8989

9090
void getControls(JsonArray controls) override {
9191
JsonObject control;
92-
control = controls.add<JsonObject>(); control["name"] = "speed"; control["type"] = "Range"; control["value"] = speed;
92+
control = controls.add<JsonObject>(); control["name"] = "speed"; control["type"] = "range"; control["default"] = 5; control["value"] = speed;
9393
}
9494

95-
void setControls(JsonArray controls) override {
96-
ESP_LOGD(TAG, "%s", controls[0].as<String>().c_str());
97-
speed = controls[0]["value"];
95+
void setControl(JsonObject control) override {
96+
ESP_LOGD(TAG, "%s = %s", control["name"].as<String>().c_str(), control["value"].as<String>().c_str());
97+
if (control["name"] == "speed") speed = control["value"];
9898
}
9999

100100
const char * name() override {return "Sinus";}
@@ -135,12 +135,12 @@ class LinesEffect: public Node {
135135

136136
void getControls(JsonArray controls) override {
137137
JsonObject control;
138-
control = controls.add<JsonObject>(); control["name"] = "BPM"; control["type"] = "Range"; control["value"] = bpm;
138+
control = controls.add<JsonObject>(); control["name"] = "BPM"; control["type"] = "range"; control["default"] = 120; control["value"] = bpm;
139139
}
140140

141-
void setControls(JsonArray controls) override {
142-
ESP_LOGD(TAG, "%s", controls[0].as<String>().c_str());
143-
bpm = controls[0]["value"];
141+
void setControl(JsonObject control) override {
142+
ESP_LOGD(TAG, "%s = %s", control["name"].as<String>().c_str(), control["value"].as<String>().c_str());
143+
if (control["name"] == "BPM") bpm = control["value"];
144144
}
145145

146146
void setup() override {
@@ -172,24 +172,22 @@ class LinesEffect: public Node {
172172
class LissajousEffect: public Node {
173173
public:
174174

175-
uint8_t xFrequency = 64;// = leds.effectControls.read<uint8_t>();
176-
uint8_t fadeRate = 128;// = leds.effectControls.read<uint8_t>();
177-
uint8_t speed = 128;// = leds.effectControls.read<uint8_t>();
175+
uint8_t xFrequency = 64;
176+
uint8_t fadeRate = 128;
177+
uint8_t speed = 128;
178178

179179
void getControls(JsonArray controls) override {
180180
JsonObject control;
181-
control = controls.add<JsonObject>(); control["name"] = "xFrequency"; control["type"] = "Range"; control["value"] = xFrequency;
182-
control = controls.add<JsonObject>(); control["name"] = "fadeRate"; control["type"] = "Range"; control["value"] = fadeRate;
183-
control = controls.add<JsonObject>(); control["name"] = "speed"; control["type"] = "Range"; control["value"] = speed;
184-
}
185-
186-
void setControls(JsonArray controls) override {
187-
ESP_LOGD(TAG, "%s", controls[0].as<String>().c_str());
188-
ESP_LOGD(TAG, "%s", controls[1].as<String>().c_str());
189-
ESP_LOGD(TAG, "%s", controls[2].as<String>().c_str());
190-
xFrequency = controls[0]["value"];
191-
fadeRate = controls[1]["value"];
192-
speed = controls[2]["value"];
181+
control = controls.add<JsonObject>(); control["name"] = "xFrequency"; control["type"] = "range"; control["default"] = 64; control["value"] = xFrequency;
182+
control = controls.add<JsonObject>(); control["name"] = "fadeRate"; control["type"] = "range"; control["default"] = 128; control["value"] = fadeRate;
183+
control = controls.add<JsonObject>(); control["name"] = "speed"; control["type"] = "range"; control["default"] = 128; control["value"] = speed;
184+
}
185+
186+
void setControl(JsonObject control) override {
187+
ESP_LOGD(TAG, "%s = %s", control["name"].as<String>().c_str(), control["value"].as<String>().c_str());
188+
if (control["name"] == "xFrequency") xFrequency = control["value"];
189+
if (control["name"] == "fadeRate") fadeRate = control["value"];
190+
if (control["name"] == "speed") speed = control["value"];
193191
}
194192

195193
const char * name() override {return "Lissajous";}

src/MoonLight/Fixtures.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ class Panel16fixture: public Node {
1717

1818
void getControls(JsonArray controls) override {
1919
JsonObject control;
20-
control = controls.add<JsonObject>(); control["name"] = "width"; control["type"] = "Range"; control["value"] = width;
21-
control = controls.add<JsonObject>(); control["name"] = "height"; control["type"] = "Range"; control["value"] = height;
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;
2222
}
2323

24-
void setControls(JsonArray controls) override {
25-
ESP_LOGD(TAG, "%s", controls[0].as<String>().c_str());
26-
ESP_LOGD(TAG, "%s", controls[1].as<String>().c_str());
27-
width = controls[0]["value"];
28-
height = controls[1]["value"];
24+
void setControl(JsonObject control) override {
25+
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"];
2928
}
3029

3130
void setup() override {

src/MoonLight/Modifiers.h

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class MultiplyModifier: public Node {
1919
void modifyPixelsPre() override {
2020
layerV->size = (layerV->size + proMulti - Coord3D({1,1,1})) / proMulti; // Round up
2121
originalSize = layerV->size;
22+
ESP_LOGD(TAG, "multiply %d %d %d", layerV->size.x, layerV->size.y, layerV->size.z);
2223
}
2324

2425
void modifyPixel(Coord3D &pixel) override {
@@ -43,25 +44,24 @@ class MirrorModifier: public Node {
4344

4445
void getControls(JsonArray controls) override {
4546
JsonObject control;
46-
control = controls.add<JsonObject>(); control["name"] = "mirrorX"; control["type"] = "Checkbox"; control["value"] = mirrorX;
47-
control = controls.add<JsonObject>(); control["name"] = "mirrorY"; control["type"] = "Checkbox"; control["value"] = mirrorY;
48-
control = controls.add<JsonObject>(); control["name"] = "mirrorZ"; control["type"] = "Checkbox"; control["value"] = mirrorZ;
47+
control = controls.add<JsonObject>(); control["name"] = "mirrorX"; control["type"] = "checkbox"; control["default"] = true; control["value"] = mirrorX;
48+
control = controls.add<JsonObject>(); control["name"] = "mirrorY"; control["type"] = "checkbox"; control["default"] = false; control["value"] = mirrorY;
49+
control = controls.add<JsonObject>(); control["name"] = "mirrorZ"; control["type"] = "checkbox"; control["default"] = false; control["value"] = mirrorZ;
4950
}
5051

51-
void setControls(JsonArray controls) override {
52-
ESP_LOGD(TAG, "%s", controls[0].as<String>().c_str());
53-
ESP_LOGD(TAG, "%s", controls[1].as<String>().c_str());
54-
ESP_LOGD(TAG, "%s", controls[2].as<String>().c_str());
55-
mirrorX = controls[0]["value"];
56-
mirrorY = controls[1]["value"];
57-
mirrorZ = controls[2]["value"];
52+
void setControl(JsonObject control) override {
53+
ESP_LOGD(TAG, "%s = %s", control["name"].as<String>().c_str(), control["value"].as<String>().c_str());
54+
if (control["name"] == "mirrorX") mirrorX = control["value"];
55+
if (control["name"] == "mirrorY") mirrorY = control["value"];
56+
if (control["name"] == "mirrorZ") mirrorZ = control["value"];
5857
}
5958

6059
void modifyPixelsPre() override {
6160
if (mirrorX) layerV->size.x = (layerV->size.x + 1) / 2;
6261
if (mirrorY) layerV->size.y = (layerV->size.y + 1) / 2;
6362
if (mirrorZ) layerV->size.z = (layerV->size.z + 1) / 2;
6463
originalSize = layerV->size;
64+
ESP_LOGD(TAG, "mirror %d %d %d", layerV->size.x, layerV->size.y, layerV->size.z);
6565
}
6666

6767
void modifyPixel(Coord3D &pixel) override {
@@ -82,24 +82,20 @@ class PinwheelModifier: public Node {
8282

8383
void getControls(JsonArray controls) override {
8484
JsonObject control;
85-
control = controls.add<JsonObject>(); control["name"] = "petals"; control["type"] = "Range"; control["value"] = petals;
86-
control = controls.add<JsonObject>(); control["name"] = "swirlVal"; control["type"] = "Range"; control["value"] = swirlVal;
87-
control = controls.add<JsonObject>(); control["name"] = "reverse"; control["type"] = "Checkbox"; control["value"] = reverse;
88-
control = controls.add<JsonObject>(); control["name"] = "symmetry"; control["type"] = "Range"; control["value"] = symmetry;
89-
control = controls.add<JsonObject>(); control["name"] = "zTwist"; control["type"] = "Range"; control["value"] = zTwist;
85+
control = controls.add<JsonObject>(); control["name"] = "petals"; control["type"] = "range"; control["default"] = 60; control["value"] = petals;
86+
control = controls.add<JsonObject>(); control["name"] = "swirlVal"; control["type"] = "range"; control["default"] = 30; control["value"] = swirlVal;
87+
control = controls.add<JsonObject>(); control["name"] = "reverse"; control["type"] = "checkbox"; control["default"] = false; control["value"] = reverse;
88+
control = controls.add<JsonObject>(); control["name"] = "symmetry"; control["type"] = "range"; control["default"] = 1; control["value"] = symmetry;
89+
control = controls.add<JsonObject>(); control["name"] = "zTwist"; control["type"] = "range"; control["default"] = 0; control["value"] = zTwist;
9090
}
9191

92-
void setControls(JsonArray controls) override {
93-
ESP_LOGD(TAG, "%s", controls[0].as<String>().c_str());
94-
ESP_LOGD(TAG, "%s", controls[1].as<String>().c_str());
95-
ESP_LOGD(TAG, "%s", controls[2].as<String>().c_str());
96-
ESP_LOGD(TAG, "%s", controls[3].as<String>().c_str());
97-
ESP_LOGD(TAG, "%s", controls[4].as<String>().c_str());
98-
petals = controls[0]["value"];
99-
swirlVal = controls[1]["value"];
100-
reverse = controls[2]["value"];
101-
symmetry = controls[3]["value"];
102-
zTwist = controls[4]["value"];
92+
void setControl(JsonObject control) override {
93+
ESP_LOGD(TAG, "%s = %s", control["name"].as<String>().c_str(), control["value"].as<String>().c_str());
94+
if (control["name"] == "petals") petals = control["value"];
95+
if (control["name"] == "swirlVal") swirlVal = control["value"];
96+
if (control["name"] == "reverse") reverse = control["value"];
97+
if (control["name"] == "symmetry") symmetry = control["value"];
98+
if (control["name"] == "zTwist") zTwist = control["value"];
10399
}
104100

105101
void modifyPixelsPre() override {
@@ -114,6 +110,7 @@ class PinwheelModifier: public Node {
114110
// layerV->size.y = 1;
115111
// layerV->size.z = 1;
116112
// }
113+
ESP_LOGD(TAG, "Pinwheel %d %d %d", layerV->size.x, layerV->size.y, layerV->size.z);
117114

118115
}
119116

0 commit comments

Comments
 (0)