Browse Source

For ESP32-chips with PSRAM: JSONobj-mem-allocation is now done in PSRAM.

master
Torsten Stauder 4 years ago
parent
commit
2cf8ea4d9f
  1. 2
      src/SdCard.cpp
  2. 26
      src/Web.cpp

2
src/SdCard.cpp

@ -179,7 +179,7 @@ char **SdCard_ReturnPlaylist(const char *fileName, const uint32_t _playMode) {
uint16_t allocCount = 1; uint16_t allocCount = 1;
uint16_t allocSize = 4096; uint16_t allocSize = 4096;
if (psramInit()) { 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)); serializedPlaylist = (char *) x_calloc(allocSize, sizeof(char));

26
src/Web.cpp

@ -65,6 +65,18 @@ static void onWebsocketEvent(AsyncWebSocket *server, AsyncWebSocketClient *clien
static String templateProcessor(const String &templ); static String templateProcessor(const String &templ);
static void webserverStart(void); 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<SpiRamAllocator>;
void Web_Init(void) { void Web_Init(void) {
wServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { wServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send_P(200, "text/html", accesspoint_HTML); 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 // Takes inputs from webgui, parses JSON and saves values in NVS
// If operation was successful (NVS-write is verified) true is returned // If operation was successful (NVS-write is verified) true is returned
bool processJsonRequest(char *_serialJson) { bool processJsonRequest(char *_serialJson) {
StaticJsonDocument<1000> doc;
#ifdef BOARD_HAS_PSRAM
SpiRamJsonDocument doc(1000);
#else
StaticJsonDocument<1000> doc;
#endif
DeserializationError error = deserializeJson(doc, _serialJson); DeserializationError error = deserializeJson(doc, _serialJson);
JsonObject object = doc.as<JsonObject>(); JsonObject object = doc.as<JsonObject>();
@ -592,7 +609,12 @@ void explorerHandleFileStorageTask(void *parameter) {
// requires a GET parameter path for the directory // requires a GET parameter path for the directory
void explorerHandleListRequest(AsyncWebServerRequest *request) { void explorerHandleListRequest(AsyncWebServerRequest *request) {
//DynamicJsonDocument jsonBuffer(8192); //DynamicJsonDocument jsonBuffer(8192);
StaticJsonDocument<8192> jsonBuffer;
#ifdef BOARD_HAS_PSRAM
SpiRamJsonDocument jsonBuffer(65636);
#else
StaticJsonDocument<8192> jsonBuffer;
#endif
String serializedJsonString; String serializedJsonString;
AsyncWebParameter *param; AsyncWebParameter *param;
char filePath[MAX_FILEPATH_LENTGH]; char filePath[MAX_FILEPATH_LENTGH];

Loading…
Cancel
Save