~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/fsm-states.h

  • Committer: Selene Scriven
  • Date: 2020-09-27 09:26:01 UTC
  • mto: (483.4.1 tiny1)
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: bzr@toykeeper.net-20200927092601-e4wokla3f9lfel65
reworked nice_delay interrupt system and fixed some old issues:

- added set_state_deferred(), to avoid timing issues when changing state in loop()
  (fixes bug where first button press after version check was sometimes ignored,
   and similar issue after battcheck in simple UI)

- reduced chance of eating first button press after simple UI's battcheck,
  because it spent an extra second waiting after finishing the readout,
  and it wasn't intuitive for a single click to go from "post-battcheck darkness"
  to "off" during that period

- made interrupt_nice_delays() happen every time the state changes, instead of
  having nice_delay() explicitly check for state changes while it waits...
  (because the explicit check was buggy and used more ROM)

- made nice_delay_ms() abort immediately when interrupt is set, instead of waiting
  1ms before it even checks for the interrupt condition...  this makes aborted
  animations end a lot faster, with less visible flickering

- made blink_num() smaller and simpler, because changes listed above make it possible

- slightly changed order of events in main(), to accommodate for changes above

- fixed issue where battcheck would keep trying to blink out numbers while the user
  was holding 10H for voltage config mode

- ... and reduced ROM size by about 38 bytes

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
int8_t push_state(StatePtr new_state, uint16_t arg);
41
41
StatePtr pop_state();
42
42
uint8_t set_state(StatePtr new_state, uint16_t arg);
 
43
 
 
44
// if loop() needs to change state, use this instead of set_state()
 
45
// (because this avoids race conditions)
 
46
volatile StatePtr deferred_state;
 
47
volatile uint16_t deferred_state_arg;
 
48
void set_state_deferred(StatePtr new_state, uint16_t arg);
 
49
 
43
50
#ifndef DONT_USE_DEFAULT_STATE
44
51
uint8_t default_state(Event event, uint16_t arg);
45
52
#endif