aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-misc.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2020-09-27 03:26:01 -0600
committerSelene ToyKeeper2020-09-27 03:26:01 -0600
commit2173d1e3641ca2396a4460e5736823013e1c9357 (patch)
treed344b0d8d4fa253ef940d563a4c233e26744412f /spaghetti-monster/fsm-misc.c
parentfixed bug: momentary bike mode could sometimes get stuck on for a few seconds... (diff)
downloadanduril-2173d1e3641ca2396a4460e5736823013e1c9357.tar.gz
anduril-2173d1e3641ca2396a4460e5736823013e1c9357.tar.bz2
anduril-2173d1e3641ca2396a4460e5736823013e1c9357.zip
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
Diffstat (limited to 'spaghetti-monster/fsm-misc.c')
-rw-r--r--spaghetti-monster/fsm-misc.c34
1 files changed, 5 insertions, 29 deletions
diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c
index 82be745..15cb659 100644
--- a/spaghetti-monster/fsm-misc.c
+++ b/spaghetti-monster/fsm-misc.c
@@ -83,13 +83,12 @@ uint8_t blink_big_num(uint16_t num) {
#endif
#ifdef USE_BLINK_NUM
uint8_t blink_num(uint8_t num) {
- //StatePtr old_state = current_state;
- #if 0
+ #if 1
uint8_t hundreds = num / 100;
num = num % 100;
uint8_t tens = num / 10;
num = num % 10;
- #else // 8 bytes smaller
+ #else // can be smaller or larger, depending on whether divmod is used elsewhere
uint8_t hundreds = 0;
uint8_t tens = 0;
for(; num >= 100; hundreds ++, num -= 100);
@@ -102,32 +101,9 @@ uint8_t blink_num(uint8_t num) {
nice_delay_ms(200);
#endif
- #if 0
- if (hundreds) {
- if (! blink_digit(hundreds)) return 0;
- if (! blink_digit(tens)) return 0;
- }
- else if (tens) {
- if (! blink_digit(tens)) return 0;
- }
- if (! blink_digit(num)) return 0;
- return nice_delay_ms(1000);
- #else // same size :(
- if (hundreds) if (! blink_digit(hundreds)) return 0;
- if (hundreds || tens) if (! blink_digit(tens)) return 0;
- if (! blink_digit(num)) return 0;
- return nice_delay_ms(1000);
- #endif
-
- /*
- uint8_t volts, tenths;
- volts = voltage / 10;
- tenths = voltage % 10;
- if (! blink(volts)) return;
- nice_delay_ms(200);
- if (! blink(tenths)) return;
- nice_delay_ms(200);
- */
+ if (hundreds) blink_digit(hundreds);
+ if (hundreds || tens) blink_digit(tens);
+ return blink_digit(num);
}
#endif