From 2173d1e3641ca2396a4460e5736823013e1c9357 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 27 Sep 2020 03:26:01 -0600 Subject: 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 --- spaghetti-monster/fsm-events.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spaghetti-monster/fsm-events.c') diff --git a/spaghetti-monster/fsm-events.c b/spaghetti-monster/fsm-events.c index b4cb671..3279c14 100644 --- a/spaghetti-monster/fsm-events.c +++ b/spaghetti-monster/fsm-events.c @@ -126,7 +126,6 @@ inline void interrupt_nice_delays() { nice_delay_interrupt = 1; } // 0: state changed // 1: normal completion uint8_t nice_delay_ms(uint16_t ms) { - StatePtr old_state = current_state; /* // delay_zero() implementation if (ms == 0) { CLKPR = 1< 0) { + if (nice_delay_interrupt) { + return 0; + } + #ifdef USE_DYNAMIC_UNDERCLOCKING #ifdef USE_RAMPING uint8_t level = actual_level; // volatile, avoid repeat access @@ -168,9 +171,6 @@ uint8_t nice_delay_ms(uint16_t ms) { // run pending system processes while we wait handle_deferred_interrupts(); - if ((nice_delay_interrupt) || (old_state != current_state)) { - return 0; // state changed; abort - } // handle events only afterward, so that any collapsed delays will // finish running the UI's loop() code before taking any further actions // (this helps make sure code runs in the correct order) -- cgit v1.2.3