Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion usermods/usermod_v2_RF433/usermod_v2_RF433.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class RF433Usermod : public Usermod
char objKey[14];
bool parsed = false;

if (!requestJSONBufferLock(22)) return false;
if (!requestJSONBufferLock(JSON_LOCK_REMOTE)) return false;

sprintf_P(objKey, PSTR("\"%d\":"), button);

Expand Down
2 changes: 1 addition & 1 deletion wled00/FX_2Dfcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void WS2812FX::setUpMatrix() {
size_t gapSize = 0;
int8_t *gapTable = nullptr;

if (isFile && requestJSONBufferLock(20)) {
if (isFile && requestJSONBufferLock(JSON_LOCK_LEDGAP)) {
DEBUG_PRINT(F("Reading LED gap from "));
DEBUG_PRINTLN(fileName);
// read the array into global JSON buffer
Expand Down
2 changes: 1 addition & 1 deletion wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1982,7 +1982,7 @@ bool WS2812FX::deserializeMap(unsigned n) {
return false;
}

if (!isFile || !requestJSONBufferLock(7)) return false;
if (!isFile || !requestJSONBufferLock(JSON_LOCK_LEDMAP)) return false;

StaticJsonDocument<64> filter;
filter[F("width")] = true;
Expand Down
8 changes: 4 additions & 4 deletions wled00/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ void resetConfig() {
bool deserializeConfigFromFS() {
[[maybe_unused]] bool success = deserializeConfigSec();

if (!requestJSONBufferLock(1)) return false;
if (!requestJSONBufferLock(JSON_LOCK_CFG_DES)) return false;

DEBUG_PRINTLN(F("Reading settings from /cfg.json..."));

Expand All @@ -811,7 +811,7 @@ void serializeConfigToFS() {

DEBUG_PRINTLN(F("Writing settings to /cfg.json..."));

if (!requestJSONBufferLock(2)) return;
if (!requestJSONBufferLock(JSON_LOCK_CFG_SER)) return;

JsonObject root = pDoc->to<JsonObject>();

Expand Down Expand Up @@ -1255,7 +1255,7 @@ static const char s_wsec_json[] PROGMEM = "/wsec.json";
bool deserializeConfigSec() {
DEBUG_PRINTLN(F("Reading settings from /wsec.json..."));

if (!requestJSONBufferLock(3)) return false;
if (!requestJSONBufferLock(JSON_LOCK_CFG_SEC_DES)) return false;

bool success = readObjectFromFile(s_wsec_json, nullptr, pDoc);
if (!success) {
Expand Down Expand Up @@ -1309,7 +1309,7 @@ bool deserializeConfigSec() {
void serializeConfigSec() {
DEBUG_PRINTLN(F("Writing settings to /wsec.json..."));

if (!requestJSONBufferLock(4)) return;
if (!requestJSONBufferLock(JSON_LOCK_CFG_SEC_SER)) return;

JsonObject root = pDoc->to<JsonObject>();

Expand Down
25 changes: 25 additions & 0 deletions wled00/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,31 @@ static_assert(WLED_MAX_BUSSES <= 32, "WLED_MAX_BUSSES exceeds hard limit");
#define ERR_OVERCURRENT 31 // An attached current sensor has measured a current above the threshold (not implemented)
#define ERR_UNDERVOLT 32 // An attached voltmeter has measured a voltage below the threshold (not implemented)

// JSON buffer lock owners
#define JSON_LOCK_UNKNOWN 255
#define JSON_LOCK_CFG_DES 1
#define JSON_LOCK_CFG_SER 2
#define JSON_LOCK_CFG_SEC_DES 3
#define JSON_LOCK_CFG_SEC_SER 4
#define JSON_LOCK_SETTINGS 5
#define JSON_LOCK_XML 6
#define JSON_LOCK_LEDMAP 7
// unused 8
#define JSON_LOCK_PRESET_LOAD 9
#define JSON_LOCK_PRESET_SAVE 10
#define JSON_LOCK_WS_RECEIVE 11
#define JSON_LOCK_WS_SEND 12
#define JSON_LOCK_IR 13
#define JSON_LOCK_SERVER 14
#define JSON_LOCK_MQTT 15
#define JSON_LOCK_SERIAL 16
#define JSON_LOCK_SERVEJSON 17
#define JSON_LOCK_NOTIFY 18
#define JSON_LOCK_PRESET_NAME 19
#define JSON_LOCK_LEDGAP 20
#define JSON_LOCK_LEDMAP_ENUM 21
#define JSON_LOCK_REMOTE 22

// Timer mode types
#define NL_MODE_SET 0 //After nightlight time elapsed, set to target brightness
#define NL_MODE_FADE 1 //Fade to target brightness gradually
Expand Down
4 changes: 2 additions & 2 deletions wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ size_t printSetFormIndex(Print& settingsScript, const char* key, int index);
size_t printSetClassElementHTML(Print& settingsScript, const char* key, const int index, const char* val);
void prepareHostname(char* hostname);
[[gnu::pure]] bool isAsterisksOnly(const char* str, byte maxLen);
bool requestJSONBufferLock(uint8_t moduleID=255);
bool requestJSONBufferLock(uint8_t moduleID=JSON_LOCK_UNKNOWN);
void releaseJSONBufferLock();
uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen);
uint8_t extractModeSlider(uint8_t mode, uint8_t slider, char *dest, uint8_t maxLen, uint8_t *var = nullptr);
Expand Down Expand Up @@ -486,7 +486,7 @@ void bootloopCheckOTA(); // swap boot image if bootloop is detected instead of r
class JSONBufferGuard {
bool holding_lock;
public:
inline JSONBufferGuard(uint8_t module=255) : holding_lock(requestJSONBufferLock(module)) {};
inline JSONBufferGuard(uint8_t module=JSON_LOCK_UNKNOWN) : holding_lock(requestJSONBufferLock(module)) {};
inline ~JSONBufferGuard() { if (holding_lock) releaseJSONBufferLock(); };
inline JSONBufferGuard(const JSONBufferGuard&) = delete; // Noncopyable
inline JSONBufferGuard& operator=(const JSONBufferGuard&) = delete;
Expand Down
2 changes: 1 addition & 1 deletion wled00/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ static void decodeIRJson(uint32_t code)
JsonObject fdo;
JsonObject jsonCmdObj;

if (!requestJSONBufferLock(13)) return;
if (!requestJSONBufferLock(JSON_LOCK_IR)) return;

sprintf_P(objKey, PSTR("\"0x%lX\":"), (unsigned long)code);
strcpy_P(fileName, PSTR("/ir.json")); // for FS.exists()
Expand Down
2 changes: 1 addition & 1 deletion wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ void serveJson(AsyncWebServerRequest* request)
return;
}

if (!requestJSONBufferLock(17)) {
if (!requestJSONBufferLock(JSON_LOCK_SERVEJSON)) {
request->deferResponse();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion wled00/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProp
colorFromDecOrHexString(colPri, payloadStr);
colorUpdated(CALL_MODE_DIRECT_CHANGE);
} else if (strcmp_P(topic, PSTR("/api")) == 0) {
if (requestJSONBufferLock(15)) {
if (requestJSONBufferLock(JSON_LOCK_MQTT)) {
if (payloadStr[0] == '{') { //JSON API
deserializeJson(*pDoc, payloadStr);
deserializeState(pDoc->as<JsonObject>());
Expand Down
6 changes: 3 additions & 3 deletions wled00/presets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void doSaveState() {
unsigned long maxWait = millis() + strip.getFrameTime();
while (strip.isUpdating() && millis() < maxWait) delay(1); // wait for strip to finish updating, accessing FS during sendout causes glitches

if (!requestJSONBufferLock(10)) return;
if (!requestJSONBufferLock(JSON_LOCK_PRESET_SAVE)) return;

initPresetsFile(); // just in case if someone deleted presets.json using /edit
JsonObject sObj = pDoc->to<JsonObject>();
Expand Down Expand Up @@ -86,7 +86,7 @@ static void doSaveState() {

bool getPresetName(byte index, String& name)
{
if (!requestJSONBufferLock(19)) return false;
if (!requestJSONBufferLock(JSON_LOCK_PRESET_NAME)) return false;
bool presetExists = false;
if (readObjectFromFileUsingId(getPresetsFileName(), index, pDoc)) {
JsonObject fdo = pDoc->as<JsonObject>();
Expand Down Expand Up @@ -152,7 +152,7 @@ void handlePresets()
return;
}

if (presetToApply == 0 || !requestJSONBufferLock(9)) return; // no preset waiting to apply, or JSON buffer is already allocated, return to loop until free
if (presetToApply == 0 || !requestJSONBufferLock(JSON_LOCK_PRESET_LOAD)) return; // no preset waiting to apply, or JSON buffer is already allocated, return to loop until free

bool changePreset = false;
uint8_t tmpPreset = presetToApply; // store temporary since deserializeState() may call applyPreset()
Expand Down
2 changes: 1 addition & 1 deletion wled00/remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static bool remoteJson(int button)
char objKey[10];
bool parsed = false;

if (!requestJSONBufferLock(22)) return false;
if (!requestJSONBufferLock(JSON_LOCK_REMOTE)) return false;

sprintf_P(objKey, PSTR("\"%d\":"), button);

Expand Down
2 changes: 1 addition & 1 deletion wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
//USERMODS
if (subPage == SUBPAGE_UM)
{
if (!requestJSONBufferLock(5)) {
if (!requestJSONBufferLock(JSON_LOCK_SETTINGS)) {
request->deferResponse();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion wled00/udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ void handleNotifications()
// API over UDP
udpIn[packetSize] = '\0';

if (requestJSONBufferLock(18)) {
if (requestJSONBufferLock(JSON_LOCK_NOTIFY)) {
if (udpIn[0] >= 'A' && udpIn[0] <= 'Z') { //HTTP API
String apireq = "win"; apireq += '&'; // reduce flash string usage
apireq += (char*)udpIn;
Expand Down
2 changes: 1 addition & 1 deletion wled00/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ void enumerateLedmaps() {
ledMaps |= 1 << i;

#ifndef ESP8266
if (requestJSONBufferLock(21)) {
if (requestJSONBufferLock(JSON_LOCK_LEDMAP_ENUM)) {
if (readObjectFromFile(fileName, nullptr, pDoc, &filter)) {
size_t len = 0;
JsonObject root = pDoc->as<JsonObject>();
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void handleSerial()
else if (next == 'O') { continuousSendLED = true; } // Enable Continuous Serial Streaming
else if (next == '{') { //JSON API
bool verboseResponse = false;
if (!requestJSONBufferLock(16)) {
if (!requestJSONBufferLock(JSON_LOCK_SERIAL)) {
Serial.printf_P(PSTR("{\"error\":%d}\n"), ERR_NOBUF);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void initServer()
bool verboseResponse = false;
bool isConfig = false;

if (!requestJSONBufferLock(14)) {
if (!requestJSONBufferLock(JSON_LOCK_SERVER)) {
request->deferResponse();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions wled00/ws.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
}

bool verboseResponse = false;
if (!requestJSONBufferLock(11)) {
if (!requestJSONBufferLock(JSON_LOCK_WS_RECEIVE)) {
client->text(F("{\"error\":3}")); // ERR_NOBUF
return;
}
Expand Down Expand Up @@ -136,7 +136,7 @@ void sendDataWs(AsyncWebSocketClient * client)
{
if (!ws.count()) return;

if (!requestJSONBufferLock(12)) {
if (!requestJSONBufferLock(JSON_LOCK_WS_SEND)) {
const char* error = PSTR("{\"error\":3}");
if (client) {
client->text(FPSTR(error)); // ERR_NOBUF
Expand Down
2 changes: 1 addition & 1 deletion wled00/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void appendGPIOinfo(Print& settingsScript)
settingsScript.printf_P(PSTR(",%d,%d"), spi_mosi, spi_sclk);
}
// usermod pin reservations will become unnecessary when settings pages will read cfg.json directly
if (requestJSONBufferLock(6)) {
if (requestJSONBufferLock(JSON_LOCK_XML)) {
// if we can't allocate JSON buffer ignore usermod pins
JsonObject mods = pDoc->createNestedObject("um");
UsermodManager::addToConfig(mods);
Expand Down