Skip to content

Commit 2077b37

Browse files
committed
fix(scheduler): list was not persisted and send max info everytime over websocket
1 parent a6d549d commit 2077b37

File tree

10 files changed

+706
-734
lines changed

10 files changed

+706
-734
lines changed

.github/workflows/build-and-release.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ jobs:
6868
continue-on-error: true
6969
strategy:
7070
matrix:
71-
environment: [nodemcuv2, d1_mini_pro-ota, esp32c3, ESP32-wemos]
71+
environment: [nodemcuv2, d1_mini_pro-ota, ESP32-wemos]
7272
include:
7373
- environment: nodemcuv2
7474
artifact_name: nodemcuv2_firmware
7575
- environment: d1_mini_pro-ota
7676
artifact_name: d1_mini_pro_ota_firmware
77-
- environment: esp32c3
78-
artifact_name: esp32c3_firmware
7977
- environment: ESP32-wemos
8078
artifact_name: ESP32-wemos_firmware
8179

frontend/src/app.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, createMemo, Show } from 'solid-js';
1+
import { type Component, createMemo, Show } from 'solid-js';
22
import { Layout } from './components/layout/layout';
33
import Sidebar from './components/layout/sidebar';
44
import { LedMatrix } from './components/led-matrix';
@@ -82,9 +82,9 @@ export const App: Component = () => {
8282
wsMessage('brightness', { brightness: value });
8383
}
8484
};
85-
85+
8686
const handleArtnetUniverseChange = (value: number, shouldSend = false) => {
87-
actions?.setArtnetUniverse(value);
87+
actions?.setArtnetUniverse(value);
8888
if (shouldSend) {
8989
wsMessage('artnet', { universe: value });
9090
}

frontend/src/contexts/store.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ export const StoreProvider: ParentComponent = (props) => {
7575
const json = JSON.parse(messageEvent()?.data || '{}');
7676

7777
switch (json.event) {
78-
case 'minimal-info':
79-
actions.setSystemStatus(
80-
Object.values(SYSTEM_STATUS)[json.status as number],
81-
);
82-
actions.setRotation(json.rotation);
83-
actions.setBrightness(json.brightness);
84-
actions.setPlugin(json.plugin as number);
85-
actions.setIsActiveScheduler(json.scheduleActive);
86-
break;
8778
case 'info':
8879
batch(() => {
8980
actions.setSystemStatus(

frontend/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface StoreActions {
2323
setLeds: (leds: number[]) => void;
2424
setSystemStatus: (systemStatus: SYSTEM_STATUS) => void;
2525
setSchedule: (items: ScheduleItem[]) => void;
26+
setArtnetUniverse: (artnetUniverse: number) => void;
2627
send: (message: string | ArrayBuffer) => void;
2728
}
2829

include/websocket.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ void onWsEvent(
1515
uint8_t *data,
1616
size_t len);
1717
void sendInfo();
18-
void sendMinimalInfo();
1918
void initWebsocketServer(AsyncWebServer &server);
2019
void cleanUpClients();
2120

src/PluginManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,6 @@ void PluginManager::activateNextPlugin()
145145
setActivePluginById(1);
146146
}
147147
#ifdef ENABLE_SERVER
148-
sendMinimalInfo();
148+
sendInfo();
149149
#endif
150150
}

src/scheduler.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,22 @@ void PluginScheduler::addItem(int pluginId, unsigned long durationSeconds)
1818

1919
void PluginScheduler::clearSchedule(bool emptyStorage)
2020
{
21-
schedule.clear();
2221
currentIndex = 0;
2322
isActive = false;
2423
#ifdef ENABLE_STORAGE
2524
if (emptyStorage)
2625
{
27-
storage.begin("led-wall", false);
26+
schedule.clear();
27+
storage.begin("led-wall");
2828
storage.putString("schedule", "");
2929
storage.putInt("scheduleactive", 0);
3030
storage.end();
3131
}
32+
#else
33+
if (emptyStorage)
34+
{
35+
schedule.clear();
36+
}
3237
#endif
3338
}
3439

@@ -78,7 +83,7 @@ void PluginScheduler::switchToCurrentPlugin()
7883
{
7984
pluginManager.setActivePluginById(schedule[currentIndex].pluginId);
8085
#ifdef ENABLE_SERVER
81-
sendMinimalInfo();
86+
sendInfo();
8287
#endif
8388
}
8489
}
@@ -118,26 +123,22 @@ bool PluginScheduler::setScheduleByJSONString(String scheduleJson)
118123
}
119124

120125
#ifdef ENABLE_STORAGE
121-
storage.begin("led-wall", false);
126+
storage.begin("led-wall");
122127
storage.putString("schedule", scheduleJson);
123128
storage.end();
124129
#endif
125130

126-
Scheduler.clearSchedule();
131+
clearSchedule();
127132

128-
JsonArray schedule = doc.as<JsonArray>();
129-
for (JsonObject item : schedule)
133+
for (const auto &item : doc.as<JsonArray>())
130134
{
131-
if (!item.containsKey("pluginId") || !item.containsKey("duration"))
135+
if (item.containsKey("pluginId") && item.containsKey("duration"))
132136
{
133-
return false;
137+
int pluginId = item["pluginId"].as<int>();
138+
unsigned long duration = item["duration"].as<unsigned long>();
139+
addItem(pluginId, duration);
134140
}
135-
136-
int pluginId = item["pluginId"].as<int>();
137-
unsigned long duration = item["duration"].as<unsigned long>();
138-
Scheduler.addItem(pluginId, duration);
139141
}
140-
141142
return true;
142143
}
143144

src/screen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void Screen_::setBrightness(uint8_t brightness, bool shouldStore)
2424
#ifdef ENABLE_STORAGE
2525
if (shouldStore)
2626
{
27-
storage.begin("led-wall", false);
27+
storage.begin("led-wall");
2828
storage.putUInt("brightness", brightness);
2929
storage.end();
3030
}

0 commit comments

Comments
 (0)