LittleFS mount OK, updated interface, upload to littlefs from browser
This commit is contained in:
@@ -1,7 +1,26 @@
|
||||
#include "datasave.h"
|
||||
#include <math.h>
|
||||
|
||||
static const size_t min_free = 1024 * 1024; // minimum free space in SPIFFS to allow saving history (1MB)
|
||||
static const size_t min_free = 1024 * 1024; // minimum free space in LittleFS to allow saving history (1MB)
|
||||
|
||||
LITTLEFSGuard::LITTLEFSGuard()
|
||||
{
|
||||
if (!LittleFS.begin(true, "/littlefs", 10, "littlefs"))
|
||||
{
|
||||
LOG_ERROR("Failed to mount LittleFS");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO("LittleFS mounted successfully");
|
||||
LOG_INFO("LittleFS Free KBytes:", (LittleFS.totalBytes() - LittleFS.usedBytes()) /1024);
|
||||
}
|
||||
}
|
||||
|
||||
LITTLEFSGuard::~LITTLEFSGuard()
|
||||
{
|
||||
LittleFS.end();
|
||||
LOG_INFO("LittleFS unmounted successfully");
|
||||
}
|
||||
|
||||
void ignitionBoxStatusAverage::filter(int32_t &old, const int32_t value, const uint32_t k)
|
||||
{
|
||||
@@ -42,18 +61,18 @@ void ignitionBoxStatusAverage::update(const ignitionBoxStatus &new_status)
|
||||
filter(m_last.coils12.peak_p_out, new_status.coils12.peak_p_out, m_max_count); // incremental average calculation
|
||||
filter(m_last.coils12.peak_n_out, new_status.coils12.peak_n_out, m_max_count); // incremental average calculation
|
||||
|
||||
m_last.coils34.n_events = new_status.coils34.n_events; // sum events instead of averaging
|
||||
m_last.coils34.n_missed_firing = new_status.coils34.n_missed_firing; // sum missed firings instead of averaging
|
||||
m_last.coils34.spark_status = new_status.coils34.spark_status; // take latest spark status
|
||||
m_last.coils34.sstart_status = new_status.coils34.sstart_status; // take latest soft start status
|
||||
filter(m_last.coils34.spark_delay, new_status.coils34.spark_delay, m_max_count); // incremental average calculation
|
||||
m_last.coils34.n_events = new_status.coils34.n_events; // sum events instead of averaging
|
||||
m_last.coils34.n_missed_firing = new_status.coils34.n_missed_firing; // sum missed firings instead of averaging
|
||||
m_last.coils34.spark_status = new_status.coils34.spark_status; // take latest spark status
|
||||
m_last.coils34.sstart_status = new_status.coils34.sstart_status; // take latest soft start status
|
||||
filter(m_last.coils34.spark_delay, new_status.coils34.spark_delay, m_max_count); // incremental average calculation
|
||||
filter(m_last.coils34.peak_p_in, new_status.coils34.peak_p_in, m_max_count); // incremental average calculation
|
||||
filter(m_last.coils34.peak_n_in, new_status.coils34.peak_n_in, m_max_count); // incremental average calculation
|
||||
filter(m_last.coils34.peak_p_out, new_status.coils34.peak_p_out, m_max_count); // incremental average calculation
|
||||
filter(m_last.coils34.peak_n_out, new_status.coils34.peak_n_out, m_max_count); // incremental average calculation
|
||||
filter(m_last.eng_rpm, new_status.eng_rpm, m_max_count); // incremental average calculation // incremental average calculation
|
||||
filter(m_last.adc_read_time, m_last.adc_read_time, m_max_count); // incremental average calculation
|
||||
m_last.n_queue_errors = new_status.n_queue_errors; // take last of queue errors since it's a cumulative count of errors in the queue, not an average value
|
||||
filter(m_last.eng_rpm, new_status.eng_rpm, m_max_count); // incremental average calculation // incremental average calculation
|
||||
filter(m_last.adc_read_time, m_last.adc_read_time, m_max_count); // incremental average calculation
|
||||
m_last.n_queue_errors = new_status.n_queue_errors; // take last of queue errors since it's a cumulative count of errors in the queue, not an average value
|
||||
|
||||
if (m_count >= m_max_count)
|
||||
{
|
||||
@@ -126,7 +145,8 @@ void save_history(const PSRAMVector<ignitionBoxStatus> &history, const std::file
|
||||
// Initialize SPIFFS
|
||||
if (!SAVE_HISTORY_TO_LITTLEFS)
|
||||
return;
|
||||
// auto spiffs_guard = LITTLEFSGuard(); // use RAII guard to ensure SPIFFS is properly mounted and unmounted
|
||||
|
||||
auto littlefs_guard = LITTLEFSGuard(); // use RAII guard to ensure LittleFS is properly mounted and unmounted
|
||||
|
||||
if (LittleFS.totalBytes() - LittleFS.usedBytes() < min_free) // check if at least 1MB is free for saving history
|
||||
{
|
||||
@@ -142,7 +162,7 @@ void save_history(const PSRAMVector<ignitionBoxStatus> &history, const std::file
|
||||
if (first_save && LittleFS.exists(file_path.c_str()))
|
||||
{
|
||||
first_save = false;
|
||||
save_flags |= std::ios::trunc; // overwrite existing file
|
||||
save_flags |= std::ios::trunc; // overwrite existing file
|
||||
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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user