From 87bbfb26afb3bd590395d765d5d71074da47f1a1 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Mon, 16 Mar 2026 20:26:36 +0100 Subject: [PATCH] Display available space on SDCard --- lib/hal/HalStorage.cpp | 3 +++ lib/hal/HalStorage.h | 3 +++ src/network/CrossPointWebServer.cpp | 2 ++ src/network/html/HomePage.html | 15 +++++++++++++++ 4 files changed, 23 insertions(+) diff --git a/lib/hal/HalStorage.cpp b/lib/hal/HalStorage.cpp index 24395e4f..9d5b50f5 100644 --- a/lib/hal/HalStorage.cpp +++ b/lib/hal/HalStorage.cpp @@ -54,6 +54,9 @@ bool HalStorage::writeFile(const char* path, const String& content) { bool HalStorage::ensureDirectoryExists(const char* path) { HAL_STORAGE_WRAPPED_CALL(ensureDirectoryExists, path); } +uint64_t HalStorage::sdTotalBytes() const { HAL_STORAGE_WRAPPED_CALL(totalBytes); } +uint64_t HalStorage::sdUsedBytes() const { HAL_STORAGE_WRAPPED_CALL(usedBytes); } + class HalFile::Impl { public: Impl(FsFile&& fsFile) : file(std::move(fsFile)) {} diff --git a/lib/hal/HalStorage.h b/lib/hal/HalStorage.h index d5824bae..1317e268 100644 --- a/lib/hal/HalStorage.h +++ b/lib/hal/HalStorage.h @@ -45,6 +45,9 @@ class HalStorage { bool openFileForWrite(const char* moduleName, const String& path, HalFile& file); bool removeDir(const char* path); + uint64_t sdTotalBytes() const; + uint64_t sdUsedBytes() const; + static HalStorage& getInstance() { return instance; } class StorageLock; // private class, used internally diff --git a/src/network/CrossPointWebServer.cpp b/src/network/CrossPointWebServer.cpp index ede4aa39..733b524d 100644 --- a/src/network/CrossPointWebServer.cpp +++ b/src/network/CrossPointWebServer.cpp @@ -326,6 +326,8 @@ void CrossPointWebServer::handleStatus() const { doc["rssi"] = apMode ? 0 : WiFi.RSSI(); doc["freeHeap"] = ESP.getFreeHeap(); doc["uptime"] = millis() / 1000; + doc["sdTotal"] = Storage.sdTotalBytes(); + doc["sdUsed"] = Storage.sdUsedBytes(); String json; serializeJson(doc, json); diff --git a/src/network/html/HomePage.html b/src/network/html/HomePage.html index e073e6d8..895b93c0 100644 --- a/src/network/html/HomePage.html +++ b/src/network/html/HomePage.html @@ -124,6 +124,10 @@ Free Memory +
+ SD Card + +
@@ -132,6 +136,14 @@