Skip to content

Commit dea3aad

Browse files
authored
Merge pull request #103 from MoonModules/Node-update-mutex
Add node mutex
2 parents 1fc239a + 9db9dc5 commit dea3aad

File tree

13 files changed

+12767
-12660
lines changed

13 files changed

+12767
-12660
lines changed

docs/develop/architecture.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ MoonLight uses a multi-core, multi-task architecture on ESP32 to achieve smooth
1010
|------|------|----------|------------|-----------|---------|
1111
| **WiFi/BT** | 0 (PRO_CPU) | 23 | System | Event-driven | System networking stack |
1212
| **lwIP TCP/IP** | 0 (PRO_CPU) | 18 | System | Event-driven | TCP/IP protocol processing |
13-
| **ESP32SvelteKit** | 0 (PRO_CPU) | 2 | System | 10ms | HTTP/WebSocket UI framework |
13+
| **ESP32SvelteKit** | 1 (APP_CPU) | 2 | System | 20ms | HTTP/WebSocket UI framework |
1414
| **Driver Task** | 1 (APP_CPU) | 3 | 3-4KB | ~60 fps | Output data to LEDs via DMA/I2S/LCD/PARLIO |
1515
| **Effect Task** | 0 (PRO_CPU) | 3 | 3-4KB | ~60 fps | Calculate LED colors and effects |
1616

1717
Effect Task (Core 0, Priority 3)
1818

1919
- **Function**: Pure computation - calculates pixel colors based on effect algorithms
2020
- **Operations**: Reads/writes to `channels` array, performs mathematical calculations
21-
- **Tolerant to preemption**: WiFi interruptions are acceptable as this is non-timing-critical
21+
- **Tolerant to preemption**: WiFi interruptions are acceptable as this is non-timing-critical and we have a double buffer
2222
- **Why Core 0**: Can coexist with WiFi; uses idle CPU cycles when WiFi is not transmitting
2323

2424
Driver Task (Core 1, Priority 3)
@@ -32,7 +32,7 @@ ESP32SvelteKit Task (Core 1, Priority 2)
3232

3333
- **Function**: HTTP server and WebSocket handler for UI
3434
- **Operations**: Processes REST API calls, WebSocket messages, JSON serialization
35-
- **Runs every**: 10ms
35+
- **Runs every**: 20ms
3636
- **Why Core 1, Priority 2**: Lower priority than system Tasks
3737

3838
## Task Interaction Flow
@@ -69,6 +69,29 @@ sequenceDiagram
6969
DriverTask->>LEDs: Pixel data
7070
```
7171

72+
HTTPP task
73+
74+
* no assigned core (OS decides), prio 5
75+
* processes WebUI / Websockets
76+
* calls ModuleState read() and update() functions
77+
* MoonLight Modules: runs Modules::compareRecursive and Modules::checkReOrderSwap which calls postUpdate which presents a semaphore-guarded updatedItem (updateProcessedSem, updateReadySem)
78+
* Page refresh: runs onLayout pass 1 for the monitor
79+
80+
SvelteKit task
81+
82+
* Module::loop() runs in the SvelteKit task and calls getUpdate() to retrieve the updatedItem in a synchronized way, getUpdate() calls processUpdatedItem()
83+
* processUpdatedItem() calls Module::onUpdate(), which is a virtual function which is overridden by Modules to implement custom functionality
84+
* NodeManager::onUpdate() propagates onUpdate() to Node Controls (together with Node::updateControl()), guarded by nodeMutex
85+
86+
Driver Task
87+
88+
* PhysicalLayer::loopDrivers(): if requestMap call mapLayout(). mapLayout() calls onLayout(), guarded by nodeMutex
89+
* PhysicalLayer::loopDrivers(): Node::onSizeChanged() and Node::loop() guarded by nodeMutex
90+
91+
Effect Task
92+
93+
* PhysicalLayer::loop() calls VirtualLayer::Loop(): Node::onSizeChanged() and Node::loop(), guarded by nodeMutex
94+
7295
## Core Assignments
7396

7497
Why This Configuration is Optimal
@@ -278,16 +301,14 @@ For big setups, 16K LEDs typically, Task watchdog got triggered crashes occur mo
278301
void effectOrDriverTask(void* pvParameters) {
279302
// 🌙
280303
esp_task_wdt_add(NULL);
281-
282304
setup();
283305
284306
while (true) {
285-
286-
loop();
287-
288307
esp_task_wdt_reset();
308+
loop();
289309
vTaskDelay(1);
290310
}
311+
291312
// Cleanup (never reached in this case, but good practice)
292313
esp_task_wdt_delete(NULL);
293314
}
@@ -309,8 +330,6 @@ inline void addYield(uint8_t frequency) {
309330
vTaskDelay(1);
310331
}
311332
}
312-
313-
314333
```
315334

