kopia lustrzana https://github.com/Aircoookie/WLED
add json locking
rodzic
c4bca7a153
commit
d2280024f7
|
@ -76,32 +76,38 @@ void checkSchedule() {
|
||||||
|
|
||||||
void loadSchedule()
|
void loadSchedule()
|
||||||
{
|
{
|
||||||
if (!WLED_FS.exists(SCHEDULE_FILE))
|
if (!WLED_FS.exists(SCHEDULE_FILE)) return;
|
||||||
return;
|
|
||||||
File file = WLED_FS.open(SCHEDULE_FILE, "r");
|
|
||||||
if (!file)
|
|
||||||
return;
|
|
||||||
|
|
||||||
DynamicJsonDocument doc(4096);
|
requestJSONBufferLock(); //Prevent concurrent JSON access
|
||||||
if (deserializeJson(doc, file))
|
|
||||||
{
|
File file = WLED_FS.open(SCHEDULE_FILE, "r");
|
||||||
file.close();
|
if (!file) {
|
||||||
|
releaseJSONBufferLock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
|
DeserializationError error = deserializeJson(doc, file);
|
||||||
|
file.close(); // ✅ Close file before releasing lock
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
DEBUG_PRINTF_P(PSTR("[Schedule] JSON parse failed: %s\n"), error.c_str());
|
||||||
|
releaseJSONBufferLock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
file.close();
|
|
||||||
|
|
||||||
numScheduleEvents = 0;
|
numScheduleEvents = 0;
|
||||||
for (JsonObject e : doc.as<JsonArray>())
|
for (JsonObject e : doc.as<JsonArray>()) {
|
||||||
{
|
if (numScheduleEvents >= MAX_SCHEDULE_EVENTS) break;
|
||||||
if (numScheduleEvents >= MAX_SCHEDULE_EVENTS)
|
|
||||||
break;
|
|
||||||
scheduleEvents[numScheduleEvents++] = {
|
scheduleEvents[numScheduleEvents++] = {
|
||||||
(uint8_t)e["sm"].as<int>(), (uint8_t)e["sd"].as<int>(), // start month, day
|
(uint8_t)e["sm"].as<int>(), (uint8_t)e["sd"].as<int>(), // start month, day
|
||||||
(uint8_t)e["em"].as<int>(), (uint8_t)e["ed"].as<int>(), // end month, day
|
(uint8_t)e["em"].as<int>(), (uint8_t)e["ed"].as<int>(), // end month, day
|
||||||
(uint8_t)e["r"].as<int>(), (uint8_t)e["h"].as<int>(), // repeat mask, hour
|
(uint8_t)e["r"].as<int>(), (uint8_t)e["h"].as<int>(), // repeat mask, hour
|
||||||
(uint8_t)e["m"].as<int>(), (uint8_t)e["p"].as<int>()}; // minute, preset
|
(uint8_t)e["m"].as<int>(), (uint8_t)e["p"].as<int>() // minute, preset
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_PRINTF_P(PSTR("[Schedule] Loaded %u schedule entries from schedule.json\n"), numScheduleEvents);
|
DEBUG_PRINTF_P(PSTR("[Schedule] Loaded %u schedule entries from schedule.json\n"), numScheduleEvents);
|
||||||
|
releaseJSONBufferLock(); // Done safely
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue