Modified Task display to order based on task number or arbitraruy function

This commit is contained in:
2026-04-10 23:33:22 +02:00
parent 246ba7eeb2
commit eaeb515074
5 changed files with 103 additions and 28 deletions

View File

@@ -15,10 +15,6 @@
#include <webserver.h>
#include <ui.h>
// FreeRTOS directives
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
// Defines to enable channel B
#define CH_B_ENABLE
#define TEST
@@ -76,6 +72,7 @@ void setup()
initSparkPinInputs();
}
////////////////////// MAIN LOOP //////////////////////
void loop()
{
// global variables
@@ -223,12 +220,12 @@ void loop()
LOG_DEBUG("Real Time Tasks A & B initialized");
////////////////////// MAIN LOOP //////////////////////
bool partial_save = false; // flag to indicate if a partial save has been done after a timeout
auto last_data = millis();
auto last_info = millis();
uint32_t counter_a = 0;
uint32_t counter_b = 0;
uint32_t wait_count = 0;
ignitionBoxStatus ign_info_A;
@@ -240,12 +237,13 @@ void loop()
LITTLEFSGuard fsGuard;
WebPage webPage(80, LittleFS); // Initialize webserver and Websocket
while (running)
//////////////// INNER LOOP /////////////////////
while (running)
{
auto dataA = pdFALSE;
auto dataB = pdFALSE;
dataA = xQueueReceive(rt_taskA_queue, &ign_info_A, pdMS_TO_TICKS(10));
dataA = xQueueReceive(rt_taskA_queue, &ign_info_A, 0);
if (counter_a >= active_history_A->size()) // not concurrent with write task
{
counter_a = 0;
@@ -255,7 +253,7 @@ void loop()
}
#ifdef CH_B_ENABLE
dataB = xQueueReceive(rt_taskB_queue, &ign_info_B, pdMS_TO_TICKS(10));
dataB = xQueueReceive(rt_taskB_queue, &ign_info_B, 0);
if (counter_b >= active_history_B->size()) // not concurrent with write task
{
counter_b = 0;
@@ -274,7 +272,7 @@ void loop()
{
(*active_history_A)[counter_a++ % active_history_A->size()] = ign_info_A;
ign_info_avg_A.update(ign_info_A); // update moving average with latest ignition status
Serial.printf("Data Received A: %d/%d\n\r", counter_a, (*active_history_A).size());
// Serial.printf("Data Received A: %d/%d\n\r", counter_a, (*active_history_A).size());
if (counter_a % filter_k == 0) // send data every 10 samples
{
ArduinoJson::JsonDocument wsData;
@@ -288,7 +286,7 @@ void loop()
{
(*active_history_B)[counter_b++ % active_history_B->size()] = ign_info_B;
ign_info_avg_B.update(ign_info_B); // update moving average with latest ignition status
Serial.printf("Data Received B: %d/%d\n\r", counter_b, (*active_history_B).size());
// Serial.printf("Data Received B: %d/%d\n\r", counter_b, (*active_history_B).size());
if (counter_b % filter_k == 0) // send data every 10 samples
{
ArduinoJson::JsonDocument wsData;
@@ -298,7 +296,7 @@ void loop()
}
}
#endif
if (dataA == pdFALSE && dataB == pdFALSE && millis() - last_data > 2000)
if (dataA == pdFALSE && dataB == pdFALSE && (millis() - last_data) > 2000)
{
if (!partial_save && counter_a > 0) // if timeout occurs but we have unsaved data, save it before next timeout
{
@@ -316,16 +314,23 @@ void loop()
partial_save = true;
first_save = true;
}
Serial.printf("[%d] Waiting for data...\r", wait_count++);
delay(500);
//Serial.printf("[%d] Waiting for data...\r", wait_count++);
delay(100);
}
}
if ((millis() - last_info) > 1000)
{
clearScreen();
Serial.println();
printRunningTasksMod(Serial);
last_info = millis();
}
} //////////////// INNER LOOP /////////////////////
if (trigA_TaskHandle)
vTaskDelete(trigA_TaskHandle);
#ifdef CH_B_ENABLE
if (trigB_TaskHandle)
vTaskDelete(trigB_TaskHandle);
#endif
////////////////////// MAIN LOOP //////////////////////
}
} ////////////////////// MAIN LOOP //////////////////////