aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-main.c
diff options
context:
space:
mode:
Diffstat (limited to 'spaghetti-monster/fsm-main.c')
-rw-r--r--spaghetti-monster/fsm-main.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/spaghetti-monster/fsm-main.c b/spaghetti-monster/fsm-main.c
index 790cc68..b96bce8 100644
--- a/spaghetti-monster/fsm-main.c
+++ b/spaghetti-monster/fsm-main.c
@@ -129,6 +129,7 @@ int main() {
// fallback for handling a few things
#ifndef DONT_USE_DEFAULT_STATE
push_state(default_state, 0);
+ nice_delay_interrupt = 0;
#endif
// call recipe's setup
@@ -139,6 +140,14 @@ int main() {
// if event queue not empty, empty it
process_emissions();
+ // if loop() tried to change state, process that now
+ StatePtr df = deferred_state;
+ if (df) {
+ set_state(df, deferred_state_arg);
+ deferred_state = NULL;
+ //deferred_state_arg = 0; // unnecessary
+ }
+
// enter standby mode if requested
// (works better if deferred like this)
if (go_to_standby) {
@@ -164,11 +173,12 @@ int main() {
// catch up on interrupts
handle_deferred_interrupts();
+ // turn delays back on, if they were off
+ nice_delay_interrupt = 0;
+
// give the recipe some time slices
loop();
- // in case we fell through, turn delays back on
- nice_delay_interrupt = 0;
}
}