From 3ee0fdee5092f064883f9e367c23a5ae15771ee4 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Wed, 22 May 2019 14:54:23 +0900 Subject: [PATCH] Added the existence check of PSRAM #77 --- src/AutoConnectElementJson.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/AutoConnectElementJson.h b/src/AutoConnectElementJson.h index ed42401..2f82a73 100644 --- a/src/AutoConnectElementJson.h +++ b/src/AutoConnectElementJson.h @@ -76,7 +76,13 @@ using ArduinoJsonArray = JsonArray; // JsonDocument is assigned to PSRAM by ArduinoJson's custom allocator. struct SpiRamAllocatorST { void* allocate(size_t size) { - return heap_caps_malloc(size, MALLOC_CAP_SPIRAM); + uint32_t caps; + if (psramFound()) + caps = MALLOC_CAP_SPIRAM; + else { + caps = MALLOC_CAP_8BIT; + AC_DBG("PSRAM not found, JSON buffer allocates to the heap.\n"); + } } void deallocate(void* pointer) { heap_caps_free(pointer);