diff --git a/src/SdCard.cpp b/src/SdCard.cpp index 0026a1b..3fe31a5 100644 --- a/src/SdCard.cpp +++ b/src/SdCard.cpp @@ -179,7 +179,7 @@ char **SdCard_ReturnPlaylist(const char *fileName, const uint32_t _playMode) { uint16_t allocCount = 1; uint16_t allocSize = 4096; if (psramInit()) { - allocSize = 16384; // There's enough PSRAM. So we don't have to care... + allocSize = 65535; // There's enough PSRAM. So we don't have to care... } serializedPlaylist = (char *) x_calloc(allocSize, sizeof(char)); diff --git a/src/Web.cpp b/src/Web.cpp index 19b1c96..0764985 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -65,6 +65,18 @@ static void onWebsocketEvent(AsyncWebSocket *server, AsyncWebSocketClient *clien static String templateProcessor(const String &templ); static void webserverStart(void); +// If PSRAM is available use it allocate memory for JSON-objects +struct SpiRamAllocator { + void* allocate(size_t size) { + return ps_malloc(size); + + } + void deallocate(void* pointer) { + free(pointer); + } +}; +using SpiRamJsonDocument = BasicJsonDocument; + void Web_Init(void) { wServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { request->send_P(200, "text/html", accesspoint_HTML); @@ -278,7 +290,12 @@ String templateProcessor(const String &templ) { // Takes inputs from webgui, parses JSON and saves values in NVS // If operation was successful (NVS-write is verified) true is returned bool processJsonRequest(char *_serialJson) { - StaticJsonDocument<1000> doc; + #ifdef BOARD_HAS_PSRAM + SpiRamJsonDocument doc(1000); + #else + StaticJsonDocument<1000> doc; + #endif + DeserializationError error = deserializeJson(doc, _serialJson); JsonObject object = doc.as(); @@ -592,7 +609,12 @@ void explorerHandleFileStorageTask(void *parameter) { // requires a GET parameter path for the directory void explorerHandleListRequest(AsyncWebServerRequest *request) { //DynamicJsonDocument jsonBuffer(8192); - StaticJsonDocument<8192> jsonBuffer; + #ifdef BOARD_HAS_PSRAM + SpiRamJsonDocument jsonBuffer(65636); + #else + StaticJsonDocument<8192> jsonBuffer; + #endif + String serializedJsonString; AsyncWebParameter *param; char filePath[MAX_FILEPATH_LENTGH];