Tester first iteration
This commit is contained in:
119
RotaxMonitorTester/src/timer.cpp
Normal file
119
RotaxMonitorTester/src/timer.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
#include "timer.h"
|
||||
|
||||
#define TIME_CONST 1
|
||||
|
||||
enum State {
|
||||
S_12P,
|
||||
S_12N_DELAY,
|
||||
S_12N,
|
||||
S_WAIT_10MS,
|
||||
S_34P,
|
||||
S_34N_DELAY,
|
||||
S_34N,
|
||||
S_WAIT_1MS,
|
||||
S_WAIT_10MS_END
|
||||
};
|
||||
|
||||
volatile State state = S_12P;
|
||||
volatile uint32_t state_time = 0;
|
||||
|
||||
void onTimer(void* arg) {
|
||||
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
TaskHandle_t task = (TaskHandle_t)(arg);
|
||||
state_time += 1;
|
||||
|
||||
switch (state) {
|
||||
|
||||
case S_12P:
|
||||
digitalWrite(PIN_TRIG_A12P, HIGH);
|
||||
xTaskNotifyFromISR(task, PIN_TRIG_A12P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
|
||||
if (state_time == 2*TIME_CONST){
|
||||
xTaskNotifyFromISR(task, SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(SPARK_A12, HIGH);
|
||||
}
|
||||
|
||||
if (state_time == 7*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(SPARK_A12, LOW);
|
||||
}
|
||||
|
||||
if (state_time >= 5*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~PIN_TRIG_A12P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A12P, LOW);
|
||||
}
|
||||
|
||||
if (state_time >= 10*TIME_CONST) {
|
||||
state = S_12N;
|
||||
state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_12N:
|
||||
xTaskNotifyFromISR(task, PIN_TRIG_A12N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A12N, HIGH);
|
||||
|
||||
if (state_time >= 5*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~PIN_TRIG_A12N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A12N, LOW);
|
||||
state = S_WAIT_10MS;
|
||||
state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_WAIT_10MS:
|
||||
if (state_time >= 10*TIME_CONST) {
|
||||
state = S_34P;
|
||||
state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_34P:
|
||||
xTaskNotifyFromISR(task, PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34P, HIGH);
|
||||
|
||||
if (state_time == 2*TIME_CONST){
|
||||
xTaskNotifyFromISR(task, SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(SPARK_A34, HIGH);
|
||||
}
|
||||
|
||||
if (state_time == 7*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(SPARK_A34, LOW);
|
||||
}
|
||||
|
||||
if (state_time >= 5*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34P, LOW);
|
||||
}
|
||||
|
||||
if (state_time >= 10*TIME_CONST) {
|
||||
state = S_34N;
|
||||
state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_34N:
|
||||
xTaskNotifyFromISR(task, PIN_TRIG_A34N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34N, HIGH);
|
||||
|
||||
if (state_time >= 5*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~PIN_TRIG_A34N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34N, LOW);
|
||||
state = S_WAIT_10MS_END;
|
||||
state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_WAIT_10MS_END:
|
||||
if (state_time >= 10*TIME_CONST) {
|
||||
state = S_12P;
|
||||
state_time = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (xHigherPriorityTaskWoken)
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
Reference in New Issue
Block a user