Improved Debounce for Encoders (#1837)

* Fix variable type declaration

* Fix typo

* Two-bit encoder debouncing

* Slight optimization

* Comment change
This commit is contained in:
Mark Thompson
2024-01-31 14:13:21 -06:00
committed by GitHub
parent f59f5dfaa3
commit a2a5fb166e
5 changed files with 41 additions and 19 deletions

View File

@@ -64,4 +64,16 @@ class Debounce {
bool long_press_occurred_{false}; // TRUE when button is being held down and LONG_PRESS_DELAY has been reached (only when long_press_enabled)
};
class EncoderDebounce {
public:
bool feed(const uint8_t phase_bits); // returns TRUE if state changed after debouncing
uint8_t state(); // returns debounced phase bits from encoder
private:
uint8_t history_{0}; // shift register of previous reads from encoder
uint8_t state_{0}; // actual encoder output state (after debounce logic)
};
#endif /*__DEBOUNCE_H__*/