316335
* esp_task_wdt ( #include "esp_task_wdt.h" ) make sure the tasks are in the watchdog system and in the task loop it is reset and vTaskDelay(1) makes sure there is a yield each time

docs/gettingstarted/installer.md

Lines changed: 66 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
# MoonLight Installer
22

3-
Install <a href="https://github.com/MoonModules/MoonLight" target="_blank">MoonModules/MoonLight</a> on an ESP32 microcontroller. You need a compatible browser like Chrome, or Edge, not supported on Safari.
3+
Install <a href="https://github.com/MoonModules/MoonLight" target="_blank">MoonModules/MoonLight</a> on an ESP32 microcontroller.
4+
You need a Web Serial–compatible browser such as **Chrome** or **Edge**. **Safari is not supported.**
45

5-
For devices which have already MoonLight installed, go to [Update](#update-moonlight)
6+
For devices that already have MoonLight installed, go to [Update](#update-moonlight).
67

78
<a href="https://www.youtube.com/watch?v=7DQOEWa-Kwg">
89
<img width="380" src="https://img.youtube.com/vi/7DQOEWa-Kwg/maxresdefault.jpg" alt="Watch MoonLight Demo">
910
</a>
1011

11-
**[▶️ Watch the install tutorial](https://www.youtube.com/watch?v=7DQOEWa-Kwg)** (v0.6.0) or follow the instructions below
12+
**[▶️ Watch the install tutorial](https://www.youtube.com/watch?v=7DQOEWa-Kwg)** (v0.6.0), or follow the instructions below.
1213

13-
## Prepare an ESP32 device
14+
## Prepare an ESP32 device
1415

15-
See [Hardware](../hardware)
16+
Recommended device to get started with: [QuinLED-dig2go](https://quinled.info/quinled-dig2go/)
1617

17-
Recommended device to get started: [QuinLED-dig2go](https://quinled.info/quinled-dig2go/)
18+
![Dig2Go](https://shop.allnetchina.cn/cdn/shop/products/Led_4.jpg?v=1680836018&width=1600){: style="width:250px"}
1819

19-
![Dig2Go](https://shop.allnetchina.cn/cdn/shop/products/Led_4.jpg?v=1680836018&width=1600){: style="width:250px"}
20+
See [Hardware](../hardware) for other options.
2021

21-
Connect the device via a USB cable (which supports data transfer) to your PC.
22+
Connect the device to your PC using a USB cable that **supports data transfer**.
2223

2324
## Flash the firmware
2425

2526
<script type="module" src="https://unpkg.com/esp-web-tools@10/dist/web/install-button.js?module"></script>
2627

27-
Select your ESP32-device from the table below, press the corresponding **Connect** button and follow the steps. Your device should show up in this list. Press the **Erase** checkbox when installing MoonLight for the first time. After succesful install, go to Logs & Console, press **Restart** and close the installer.
28+
Select your ESP32 device from the table below, press the corresponding **Connect** button, and follow the steps.
29+
Your device should appear in the list.
30+
31+
When installing MoonLight for the **first time**, enable the **Erase** checkbox.
32+
After a successful install, go to **Logs & Console**, press **Reset Device**, and close the installer.
2833

2934
!!! info "Bootloader mode"
30-
If install doesn't work: some boards have to be placed in bootloader mode the first time: press and hold the `Boot` button on the ESP32, press the `Reset` button on the ESP32 and then release the `Boot` button.
35+
If installation does not work, some boards must be placed into bootloader mode the first time:
36+
press and hold the `Boot` button on the ESP32, press the `Reset` button, then release the `Boot` button.
3137

3238
| Name | Image* | Flash | Shop & Board presets |
3339
|------|--------|-------|----------------------|
@@ -37,7 +43,7 @@ Select your ESP32-device from the table below, press the corresponding **Connect
3743
| esp32-s3-n16r8v | ![esp32-s3-n16r8v](../firmware/installer/images/esp32-s3-n8r8v.jpg){: style="width:100px"} | <esp-web-install-button manifest="https://moonmodules.org/MoonLight/firmware/installer/manifest_esp32-s3-n16r8v.json"></esp-web-install-button> | [Ali*](https://s.click.aliexpress.com/e/_DBAtJ2H){:target="_blank"} |
3844
| esp32-s3-atoms3r | ![esp32-s3-atoms3r](../firmware/installer/images/esp32-s3-atoms3r.jpg){: style="width:100px"} | <esp-web-install-button manifest="https://moonmodules.org/MoonLight/firmware/installer/manifest_esp32-s3-atoms3r.json"></esp-web-install-button> | [M5Stack store](https://shop.m5stack.com/products/atoms3r-dev-kit){:target="_blank"} |
3945
| esp32-s3-zero-n4r2 | ![esp32-s3-zero-n4r2](../firmware/installer/images/esp32-s3-zero-n4r2.jpg){: style="width:100px"} | <esp-web-install-button manifest="https://moonmodules.org/MoonLight/firmware/installer/manifest_esp32-s3-zero-n4r2.json"></esp-web-install-button> | [Ali*](https://s.click.aliexpress.com/e/_EukjHX8){:target="_blank"} |
40-
| esp32-p4-nano | ![esp32-p4-nano](../firmware/installer/images/esp32-p4-nano.jpg){: style="width:100px"} | install [esp32-c6-firmware-update](https://esp32-c6-firmware-update.github.io) first <br><esp-web-install-button manifest="https://moonmodules.org/MoonLight/firmware/installer/manifest_esp32-p4-nano.json"></esp-web-install-button> | [Waveshare](https://www.waveshare.com/esp32-p4-nano.htm){:target="_blank"} <br>[ESP32-P4 shield](https://shop.myhome-control.de/en/ABC-WLED-ESP32-P4-shield/HW10027):<br>![ESP32-P4 shield](https://shop.myhome-control.de/thumbnail/ed/a1/f1/1762031307/WLED_ESP32_P4_Shield_04_1920x1354.jpg?ts=1762031316){: style="width:100px"} |
46+
| esp32-p4-nano | ![esp32-p4-nano](../firmware/installer/images/esp32-p4-nano.jpg){: style="width:100px"} | Install [esp32-c6-firmware-update](https://esp32-c6-firmware-update.github.io) first<br><esp-web-install-button manifest="https://moonmodules.org/MoonLight/firmware/installer/manifest_esp32-p4-nano.json"></esp-web-install-button> | [Waveshare](https://www.waveshare.com/esp32-p4-nano.htm){:target="_blank"}<br>[ESP32-P4 shield](https://shop.myhome-control.de/en/ABC-WLED-ESP32-P4-shield/HW10027):<br>![ESP32-P4 shield](https://shop.myhome-control.de/thumbnail/ed/a1/f1/1762031307/WLED_ESP32_P4_Shield_04_1920x1354.jpg?ts=1762031316){: style="width:100px"} |
4147
| esp32-d0-wrover | ![esp32-d0-wrover](../firmware/installer/images/esp32-d0-wrover.jpg){: style="width:100px"} | <esp-web-install-button manifest="https://moonmodules.org/MoonLight/firmware/installer/manifest_esp32-d0-wrover.json"></esp-web-install-button> | [Ali*](https://a.aliexpress.com/_EzhPi6g){:target="_blank"} |
4248
| esp32-p4-olimex | ![esp32-p4-olimex](../firmware/installer/images/esp32-p4-olimex.jpg){: style="width:100px"} | <esp-web-install-button manifest="https://moonmodules.org/MoonLight/firmware/installer/manifest_esp32-p4-olimex.json"></esp-web-install-button> | [Olimex](https://www.olimex.com/Products/IoT/ESP32-P4/ESP32-P4-DevKit/open-source-hardware){:target="_blank"} |
4349
| esp32-c3 | ![esp32-c3](../firmware/installer/images/esp32-c3.jpg){: style="width:100px"} | <esp-web-install-button manifest="https://moonmodules.org/MoonLight/firmware/installer/manifest_esp32-c3.json"></esp-web-install-button> | [Ali*](https://s.click.aliexpress.com/e/_EIl7NKw){:target="_blank"} |
@@ -54,95 +60,114 @@ Install steps in pictures:
5460

5561
## Setup MoonLight
5662

57-
A new MoonLight device will show itself as a WiFi Access Point (AP) in the WiFi settings of your PC, tablet or smartphone. The name starts with ML- and 4 characters.
63+
A new MoonLight device will appear as a WiFi Access Point (AP) in the WiFi settings of your PC, tablet, or smartphone.
64+
The name starts with `ML-` followed by four characters.
5865

5966
<img width="200" src="https://github.com/user-attachments/assets/9a146e3c-1a53-4906-ad2a-d70215efcf4b" />
6067

61-
Select ML-xxxx, MoonLight will start in a browser:
68+
Select `ML-xxxx`. MoonLight will open in your browser:
6269

6370
<img width="350" src="../../media/moonlight/ML-Start.png"/>
6471

65-
Follow the steps:
72+
Follow the steps below.
6673

6774
### WiFi connection
6875

69-
Add a [WiFi](../../network/sta) connection
76+
Add a [WiFi](../../network/sta) connection.
7077

7178
<img width="350" src="../../media/network/MB-WiFi2.png"/>
7279

73-
Enter a hostname, add your WiFi by adding the (+) button, enter SSID and password and press Apply Settings.
80+
Enter a hostname, add your WiFi network using the (+) button, enter the SSID and password, and press **Apply Settings**.
7481

75-
Restart the device by pressing the boot button or simple unplug and plug the usb cable.
82+
Restart the device by pressing the boot button, or simply unplug and reconnect the USB cable.
7683

77-
Go back to your home WiFi open a browser and enter hostname.local to open MoonLight via the new WiFi connection.
84+
Reconnect to your home WiFi, open a browser, and go to `hostname.local` to access MoonLight via the new WiFi connection.
7885

7986
### IO Board Presets
8087

81-
Select your board in [Module IO](../../moonbase/inputoutput), if you have one of the premade boards supported (see above table), select this. If not sure, leave it as is.
88+
Select your board in [Module IO](../../moonbase/inputoutput).
89+
If you have one of the supported premade boards (see table above), select it.
90+
If you are unsure, leave the default settings.
8291

8392
<img width="320" height="441" src="../../media/moonbase/inputoutput.png" />
8493

85-
Make sure the defined LED pin(s) are the same as the physical connections on the ESP32 board.
94+
Ensure the configured LED pin(s) match the physical connections on your ESP32 board.
8695

8796
### Drivers
8897

89-
The drivers module contains [Layouts](../../moonlight/layouts) and [Drivers](../../moonlight/drivers).
98+
The Drivers module contains [Layouts](../../moonlight/layouts) and [Drivers](../../moonlight/drivers).
9099

91-
Layouts define how your LEDs are arranged. Add a layout first, Press (+)
100+
Layouts define how your LEDs are arranged.
101+
First, add a layout by pressing (+).
92102

93103
<img width="320" src="../../media/moonlight/layouts/PanelLayout.png"/>
94104

95-
For LED strips, choose Single Column, for Panels choose Panel(s) or other layouts. Layouts are recognized by 🚥. Enter the size of your LEDs
105+
For LED strips, choose **Single Column**.
106+
For panels, choose **Panel(s)** or another suitable layout.
107+
Layouts are indicated by 🚥. Enter the size of your LED setup.
96108

97-
Next add a LED driver by pressing the (+) button and select the Physical LED driver or FastLED driver. Drivers are recognized by ☸️
109+
Next, add an LED driver by pressing (+) and selecting either the **Physical LED driver** or **FastLED driver**.
110+
Drivers are indicated by ☸️.
98111

99112
<img width="350" src="https://github.com/user-attachments/assets/e7fab24f-3803-4aa5-8638-459cca8a9caf" />
100113

101114
### Effect
102115

103-
The Effects module contains [Effects](../../moonlight/effects) and [Modifiers](../../moonlight/modifiers). Start by adding one effect, press (+)
116+
The Effects module contains [Effects](../../moonlight/effects) and [Modifiers](../../moonlight/modifiers).
117+
118+
Start by adding an effect using the (+) button.
104119

105120
<img width="350" src="https://github.com/user-attachments/assets/2c8a8b75-c429-4038-a5af-adc82b11c9de" />
106121

107-
The effect should be visible on the Monitor in MoonLight and on your LEDs
122+
The effect should now be visible in the MoonLight monitor and on your LEDs.
108123

109124
<img width="320" src="../../media/moonlight/effects/LissajousShot.png"/>
110125

111126
### Save and next steps
112127

113-
Press save (💾). Saves your setup to the file system, so if a device is restarted, your settings are still there.
128+
Press **Save** (💾).
129+
This stores your configuration on the device, so your settings persist after a reboot.
114130

115-
If anything not working as expected, log an issue on GitHUB or contact us on Discord, Reddit or YouTube. See also [Installer troubleshooting](../../develop/installation/#moonlight-installer) and [USB-to-serial chip drivers](../../develop/installation/#usb-to-serial-chip-drivers)
131+
If something does not work as expected, log an issue on GitHub or contact us via [Discord](https://discord.gg/TC8NSUSCdV), [Reddit](https://reddit.com/r/moonmodules) or [YouTube](https://www.youtube.com/@MoonModulesLighting).
132+
See also [Installer troubleshooting](../../develop/installation/#moonlight-installer) and [USB-to-serial chip drivers](../../develop/installation/#usb-to-serial-chip-drivers).
116133

117134
!!! info "Next steps"
118-
* You can now change effect or add effects, modifiers, layouts and drivers
119-
* Go to [MoonLight Overview](../../moonlight/overview) to learn more
120-
* press the (?) in MoonLight to go directly to the relevant page
135+
* You can now change or add effects, modifiers, layouts, and drivers
136+
* Visit the [MoonLight Overview](../../moonlight/overview) to learn more
137+
* Press (?) in MoonLight to jump directly to the relevant documentation page
121138

122139
## Update MoonLight
123140

124-
MoonLight releases new versions regularly. As it is a new and growing platform it is recommended to update as soon as new releases are published. They can be installed via above procedure (without erase) or via one of the following procedures:
141+
MoonLight releases new versions regularly.
142+
As this is a new and growing platform, it is recommended to update as soon as new releases are published.
143+
144+
Updates can be installed using the installer above (without erasing), or via one of the methods below.
125145

126146
### System update
127147

128-
The preferred way to update MoonLight is directly in MoonLight via [System update](../../system/update). MoonLight notifies when new versions are available.
148+
The preferred way to update MoonLight is directly within MoonLight via [System update](../../system/update).
149+
MoonLight will notify you when new versions are available.
129150

130151
<img width="350" src="https://github.com/user-attachments/assets/523ea32f-88f8-4994-8d23-9541dce67ba1" />
131152

132-
Currently not supported on smaller devices like the ESP32-D0 and ESP32-C3. Use the MoonLight Installer in this case.
153+
This method is currently not supported on smaller devices such as the ESP32-D0 and ESP32-C3.
154+
Use the MoonLight Installer instead for these devices.
133155

134156
### ESPConnect
135157

136-
Use ESPConnect to install unreleased firmware e.g. provided via [discord](https://discord.gg/MTn9mVUG5n) or GitHub issues. Published [releases](https://github.com/MoonModules/MoonLight/releases) can also be installed via this way.
158+
Use ESPConnect to install unreleased firmware (for example, versions shared via [Discord](https://discord.gg/TC8NSUSCdV) or [GitHub issues](https://github.com/MoonModules/MoonLight/issues)).
159+
Published [releases](https://github.com/MoonModules/MoonLight/releases) can also be installed this way.
137160

138-
Launch [ESPConnect](https://thelastoutpostworkshop.github.io/microcontroller_devkit/espconnect)
161+
Launch [ESPConnect](https://thelastoutpostworkshop.github.io/microcontroller_devkit/espconnect).
139162

140163
<img width="400" src="https://github.com/user-attachments/assets/3b702b3e-62cc-4330-83f6-d473067df449" />
141164

142-
Click Connect and choose your device. Select Flash Tools, go to Flash Firmware, open a firmware.bin file from your file system, select Flash Offset App0 and Flash.
143-
144-
### Visual Studio code
165+
Click **Connect** and select your device.
166+
Choose **Flash Tools**, go to **Flash Firmware**, open a `firmware.bin` file from your file system, select **Flash Offset App0**, and click **Flash**.
167+
168+
### Visual Studio Code
145169

146-
For developers. Upload directly from VSCode, see [Develop / Installation](../../develop/installation)
170+
For developers: upload firmware directly from VS Code.
171+
See [Develop / Installation](../../develop/installation).
147172

148-
*: This page contains affiliate links
173+
\*: This page contains affiliate links

docs/moonlight/effects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ These effects have first been created in MoonLight:
5757
| Praxis | ![Praxis](https://github.com/user-attachments/assets/f9271d1c-bcd1-4a79-bc1a-cac951758195) | <img width="320" alt="Praxis" src="https://github.com/user-attachments/assets/536ab4c8-5c90-4b76-9f80-2aaed4170901" />| |
5858
| Wave | ![Wave](https://github.com/user-attachments/assets/a699f3a6-c981-4159-a96e-85d43c9a853c) | <img width="320" alt="Wave" src="https://github.com/user-attachments/assets/2e8408e8-4610-45dd-af36-8560fe5ec024" /> | Type: Saw, Triangle, Sinus, Square, Sin3, Noise |
5959
| Fixed Rectangle | <img width="120" alt="Rectangle" src="https://github.com/user-attachments/assets/474bd313-d961-4a95-8e44-015539a0ba7f" /> | <img width="320" alt="RectangleC" src="https://github.com/user-attachments/assets/e9c1fca4-d7a2-42f4-9d23-643371b3c615" /> | To test a layout |
60-
| Star Sky | ![lines](../../media/moonlight/effects/starsky.gif) | ![lines](../../media/moonlight/effects/starskycontrols.png) | tip: add the rotate modifier |
60+
| Star Sky | ![lines](../../media/moonlight/effects/StarSky.gif) | ![lines](../../media/moonlight/effects/StarSkyControls.png) | tip: add the rotate modifier |
6161

6262
### MoonModules effects
6363

0 commit comments

Comments
 (0)