Webpage is OK, html in memory since SPIFFS is to slow.

Moving average to be fixed
This commit is contained in:
Emanuele Trabattoni
2026-04-08 15:23:21 +02:00
parent 07eb06f67b
commit 4dc45954e9
7 changed files with 629 additions and 78 deletions

View File

@@ -8,14 +8,15 @@
#include <string>
#include <fstream>
#include <filesystem>
#include <ArduinoJson.h>
// Project Includes
#include "isr.h"
#include "psvector.h"
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)
const bool SAVE_HISTORY_TO_SPIFFS = false; // 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
{
@@ -26,23 +27,40 @@ struct dataSaveParams
class SPIFFSGuard
{
public:
SPIFFSGuard() {
if (!SPIFFS.begin(true)) {
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");
LOG_INFO("SPIFFS mounted successfully");
}
~SPIFFSGuard() {
~SPIFFSGuard()
{
SPIFFS.end();
LOG_DEBUG("SPIFFS unmounted successfully");
LOG_INFO("SPIFFS unmounted successfully");
}
};
class ignitionBoxStatusAverage
{
private:
ignitionBoxStatus m_last;
uint32_t m_count = 0;
uint32_t m_max_count = 100; // number of samples to average before resetting
bool m_data_valid = false; // flag to indicate if the average data is valid (i.e. at least one sample has been added)
public:
ignitionBoxStatusAverage() = default;
ignitionBoxStatusAverage(const uint32_t max_count) : m_max_count(max_count) {}
void reset();
void update(const ignitionBoxStatus &new_status);
const bool get(ignitionBoxStatus &status) const;
const ArduinoJson::JsonDocument toJson() const;
};
// Task and function declarations
void saveHistoryTask(void *pvParameters);
void save_history(const PSRAMVector<ignitionBoxStatus> &history, const std::filesystem::path& file_path);
void save_history(const PSRAMVector<ignitionBoxStatus> &history, const std::filesystem::path &file_path);