From 0d5d353e999be50de1c64ecfa6603bf48615b5f5 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sat, 17 Sep 2022 17:10:23 +0200 Subject: [PATCH] read LittleFS.totalBytes only once on start --- lib/framework/SystemStatus.cpp | 2 +- src/system.cpp | 3 ++- src/system.h | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/framework/SystemStatus.cpp b/lib/framework/SystemStatus.cpp index baf933050..c9f810382 100644 --- a/lib/framework/SystemStatus.cpp +++ b/lib/framework/SystemStatus.cpp @@ -24,7 +24,7 @@ void SystemStatus::systemStatus(AsyncWebServerRequest * request) { root["flash_chip_size"] = ESP.getFlashChipSize(); root["flash_chip_speed"] = ESP.getFlashChipSpeed(); - root["fs_total"] = LittleFS.totalBytes(); + root["fs_total"] = emsesp::EMSESP::system_.FStotal(); root["fs_used"] = LittleFS.usedBytes(); root["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3); diff --git a/src/system.cpp b/src/system.cpp index 98c230298..1dc87f4b6 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -373,6 +373,7 @@ void System::start() { if (low_clock_) { setCpuFrequencyMhz(160); } + fstotal_ = LittleFS.totalBytes(); // read only once, it takes 500 ms to read #endif EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) { @@ -784,7 +785,7 @@ void System::show_system(uuid::console::Shell & shell) { shell.printfln(F(" SDK version: %s"), ESP.getSdkVersion()); shell.printfln(F(" CPU frequency: %lu MHz"), ESP.getCpuFreqMHz()); shell.printfln(F(" Free heap: %lu bytes"), (uint32_t)ESP.getFreeHeap()); - shell.printfln(F(" FS used/total: %lu/%lu (bytes)"), LittleFS.usedBytes(), LittleFS.totalBytes()); + shell.printfln(F(" FS used/total: %lu/%lu (bytes)"), LittleFS.usedBytes(), FStotal()); shell.println(); shell.println("Network:"); diff --git a/src/system.h b/src/system.h index c8a90ba24..e0a0340b8 100644 --- a/src/system.h +++ b/src/system.h @@ -220,6 +220,10 @@ class System { void wifi_reconnect(); void show_users(uuid::console::Shell & shell); + uint32_t FStotal() { + return fstotal_; + } + private: static uuid::log::Logger logger_; static bool restart_requested_; @@ -293,6 +297,9 @@ class System { int8_t eth_power_; uint8_t eth_phy_addr_; uint8_t eth_clock_mode_; + + uint32_t fstotal_; + }; } // namespace emsesp