From 46db889558b953d5a8831c7912bfff4570ae9305 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 14 Sep 2020 02:48:34 -0600 Subject: fixed bug: ticks_since_last_event wasn't getting reset on button hold release The visible symptom was: Ramp up for 1s or longer, release, wait more than 1s, then hold again. It should ramp up, but it would ramp down instead. The clause for resetting ramp_direction wasn't happening, because the EV_tick counter started at a value higher than 1s where it would normally trigger. The underlying cause was a bit complicated. Recent changes in PCINT_inner() were causing ticks_since_last_event to get set to 0 (at push_event()) and then back to its previous value (at emit_current_event()). The EV_tick counter would then start at whatever the button release event used. The fix involved removing the part of emit_current_event() where it would set ticks_since_last_event to "arg". That line was a very old bug which simply hadn't caused any visible issues until recently. Instead, it needs to set ticks_since_last_event more carefully, at other locations. Specifically, it resets to 0 now in empty_event_sequence() and one more location in the deferred WDT handler (when HOLD_TIMEOUT triggers). Additionally, push_event() was only ever used from PCINT_inner()... so I moved the tick reset logic to PCINT_inner() instead. This allows us to decrease size by about 10 bytes, since PCINT_inner() no longer needs to copy the counter before it gets reset. However, it also means push_event() should never be called from any other function. --- spaghetti-monster/fsm-events.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'spaghetti-monster/fsm-events.c') diff --git a/spaghetti-monster/fsm-events.c b/spaghetti-monster/fsm-events.c index ad869a6..93c38c9 100644 --- a/spaghetti-monster/fsm-events.c +++ b/spaghetti-monster/fsm-events.c @@ -25,6 +25,7 @@ void empty_event_sequence() { current_event = EV_none; + ticks_since_last_event = 0; // when the user completes an input sequence, interrupt any running timers // to cancel any delays currently in progress // This eliminates a whole bunch of extra code: @@ -33,8 +34,9 @@ void empty_event_sequence() { interrupt_nice_delays(); } -uint8_t push_event(uint8_t ev_type) { - ticks_since_last_event = 0; // something happened +uint8_t push_event(uint8_t ev_type) { // only for use by PCINT_inner() + // don't do this here; do it in PCINT_inner() instead + //ticks_since_last_event = 0; // something happened // only click events are sent to this function current_event |= B_CLICK; @@ -208,7 +210,6 @@ void emit(Event event, uint16_t arg) { } void emit_current_event(uint16_t arg) { - ticks_since_last_event = arg; emit(current_event, arg); } -- cgit v1.2.3