changed partition to littlefs, not working yet

This commit is contained in:
Emanuele Trabattoni
2026-04-08 17:10:30 +02:00
parent 12e1e8e7a4
commit 97bce90ba6
5 changed files with 30 additions and 23 deletions

View File

@@ -126,30 +126,30 @@ void save_history(const PSRAMVector<ignitionBoxStatus> &history, const std::file
// Initialize SPIFFS
if (!SAVE_HISTORY_TO_SPIFFS)
return;
// auto spiffs_guard = SPIFFSGuard(); // use RAII guard to ensure SPIFFS is properly mounted and unmounted
// auto spiffs_guard = LITTLEFSGuard(); // use RAII guard to ensure SPIFFS is properly mounted and unmounted
if (SPIFFS.totalBytes() - SPIFFS.usedBytes() < min_free) // check if at least 1MB is free for saving history
if (LittleFS.totalBytes() - LittleFS.usedBytes() < min_free) // check if at least 1MB is free for saving history
{
LOG_ERROR("Not enough space in SPIFFS to save history");
return;
}
std::filesystem::path file_path = file_name;
if (file_name.root_path() != "/spiffs")
file_path = std::filesystem::path("/spiffs") / file_name;
if (file_name.root_path() != "/littlefs")
file_path = std::filesystem::path("/littlefs") / file_name;
auto save_flags = std::ios::out;
if (first_save && SPIFFS.exists(file_path.c_str()))
if (first_save && LittleFS.exists(file_path.c_str()))
{
first_save = false;
save_flags |= std::ios::trunc; // overwrite existing file
SPIFFS.remove(file_path.c_str()); // ensure file is removed before saving to avoid issues with appending to existing file in SPIFFS
LOG_INFO("Saving history to SPIFFS, new file:", file_path.c_str());
LittleFS.remove(file_path.c_str()); // ensure file is removed before saving to avoid issues with appending to existing file in SPIFFS
LOG_INFO("Saving history to LittleFS, new file:", file_path.c_str());
}
else
{
save_flags |= std::ios::app; // append to new file
LOG_INFO("Saving history to SPIFFS, appending to existing file:", file_path.c_str());
LOG_INFO("Saving history to LittleFS, appending to existing file:", file_path.c_str());
}
std::ofstream ofs(file_path, save_flags);
@@ -197,5 +197,5 @@ void save_history(const PSRAMVector<ignitionBoxStatus> &history, const std::file
}
ofs.close();
LOG_INFO("Ignition A history saved to SPIFFS, records written: ", history.size());
LOG_INFO("Ignition A history saved to LittleFS, records written: ", history.size());
}