diff --git a/examples/companion_radio/ui-new/DiagnosticsScreen.h b/examples/companion_radio/ui-new/DiagnosticsScreen.h index 7cdc89cd..b1cdb8a4 100644 --- a/examples/companion_radio/ui-new/DiagnosticsScreen.h +++ b/examples/companion_radio/ui-new/DiagnosticsScreen.h @@ -110,6 +110,8 @@ class DiagnosticsScreen : public UIScreen { if (err & ERR_EVENT_FULL) strcat(buf, "F "); if (err & ERR_EVENT_CAD_TIMEOUT) strcat(buf, "C "); if (err & ERR_EVENT_STARTRX_TIMEOUT) strcat(buf, "R "); + int len = strlen(buf); // drop the trailing space so right-alignment sits flush + if (len > 0 && buf[len - 1] == ' ') buf[len - 1] = '\0'; } addRow("Errors", buf); } diff --git a/src/helpers/DeviceDiag.cpp b/src/helpers/DeviceDiag.cpp index bfee9186..117dd72d 100644 --- a/src/helpers/DeviceDiag.cpp +++ b/src/helpers/DeviceDiag.cpp @@ -3,17 +3,20 @@ #if defined(NRF52_PLATFORM) #include "FreeRTOS.h" #include "task.h" +#include -// Same linker symbols + _sbrk() the core's own new.cpp uses to implement -// malloc's heap (see framework-arduinoadafruitnrf52/cores/nRF5/new.cpp) — -// there's no separate "free heap" API on this core, so this mirrors it. -extern "C" char* _sbrk(int incr); +// Heap region size from the linker symbols the core's new.cpp uses for sbrk +// (framework-arduinoadafruitnrf52/cores/nRF5/new.cpp). "Used" comes from +// newlib's mallinfo().uordblks (bytes actually outstanding) rather than +// sbrk(0) - __HeapBase: sbrk only ever grows, so a high-water mark there +// counts freed-and-recycled blocks as permanently "used" and free heap looks +// far lower than it really is. extern unsigned char __HeapBase[]; extern unsigned char __HeapLimit[]; void DeviceDiag::getHeapStats(uint32_t& free_bytes, uint32_t& total_bytes) { total_bytes = (uint32_t)(__HeapLimit - __HeapBase); - uint32_t used = (uint32_t)((unsigned char*)_sbrk(0) - __HeapBase); + uint32_t used = (uint32_t)mallinfo().uordblks; free_bytes = (used < total_bytes) ? (total_bytes - used) : 0; }