mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-07-23 23:11:28 -04:00
* Fix debounce to handle noisy switch transitions * Fix debounce to handle noisy switch transitions * Fix debounce to handle noisy switch transitions * Removed inline comment to see if Clang checker will be happy * Test fix for supposed Clang formatting issue
This commit is contained in:
parent
be1b2716d6
commit
4d1269051b
2 changed files with 19 additions and 8 deletions
|
@ -23,17 +23,24 @@
|
|||
|
||||
#include "utility.hpp"
|
||||
|
||||
// Returns TRUE if button state changed (after debouncing)
|
||||
bool Debounce::feed(const uint8_t bit) {
|
||||
history_ = (history_ << 1) | (bit & 1);
|
||||
|
||||
if (history_ == 0b00001111) {
|
||||
state_ = 1;
|
||||
return true;
|
||||
if (state_ == 0) {
|
||||
// Previous button state was 0 (released);
|
||||
// Has button been held for DEBOUNCE_COUNT ticks?
|
||||
if ((history_ & DEBOUNCE_MASK) == DEBOUNCE_MASK) {
|
||||
state_ = 1;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// Previous button state was 1 (pressed);
|
||||
// Has button been released for DEBOUNCE_COUNT ticks?
|
||||
if ((history_ & DEBOUNCE_MASK) == 0) {
|
||||
state_ = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (history_ == 0b11110000) {
|
||||
state_ = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue