From 131d447338658ceb95fa5635f2850eecdb9e4f4e Mon Sep 17 00:00:00 2001 From: Michael Williams Date: Sun, 9 May 2021 23:32:59 +1200 Subject: [PATCH] nope --- src/main.cpp | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a1b91b0..7523487 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -91,30 +91,38 @@ struct Transitions { } }; -template +template struct Machine { - StateVariant current_state; + Machine(Parameters parameters); + ~Machine(); - void dispatch(const EventVariant &Event) - { - std::optional new_state = std::visit(Transitions{}, current_state, Event); - if (new_state) - current_state = *std::move(new_state); - } + Parameters parameters; + StateVariant current_state; + + void dispatch(const EventVariant &Event) { + std::optional new_state = std::visit(Transitions{}, current_state, Event); + if (new_state) + current_state = *std::move(new_state); + } +}; + +struct Params { + uint8_t led_pin; + uint16_t ticks_until_switch; }; +Params green_params = { + LED_BUILTIN, // led_pin + 10 // ticks_until_switch +}; + +volatile Machine green_machine(green_params); void TimerHandler() { ISR_Timer.run(); } -Machine led; - -void process_green () { - led.dispatch(EventTick{}); -} - void setup() { Serial.begin(115200); @@ -136,8 +144,8 @@ void setup() Serial.println(F("Can't set ITimer. Select another freq. or timer")); } - led.dispatch(EventStart{}); - ISR_Timer.setInterval(TIMER_INTERVAL_TICK, [](){ led.dispatch(EventTick{}); }); + green_machine.dispatch(EventStart{}); + ISR_Timer.setInterval(TIMER_INTERVAL_TICK, [](){ green_machine.dispatch(EventTick{}); }); } void loop()