diff options
| author | Selene ToyKeeper | 2020-09-14 02:48:34 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2020-09-14 02:48:34 -0600 |
| commit | 46db889558b953d5a8831c7912bfff4570ae9305 (patch) | |
| tree | b8ee1f10e58a2472dd00a9f37e770a6cb1c3b8f9 /spaghetti-monster/fsm-wdt.c | |
| parent | fixed bug: ramp 2H at floor went up instead of staying at floor (diff) | |
| download | anduril-46db889558b953d5a8831c7912bfff4570ae9305.tar.gz anduril-46db889558b953d5a8831c7912bfff4570ae9305.tar.bz2 anduril-46db889558b953d5a8831c7912bfff4570ae9305.zip | |
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.
Diffstat (limited to 'spaghetti-monster/fsm-wdt.c')
| -rw-r--r-- | spaghetti-monster/fsm-wdt.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c index 94266c1..9e8d9af 100644 --- a/spaghetti-monster/fsm-wdt.c +++ b/spaghetti-monster/fsm-wdt.c @@ -150,6 +150,7 @@ void WDT_inner() { // (first frame of a "hold" event) else { if (ticks_since_last >= HOLD_TIMEOUT) { + ticks_since_last_event = 0; current_event |= B_HOLD; emit_current_event(0); } @@ -160,9 +161,8 @@ void WDT_inner() { else if (current_event) { // "hold" event just ended // no timeout required when releasing a long-press - // TODO? move this logic to PCINT() and simplify things here? if (current_event & B_HOLD) { - //emit_current_event(0); // should have been emitted by PCINT_inner() + //emit_current_event(ticks_since_last); // should have been emitted by PCINT_inner() empty_event_sequence(); } // end and clear event after release timeout |
