From d50c46d08a6d7f52dffb9b43784c62b11d78df8c Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 11 Dec 2017 19:56:15 -0700 Subject: Greatly improved button debouncing. Helps a lot on FW3A and my light saber. Debouncing isn't 100% yet though. --- spaghetti-monster/fsm-pcint.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'spaghetti-monster/fsm-pcint.c') diff --git a/spaghetti-monster/fsm-pcint.c b/spaghetti-monster/fsm-pcint.c index 763c1fe..c04375a 100644 --- a/spaghetti-monster/fsm-pcint.c +++ b/spaghetti-monster/fsm-pcint.c @@ -59,10 +59,25 @@ ISR(PCINT0_vect) { //DEBUG_FLASH; - uint8_t pushed; + /* + uint8_t pressed; // add event to current sequence - if (button_is_pressed()) { + pressed = button_is_pressed(); + PCINT_inner(pressed); + */ + if (! PCINT_since_WDT) { + PCINT_since_WDT = 1; + PCINT_inner(button_is_pressed()); + } +} + +// should only be called from PCINT and WDT +// (is a separate function to reduce code duplication) +void PCINT_inner(uint8_t pressed) { + uint8_t pushed; + + if (pressed) { pushed = push_event(A_PRESS); } else { pushed = push_event(A_RELEASE); @@ -70,7 +85,9 @@ ISR(PCINT0_vect) { // check if sequence matches any defined sequences // if so, send event to current state callback - if (pushed) emit_current_event(0); + if (pushed) { + button_last_state = pressed; + emit_current_event(0); + } } - #endif -- cgit v1.2.3