]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/eb_lift/fsm.c
eb_lift: Add new project that is common lift ccntroler for year 2012 and the future...
[eurobot/public.git] / src / eb_lift / fsm.c
1 #include "fsm.h"
2
3 void init_fsm(struct fsm *fsm, state_fcn initial_state)
4 {
5         fsm->current_state = initial_state;
6         fsm->current_state(fsm, EVENT_ENTRY);
7 }
8
9 void run_fsm(struct fsm *fsm){
10         fsm->last_state = fsm->current_state;           // set actual state
11         fsm->current_state(fsm, EVENT_DO);              // change parameter
12         
13         if(fsm->last_state != fsm->current_state){      // if state was changed
14                 fsm->last_state(fsm, EVENT_EXIT);       // finish the old state
15                 fsm->current_state(fsm, EVENT_ENTRY);   // initialize the new state
16         }
17 }
18
19