diff options
author | Daniel Friesel <derf@finalrewind.org> | 2016-03-17 18:56:01 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2016-03-17 18:56:01 +0100 |
commit | 86c7c308e85bbde06fe298414bb23963f44b6cf5 (patch) | |
tree | cc614d7c6e122f347abdc5b43c6cb1f99352b514 /src/system.cc | |
parent | 092f52f813dbec9269e0b35bd984209afaf1a8d5 (diff) |
add software debouncing in the animation switcher
Diffstat (limited to 'src/system.cc')
-rw-r--r-- | src/system.cc | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/src/system.cc b/src/system.cc index e7c12ff..2d019e1 100644 --- a/src/system.cc +++ b/src/system.cc @@ -241,30 +241,37 @@ void System::loop() want_shutdown = 0; } - if ((PINC & _BV(PC3)) == 0) { - btnMask = (ButtonMask)(btnMask | BUTTON_RIGHT); - } - if ((PINC & _BV(PC7)) == 0) { - btnMask = (ButtonMask)(btnMask | BUTTON_LEFT); - } - - /* - * Only handle button presses when they are released to avoid - * double actions, such as switching to the next/previous pattern - * when the user actually wants to press the shutdown combo. - */ - if ((PINC & (_BV(PC3) | _BV(PC7))) == (_BV(PC3) | _BV(PC7))) { - if (btnMask == BUTTON_RIGHT) { - current_anim_no = (current_anim_no + 1) % storage.numPatterns(); - loadPattern(current_anim_no); - } else if (btnMask == BUTTON_LEFT) { - if (current_anim_no == 0) - current_anim_no = storage.numPatterns() - 1; - else - current_anim_no--; - loadPattern(current_anim_no); + if (btn_debounce == 0) { + if ((PINC & _BV(PC3)) == 0) { + btnMask = (ButtonMask)(btnMask | BUTTON_RIGHT); + } + if ((PINC & _BV(PC7)) == 0) { + btnMask = (ButtonMask)(btnMask | BUTTON_LEFT); } - btnMask = BUTTON_NONE; + /* + * Only handle button presses when they are released to avoid + * double actions, such as switching to the next/previous pattern + * when the user actually wants to press the shutdown combo. + */ + if ((PINC & (_BV(PC3) | _BV(PC7))) == (_BV(PC3) | _BV(PC7))) { + if (btnMask == BUTTON_RIGHT) { + current_anim_no = (current_anim_no + 1) % storage.numPatterns(); + loadPattern(current_anim_no); + } else if (btnMask == BUTTON_LEFT) { + if (current_anim_no == 0) + current_anim_no = storage.numPatterns() - 1; + else + current_anim_no--; + loadPattern(current_anim_no); + } + btnMask = BUTTON_NONE; + /* + * Ignore keypresses for 25ms to work around bouncing buttons + */ + btn_debounce = 100; + } + } else { + btn_debounce--; } while (modem.buffer_available()) { |