Updated pin definitions and trigger tasks from pickups

This commit is contained in:
Emanuele Trabattoni
2026-03-25 14:16:23 +01:00
parent b42474fff5
commit 8c5b7d4a1c
4 changed files with 294 additions and 98 deletions

98
RotaxMonitor/src/tasks.h Normal file
View File

@@ -0,0 +1,98 @@
// Arduino Libraries
#include <Arduino.h>
#include <DebugLog.h>
// ISR
#include "isr.h"
const uint16_t spark_delay_us = 500;
void ignitionA_task(void *pvParameters) {
uint32_t notifiedValue;
while (true) {
// attende eventi
xTaskNotifyWait(
0x00, // non pulire all'ingresso
ULONG_MAX, // pulisci tutti i bit all'uscita
&notifiedValue, // valore ricevuto
portMAX_DELAY
);
uint64_t wait_time=0;
switch (notifiedValue) {
case TRIG_FLAG_A12P:
case TRIG_FLAG_A12N:
bool spark12_timeout = false;
if (ignA_status.trig12_complete) {
// read peak adc values from sample and hold
} else {
while(!digitalRead(SPARK_A12)) {
wait_time = ignA_status.trig12_start - esp_timer_get_time();
if (wait_time >= spark_delay_us) {
spark12_timeout = true;
break;
}
}
if (spark12_timeout) { // spark did not happen, timeout
ignA_status.trig12_complete = false;
} else { // spark did happen
ignA_status.trig12_complete = true;
ignA_status.trig12_time = wait_time;
}
}
break;
case TRIG_FLAG_A34P:
case TRIG_FLAG_A34N:
bool spark34_timeout = false;
if (ignA_status.trig12_complete) {
// read peak adc values from sample and hold
} else {
while(!digitalRead(SPARK_A34)) {
wait_time = ignA_status.trig34_start - esp_timer_get_time();
if (wait_time >= spark_delay_us) {
spark12_timeout = true;
break;
}
}
if (spark34_timeout) { // spark did not happen, timeout
ignA_status.trig34_complete = false;
} else { // spark did happen
ignA_status.trig34_complete = true;
ignA_status.trig34_time = wait_time;
}
}
break;
default:
LOG_ERROR("Invalid A Interrupt: ", notifiedValue);
}
}
}
void ignitionB_task(void *pvParameters) {
uint32_t notifiedValue;
while (true) {
// attende eventi
xTaskNotifyWait(
0x00, // non pulire all'ingresso
0xFFFFFFFF, // pulisci tutti i bit all'uscita
&notifiedValue, // valore ricevuto
portMAX_DELAY
);
switch (notifiedValue) {
case TRIG_FLAG_B12P:
break;
case TRIG_FLAG_B34P:
break;
case TRIG_FLAG_B12N:
break;
case TRIG_FLAG_B34N:
break;
default:
LOG_ERROR("Invalid B Interrupt: ", notifiedValue);
}
}
}