refactor variables and LittleFS mount
This commit is contained in:
Binary file not shown.
@@ -124,7 +124,7 @@ void saveHistoryTask(void *pvParameters)
|
||||
void save_history(const PSRAMVector<ignitionBoxStatus> &history, const std::filesystem::path &file_name)
|
||||
{
|
||||
// Initialize SPIFFS
|
||||
if (!SAVE_HISTORY_TO_SPIFFS)
|
||||
if (!SAVE_HISTORY_TO_LITTLEFS)
|
||||
return;
|
||||
// auto spiffs_guard = LITTLEFSGuard(); // use RAII guard to ensure SPIFFS is properly mounted and unmounted
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "psvector.h"
|
||||
|
||||
const uint32_t max_history = 256;
|
||||
const bool SAVE_HISTORY_TO_SPIFFS = false; // Set to true to enable saving history to SPIFFS, false to disable
|
||||
const bool SAVE_HISTORY_TO_LITTLEFS = 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
|
||||
|
||||
@@ -101,14 +101,14 @@ void loop()
|
||||
auto *writable_history = &ignA_history_1;
|
||||
|
||||
// Resources Initialization
|
||||
static Devices dev;
|
||||
Devices dev;
|
||||
// Task handle
|
||||
static TaskHandle_t trigA_TaskHandle = NULL;
|
||||
static TaskHandle_t trigB_TaskHandle = NULL;
|
||||
TaskHandle_t trigA_TaskHandle = NULL;
|
||||
TaskHandle_t trigB_TaskHandle = NULL;
|
||||
// Data Queue for real time task to main loop communication
|
||||
static QueueHandle_t rt_taskA_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
|
||||
static QueueHandle_t rt_taskB_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
|
||||
static rtTaskParams taskA_params{
|
||||
QueueHandle_t rt_taskA_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
|
||||
QueueHandle_t rt_taskB_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
|
||||
rtTaskParams taskA_params{
|
||||
.rt_running = true,
|
||||
.dev = &dev,
|
||||
.rt_handle_ptr = &trigA_TaskHandle,
|
||||
@@ -219,22 +219,18 @@ void loop()
|
||||
uint32_t counter = 0;
|
||||
uint32_t wait_count = 0;
|
||||
ignitionBoxStatus ign_info;
|
||||
int64_t last = esp_timer_get_time();
|
||||
uint32_t missed_firings12 = 0;
|
||||
uint32_t missed_firings34 = 0;
|
||||
ignitionBoxStatusAverage ignA_avg(filter_k); // moving average calculator for ignition box A with a window of 100 samples
|
||||
ignitionBoxStatusAverage ign_info_avg(filter_k);
|
||||
|
||||
// Initialize Web page
|
||||
AsyncWebServer server(80);
|
||||
AsyncWebSocket ws("/ws");
|
||||
ws.onEvent(onWsEvent);
|
||||
server.addHandler(&ws);
|
||||
|
||||
auto spiffs_guard = LITTLEFSGuard(); // use RAII guard to ensure SPIFFS is properly mounted and unmounted
|
||||
server.serveStatic("/", LittleFS, "/").setDefaultFile("index.html");
|
||||
server.begin();
|
||||
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||
{ request->send(200, "text/html", htmlTest.c_str()); });
|
||||
{ request->send(200, "text/plain", "OK"); });
|
||||
|
||||
while (running)
|
||||
{
|
||||
@@ -256,14 +252,14 @@ void loop()
|
||||
// printInfo(ign_info);
|
||||
auto &hist = *active_history;
|
||||
hist[counter++ % active_history->size()] = ign_info;
|
||||
ignA_avg.update(ign_info); // update moving average with latest ignition status
|
||||
ign_info_avg.update(ign_info); // update moving average with latest ignition status
|
||||
Serial.print("Data Received: " + String(counter) + "/" + String(hist.size()) + '\r');
|
||||
|
||||
if (ws.count() > 0 && counter % 10 == 0) // send data every 10 samples
|
||||
{
|
||||
Serial.println();
|
||||
LOG_INFO("Sending average ignition status to websocket clients...");
|
||||
auto msg = ignA_avg.toJson().as<String>();
|
||||
auto msg = ign_info_avg.toJson().as<String>();
|
||||
ws.textAll(msg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user