Task A+B concurrency <check ok without ADC
This commit is contained in:
3
RotaxMonitor/.vscode/extensions.json
vendored
3
RotaxMonitor/.vscode/extensions.json
vendored
@@ -1,8 +1,7 @@
|
|||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"Jason2866.esp-decoder",
|
"Jason2866.esp-decoder",
|
||||||
"pioarduino.pioarduino-ide",
|
"pioarduino.pioarduino-ide"
|
||||||
"platformio.platformio-ide"
|
|
||||||
],
|
],
|
||||||
"unwantedRecommendations": [
|
"unwantedRecommendations": [
|
||||||
"ms-vscode.cpptools-extension-pack"
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
|||||||
@@ -26,14 +26,14 @@
|
|||||||
<div class="box">
|
<div class="box">
|
||||||
<h2>Box_A</h2>
|
<h2>Box_A</h2>
|
||||||
<div class="box-data">
|
<div class="box-data">
|
||||||
<p><strong>Timestamp:</strong> <span id="timestamp">-</span></p>
|
<p><strong>Timestamp:</strong> <span id="a_timestamp">-</span></p>
|
||||||
<p><strong>Data Valid:</strong> <span id="datavalid">-</span></p>
|
<p><strong>Data Valid:</strong> <span id="a_datavalid">-</span></p>
|
||||||
<p><strong>Generator voltage:</strong> <span id="volts_gen">-</span></p>
|
<p><strong>Generator voltage:</strong> <span id="a_volts_gen">-</span></p>
|
||||||
<p><strong>ADC read time:</strong> <span id="adc_read_time">-</span></p>
|
<p><strong>ADC read time:</strong> <span id="a_adc_read_time">-</span></p>
|
||||||
<p><strong>Queue errors:</strong> <span id="n_queue_errors">-</span></p>
|
<p><strong>Queue errors:</strong> <span id="a_n_queue_errors">-</span></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="rpm-highlight">
|
<div class="rpm-highlight">
|
||||||
<strong>Engine RPM:</strong> <span id="eng_rpm">-</span>
|
<strong>Engine RPM:</strong> <span id="a_eng_rpm">-</span>
|
||||||
</div>
|
</div>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
@@ -46,53 +46,53 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Spark delay</td>
|
<td>Spark delay</td>
|
||||||
<td id="coils12_spark_delay">-</td>
|
<td id="a_coils12_spark_delay">-</td>
|
||||||
<td id="coils34_spark_delay">-</td>
|
<td id="a_coils34_spark_delay">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Spark status</td>
|
<td>Spark status</td>
|
||||||
<td id="coils12_spark_status">-</td>
|
<td id="a_coils12_spark_status">-</td>
|
||||||
<td id="coils34_spark_status">-</td>
|
<td id="a_coils34_spark_status">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Soft start status</td>
|
<td>Soft start status</td>
|
||||||
<td id="coils12_sstart_status">-</td>
|
<td id="a_coils12_sstart_status">-</td>
|
||||||
<td id="coils34_sstart_status">-</td>
|
<td id="a_coils34_sstart_status">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Peak P in</td>
|
<td>Peak P in</td>
|
||||||
<td id="coils12_peak_p_in">-</td>
|
<td id="a_coils12_peak_p_in">-</td>
|
||||||
<td id="coils34_peak_p_in">-</td>
|
<td id="a_coils34_peak_p_in">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Peak N in</td>
|
<td>Peak N in</td>
|
||||||
<td id="coils12_peak_n_in">-</td>
|
<td id="a_coils12_peak_n_in">-</td>
|
||||||
<td id="coils34_peak_n_in">-</td>
|
<td id="a_coils34_peak_n_in">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Peak P out</td>
|
<td>Peak P out</td>
|
||||||
<td id="coils12_peak_p_out">-</td>
|
<td id="a_coils12_peak_p_out">-</td>
|
||||||
<td id="coils34_peak_p_out">-</td>
|
<td id="a_coils34_peak_p_out">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Peak N out</td>
|
<td>Peak N out</td>
|
||||||
<td id="coils12_peak_n_out">-</td>
|
<td id="a_coils12_peak_n_out">-</td>
|
||||||
<td id="coils34_peak_n_out">-</td>
|
<td id="a_coils34_peak_n_out">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Level spark</td>
|
<td>Level spark</td>
|
||||||
<td id="coils12_level_spark">-</td>
|
<td id="a_coils12_level_spark">-</td>
|
||||||
<td id="coils34_level_spark">-</td>
|
<td id="a_coils34_level_spark">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Spark Events</td>
|
<td>Spark Events</td>
|
||||||
<td id="coils12_n_events">-</td>
|
<td id="a_coils12_n_events">-</td>
|
||||||
<td id="coils34_n_events">-</td>
|
<td id="a_coils34_n_events">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Missed Events</td>
|
<td>Missed Events</td>
|
||||||
<td id="coils12_n_missed_firing">-</td>
|
<td id="a_coils12_n_missed_firing">-</td>
|
||||||
<td id="coils34_n_missed_firing">-</td>
|
<td id="a_coils34_n_missed_firing">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -49,36 +49,36 @@ function connectWS() {
|
|||||||
// Update Box_A
|
// Update Box_A
|
||||||
if (data.box_a) {
|
if (data.box_a) {
|
||||||
const boxA = data.box_a;
|
const boxA = data.box_a;
|
||||||
document.getElementById("datavalid").textContent = boxA.datavalid ?? "-";
|
document.getElementById("a_datavalid").textContent = boxA.datavalid ?? "-";
|
||||||
document.getElementById("timestamp").textContent = boxA.timestamp ?? "-";
|
document.getElementById("a_timestamp").textContent = boxA.timestamp ?? "-";
|
||||||
document.getElementById("volts_gen").textContent = boxA.volts_gen ?? "-";
|
document.getElementById("a_volts_gen").textContent = boxA.volts_gen ?? "-";
|
||||||
document.getElementById("eng_rpm").textContent = boxA.eng_rpm ?? "-";
|
document.getElementById("a_eng_rpm").textContent = boxA.eng_rpm ?? "-";
|
||||||
document.getElementById("adc_read_time").textContent = boxA.adc_read_time ?? "-";
|
document.getElementById("a_adc_read_time").textContent = boxA.adc_read_time ?? "-";
|
||||||
document.getElementById("n_queue_errors").textContent = boxA.n_queue_errors ?? "-";
|
document.getElementById("a_n_queue_errors").textContent = boxA.n_queue_errors ?? "-";
|
||||||
|
|
||||||
const coils12A = boxA.coils12 || {};
|
const coils12A = boxA.coils12 || {};
|
||||||
const coils34A = boxA.coils34 || {};
|
const coils34A = boxA.coils34 || {};
|
||||||
|
|
||||||
document.getElementById("coils12_spark_delay").textContent = coils12A.spark_delay ?? "-";
|
document.getElementById("a_coils12_spark_delay").textContent = coils12A.spark_delay ?? "-";
|
||||||
document.getElementById("coils34_spark_delay").textContent = coils34A.spark_delay ?? "-";
|
document.getElementById("a_coils34_spark_delay").textContent = coils34A.spark_delay ?? "-";
|
||||||
document.getElementById("coils12_spark_status").textContent = coils12A.spark_status ?? "-";
|
document.getElementById("a_coils12_spark_status").textContent = coils12A.spark_status ?? "-";
|
||||||
document.getElementById("coils34_spark_status").textContent = coils34A.spark_status ?? "-";
|
document.getElementById("a_coils34_spark_status").textContent = coils34A.spark_status ?? "-";
|
||||||
document.getElementById("coils12_sstart_status").textContent = coils12A.sstart_status ?? "-";
|
document.getElementById("a_coils12_sstart_status").textContent = coils12A.sstart_status ?? "-";
|
||||||
document.getElementById("coils34_sstart_status").textContent = coils34A.sstart_status ?? "-";
|
document.getElementById("a_coils34_sstart_status").textContent = coils34A.sstart_status ?? "-";
|
||||||
document.getElementById("coils12_peak_p_in").textContent = coils12A.peak_p_in ?? "-";
|
document.getElementById("a_coils12_peak_p_in").textContent = coils12A.peak_p_in ?? "-";
|
||||||
document.getElementById("coils34_peak_p_in").textContent = coils34A.peak_p_in ?? "-";
|
document.getElementById("a_coils34_peak_p_in").textContent = coils34A.peak_p_in ?? "-";
|
||||||
document.getElementById("coils12_peak_n_in").textContent = coils12A.peak_n_in ?? "-";
|
document.getElementById("a_coils12_peak_n_in").textContent = coils12A.peak_n_in ?? "-";
|
||||||
document.getElementById("coils34_peak_n_in").textContent = coils34A.peak_n_in ?? "-";
|
document.getElementById("a_coils34_peak_n_in").textContent = coils34A.peak_n_in ?? "-";
|
||||||
document.getElementById("coils12_peak_p_out").textContent = coils12A.peak_p_out ?? "-";
|
document.getElementById("a_coils12_peak_p_out").textContent = coils12A.peak_p_out ?? "-";
|
||||||
document.getElementById("coils34_peak_p_out").textContent = coils34A.peak_p_out ?? "-";
|
document.getElementById("a_coils34_peak_p_out").textContent = coils34A.peak_p_out ?? "-";
|
||||||
document.getElementById("coils12_peak_n_out").textContent = coils12A.peak_n_out ?? "-";
|
document.getElementById("a_coils12_peak_n_out").textContent = coils12A.peak_n_out ?? "-";
|
||||||
document.getElementById("coils34_peak_n_out").textContent = coils34A.peak_n_out ?? "-";
|
document.getElementById("a_coils34_peak_n_out").textContent = coils34A.peak_n_out ?? "-";
|
||||||
document.getElementById("coils12_level_spark").textContent = coils12A.level_spark ?? "-";
|
document.getElementById("a_coils12_level_spark").textContent = coils12A.level_spark ?? "-";
|
||||||
document.getElementById("coils34_level_spark").textContent = coils34A.level_spark ?? "-";
|
document.getElementById("a_coils34_level_spark").textContent = coils34A.level_spark ?? "-";
|
||||||
document.getElementById("coils12_n_events").textContent = coils12A.n_events ?? "-";
|
document.getElementById("a_coils12_n_events").textContent = coils12A.n_events ?? "-";
|
||||||
document.getElementById("coils34_n_events").textContent = coils34A.n_events ?? "-";
|
document.getElementById("a_coils34_n_events").textContent = coils34A.n_events ?? "-";
|
||||||
document.getElementById("coils12_n_missed_firing").textContent = coils12A.n_missed_firing ?? "-";
|
document.getElementById("a_coils12_n_missed_firing").textContent = coils12A.n_missed_firing ?? "-";
|
||||||
document.getElementById("coils34_n_missed_firing").textContent = coils34A.n_missed_firing ?? "-";
|
document.getElementById("a_coils34_n_missed_firing").textContent = coils34A.n_missed_firing ?? "-";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Box_B
|
// Update Box_B
|
||||||
|
|||||||
@@ -21,17 +21,15 @@ lib_deps =
|
|||||||
me-no-dev/AsyncTCP@^3.3.2
|
me-no-dev/AsyncTCP@^3.3.2
|
||||||
me-no-dev/ESPAsyncWebServer@^3.6.0
|
me-no-dev/ESPAsyncWebServer@^3.6.0
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
upload_port = COM8
|
upload_port = /dev/ttyACM1
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_port = COM4
|
monitor_port = /dev/ttyACM0
|
||||||
monitor_speed = 921600
|
monitor_speed = 921600
|
||||||
build_type = release
|
build_type = release
|
||||||
build_flags =
|
build_flags =
|
||||||
-DCORE_DEBUG_LEVEL=4
|
-DCORE_DEBUG_LEVEL=4
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=0
|
-DARDUINO_USB_CDC_ON_BOOT=0
|
||||||
-DARDUINO_USB_MODE=0
|
-DARDUINO_USB_MODE=0
|
||||||
-DCONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=1
|
|
||||||
-DCONFIG_FREERTOS_USE_TRACE_FACILITY=1
|
|
||||||
-DCONFIG_ASYNC_TCP_MAX_ACK_TIME=5000
|
-DCONFIG_ASYNC_TCP_MAX_ACK_TIME=5000
|
||||||
-DCONFIG_ASYNC_TCP_PRIORITY=20
|
-DCONFIG_ASYNC_TCP_PRIORITY=20
|
||||||
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
|
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
|
||||||
@@ -48,9 +46,9 @@ framework = ${env:esp32-s3-devkitc1-n16r8.framework}
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
${env:esp32-s3-devkitc1-n16r8.lib_deps}
|
${env:esp32-s3-devkitc1-n16r8.lib_deps}
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
upload_port = COM8
|
upload_port = /dev/ttyACM1
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_port = COM4
|
monitor_port = /dev/ttyACM0
|
||||||
monitor_speed = 921600
|
monitor_speed = 921600
|
||||||
debug_tool = esp-builtin
|
debug_tool = esp-builtin
|
||||||
debug_speed = 15000
|
debug_speed = 15000
|
||||||
@@ -62,8 +60,6 @@ build_flags =
|
|||||||
-DCORE_DEBUG_LEVEL=3
|
-DCORE_DEBUG_LEVEL=3
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=0
|
-DARDUINO_USB_CDC_ON_BOOT=0
|
||||||
-DARDUINO_USB_MODE=0
|
-DARDUINO_USB_MODE=0
|
||||||
-DCONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=1
|
|
||||||
-DCONFIG_FREERTOS_USE_TRACE_FACILITY=1
|
|
||||||
-DCONFIG_ASYNC_TCP_MAX_ACK_TIME=5000
|
-DCONFIG_ASYNC_TCP_MAX_ACK_TIME=5000
|
||||||
-DCONFIG_ASYNC_TCP_PRIORITY=20
|
-DCONFIG_ASYNC_TCP_PRIORITY=20
|
||||||
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
|
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
|
|
||||||
// Defines to enable channel B
|
// Defines to enable channel B
|
||||||
// #define CH_B_ENABLE
|
#define CH_B_ENABLE
|
||||||
#define TEST
|
#define TEST
|
||||||
|
|
||||||
// Debug Defines
|
// Debug Defines
|
||||||
@@ -99,15 +99,17 @@ void loop()
|
|||||||
Devices dev;
|
Devices dev;
|
||||||
// Task handle
|
// Task handle
|
||||||
TaskHandle_t trigA_TaskHandle = NULL;
|
TaskHandle_t trigA_TaskHandle = NULL;
|
||||||
|
TaskHandle_t trigB_TaskHandle = NULL;
|
||||||
// Data Queue for real time task to main loop communication
|
// Data Queue for real time task to main loop communication
|
||||||
QueueHandle_t rt_taskA_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
|
QueueHandle_t rt_taskA_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
|
||||||
|
QueueHandle_t rt_taskB_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
|
||||||
|
|
||||||
rtTaskParams taskA_params{
|
rtTaskParams taskA_params{
|
||||||
.rt_running = true,
|
.rt_running = true,
|
||||||
.dev = &dev,
|
.dev = &dev,
|
||||||
.rt_handle_ptr = &trigA_TaskHandle,
|
|
||||||
.rt_queue = rt_taskA_queue,
|
.rt_queue = rt_taskA_queue,
|
||||||
.rt_int = rtTaskInterrupts{
|
.rt_int = rtTaskInterrupts{
|
||||||
.isr_ptr = trig_isr_A,
|
.isr_ptr = &trig_isr_A,
|
||||||
.trig_pin_12p = TRIG_PIN_A12P,
|
.trig_pin_12p = TRIG_PIN_A12P,
|
||||||
.trig_pin_12n = TRIG_PIN_A12N,
|
.trig_pin_12n = TRIG_PIN_A12N,
|
||||||
.trig_pin_34p = TRIG_PIN_A34P,
|
.trig_pin_34p = TRIG_PIN_A34P,
|
||||||
@@ -117,15 +119,12 @@ void loop()
|
|||||||
.rt_resets = rtTaskResets{.rst_io_peak = RST_EXT_PEAK_DETECT_A, .rst_io_sh = RST_EXT_SAMPLE_HOLD_A}};
|
.rt_resets = rtTaskResets{.rst_io_peak = RST_EXT_PEAK_DETECT_A, .rst_io_sh = RST_EXT_SAMPLE_HOLD_A}};
|
||||||
|
|
||||||
#ifdef CH_B_ENABLE
|
#ifdef CH_B_ENABLE
|
||||||
TaskHandle_t trigB_TaskHandle = NULL;
|
|
||||||
QueueHandle_t rt_taskB_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
|
|
||||||
rtTaskParams taskB_params{
|
rtTaskParams taskB_params{
|
||||||
.rt_running = true,
|
.rt_running = true,
|
||||||
.dev = &dev,
|
.dev = &dev,
|
||||||
.rt_handle_ptr = &trigB_TaskHandle,
|
|
||||||
.rt_queue = rt_taskB_queue,
|
.rt_queue = rt_taskB_queue,
|
||||||
.rt_int = rtTaskInterrupts{
|
.rt_int = rtTaskInterrupts{
|
||||||
.isr_ptr = trig_isr_B,
|
.isr_ptr = &trig_isr_B,
|
||||||
.trig_pin_12p = TRIG_PIN_B12P,
|
.trig_pin_12p = TRIG_PIN_B12P,
|
||||||
.trig_pin_12n = TRIG_PIN_B12N,
|
.trig_pin_12n = TRIG_PIN_B12N,
|
||||||
.trig_pin_34p = TRIG_PIN_B34P,
|
.trig_pin_34p = TRIG_PIN_B34P,
|
||||||
@@ -135,7 +134,7 @@ void loop()
|
|||||||
.rt_resets = rtTaskResets{.rst_io_peak = RST_EXT_PEAK_DETECT_B, .rst_io_sh = RST_EXT_SAMPLE_HOLD_B}};
|
.rt_resets = rtTaskResets{.rst_io_peak = RST_EXT_PEAK_DETECT_B, .rst_io_sh = RST_EXT_SAMPLE_HOLD_B}};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!rt_taskA_queue /*|| !rt_taskB_queue*/)
|
if (!rt_taskA_queue || !rt_taskB_queue)
|
||||||
{
|
{
|
||||||
LOG_ERROR("Unable To Create task queues");
|
LOG_ERROR("Unable To Create task queues");
|
||||||
LOG_ERROR("5 seconds to restart...");
|
LOG_ERROR("5 seconds to restart...");
|
||||||
@@ -210,7 +209,7 @@ void loop()
|
|||||||
(void *)&taskB_params,
|
(void *)&taskB_params,
|
||||||
RT_TASK_PRIORITY, // priorità leggermente più alta
|
RT_TASK_PRIORITY, // priorità leggermente più alta
|
||||||
&trigB_TaskHandle,
|
&trigB_TaskHandle,
|
||||||
CORE_0);
|
CORE_1);
|
||||||
delay(100); // give some time to the thread to start
|
delay(100); // give some time to the thread to start
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -226,12 +225,18 @@ void loop()
|
|||||||
|
|
||||||
////////////////////// MAIN LOOP //////////////////////
|
////////////////////// MAIN LOOP //////////////////////
|
||||||
bool partial_save = false; // flag to indicate if a partial save has been done after a timeout
|
bool partial_save = false; // flag to indicate if a partial save has been done after a timeout
|
||||||
uint32_t counter = 0;
|
auto last_data = millis();
|
||||||
|
uint32_t counter_a = 0;
|
||||||
|
uint32_t counter_b = 0;
|
||||||
|
|
||||||
uint32_t wait_count = 0;
|
uint32_t wait_count = 0;
|
||||||
|
|
||||||
ignitionBoxStatus ign_info_A;
|
ignitionBoxStatus ign_info_A;
|
||||||
ignitionBoxStatus ign_info_B;
|
ignitionBoxStatus ign_info_B;
|
||||||
|
|
||||||
ignitionBoxStatusAverage ign_info_avg_A(filter_k);
|
ignitionBoxStatusAverage ign_info_avg_A(filter_k);
|
||||||
ignitionBoxStatusAverage ign_info_avg_B(filter_k);
|
ignitionBoxStatusAverage ign_info_avg_B(filter_k);
|
||||||
|
|
||||||
LITTLEFSGuard fsGuard;
|
LITTLEFSGuard fsGuard;
|
||||||
WebPage webPage(80, LittleFS); // Initialize webserver and Websocket
|
WebPage webPage(80, LittleFS); // Initialize webserver and Websocket
|
||||||
|
|
||||||
@@ -240,66 +245,78 @@ void loop()
|
|||||||
auto dataA = pdFALSE;
|
auto dataA = pdFALSE;
|
||||||
auto dataB = pdFALSE;
|
auto dataB = pdFALSE;
|
||||||
|
|
||||||
if (counter >= active_history_A->size()) // not concurrent with write task
|
dataA = xQueueReceive(rt_taskA_queue, &ign_info_A, pdMS_TO_TICKS(10));
|
||||||
|
if (counter_a >= active_history_A->size()) // not concurrent with write task
|
||||||
{
|
{
|
||||||
counter = 0;
|
counter_a = 0;
|
||||||
partial_save = false; // reset partial save flag on new data cycle
|
partial_save = false; // reset partial save flag on new data cycle
|
||||||
swapHistory(active_history_A, writable_history_A);
|
swapHistory(active_history_A, writable_history_A);
|
||||||
save_history(*writable_history_A, "ignition_historyA.csv"); // directly call the save task function to save without delay
|
save_history(*writable_history_A, "ignition_historyA.csv"); // directly call the save task function to save without delay
|
||||||
}
|
}
|
||||||
dataA = xQueueReceive(rt_taskA_queue, &ign_info_A, pdMS_TO_TICKS(100));
|
|
||||||
#ifdef CH_B_ENABLE
|
#ifdef CH_B_ENABLE
|
||||||
if (counter >= active_history_B->size()) // not concurrent with write task
|
dataB = xQueueReceive(rt_taskB_queue, &ign_info_B, pdMS_TO_TICKS(10));
|
||||||
|
if (counter_b >= active_history_B->size()) // not concurrent with write task
|
||||||
{
|
{
|
||||||
counter = 0;
|
counter_b = 0;
|
||||||
partial_save = false; // reset partial save flag on new data cycle
|
partial_save = false; // reset partial save flag on new data cycle
|
||||||
swapHistory(active_history_B, writable_history_B);
|
swapHistory(active_history_B, writable_history_B);
|
||||||
save_history(*writable_history_B, "ignition_historyB.csv"); // directly call the save task function to save without delay
|
save_history(*writable_history_B, "ignition_historyB.csv"); // directly call the save task function to save without delay
|
||||||
}
|
}
|
||||||
dataB = xQueueReceive(rt_taskB_queue, &ign_info_B, pdMS_TO_TICKS(100));
|
|
||||||
#endif
|
#endif
|
||||||
|
// Update last data
|
||||||
if (dataA == pdTRUE || dataB == pdTRUE)
|
if (dataA == pdTRUE || dataB == pdTRUE)
|
||||||
{
|
{
|
||||||
// printInfo(ign_info);
|
last_data = millis();
|
||||||
(*active_history_A)[counter % active_history_A->size()] = ign_info_A;
|
}
|
||||||
#ifdef CH_B_ENABLE
|
|
||||||
(*active_history_B)[counter % active_history_B->size()] = ign_info_B;
|
|
||||||
#endif
|
|
||||||
ign_info_avg_A.update(ign_info_A); // update moving average with latest ignition status
|
|
||||||
ign_info_avg_B.update(ign_info_B); // update moving average with latest ignition status
|
|
||||||
|
|
||||||
Serial.printf("\033[2K Data Received A: %d/%d\r", counter, (*active_history_A).size());
|
if (dataA == pdTRUE)
|
||||||
|
{
|
||||||
if (counter % filter_k == 0) // send data every 10 samples
|
(*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());
|
||||||
|
if (counter_a % filter_k == 0) // send data every 10 samples
|
||||||
{
|
{
|
||||||
Serial.println();
|
|
||||||
LOG_DEBUG("Sending average ignition status to websocket clients...");
|
|
||||||
ArduinoJson::JsonDocument wsData;
|
ArduinoJson::JsonDocument wsData;
|
||||||
wsData["box_a"] = ign_info_avg_A.toJson();
|
wsData["box_a"] = ign_info_avg_A.toJson();
|
||||||
|
wsData["box_b"] = JsonObject();
|
||||||
|
webPage.sendWsData(wsData.as<String>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef CH_B_ENABLE
|
||||||
|
if (dataB == pdTRUE)
|
||||||
|
{
|
||||||
|
(*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());
|
||||||
|
if (counter_b % filter_k == 0) // send data every 10 samples
|
||||||
|
{
|
||||||
|
ArduinoJson::JsonDocument wsData;
|
||||||
|
wsData["box_a"] = JsonObject();
|
||||||
wsData["box_b"] = ign_info_avg_B.toJson();
|
wsData["box_b"] = ign_info_avg_B.toJson();
|
||||||
webPage.sendWsData(wsData.as<String>());
|
webPage.sendWsData(wsData.as<String>());
|
||||||
}
|
}
|
||||||
|
|
||||||
counter++;
|
|
||||||
}
|
}
|
||||||
else
|
#endif
|
||||||
|
if (dataA == pdFALSE && dataB == pdFALSE && millis() - last_data > 2000)
|
||||||
{
|
{
|
||||||
Serial.printf("[%d] Waiting for data...\r", wait_count++);
|
if (!partial_save && counter_a > 0) // if timeout occurs but we have unsaved data, save it before next timeout
|
||||||
if (!partial_save && counter > 0) // if timeout occurs but we have unsaved data, save it before next timeout
|
|
||||||
{
|
{
|
||||||
active_history_A->resize(counter); // resize active history to actual number of records received to avoid saving empty records
|
active_history_A->resize(counter_a); // resize active history to actual number of records received to avoid saving empty records
|
||||||
save_history(*active_history_A, "ignition_history_A.csv");
|
save_history(*active_history_A, "ignition_history_A.csv");
|
||||||
active_history_A->resize(max_history); // resize back to max history size for next data cycle
|
active_history_A->resize(max_history); // resize back to max history size for next data cycle
|
||||||
#ifdef CH_B_ENABLE
|
#ifdef CH_B_ENABLE
|
||||||
active_history_B->resize(counter); // resize active history to actual number of records received to avoid saving empty records
|
active_history_B->resize(counter_a); // resize active history to actual number of records received to avoid saving empty records
|
||||||
save_history(*active_history_B, "ignition_history_B.csv");
|
save_history(*active_history_B, "ignition_history_B.csv");
|
||||||
active_history_B->resize(max_history); // resize back to max history size for next data cycle
|
active_history_B->resize(max_history); // resize back to max history size for next data cycle
|
||||||
#endif
|
#endif
|
||||||
counter = 0; // reset counter after saving
|
counter_a = 0; // reset counter after saving
|
||||||
|
counter_b = 0; // reset counter after saving
|
||||||
|
|
||||||
partial_save = true;
|
partial_save = true;
|
||||||
first_save = true;
|
first_save = true;
|
||||||
}
|
}
|
||||||
|
Serial.printf("[%d] Waiting for data...\r", wait_count++);
|
||||||
delay(500);
|
delay(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,57 +17,65 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
LOG_ERROR("Null rt_task_ptr parameters");
|
LOG_ERROR("Null rt_task_ptr parameters");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
LOG_INFO("rtTask Params OK");
|
|
||||||
|
|
||||||
// Task Parameters and Devices
|
// Task Parameters and Devices
|
||||||
rtTaskParams *params = (rtTaskParams *)pvParameters;
|
rtTaskParams *params = (rtTaskParams *)pvParameters;
|
||||||
const rtTaskInterrupts rt_int = params->rt_int; // copy to avoid external override
|
const rtTaskInterrupts rt_int = params->rt_int; // copy to avoid external override
|
||||||
const rtTaskResets rt_rst = params->rt_resets; // copy to avoid external override
|
const rtTaskResets rt_rst = params->rt_resets; // copy to avoid external override
|
||||||
QueueHandle_t rt_queue = params->rt_queue;
|
QueueHandle_t rt_queue = params->rt_queue;
|
||||||
TaskHandle_t rt_handle_ptr = *params->rt_handle_ptr;
|
|
||||||
Devices *dev = params->dev;
|
Devices *dev = params->dev;
|
||||||
ADS1256 *adc = dev->adc_a;
|
ADS1256 *adc = dev->adc_a;
|
||||||
PCA9555 *io = dev->io;
|
PCA9555 *io = dev->io;
|
||||||
|
|
||||||
|
TaskStatus_t rt_task_info;
|
||||||
|
vTaskGetInfo(NULL, &rt_task_info, pdFALSE, eInvalid);
|
||||||
|
|
||||||
|
const auto rt_task_name = pcTaskGetName(rt_task_info.xHandle);
|
||||||
|
LOG_INFO("rtTask Params OK [", rt_task_name, "]");
|
||||||
|
|
||||||
ignitionBoxStatus ign_box_sts;
|
ignitionBoxStatus ign_box_sts;
|
||||||
|
|
||||||
// Variables for ISR, static to be fixed in memory locations
|
// Variables for ISR, static to be fixed in memory locations
|
||||||
static isrParams isr_params_t12p{
|
isrParams isr_params_t12p{
|
||||||
.flag = TRIG_FLAG_12P,
|
.flag = TRIG_FLAG_12P,
|
||||||
.ign_stat = &ign_box_sts,
|
.ign_stat = &ign_box_sts,
|
||||||
.rt_handle_ptr = rt_handle_ptr};
|
.rt_handle_ptr = rt_task_info.xHandle};
|
||||||
static isrParams isr_params_t12n{
|
isrParams isr_params_t12n{
|
||||||
.flag = TRIG_FLAG_12N,
|
.flag = TRIG_FLAG_12N,
|
||||||
.ign_stat = &ign_box_sts,
|
.ign_stat = &ign_box_sts,
|
||||||
.rt_handle_ptr = rt_handle_ptr};
|
.rt_handle_ptr = rt_task_info.xHandle};
|
||||||
static isrParams isr_params_t34p{
|
isrParams isr_params_t34p{
|
||||||
.flag = TRIG_FLAG_34P,
|
.flag = TRIG_FLAG_34P,
|
||||||
.ign_stat = &ign_box_sts,
|
.ign_stat = &ign_box_sts,
|
||||||
.rt_handle_ptr = rt_handle_ptr};
|
.rt_handle_ptr = rt_task_info.xHandle};
|
||||||
static isrParams isr_params_t34n{
|
isrParams isr_params_t34n{
|
||||||
.flag = TRIG_FLAG_34N,
|
.flag = TRIG_FLAG_34N,
|
||||||
.ign_stat = &ign_box_sts,
|
.ign_stat = &ign_box_sts,
|
||||||
.rt_handle_ptr = rt_handle_ptr};
|
.rt_handle_ptr = rt_task_info.xHandle};
|
||||||
static isrParams isr_params_sp12{
|
isrParams isr_params_sp12{
|
||||||
.flag = SPARK_FLAG_12,
|
.flag = SPARK_FLAG_12,
|
||||||
.ign_stat = &ign_box_sts,
|
.ign_stat = &ign_box_sts,
|
||||||
.rt_handle_ptr = rt_handle_ptr};
|
.rt_handle_ptr = rt_task_info.xHandle};
|
||||||
static isrParams isr_params_sp34{
|
isrParams isr_params_sp34{
|
||||||
.flag = SPARK_FLAG_34,
|
.flag = SPARK_FLAG_34,
|
||||||
.ign_stat = &ign_box_sts,
|
.ign_stat = &ign_box_sts,
|
||||||
.rt_handle_ptr = rt_handle_ptr};
|
.rt_handle_ptr = rt_task_info.xHandle};
|
||||||
|
|
||||||
LOG_INFO("rtTask ISR Params OK");
|
LOG_DEBUG("rtTask HDL Params OK, HDL* [", (uint32_t)rt_task_info.xHandle, "]");
|
||||||
|
LOG_DEBUG("rtTask ISR Params OK, ISR* [", (uint32_t)rt_int.isr_ptr, "]");
|
||||||
|
LOG_DEBUG("rtTask QUE Params OK, QUE* [", (uint32_t)rt_queue, "]");
|
||||||
|
|
||||||
// Create esp_timer for microsecond precision timeout
|
// Create esp_timer for microsecond precision timeout
|
||||||
esp_timer_handle_t timeout_timer;
|
esp_timer_handle_t timeout_timer;
|
||||||
esp_timer_create_args_t timer_args = {
|
esp_timer_create_args_t timer_args = {
|
||||||
.callback = spark_timeout_callback,
|
.callback = spark_timeout_callback,
|
||||||
.arg = (void *)rt_handle_ptr,
|
.arg = (void *)rt_task_info.xHandle,
|
||||||
.dispatch_method = ESP_TIMER_TASK,
|
.dispatch_method = ESP_TIMER_TASK,
|
||||||
.name = "spark_timeout"};
|
.name = "spark_timeout"};
|
||||||
esp_timer_create(&timer_args, &timeout_timer);
|
esp_timer_create(&timer_args, &timeout_timer);
|
||||||
|
|
||||||
|
|
||||||
// Attach Pin Interrupts
|
// Attach Pin Interrupts
|
||||||
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12p), rt_int.isr_ptr, (void *)&isr_params_t12p, RISING);
|
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12p), rt_int.isr_ptr, (void *)&isr_params_t12p, RISING);
|
||||||
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12n), rt_int.isr_ptr, (void *)&isr_params_t12n, RISING);
|
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12n), rt_int.isr_ptr, (void *)&isr_params_t12n, RISING);
|
||||||
@@ -76,7 +84,7 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
attachInterruptArg(digitalPinToInterrupt(rt_int.spark_pin_12), rt_int.isr_ptr, (void *)&isr_params_sp12, RISING);
|
attachInterruptArg(digitalPinToInterrupt(rt_int.spark_pin_12), rt_int.isr_ptr, (void *)&isr_params_sp12, RISING);
|
||||||
attachInterruptArg(digitalPinToInterrupt(rt_int.spark_pin_34), rt_int.isr_ptr, (void *)&isr_params_sp34, RISING);
|
attachInterruptArg(digitalPinToInterrupt(rt_int.spark_pin_34), rt_int.isr_ptr, (void *)&isr_params_sp34, RISING);
|
||||||
|
|
||||||
LOG_INFO("rtTask ISR Attach OK");
|
LOG_INFO("rtTask ISR Attach OK [", rt_task_name, "]");
|
||||||
|
|
||||||
// Global rt_task_ptr variables
|
// Global rt_task_ptr variables
|
||||||
bool first_cycle = true;
|
bool first_cycle = true;
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ struct rtTaskParams
|
|||||||
{
|
{
|
||||||
bool rt_running; // run flag, false to terminate
|
bool rt_running; // run flag, false to terminate
|
||||||
Devices *dev;
|
Devices *dev;
|
||||||
TaskHandle_t* rt_handle_ptr;
|
|
||||||
const QueueHandle_t rt_queue;
|
const QueueHandle_t rt_queue;
|
||||||
const rtTaskInterrupts rt_int; // interrupt pins to attach
|
const rtTaskInterrupts rt_int; // interrupt pins to attach
|
||||||
const rtTaskResets rt_resets; // reset ping for peak detectors
|
const rtTaskResets rt_resets; // reset ping for peak detectors
|
||||||
|
|||||||
@@ -14,191 +14,3 @@ void printField(const char name[], const char *val);
|
|||||||
|
|
||||||
void printInfo(const ignitionBoxStatus &info);
|
void printInfo(const ignitionBoxStatus &info);
|
||||||
|
|
||||||
static const std::string htmlTest = R"rawliteral(
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>ESP32 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
font-family: Arial;
|
|
||||||
text-align: center;
|
|
||||||
margin-top: 40px;
|
|
||||||
}
|
|
||||||
|
|
||||||
table {
|
|
||||||
margin: auto;
|
|
||||||
border-collapse: collapse;
|
|
||||||
width: 100%;
|
|
||||||
max-width: 900px;
|
|
||||||
}
|
|
||||||
|
|
||||||
th, td {
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
padding: 10px;
|
|
||||||
font-size: 16px;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
th {
|
|
||||||
background-color: #f4f4f4;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
margin: 10px;
|
|
||||||
padding: 10px 20px;
|
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<h2>RotaxMonitor realtime data</h2>
|
|
||||||
|
|
||||||
<button onclick="start()">Start</button>
|
|
||||||
<button onclick="stop()">Stop</button>
|
|
||||||
|
|
||||||
<div style="max-width: 900px; margin: 0 auto; text-align: left;">
|
|
||||||
<p><strong>Timestamp:</strong> <span id="timestamp">-</span></p>
|
|
||||||
<p><strong>Data Valid:</strong> <span id="datavalid">-</span></p>
|
|
||||||
<p><strong>Generator voltage:</strong> <span id="volts_gen">-</span></p>
|
|
||||||
<p><strong>Engine RPM:</strong> <span id="eng_rpm">-</span></p>
|
|
||||||
<p><strong>ADC read time:</strong> <span id="adc_read_time">-</span></p>
|
|
||||||
<p><strong>Queue errors:</strong> <span id="n_queue_errors">-</span></p>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Property</th>
|
|
||||||
<th>Coils 12</th>
|
|
||||||
<th>Coils 34</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td>Spark delay</td>
|
|
||||||
<td id="coils12_spark_delay">-</td>
|
|
||||||
<td id="coils34_spark_delay">-</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Spark status</td>
|
|
||||||
<td id="coils12_spark_status">-</td>
|
|
||||||
<td id="coils34_spark_status">-</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Soft start status</td>
|
|
||||||
<td id="coils12_sstart_status">-</td>
|
|
||||||
<td id="coils34_sstart_status">-</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Peak P in</td>
|
|
||||||
<td id="coils12_peak_p_in">-</td>
|
|
||||||
<td id="coils34_peak_p_in">-</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Peak N in</td>
|
|
||||||
<td id="coils12_peak_n_in">-</td>
|
|
||||||
<td id="coils34_peak_n_in">-</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Peak P out</td>
|
|
||||||
<td id="coils12_peak_p_out">-</td>
|
|
||||||
<td id="coils34_peak_p_out">-</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Peak N out</td>
|
|
||||||
<td id="coils12_peak_n_out">-</td>
|
|
||||||
<td id="coils34_peak_n_out">-</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Level spark</td>
|
|
||||||
<td id="coils12_level_spark">-</td>
|
|
||||||
<td id="coils34_level_spark">-</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Events</td>
|
|
||||||
<td id="coils12_n_events">-</td>
|
|
||||||
<td id="coils34_n_events">-</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Missed firings</td>
|
|
||||||
<td id="coils12_n_missed_firing">-</td>
|
|
||||||
<td id="coils34_n_missed_firing">-</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
let ws;
|
|
||||||
|
|
||||||
function connectWS() {
|
|
||||||
ws = new WebSocket("ws://" + location.host + "/ws");
|
|
||||||
|
|
||||||
ws.onopen = () => {
|
|
||||||
console.log("WebSocket connesso");
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onclose = () => {
|
|
||||||
console.log("WebSocket disconnesso, retry...");
|
|
||||||
setTimeout(connectWS, 5000);
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onmessage = (event) => {
|
|
||||||
let data;
|
|
||||||
|
|
||||||
try {
|
|
||||||
data = JSON.parse(event.data);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Invalid JSON received", e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById("datavalid").textContent = data.datavalid ?? "-";
|
|
||||||
document.getElementById("timestamp").textContent = data.timestamp ?? "-";
|
|
||||||
document.getElementById("volts_gen").textContent = data.volts_gen ?? "-";
|
|
||||||
document.getElementById("eng_rpm").textContent = data.eng_rpm ?? "-";
|
|
||||||
document.getElementById("adc_read_time").textContent = data.adc_read_time ?? "-";
|
|
||||||
document.getElementById("n_queue_errors").textContent = data.n_queue_errors ?? "-";
|
|
||||||
|
|
||||||
const coils12 = data.coils12 || {};
|
|
||||||
const coils34 = data.coils34 || {};
|
|
||||||
|
|
||||||
document.getElementById("coils12_spark_delay").textContent = coils12.spark_delay ?? "-";
|
|
||||||
document.getElementById("coils34_spark_delay").textContent = coils34.spark_delay ?? "-";
|
|
||||||
document.getElementById("coils12_spark_status").textContent = coils12.spark_status ?? "-";
|
|
||||||
document.getElementById("coils34_spark_status").textContent = coils34.spark_status ?? "-";
|
|
||||||
document.getElementById("coils12_sstart_status").textContent = coils12.sstart_status ?? "-";
|
|
||||||
document.getElementById("coils34_sstart_status").textContent = coils34.sstart_status ?? "-";
|
|
||||||
document.getElementById("coils12_peak_p_in").textContent = coils12.peak_p_in ?? "-";
|
|
||||||
document.getElementById("coils34_peak_p_in").textContent = coils34.peak_p_in ?? "-";
|
|
||||||
document.getElementById("coils12_peak_n_in").textContent = coils12.peak_n_in ?? "-";
|
|
||||||
document.getElementById("coils34_peak_n_in").textContent = coils34.peak_n_in ?? "-";
|
|
||||||
document.getElementById("coils12_peak_p_out").textContent = coils12.peak_p_out ?? "-";
|
|
||||||
document.getElementById("coils34_peak_p_out").textContent = coils34.peak_p_out ?? "-";
|
|
||||||
document.getElementById("coils12_peak_n_out").textContent = coils12.peak_n_out ?? "-";
|
|
||||||
document.getElementById("coils34_peak_n_out").textContent = coils34.peak_n_out ?? "-";
|
|
||||||
document.getElementById("coils12_level_spark").textContent = coils12.level_spark ?? "-";
|
|
||||||
document.getElementById("coils34_level_spark").textContent = coils34.level_spark ?? "-";
|
|
||||||
document.getElementById("coils12_n_events").textContent = coils12.n_events ?? "-";
|
|
||||||
document.getElementById("coils34_n_events").textContent = coils34.n_events ?? "-";
|
|
||||||
document.getElementById("coils12_n_missed_firing").textContent = coils12.n_missed_firing ?? "-";
|
|
||||||
document.getElementById("coils34_n_missed_firing").textContent = coils34.n_missed_firing ?? "-";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function start() {
|
|
||||||
fetch("/start");
|
|
||||||
}
|
|
||||||
|
|
||||||
function stop() {
|
|
||||||
fetch("/stop");
|
|
||||||
}
|
|
||||||
|
|
||||||
connectWS();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
)rawliteral";
|
|
||||||
3
RotaxMonitorTester/.vscode/extensions.json
vendored
3
RotaxMonitorTester/.vscode/extensions.json
vendored
@@ -1,8 +1,7 @@
|
|||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"Jason2866.esp-decoder",
|
"Jason2866.esp-decoder",
|
||||||
"pioarduino.pioarduino-ide",
|
"pioarduino.pioarduino-ide"
|
||||||
"platformio.platformio-ide"
|
|
||||||
],
|
],
|
||||||
"unwantedRecommendations": [
|
"unwantedRecommendations": [
|
||||||
"ms-vscode.cpptools-extension-pack"
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ static uint32_t count = 0;
|
|||||||
#define PAUSE_LONG_MIN 5000
|
#define PAUSE_LONG_MIN 5000
|
||||||
#define PAUSE_LONG_MAX PAUSE_LONG_MIN * 100
|
#define PAUSE_LONG_MAX PAUSE_LONG_MIN * 100
|
||||||
|
|
||||||
#define RPM_MIN 800
|
#define RPM_MIN 250
|
||||||
#define RPM_MAX 5500
|
#define RPM_MAX 5500
|
||||||
|
|
||||||
void clearScreen(){
|
void clearScreen()
|
||||||
|
{
|
||||||
Serial.print("\033[2J"); // clear screen
|
Serial.print("\033[2J"); // clear screen
|
||||||
Serial.print("\033[H"); // cursor home
|
Serial.print("\033[H"); // cursor home
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
@@ -60,8 +61,7 @@ static timerStatus stsA = {
|
|||||||
.pin_trig_34p = PIN_TRIG_A34P,
|
.pin_trig_34p = PIN_TRIG_A34P,
|
||||||
.pin_trig_34n = PIN_TRIG_A34N,
|
.pin_trig_34n = PIN_TRIG_A34N,
|
||||||
.pin_spark_12 = SPARK_A12,
|
.pin_spark_12 = SPARK_A12,
|
||||||
.pin_spark_34 = SPARK_A34
|
.pin_spark_34 = SPARK_A34},
|
||||||
},
|
|
||||||
.main_task = NULL};
|
.main_task = NULL};
|
||||||
|
|
||||||
static timerStatus stsB = {
|
static timerStatus stsB = {
|
||||||
@@ -77,16 +77,16 @@ static timerStatus stsB = {
|
|||||||
.pin_trig_34p = PIN_TRIG_B34P,
|
.pin_trig_34p = PIN_TRIG_B34P,
|
||||||
.pin_trig_34n = PIN_TRIG_B34N,
|
.pin_trig_34n = PIN_TRIG_B34N,
|
||||||
.pin_spark_12 = SPARK_B12,
|
.pin_spark_12 = SPARK_B12,
|
||||||
.pin_spark_34 = SPARK_B34
|
.pin_spark_34 = SPARK_B34},
|
||||||
},
|
|
||||||
.main_task = NULL};
|
.main_task = NULL};
|
||||||
|
|
||||||
static bool isEnabled = false;
|
static bool isEnabled_A = false;
|
||||||
|
static bool isEnabled_B = false;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
Serial.begin(921600);
|
Serial.begin(115200);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
LOG_ATTACH_SERIAL(Serial);
|
LOG_ATTACH_SERIAL(Serial);
|
||||||
|
|
||||||
@@ -107,7 +107,8 @@ void setup()
|
|||||||
pinMode(SPARK_DELAY_POT, ANALOG);
|
pinMode(SPARK_DELAY_POT, ANALOG);
|
||||||
pinMode(FREQ_POT, ANALOG);
|
pinMode(FREQ_POT, ANALOG);
|
||||||
|
|
||||||
pinMode(ENABLE_PIN, INPUT_PULLUP);
|
pinMode(ENABLE_PIN_A, INPUT_PULLUP);
|
||||||
|
pinMode(ENABLE_PIN_B, INPUT_PULLUP);
|
||||||
|
|
||||||
// get the task handle for the main loop
|
// get the task handle for the main loop
|
||||||
stsA.main_task = xTaskGetCurrentTaskHandleForCore(1);
|
stsA.main_task = xTaskGetCurrentTaskHandleForCore(1);
|
||||||
@@ -135,10 +136,13 @@ void loop()
|
|||||||
LOG_INFO("Loop: ", count++);
|
LOG_INFO("Loop: ", count++);
|
||||||
uint32_t spark_delay = (uint32_t)(map(analogRead(SPARK_DELAY_POT), 0, 4096, SPARK_DLY_MIN, SPARK_DLY_MAX) / PERIOD_US);
|
uint32_t spark_delay = (uint32_t)(map(analogRead(SPARK_DELAY_POT), 0, 4096, SPARK_DLY_MIN, SPARK_DLY_MAX) / PERIOD_US);
|
||||||
stsA.spark_delay_us = spark_delay * PERIOD_US;
|
stsA.spark_delay_us = spark_delay * PERIOD_US;
|
||||||
if (stsA.spark_delay_us > (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2) {
|
if (stsA.spark_delay_us > (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2)
|
||||||
|
{
|
||||||
stsA.soft_start = true;
|
stsA.soft_start = true;
|
||||||
stsA.spark_delay_us -= (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2;
|
stsA.spark_delay_us -= (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
stsA.soft_start = false;
|
stsA.soft_start = false;
|
||||||
}
|
}
|
||||||
stsB.soft_start = stsA.soft_start;
|
stsB.soft_start = stsA.soft_start;
|
||||||
@@ -149,26 +153,41 @@ void loop()
|
|||||||
stsA.pause_long_us = (uint32_t)(60000000.0f / filtered_rpm / 2.0f);
|
stsA.pause_long_us = (uint32_t)(60000000.0f / filtered_rpm / 2.0f);
|
||||||
stsB.pause_long_us = stsA.pause_long_us;
|
stsB.pause_long_us = stsA.pause_long_us;
|
||||||
|
|
||||||
if (isEnabled) {
|
if (isEnabled_A)
|
||||||
LOG_INFO("==== System is ENABLED ====");
|
LOG_INFO("==== System A is ENABLED ====");
|
||||||
} else {
|
else
|
||||||
LOG_INFO("==== System is DISABLED ====");
|
LOG_INFO("==== System A is DISABLED ====");
|
||||||
}
|
|
||||||
|
if (isEnabled_B)
|
||||||
|
LOG_INFO("==== System B is ENABLED ====");
|
||||||
|
else
|
||||||
|
LOG_INFO("==== System B is DISABLED ====");
|
||||||
|
|
||||||
LOG_INFO("Spark Delay uS: ", stsA.spark_delay_us, "\tSoft Start: ", stsA.soft_start ? "TRUE" : "FALSE");
|
LOG_INFO("Spark Delay uS: ", stsA.spark_delay_us, "\tSoft Start: ", stsA.soft_start ? "TRUE" : "FALSE");
|
||||||
LOG_INFO("Engine Rpm: ", (uint32_t)(filtered_rpm));
|
LOG_INFO("Engine Rpm: ", (uint32_t)(filtered_rpm));
|
||||||
LOG_INFO("Coil Pulse: ", stsA.coil_pulse_us, "us");
|
LOG_INFO("Coil Pulse: ", stsA.coil_pulse_us, "us");
|
||||||
LOG_INFO("Spark Pulse: ", stsA.spark_pulse_us, "us");
|
LOG_INFO("Spark Pulse: ", stsA.spark_pulse_us, "us");
|
||||||
|
|
||||||
if (digitalRead(ENABLE_PIN) == LOW && !isEnabled) {
|
if (digitalRead(ENABLE_PIN_A) == LOW && !isEnabled_A)
|
||||||
|
{
|
||||||
timerStart(timerA);
|
timerStart(timerA);
|
||||||
delayMicroseconds(50);
|
isEnabled_A = true;
|
||||||
|
}
|
||||||
|
else if (digitalRead(ENABLE_PIN_A) == HIGH && isEnabled_A)
|
||||||
|
{
|
||||||
|
timerStop(timerA);
|
||||||
|
isEnabled_A = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (digitalRead(ENABLE_PIN_B) == LOW && !isEnabled_B)
|
||||||
|
{
|
||||||
timerStart(timerB);
|
timerStart(timerB);
|
||||||
isEnabled = true;
|
isEnabled_B = true;
|
||||||
} else if (digitalRead(ENABLE_PIN) == HIGH && isEnabled) {
|
}
|
||||||
timerStop(timerA);
|
else if (digitalRead(ENABLE_PIN_B) == HIGH && isEnabled_B)
|
||||||
timerStop(timerA);
|
{
|
||||||
isEnabled = false;
|
timerStop(timerB);
|
||||||
|
isEnabled_B = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Enable Pin
|
// Enable Pin
|
||||||
#define ENABLE_PIN 16
|
#define ENABLE_PIN_A 16
|
||||||
|
#define ENABLE_PIN_B 15
|
||||||
|
|
||||||
///// Ignition Box A /////
|
///// Ignition Box A /////
|
||||||
#define PIN_TRIG_A12P 18
|
#define PIN_TRIG_A12P 18
|
||||||
|
|||||||
Reference in New Issue
Block a user