Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
automaton.h
- Committer:
- gwappa
- Date:
- 2018-05-14
- Revision:
- 0:f736749c33d2
- Child:
- 4:fcf597f82632
File content as of revision 0:f736749c33d2:
#ifndef AUTOMATON_H_ #define AUTOMATON_H_ #include "mbed.h" namespace automaton { /** * event enum to notice changes to the instance */ enum Event { None = 0x00, Transition = 0x01, Done = 0x02, }; /** * a callback that does nothing */ void do_nothing_callback(); extern Callback<void()> entry; extern Callback<void()> teardown_prev; extern Callback<void()> setup_next; extern volatile Event event; /** * marks for performing a transition from FromState to ToState. */ template<typename FromState, typename ToState> void transit() { if ( event == None ){ teardown_prev = &FromState::teardown; setup_next = &ToState::setup; event = Transition; } } template<typename State> void done() { if (event == None){ teardown_prev = &State::teardown; setup_next = &do_nothing_callback; event = Done; } } template<typename State> void init() { entry = &State::setup; teardown_prev = &do_nothing_callback; setup_next = &do_nothing_callback; event = None; } /** * runs the automaton once */ void run(); } #endif