Skip to content

Commit 301bdf2

Browse files
authored
Merge pull request #3610 from Aircoookie/psram-4-json
Allow PSRAM (SPI RAM) to be used for JSON buffer
2 parents 1c1b67e + d3be7a3 commit 301bdf2

19 files changed

+105
-74
lines changed

wled00/FX_2Dfcn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ void WS2812FX::setUpMatrix() {
9191
DEBUG_PRINT(F("Reading LED gap from "));
9292
DEBUG_PRINTLN(fileName);
9393
// read the array into global JSON buffer
94-
if (readObjectFromFile(fileName, nullptr, &doc)) {
94+
if (readObjectFromFile(fileName, nullptr, pDoc)) {
9595
// the array is similar to ledmap, except it has only 3 values:
9696
// -1 ... missing pixel (do not increase pixel count)
9797
// 0 ... inactive pixel (it does count, but should be mapped out (-1))
9898
// 1 ... active pixel (it will count and will be mapped)
99-
JsonArray map = doc.as<JsonArray>();
99+
JsonArray map = pDoc->as<JsonArray>();
100100
gapSize = map.size();
101101
if (!map.isNull() && gapSize >= matrixSize) { // not an empty map
102102
gapTable = new int8_t[gapSize];

wled00/FX_fcn.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ bool WS2812FX::deserializeMap(uint8_t n) {
16661666

16671667
if (!isFile || !requestJSONBufferLock(7)) return false; // this will trigger setUpMatrix() when called from wled.cpp
16681668

1669-
if (!readObjectFromFile(fileName, nullptr, &doc)) {
1669+
if (!readObjectFromFile(fileName, nullptr, pDoc)) {
16701670
DEBUG_PRINT(F("ERROR Invalid ledmap in ")); DEBUG_PRINTLN(fileName);
16711671
releaseJSONBufferLock();
16721672
return false; // if file does not load properly then exit
@@ -1676,7 +1676,8 @@ bool WS2812FX::deserializeMap(uint8_t n) {
16761676

16771677
if (customMappingTable == nullptr) customMappingTable = new uint16_t[getLengthTotal()];
16781678

1679-
JsonArray map = doc[F("map")];
1679+
JsonObject root = pDoc->as<JsonObject>();
1680+
JsonArray map = root[F("map")];
16801681
if (!map.isNull() && map.size()) { // not an empty map
16811682
customMappingSize = min((unsigned)map.size(), (unsigned)getLengthTotal());
16821683
for (unsigned i=0; i<customMappingSize; i++) customMappingTable[i] = (uint16_t) (map[i]<0 ? 0xFFFFU : map[i]);

wled00/cfg.cpp

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ void deserializeConfigFromFS() {
609609

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

612-
success = readObjectFromFile("/cfg.json", nullptr, &doc);
612+
success = readObjectFromFile("/cfg.json", nullptr, pDoc);
613613
if (!success) { // if file does not exist, optionally try reading from EEPROM and then save defaults to FS
614614
releaseJSONBufferLock();
615615
#ifdef WLED_ADD_EEPROM_SUPPORT
@@ -630,7 +630,8 @@ void deserializeConfigFromFS() {
630630

631631
// NOTE: This routine deserializes *and* applies the configuration
632632
// Therefore, must also initialize ethernet from this function
633-
bool needsSave = deserializeConfig(doc.as<JsonObject>(), true);
633+
JsonObject root = pDoc->as<JsonObject>();
634+
bool needsSave = deserializeConfig(root, true);
634635
releaseJSONBufferLock();
635636

636637
if (needsSave) serializeConfig(); // usermods required new parameters
@@ -643,19 +644,21 @@ void serializeConfig() {
643644

644645
if (!requestJSONBufferLock(2)) return;
645646

646-
JsonArray rev = doc.createNestedArray("rev");
647+
JsonObject root = pDoc->to<JsonObject>();
648+
649+
JsonArray rev = root.createNestedArray("rev");
647650
rev.add(1); //major settings revision
648651
rev.add(0); //minor settings revision
649652

650-
doc[F("vid")] = VERSION;
653+
root[F("vid")] = VERSION;
651654

652-
JsonObject id = doc.createNestedObject("id");
655+
JsonObject id = root.createNestedObject("id");
653656
id[F("mdns")] = cmDNS;
654657
id[F("name")] = serverDescription;
655658
id[F("inv")] = alexaInvocationName;
656659
id[F("sui")] = simplifiedUI;
657660

658-
JsonObject nw = doc.createNestedObject("nw");
661+
JsonObject nw = root.createNestedObject("nw");
659662
#ifndef WLED_DISABLE_ESPNOW
660663
nw[F("espnow")] = enableESPNow;
661664
nw[F("linked_remote")] = linked_remote;
@@ -677,7 +680,7 @@ void serializeConfig() {
677680
nw_ins_0_sn.add(staticSubnet[i]);
678681
}
679682

680-
JsonObject ap = doc.createNestedObject("ap");
683+
JsonObject ap = root.createNestedObject("ap");
681684
ap[F("ssid")] = apSSID;
682685
ap[F("pskl")] = strlen(apPass);
683686
ap[F("chan")] = apChannel;
@@ -690,12 +693,12 @@ void serializeConfig() {
690693
ap_ip.add(2);
691694
ap_ip.add(1);
692695

693-
JsonObject wifi = doc.createNestedObject("wifi");
696+
JsonObject wifi = root.createNestedObject("wifi");
694697
wifi[F("sleep")] = !noWifiSleep;
695698
wifi[F("phy")] = (int)force802_3g;
696699

697700
#ifdef WLED_USE_ETHERNET
698-
JsonObject ethernet = doc.createNestedObject("eth");
701+
JsonObject ethernet = root.createNestedObject("eth");
699702
ethernet["type"] = ethernetType;
700703
if (ethernetType != WLED_ETH_NONE && ethernetType < WLED_NUM_ETH_TYPES) {
701704
JsonArray pins = ethernet.createNestedArray("pin");
@@ -718,7 +721,7 @@ void serializeConfig() {
718721
}
719722
#endif
720723

721-
JsonObject hw = doc.createNestedObject("hw");
724+
JsonObject hw = root.createNestedObject("hw");
722725

723726
JsonObject hw_led = hw.createNestedObject("led");
724727
hw_led[F("total")] = strip.getLengthTotal(); //provided for compatibility on downgrade and per-output ABL
@@ -830,7 +833,7 @@ void serializeConfig() {
830833
//JsonObject hw_status = hw.createNestedObject("status");
831834
//hw_status["pin"] = -1;
832835

833-
JsonObject light = doc.createNestedObject(F("light"));
836+
JsonObject light = root.createNestedObject(F("light"));
834837
light[F("scale-bri")] = briMultiplier;
835838
light[F("pal-mode")] = strip.paletteBlend;
836839
light[F("aseg")] = autoSegments;
@@ -853,12 +856,12 @@ void serializeConfig() {
853856
light_nl[F("tbri")] = nightlightTargetBri;
854857
light_nl["macro"] = macroNl;
855858

856-
JsonObject def = doc.createNestedObject("def");
859+
JsonObject def = root.createNestedObject("def");
857860
def["ps"] = bootPreset;
858861
def["on"] = turnOnAtBoot;
859862
def["bri"] = briS;
860863

861-
JsonObject interfaces = doc.createNestedObject("if");
864+
JsonObject interfaces = root.createNestedObject("if");
862865

863866
JsonObject if_sync = interfaces.createNestedObject("sync");
864867
if_sync[F("port0")] = udpPort;
@@ -961,7 +964,7 @@ void serializeConfig() {
961964
if_ntp[F("ln")] = longitude;
962965
if_ntp[F("lt")] = latitude;
963966

964-
JsonObject ol = doc.createNestedObject("ol");
967+
JsonObject ol = root.createNestedObject("ol");
965968
ol[F("clock")] = overlayCurrent;
966969
ol[F("cntdwn")] = countdownMode;
967970

@@ -971,7 +974,7 @@ void serializeConfig() {
971974
ol[F("o5m")] = analogClock5MinuteMarks;
972975
ol[F("osec")] = analogClockSecondsTrail;
973976

974-
JsonObject timers = doc.createNestedObject(F("timers"));
977+
JsonObject timers = root.createNestedObject(F("timers"));
975978

976979
JsonObject cntdwn = timers.createNestedObject(F("cntdwn"));
977980
JsonArray goal = cntdwn.createNestedArray(F("goal"));
@@ -999,14 +1002,14 @@ void serializeConfig() {
9991002
}
10001003
}
10011004

1002-
JsonObject ota = doc.createNestedObject("ota");
1005+
JsonObject ota = root.createNestedObject("ota");
10031006
ota[F("lock")] = otaLock;
10041007
ota[F("lock-wifi")] = wifiLock;
10051008
ota[F("pskl")] = strlen(otaPass);
10061009
ota[F("aota")] = aOtaEnabled;
10071010

10081011
#ifdef WLED_ENABLE_DMX
1009-
JsonObject dmx = doc.createNestedObject("dmx");
1012+
JsonObject dmx = root.createNestedObject("dmx");
10101013
dmx[F("chan")] = DMXChannels;
10111014
dmx[F("gap")] = DMXGap;
10121015
dmx["start"] = DMXStart;
@@ -1020,11 +1023,11 @@ void serializeConfig() {
10201023
dmx[F("e131proxy")] = e131ProxyUniverse;
10211024
#endif
10221025

1023-
JsonObject usermods_settings = doc.createNestedObject("um");
1026+
JsonObject usermods_settings = root.createNestedObject("um");
10241027
usermods.addToConfig(usermods_settings);
10251028

10261029
File f = WLED_FS.open("/cfg.json", "w");
1027-
if (f) serializeJson(doc, f);
1030+
if (f) serializeJson(root, f);
10281031
f.close();
10291032
releaseJSONBufferLock();
10301033

@@ -1037,19 +1040,21 @@ bool deserializeConfigSec() {
10371040

10381041
if (!requestJSONBufferLock(3)) return false;
10391042

1040-
bool success = readObjectFromFile("/wsec.json", nullptr, &doc);
1043+
bool success = readObjectFromFile("/wsec.json", nullptr, pDoc);
10411044
if (!success) {
10421045
releaseJSONBufferLock();
10431046
return false;
10441047
}
10451048

1046-
JsonObject nw_ins_0 = doc["nw"]["ins"][0];
1049+
JsonObject root = pDoc->as<JsonObject>();
1050+
1051+
JsonObject nw_ins_0 = root["nw"]["ins"][0];
10471052
getStringFromJson(clientPass, nw_ins_0["psk"], 65);
10481053

1049-
JsonObject ap = doc["ap"];
1054+
JsonObject ap = root["ap"];
10501055
getStringFromJson(apPass, ap["psk"] , 65);
10511056

1052-
[[maybe_unused]] JsonObject interfaces = doc["if"];
1057+
[[maybe_unused]] JsonObject interfaces = root["if"];
10531058

10541059
#ifdef WLED_ENABLE_MQTT
10551060
JsonObject if_mqtt = interfaces["mqtt"];
@@ -1060,10 +1065,10 @@ bool deserializeConfigSec() {
10601065
getStringFromJson(hueApiKey, interfaces["hue"][F("key")], 47);
10611066
#endif
10621067

1063-
getStringFromJson(settingsPIN, doc["pin"], 5);
1068+
getStringFromJson(settingsPIN, root["pin"], 5);
10641069
correctPIN = !strlen(settingsPIN);
10651070

1066-
JsonObject ota = doc["ota"];
1071+
JsonObject ota = root["ota"];
10671072
getStringFromJson(otaPass, ota[F("pwd")], 33);
10681073
CJSON(otaLock, ota[F("lock")]);
10691074
CJSON(wifiLock, ota[F("lock-wifi")]);
@@ -1078,17 +1083,19 @@ void serializeConfigSec() {
10781083

10791084
if (!requestJSONBufferLock(4)) return;
10801085

1081-
JsonObject nw = doc.createNestedObject("nw");
1086+
JsonObject root = pDoc->to<JsonObject>();
1087+
1088+
JsonObject nw = root.createNestedObject("nw");
10821089

10831090
JsonArray nw_ins = nw.createNestedArray("ins");
10841091

10851092
JsonObject nw_ins_0 = nw_ins.createNestedObject();
10861093
nw_ins_0["psk"] = clientPass;
10871094

1088-
JsonObject ap = doc.createNestedObject("ap");
1095+
JsonObject ap = root.createNestedObject("ap");
10891096
ap["psk"] = apPass;
10901097

1091-
[[maybe_unused]] JsonObject interfaces = doc.createNestedObject("if");
1098+
[[maybe_unused]] JsonObject interfaces = root.createNestedObject("if");
10921099
#ifdef WLED_ENABLE_MQTT
10931100
JsonObject if_mqtt = interfaces.createNestedObject("mqtt");
10941101
if_mqtt["psk"] = mqttPass;
@@ -1098,16 +1105,16 @@ void serializeConfigSec() {
10981105
if_hue[F("key")] = hueApiKey;
10991106
#endif
11001107

1101-
doc["pin"] = settingsPIN;
1108+
root["pin"] = settingsPIN;
11021109

1103-
JsonObject ota = doc.createNestedObject("ota");
1110+
JsonObject ota = root.createNestedObject("ota");
11041111
ota[F("pwd")] = otaPass;
11051112
ota[F("lock")] = otaLock;
11061113
ota[F("lock-wifi")] = wifiLock;
11071114
ota[F("aota")] = aOtaEnabled;
11081115

11091116
File f = WLED_FS.open("/wsec.json", "w");
1110-
if (f) serializeJson(doc, f);
1117+
if (f) serializeJson(root, f);
11111118
f.close();
11121119
releaseJSONBufferLock();
11131120
}

wled00/ir.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,8 @@ void decodeIRJson(uint32_t code)
643643
// this may fail for two reasons: ir.json does not exist or IR code not found
644644
// if the IR code is not found readObjectFromFile() will clean() doc JSON document
645645
// so we can differentiate between the two
646-
readObjectFromFile("/ir.json", objKey, &doc);
647-
fdo = doc.as<JsonObject>();
646+
readObjectFromFile("/ir.json", objKey, pDoc);
647+
fdo = pDoc->as<JsonObject>();
648648
lastValidCode = 0;
649649
if (fdo.isNull()) {
650650
//the received code does not exist

wled00/json.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ void serveJson(AsyncWebServerRequest* request)
10551055
servingClient = false;
10561056
return;
10571057
}
1058-
AsyncJsonResponse *response = new AsyncJsonResponse(&doc, subJson==JSON_PATH_FXDATA || subJson==JSON_PATH_EFFECTS); // will clear and convert JsonDocument into JsonArray if necessary
1058+
AsyncJsonResponse *response = new AsyncJsonResponse(pDoc, subJson==JSON_PATH_FXDATA || subJson==JSON_PATH_EFFECTS); // will clear and convert JsonDocument into JsonArray if necessary
10591059

10601060
JsonVariant lDoc = response->getRoot();
10611061

wled00/mqtt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
109109
return;
110110
}
111111
if (payloadStr[0] == '{') { //JSON API
112-
deserializeJson(doc, payloadStr);
113-
deserializeState(doc.as<JsonObject>());
112+
deserializeJson(*pDoc, payloadStr);
113+
deserializeState(pDoc->as<JsonObject>());
114114
} else { //HTTP API
115115
String apireq = "win"; apireq += '&'; // reduce flash string usage
116116
apireq += payloadStr;

wled00/pin_manager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ bool PinManagerClass::isPinAllocated(byte gpio, PinOwner tag)
238238
// Check if supplied GPIO is ok to use
239239
bool PinManagerClass::isPinOk(byte gpio, bool output)
240240
{
241-
#ifdef ESP32
241+
#ifdef ARDUINO_ARCH_ESP32
242242
if (digitalPinIsValid(gpio)) {
243243
#if defined(CONFIG_IDF_TARGET_ESP32C3)
244244
// strapping pins: 2, 8, & 9
@@ -257,6 +257,9 @@ bool PinManagerClass::isPinOk(byte gpio, bool output)
257257
// GPIO46 is input only and pulled down
258258
#else
259259
if (gpio > 5 && gpio < 12) return false; //SPI flash pins
260+
#ifdef BOARD_HAS_PSRAM
261+
if (gpio == 16 || gpio == 17) return false; //PSRAM pins
262+
#endif
260263
#endif
261264
if (output) return digitalPinCanOutput(gpio);
262265
else return true;

wled00/presets.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static void doSaveState() {
2727
if (!requestJSONBufferLock(10)) return; // will set fileDoc
2828

2929
initPresetsFile(); // just in case if someone deleted presets.json using /edit
30-
JsonObject sObj = doc.to<JsonObject>();
30+
JsonObject sObj = pDoc->to<JsonObject>();
3131

3232
DEBUG_PRINTLN(F("Serialize current state"));
3333
if (playlistSave) {
@@ -42,7 +42,7 @@ static void doSaveState() {
4242
/*
4343
#ifdef WLED_DEBUG
4444
DEBUG_PRINTLN(F("Serialized preset"));
45-
serializeJson(doc,Serial);
45+
serializeJson(*pDoc,Serial);
4646
DEBUG_PRINTLN();
4747
#endif
4848
*/
@@ -83,9 +83,9 @@ bool getPresetName(byte index, String& name)
8383
{
8484
if (!requestJSONBufferLock(9)) return false;
8585
bool presetExists = false;
86-
if (readObjectFromFileUsingId(getFileName(), index, &doc))
86+
if (readObjectFromFileUsingId(getFileName(), index, pDoc))
8787
{
88-
JsonObject fdo = doc.as<JsonObject>();
88+
JsonObject fdo = pDoc->as<JsonObject>();
8989
if (fdo["n"]) {
9090
name = (const char*)(fdo["n"]);
9191
presetExists = true;

wled00/remote.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ static bool remoteJson(int button)
123123
sprintf_P(objKey, PSTR("\"%d\":"), button);
124124

125125
// attempt to read command from remote.json
126-
readObjectFromFile("/remote.json", objKey, &doc);
127-
JsonObject fdo = doc.as<JsonObject>();
126+
readObjectFromFile("/remote.json", objKey, pDoc);
127+
JsonObject fdo = pDoc->as<JsonObject>();
128128
if (fdo.isNull()) {
129129
// the received button does not exist
130130
if (!WLED_FS.exists("/remote.json")) errorFlag = ERR_FS_RMLOAD; //warn if file itself doesn't exist

wled00/set.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
626626
}
627627
}
628628

629-
JsonObject um = doc.createNestedObject("um");
629+
JsonObject um = pDoc->createNestedObject("um");
630630

631631
size_t args = request->args();
632632
uint16_t j=0;

wled00/udp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,8 @@ void handleNotifications()
664664
apireq += (char*)udpIn;
665665
handleSet(nullptr, apireq);
666666
} else if (udpIn[0] == '{') { //JSON API
667-
DeserializationError error = deserializeJson(doc, udpIn);
668-
JsonObject root = doc.as<JsonObject>();
667+
DeserializationError error = deserializeJson(*pDoc, udpIn);
668+
JsonObject root = pDoc->as<JsonObject>();
669669
if (!error && !root.isNull()) deserializeState(root);
670670
}
671671
releaseJSONBufferLock();

0 commit comments

Comments
 (0)