Save History Sync on flash, still some issues in deleting previous file

This commit is contained in:
Emanuele Trabattoni
2026-04-08 10:27:18 +02:00
parent 481f12f526
commit 07eb06f67b
5 changed files with 59 additions and 42 deletions

View File

@@ -1,4 +1,5 @@
#pragma once
#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO
// System Includes
#include <Arduino.h>
@@ -14,6 +15,7 @@
const uint32_t max_history = 256;
const bool SAVE_HISTORY_TO_SPIFFS = true; // Set to true to enable saving history to SPIFFS, false to disable
static bool first_save = true; // flag to indicate if this is the first save (to write header)
struct dataSaveParams
{
@@ -21,18 +23,26 @@ struct dataSaveParams
const std::filesystem::path file_path;
};
class SPIFFSGuard
{
public:
SPIFFSGuard() {
if (!SPIFFS.begin(true)) {
LOG_ERROR("Failed to mount SPIFFS");
LOG_ERROR("5 seconds to restart...");
vTaskDelay(pdMS_TO_TICKS(5000));
esp_restart();
}
LOG_DEBUG("SPIFFS mounted successfully");
}
~SPIFFSGuard() {
SPIFFS.end();
LOG_DEBUG("SPIFFS unmounted successfully");
}
};
// Task and function declarations
void saveHistoryTask(void *pvParameters);
void save_history(const PSRAMVector<ignitionBoxStatus> &history, const std::filesystem::path& file_path);
static void saveHistoryTask(void *pvParameters)
{
const auto *params = static_cast<dataSaveParams *>(pvParameters);
const auto &history = *params->history;
const auto &file_path = params->file_path;
if (!params) {
LOG_ERROR("Invalid parameters for saveHistoryTask");
return;
}
LOG_INFO("Starting saving: ", file_path.c_str());
save_history(history, file_path);
//vTaskDelete(NULL);
}