mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-02-10 03:38:50 -05: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
@ -23,17 +23,24 @@
|
|||||||
|
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
|
// Returns TRUE if button state changed (after debouncing)
|
||||||
bool Debounce::feed(const uint8_t bit) {
|
bool Debounce::feed(const uint8_t bit) {
|
||||||
history_ = (history_ << 1) | (bit & 1);
|
history_ = (history_ << 1) | (bit & 1);
|
||||||
|
|
||||||
if (history_ == 0b00001111) {
|
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;
|
state_ = 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (history_ == 0b11110000) {
|
} else {
|
||||||
|
// Previous button state was 1 (pressed);
|
||||||
|
// Has button been released for DEBOUNCE_COUNT ticks?
|
||||||
|
if ((history_ & DEBOUNCE_MASK) == 0) {
|
||||||
state_ = 0;
|
state_ = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,10 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
// consecutive # of times button input must be same (<=8)
|
||||||
|
#define DEBOUNCE_COUNT 4
|
||||||
|
#define DEBOUNCE_MASK ((1 << DEBOUNCE_COUNT) - 1)
|
||||||
|
|
||||||
class Debounce {
|
class Debounce {
|
||||||
public:
|
public:
|
||||||
bool feed(const uint8_t bit);
|
bool feed(const uint8_t bit);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user