Skip to content

Commit d0cff71

Browse files
committed
Add SafeMode and show in SystemStatus and StatusBar
1 parent c1f96c5 commit d0cff71

File tree

16 files changed

+14012
-13935
lines changed

16 files changed

+14012
-13935
lines changed

docs/moonbase/module/editor.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ Ultimately the nodes will be displayed in a graphical interface where nodes are
1111

1212
Typically a node will define a layout (🚥), or an effect (🔥), or a modifier (💎) or a supporting process (☸️) but can also combine these tasks (experimental at the moment). To avoid duplication it's in most cases recommended to keep them seperated so an effect can run on multiple layouts and a modifier can modify any effect.
1313

14-
* **Layout** 🚥: a layout defines what lights are connected to MoonLight. Currently only one layout node is supported defining all the lights (But might change in the future). It defines the coordinates of all lights (addLight) and assigns lights to the GPIO pins of the ESP32 (addPin) and how many channels each light has (normal LEDs 3: Red, Green and Blue).
14+
* **Layout** 🚥: a layout defines what lights are connected to MoonLight. It defines the coordinates of all lights (addLight) and assigns lights to the GPIO pins of the ESP32 (addPin) and how many channels each light has (normal LEDs 3: Red, Green and Blue).
1515
* The **coordinates** of each light are defined in a 3D coordinate space where each coordinate range between 1 and 255. Currently a strip until 255 leds is supported, a panel until 128x96 LEDS and a cube max 20x20x20.
1616
* Coordinates needs to be specified in the order the lights are wired so MoonLight knows which light is first, which is second etc.
1717
* If a 1D strip is longer, you can address more leds by pretending it is a 2D fixture, e.g. 32x32 to address a strip of 1024 LEDs.
1818
* In the future we might look at redefining Coord3D where width is 12 bytes, height is 7 bytes and depth is 5 bytes allowing for max 4096 x 128 x 32 ...
1919
* Currently **pins** are by default driven by FastLED.show. FastLED needs all LEDs specifications be defined at compile time, e.g. LED type, color order, etc. Normally also the pin(s) need to be defined beforehand but all pins are predefined in the code to avoid this (at a cost of larger firmware). As we want to be able to define all LED specs in the UI instead of during compile, we need to see how / if this can be done.
20+
* 🆕 **Multiple layout nodes** can be defined which will execute one after the other
2021
* In the future, instead of pins, also **IP addresses and universes** can be specified to support sending lights data to ArtNet devices - e.g. [Pknight Artnet DMX 512](https://s.click.aliexpress.com/e/_ExQK8Dc) to control DMX lights or [ArtNet LED controller](https://s.click.aliexpress.com/e/_Ex9uaOk) to control LED strips or panels over local network. Currently this is handled by [Module ArtNet](https://moonmodules.org/MoonLight/moonbase/module/artnet/).
2122
* Alternatively Moonlight supports 2 other drivers: [Physical Driver](https://github.com/hpwit/I2SClocklessLedDriver) and [Virtual Driver](https://github.com/ewowi/I2SClocklessVirtualLedDriver). Firmware ending with PD or VD will have this enabled. Code has been included but not tested yet (tested in StarLight), this is planned for June/July.
2223
* The physical driver is an alternative to the FastLED driver and does not need LED specifications defined at compile time, all can be controlled via UI.

docs/moonlight/general.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# General
2+
3+
## Functional
4+
5+
* **Safe Mode**: MoonBase will jump into safe mode after a crash, see [System Status](https://moonmodules.org/MoonLight/system/status/). In safe mode, MoonLight will disable the following features:
6+
* Add more then 1024 lights
7+
* Execute a live script
8+
9+
This list is dynamic and will change over time if crash reasons change.
10+
11+
## Technical
12+
13+
### Server
14+
15+
### UI

docs/system/status.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
## Functional
66

7-
* <img width="30" src="https://github.com/user-attachments/assets/b0e8af99-ed76-422a-8bd1-bfbd9e0f4c44"/> Performance: loops per second: nr of times main loop is executed
7+
* 🌙 **Performance**: loops per second: nr of times main loop is executed
8+
* 🌙 **Safe Mode** 🆕: After a crash, the device will start in Safe Mode disabling possible causes of crashes. See also [MoonLight](https://moonmodules.org/MoonLight/moonlight/general/). In case of safe mode, the statusbar will show a shield: 🛡️. Try to find the reason of the crash and correct and restart the device. If no crash, it will go out of safe mode.
89

9-
* Sleep: Device is set in low power mode.
10-
* Restart: The device will restart
11-
* Factory reset: all settings will be removed.
10+
* **Sleep**: Device is set in low power mode.
11+
* **Restart**: The device will restart
12+
* **Factory reset**: all settings will be removed.
1213

1314
## Technical
1415

15-
* <img width="30" src="https://github.com/user-attachments/assets/b0e8af99-ed76-422a-8bd1-bfbd9e0f4c44"/> Reordered info from dynamic to static
16+
* 🌙 Reordered info from dynamic to static
1617

1718
### Server
1819

interface/src/lib/stores/telemetry.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ let telemetry_data = {
77
rssi: {
88
rssi: 0,
99
ssid: '',
10-
disconnected: true
10+
disconnected: true,
11+
safeMode: false // 🌙 safeMode Indicates if the system is in safe mode
1112
},
1213
battery: {
1314
soc: 100,
@@ -29,12 +30,12 @@ function createTelemetry() {
2930
if (!isNaN(Number(data.rssi))) {
3031
update((telemetry_data) => ({
3132
...telemetry_data,
32-
rssi: { rssi: Number(data.rssi), ssid: data.ssid, disconnected: false }
33+
rssi: { rssi: Number(data.rssi), ssid: data.ssid, disconnected: false, safeMode: data.safeMode } // 🌙 safeMode
3334
}));
3435
} else {
3536
update((telemetry_data) => ({
3637
...telemetry_data,
37-
rssi: { rssi: 0, ssid: data.ssid, disconnected: true }
38+
rssi: { rssi: 0, ssid: data.ssid, disconnected: true, safeMode: data.safeMode } // 🌙 safeMode
3839
}));
3940
}
4041
},

interface/src/lib/types/models.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export type Analytics = {
100100
export type RSSI = {
101101
rssi: number;
102102
ssid: string;
103+
safeMode: boolean; // 🌙 safeMode Indicates if the system is in safe mode
103104
};
104105

105106
export type Battery = {
@@ -127,6 +128,7 @@ export type StaticSystemInformation = {
127128
flash_chip_size: number;
128129
flash_chip_speed: number;
129130
cpu_reset_reason: string;
131+
safeMode: boolean; // 🌙 safeMode Indicates if the system is in safe mode
130132
};
131133

132134
export type SystemInformation = Analytics & StaticSystemInformation;

interface/src/routes/statusbar.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@
4444
<label for="main-menu" class="btn btn-ghost btn-circle btn-sm drawer-button lg:hidden"
4545
><Hamburger class="h-6 w-auto" /></label
4646
>
47-
<span class="px-2 text-xl font-bold lg:text-2xl">{page.data.instances.instanceName}</span>
47+
<span class="px-2 text-xl font-bold lg:text-2xl">{page.data.instances.instanceName}</span> <!-- 🌙 -->
4848
</div>
4949
<div class="indicator flex-none">
5050
<UpdateIndicator />
5151
</div>
52+
<!-- 🌙 safeMode -->
53+
<div class="indicator flex-none">
54+
{#if $telemetry.rssi.safeMode}
55+
🛡️
56+
{/if}
57+
</div>
5258
<div class="flex-none">
5359
{#if $telemetry.rssi.disconnected}
5460
<WiFiOff class="h-7 w-7" />

interface/src/routes/system/status/SystemStatus.svelte

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
{/snippet}
161161
{#snippet title()}
162162
<span >System Status</span>
163-
<div class="absolute right-5"><a href="https://{page.data.github.split("/")[0]}.github.io/{page.data.github.split("/")[1]}{page.url.pathname}" target="_blank" title="Documentation"><Help class="lex-shrink-0 mr-2 h-6 w-6 self-end" /></a></div>
163+
<div class="absolute right-5"><a href="https://{page.data.github.split("/")[0]}.github.io/{page.data.github.split("/")[1]}{page.url.pathname}" target="_blank" title="Documentation"><Help class="lex-shrink-0 mr-2 h-6 w-6 self-end" /></a></div> <!-- 🌙 link to docs -->
164164
{/snippet}
165165

166166
<div class="w-full overflow-x-auto">
@@ -287,6 +287,18 @@
287287
</div>
288288
</div>
289289

290+
<div class="rounded-box bg-base-100 flex items-center space-x-3 px-4 py-2">
291+
<div class="mask mask-hexagon bg-primary h-auto w-10 flex-none">
292+
<Power class="text-primary-content h-auto w-full scale-75" />
293+
</div>
294+
<div>
295+
<div class="font-bold">Safe mode</div>
296+
<div class="text-sm opacity-75">
297+
{systemInformation.safeMode}
298+
</div>
299+
</div>
300+
</div>
301+
290302
<div class="rounded-box bg-base-100 flex items-center space-x-3 px-4 py-2">
291303
<div class="mask mask-hexagon bg-primary h-auto w-10 flex-none">
292304
<Sketch class="text-primary-content h-auto w-full scale-75" />

lib/framework/ESP32SvelteKit.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <ESP32SvelteKit.h>
1616

1717
std::vector<std::function<void()>> runInLoopTask; // 🌙 see .h
18+
bool safeModeMB = false; // 🌙 see .h
1819

1920
ESP32SvelteKit::ESP32SvelteKit(PsychicHttpServer *server, unsigned int numberEndpoints) : _server(server),
2021
_numberEndpoints(numberEndpoints),

lib/framework/ESP32SvelteKit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ enum class ConnectionStatus
8585
};
8686

8787
extern std::vector<std::function<void()>> runInLoopTask; // 🌙 functions to be called in main loopTask (to avoid https to run out of stack space)
88+
extern bool safeModeMB; // 🌙 true when the ESP32 is in safe mode, false when it is not
8889

8990
class ESP32SvelteKit
9091
{

lib/framework/SystemStatus.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
**/
1414

1515
#include <SystemStatus.h>
16+
17+
#include <ESP32SvelteKit.h> // 🌙 safeMode
18+
1619
#include <esp32-hal.h>
1720

1821
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
@@ -164,6 +167,7 @@ esp_err_t SystemStatus::systemStatus(PsychicRequest *request)
164167
root["core_temp"] = temperatureRead();
165168
root["cpu_reset_reason"] = verbosePrintResetReason(esp_reset_reason());
166169
root["uptime"] = millis() / 1000;
170+
root["safeMode"] = safeModeMB; // 🌙 safeMode
167171

168172
return response.send();
169173
}

0 commit comments

Comments
 (0)