From cea26d124781867de9b8802ab72285a43e608981 Mon Sep 17 00:00:00 2001 From: philmoz Date: Sun, 7 May 2023 11:14:01 +1000 Subject: [PATCH] fix(color): Return actual free memory avail from 'malloc/new' calls in 'availableMemory' (#3512) --- radio/src/opentx.cpp | 17 +++++++++++++++++ radio/src/opentx.h | 9 +-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index a5add9f53..e1067fb6e 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -37,6 +37,9 @@ #include "gui/colorlcd/LvglWrapper.h" #endif +#if !defined(SIMU) +#include +#endif RadioData g_eeGeneral; ModelData g_model; @@ -1926,3 +1929,17 @@ uint32_t pwrCheck() } #endif // defined(PWR_BUTTON_PRESS) #endif // !defined(SIMU) + +uint32_t availableMemory() +{ +#if defined(SIMU) + return 1000; +#else + extern unsigned char *heap; + extern int _heap_end; + + struct mallinfo info = mallinfo(); + + return ((uint32_t)((unsigned char *)&_heap_end - heap)) + info.fordblks; +#endif +} diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 1a357ba3d..8d32151a3 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -469,14 +469,7 @@ extern uint8_t mixerCurrentFlightMode; extern uint8_t lastFlightMode; extern uint8_t flightModeTransitionLast; -#if defined(SIMU) - inline int availableMemory() { return 1000; } -#else - extern unsigned char *heap; - extern int _end; - extern int _heap_end; - #define availableMemory() ((unsigned int)((unsigned char *)&_heap_end - heap)) -#endif +extern uint32_t availableMemory(); void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms);