diff options
| author | Selene ToyKeeper | 2017-08-27 19:40:40 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2017-08-27 19:40:40 -0600 |
| commit | dce497bf15799133bf336ab46c3e39d7b0d92839 (patch) | |
| tree | 6a39b7912f046af72563c93344376e3830fe810a /spaghetti-monster/fsm-states.c | |
| parent | Reduced ROM size, simplified logic, made sure discrete ramp won't overflow ou... (diff) | |
| download | anduril-dce497bf15799133bf336ab46c3e39d7b0d92839.tar.gz anduril-dce497bf15799133bf336ab46c3e39d7b0d92839.tar.bz2 anduril-dce497bf15799133bf336ab46c3e39d7b0d92839.zip | |
Ramp config mode actually works now...
Added EV_reenter_state event to indicate an obscuring state was popped off the stack
and the underlying one is now on top again.
Diffstat (limited to 'spaghetti-monster/fsm-states.c')
| -rw-r--r-- | spaghetti-monster/fsm-states.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/spaghetti-monster/fsm-states.c b/spaghetti-monster/fsm-states.c index ec24dc8..2939475 100644 --- a/spaghetti-monster/fsm-states.c +++ b/spaghetti-monster/fsm-states.c @@ -31,13 +31,14 @@ // 255: error (not sure what this would even mean though, or what difference it would make) // TODO: function to call stacked callbacks until one returns "handled" -void _set_state(StatePtr new_state, uint16_t arg) { +void _set_state(StatePtr new_state, uint16_t arg, + EventPtr exit_event, EventPtr enter_event) { // call old state-exit hook (don't use stack) - if (current_state != NULL) current_state(EV_leave_state, arg); + if (current_state != NULL) current_state(exit_event, arg); // set new state current_state = new_state; // call new state-enter hook (don't use stack) - if (new_state != NULL) current_state(EV_enter_state, arg); + if (new_state != NULL) current_state(enter_event, arg); } int8_t push_state(StatePtr new_state, uint16_t arg) { @@ -46,7 +47,8 @@ int8_t push_state(StatePtr new_state, uint16_t arg) { // new hook for non-exit recursion into child? state_stack[state_stack_len] = new_state; state_stack_len ++; - _set_state(new_state, arg); + // FIXME: use EV_stacked_state? + _set_state(new_state, arg, EV_leave_state, EV_enter_state); return state_stack_len; } else { // TODO: um... how is a flashlight supposed to handle a recursion depth error? @@ -66,8 +68,7 @@ StatePtr pop_state() { new_state = state_stack[state_stack_len-1]; } // FIXME: what should 'arg' be? - // FIXME: do we need a EV_reenter_state? - _set_state(new_state, 0); + _set_state(new_state, 0, EV_leave_state, EV_reenter_state); return old_state; } |
