diff options
| author | Selene ToyKeeper | 2017-08-24 16:21:45 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2017-08-24 16:21:45 -0600 |
| commit | 32eaeddee34c76dda5456ed960be6278ed68e48d (patch) | |
| tree | 44cbbcfb3e1b47c777eacd1a707bba653bb4b49e /spaghetti-monster/fsm-events.c | |
| parent | Fixed repeating blinks at ends of ramp -- only blinks once now. (diff) | |
| download | anduril-32eaeddee34c76dda5456ed960be6278ed68e48d.tar.gz anduril-32eaeddee34c76dda5456ed960be6278ed68e48d.tar.bz2 anduril-32eaeddee34c76dda5456ed960be6278ed68e48d.zip | |
Added loop() to API, executes constantly.
Added nice_delay_ms() to process events while waiting, and abort on state change.
Converted ramping-ui strobe to smoothly variable with party and tactical modes.
Diffstat (limited to '')
| -rw-r--r-- | spaghetti-monster/fsm-events.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/spaghetti-monster/fsm-events.c b/spaghetti-monster/fsm-events.c index 6dda236..4831df6 100644 --- a/spaghetti-monster/fsm-events.c +++ b/spaghetti-monster/fsm-events.c @@ -99,6 +99,29 @@ void delete_first_emission() { emissions[i].arg = 0; } +void process_emissions() { + while (emissions[0].event != NULL) { + emit_now(emissions[0].event, emissions[0].arg); + delete_first_emission(); + } +} + +// like delay_ms, except it aborts on state change +// return value: +// 0: state changed +// 1: normal completion +uint8_t nice_delay_ms(uint16_t ms) { + StatePtr old_state = current_state; + while(ms-- > 0) { + _delay_loop_2(BOGOMIPS*98/100); + process_emissions(); + if (old_state != current_state) { + return 0; // state changed; abort + } + } + return 1; +} + // Call stacked callbacks for the given event until one handles it. uint8_t emit_now(EventPtr event, uint16_t arg) { for(int8_t i=state_stack_len-1; i>=0; i--) { |
