Skip to content

Commit 719458b

Browse files
committed
Module: update read only properties, use in animations scripts
UI == - Rename Array to ObjectArray - Module: add handleRO and updateRecursive - WIP Server - Animations: rename socket livescripts to animationsRO, add Sinus, add kill handle , add loop1s to send scripts data
1 parent 3d50344 commit 719458b

File tree

11 files changed

+12788
-12672
lines changed

11 files changed

+12788
-12672
lines changed

docs/general/pull-requests.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ Below lists are ordered in terms of likelyhood to be accepted:
88

99
## Pending - Ready to PR
1010

11-
* [bug-metadata-parent-wifi](https://github.com/theelims/ESP32-sveltekit/commit/8573d90784f4fbf28de1d30be24b7421e965d0b4): avoid console.log errors
12-
* [components-small-fixes](https://github.com/theelims/ESP32-sveltekit/commit/da2c641eea81799f683bbc452d708d4d159e357e): avoid console.log errors
13-
* [compile-warnings](https://github.com/theelims/ESP32-sveltekit/commit/8a4dc4171c37d04754744f76513c2d2a08b0662d): role and tab index
14-
* [system-status-metrics](https://github.com/theelims/ESP32-sveltekit/commit/352cfe3e376b25f7470ad4f764cdf54f7069c645): use max instead of first
15-
* [help-to-docs](https://github.com/theelims/ESP32-sveltekit/commit/2c2d2fae5c37b220bc61dfb1ba6655485de6547f): Help link to github.io docs e.g. [animations](https://ewowi.github.io/MoonBase/moonbase/module/animations)
16-
* [System metrics](https://ewowi.github.io/MoonBase/system/metrics/)
11+
* 🐛 [bug-metadata-parent-wifi](https://github.com/theelims/ESP32-sveltekit/commit/8573d90784f4fbf28de1d30be24b7421e965d0b4): avoid console.log errors
12+
* ⚠️ [components-small-fixes](https://github.com/theelims/ESP32-sveltekit/commit/da2c641eea81799f683bbc452d708d4d159e357e): avoid console.log errors
13+
* ⚠️ [compile-warnings](https://github.com/theelims/ESP32-sveltekit/commit/8a4dc4171c37d04754744f76513c2d2a08b0662d): role and tab index
14+
* 💡 [service-name-string](https://github.com/theelims/ESP32-sveltekit/commit/05a7bd9a12999e087d0b05a62859d263679cc76a): Allow service names to be non string literals (e.g. done in MoonBase-Modules)
15+
* ⚠️ [EventSocket emitEvent: use String type](https://github.com/theelims/ESP32-sveltekit/commit/54c4a44eb95be2fe344bb78f022c8afcbbd8c731)
16+
* 💡 [system-status-metrics](https://github.com/theelims/ESP32-sveltekit/commit/352cfe3e376b25f7470ad4f764cdf54f7069c645): use max instead of first
17+
* 💡 [help-to-docs](https://github.com/theelims/ESP32-sveltekit/commit/2c2d2fae5c37b220bc61dfb1ba6655485de6547f): Help link to github.io docs e.g. [animations](https://ewowi.github.io/MoonBase/moonbase/module/animations)
18+
* 💡 [System metrics](https://ewowi.github.io/MoonBase/system/metrics/)
1719
* Loops per second (performance)
18-
* [System status](https://ewowi.github.io/MoonBase/system/status/)
20+
* 💡 [System status](https://ewowi.github.io/MoonBase/system/status/)
1921
* Loops per second (performance)
20-
* [service-name-string](https://github.com/theelims/ESP32-sveltekit/commit/05a7bd9a12999e087d0b05a62859d263679cc76a): Allow service names to be non string literals (e.g. done in MoonBase-Modules)
21-
* [menu-href-unique](https://github.com/theelims/ESP32-sveltekit/commit/92acbd046e478bccf7eec469e0dab5dcda53c0ae): Allow multiple modules using same Module.svelte
22-
* [measure-battery-pin](https://github.com/theelims/ESP32-sveltekit/commit/bcd3abd1f981d48d7a76c5ee71fc99f4fe54eb08)
22+
* 💡 [menu-href-unique](https://github.com/theelims/ESP32-sveltekit/commit/92acbd046e478bccf7eec469e0dab5dcda53c0ae): Allow multiple modules using same Module.svelte
23+
* 💡 [measure-battery-pin](https://github.com/theelims/ESP32-sveltekit/commit/bcd3abd1f981d48d7a76c5ee71fc99f4fe54eb08)
2324

2425
## Pending - WIP
2526

docs/moonbase/module/animations.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* e.g. if the fixture is a globe, you can map that to 2D using mercator projection mapping
3939
* if the fixture is 200x200 you can map it to 50x50
4040
* Effect: run an effect in (part of) the virtual coordinate space
41-
* or in the physical space if you want to run at highest performance, e.g. a random effect doesn't need to go through mappings
41+
* or in the physical space if you want to run at highest performance, e.g. a random effect doesn't need to go through mappings
4242
* Modifier: Mirror, rotate, etc, multiple projections allowed (projection in StarLight)
4343
* Driver show: show the result on Leds (using FastLED, hpwit drivers), ArtNet, DDP, ...
4444
* Future situation: Nodes and noodles (2)
@@ -52,6 +52,8 @@
5252
* Nodes manipulate the mapping model and/or interfere in the effects loop
5353
* Presets/playlist: change (part of) the nodes model
5454

55+
✅: Done
56+
5557
### Server
5658

5759
[ModuleAnimations.h](https://github.com/ewowi/MoonBase/blob/main/src/custom/ModuleAnimations.h)

interface/src/lib/components/custom/ArrayLight.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import Edit from '~icons/tabler/pencil';
2424
import Delete from '~icons/tabler/trash';
2525
import MultiInput from '$lib/components/custom/MultiInput.svelte';
26-
import Array from '$lib/components/custom/Array.svelte';
26+
import ObjectArray from '$lib/components/custom/ObjectArray.svelte';
2727
2828
let { property, data, definition, showEditor = false, onChange, changeOnInput, value1=$bindable(), value2 } = $props();
2929

interface/src/lib/components/custom/Array.svelte renamed to interface/src/lib/components/custom/ObjectArray.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import Edit from '~icons/tabler/pencil';
2424
import Delete from '~icons/tabler/trash';
2525
import MultiInput from '$lib/components/custom/MultiInput.svelte';
26-
import Array from '$lib/components/custom/Array.svelte';
26+
import ObjectArray from '$lib/components/custom/ObjectArray.svelte';
2727
import ArrayLight from '$lib/components/custom/ArrayLight.svelte';
2828
import {initCap} from '$lib/stores/custom_utilities';
2929
@@ -49,7 +49,7 @@
4949
// console.log("addItem def", propertyName, property)
5050
if (property.name == definition[i].name) {
5151
localDefinition = definition[i].n;
52-
console.log("localDefinition", property.name, definition[i].n)
52+
// console.log("localDefinition", property.name, definition[i].n)
5353
}
5454
}
5555
@@ -84,7 +84,7 @@
8484
}
8585
8686
function handleEdit(propertyName: string, index: number) {
87-
console.log("handleEdit", propertyName, index, data[propertyName][index])
87+
// console.log("handleEdit", propertyName, index, data[propertyName][index])
8888
if (lastIndex != index) {
8989
showEditor = true;
9090
lastIndex = index;
@@ -191,7 +191,7 @@
191191
{/snippet}
192192
</DragDropList>
193193
</div>
194-
{#if showEditor && property.name == propertyEditable}
194+
{#if showEditor && property.name == propertyEditable && data[property.name] && data[property.name].length}
195195
<div class="divider my-0"></div>
196196
{#each property.n as propertyN}
197197
{#if propertyN.type != "array"}
@@ -200,7 +200,7 @@
200200
</div>
201201
{:else if propertyN.type == "array"}
202202
<label for="{propertyN.name}">{propertyN.name}</label>
203-
<Array property={propertyN} bind:value1={data[propertyN.name]} value2={data} data={dataEditable} definition={localDefinition} onChange={onChange} changeOnInput={changeOnInput}></Array>
203+
<ObjectArray property={propertyN} bind:value1={data[propertyN.name]} value2={data} data={dataEditable} definition={localDefinition} onChange={onChange} changeOnInput={changeOnInput}></ObjectArray>
204204
{/if}
205205
{/each}
206206
{/if}

interface/src/routes/moonbase/module/Module.svelte

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@
1010
import MultiInput from '$lib/components/custom/MultiInput.svelte';
1111
import { onMount, onDestroy } from 'svelte';
1212
import { socket } from '$lib/stores/socket';
13-
import Array from '$lib/components/custom/Array.svelte';
13+
import ObjectArray from '$lib/components/custom/ObjectArray.svelte';
1414
import {initCap} from '$lib/stores/custom_utilities';
1515
1616
let definition: any = $state([]);
1717
let data: any = $state({});
1818
19-
let showEditor: boolean = $state(false);
2019
let changed: boolean = $state(false);
2120
2221
const modeWS: boolean = true; //todo: make this an argument
2322
2423
async function getState() {
2524
26-
let moduleName = page.url.searchParams.get('module');
25+
let moduleName = page.url.searchParams.get('module') || '';
2726
2827
console.log("getState", '/rest/' + moduleName)
2928
@@ -64,7 +63,7 @@
6463
//validation (if needed) here?
6564
//optional checks if the whole state is correct
6665
67-
let moduleName = page.url.searchParams.get('module')
66+
let moduleName = page.url.searchParams.get('module') || ''
6867
6968
try {
7069
const response = await fetch('/rest/' + moduleName, {
@@ -85,36 +84,66 @@
8584
} catch (error) {
8685
console.error('Error:', error);
8786
}
88-
showEditor = false;
8987
}
9088
9189
function cancelState() {
9290
getState();
93-
showEditor = false;
9491
changed = false;
9592
}
9693
9794
function inputChanged() {
9895
if (modeWS) {
9996
let moduleName = page.url.searchParams.get('module')||'';
100-
console.log(moduleName, data);
97+
// console.log("inputChanged", moduleName, data);
10198
socket.sendEvent(moduleName, data)
10299
} else {
103100
changed = true;
104101
}
105102
}
106103
104+
function updateRecursive(oldData:any, newData: any) {
105+
//loop over properties
106+
for (let key in newData) {
107+
if (typeof newData[key] != 'object') {
108+
// console.log("updateRecursive", key, newData[key], oldData);
109+
if (newData[key] != oldData[key]) {
110+
oldData[key] = newData[key]; //trigger reactiveness
111+
}
112+
} else {
113+
if (Array.isArray(newData[key])) {
114+
//loop over array
115+
for (let i = 0; i < Math.max(oldData[key].length, newData[key].length); i++) {
116+
if (oldData[key][i] == undefined) {
117+
oldData[key][i] = newData[key][i]; //create new row if not existed, trigger reactiveness
118+
} else if (newData[key][i] == undefined) {
119+
console.log("remove row", key, i);
120+
//remove row if not existing anymore
121+
oldData[key].splice(i, 1);
122+
// oldData[key] = [...oldData[key]]; //Trigger reactivity ???
123+
} else
124+
updateRecursive(oldData[key][i], newData[key][i]);
125+
}
126+
}
127+
}
128+
}
129+
}
130+
107131
const handleState = (state: any) => {
108-
console.log("handleState", state);
132+
// console.log("handleState", state);
109133
data = state;
110-
showEditor = false;
134+
};
135+
136+
const handleRO = (state: any) => {
137+
console.log("handleRO", state);
138+
updateRecursive(data, state);
111139
};
112140
113141
onMount(() => {
114142
if (modeWS) {
115143
let moduleName = page.url.searchParams.get('module') || ''
116144
console.log("onMount", moduleName);
117145
socket.on(moduleName, handleState);
146+
socket.on(moduleName + "RO", handleRO);
118147
}
119148
});
120149
@@ -123,6 +152,7 @@
123152
let moduleName = page.url.searchParams.get('module') || ''
124153
console.log("onDestroy", moduleName);
125154
socket.off(moduleName, handleState);
155+
socket.off(moduleName + "RO", handleRO);
126156
}
127157
});
128158
@@ -150,7 +180,7 @@
150180
<MultiInput property={property} bind:value={data[property.name]} onChange={inputChanged} changeOnInput={!modeWS}></MultiInput>
151181
</div>
152182
{:else if property.type == "array"}
153-
<Array property={property} value2={data[property.name]} data={data} definition={definition} onChange={inputChanged} changeOnInput={!modeWS}></Array>
183+
<ObjectArray property={property} value2={data[property.name]} data={data} definition={definition} onChange={inputChanged} changeOnInput={!modeWS}></ObjectArray>
154184
{/if}
155185
{/each}
156186
</div>

lib/framework/EventSocket.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ void EventSocket::emitEvent(String event, JsonObject &jsonObject, const char *or
110110
if (!isEventValid(event))
111111
{
112112
ESP_LOGW("EventSocket", "Method tried to emit unregistered event: %s", event.c_str());
113+
ESP_LOGW(TAG, "Method tried to emit unregistered event: %s", event.c_str());
113114
return;
114115
}
115116

@@ -149,7 +150,7 @@ void EventSocket::emitEvent(String event, JsonObject &jsonObject, const char *or
149150
auto *client = _socket.getClient(originSubscriptionId);
150151
if (client)
151152
{
152-
ESP_LOGV("EventSocket", "Emitting event: %s to %s[%u], Message[%d]: %s", event.c_str(), client->remoteIP().toString().c_str(), client->socket(), len, output);
153+
ESP_LOGV(TAG, "Emitting event: %s to %s[%u], Message[%d]: %s", event.c_str(), client->remoteIP().toString().c_str(), client->socket(), len, output);
153154
#if FT_ENABLED(EVENT_USE_JSON)
154155
client->sendMessage(HTTPD_WS_TYPE_TEXT, output, len);
155156
#else
@@ -170,7 +171,7 @@ void EventSocket::emitEvent(String event, JsonObject &jsonObject, const char *or
170171
subscriptions.remove(subscription);
171172
continue;
172173
}
173-
ESP_LOGV("EventSocket", "Emitting event: %s to %s[%u], Message[%d]: %s", event.c_str(), client->remoteIP().toString().c_str(), client->socket(), len, output);
174+
ESP_LOGV(TAG, "Emitting event: %s to %s[%u], Message[%d]: %s", event.c_str(), client->remoteIP().toString().c_str(), client->socket(), len, output);
174175
#if FT_ENABLED(EVENT_USE_JSON)
175176
client->sendMessage(HTTPD_WS_TYPE_TEXT, output, len);
176177
#else

0 commit comments

Comments
 (0)