borrwoed a lot code from https://github.com/foriequal0/devterm_keyboard in order to optimize the trackball

This commit is contained in:
cuu
2021-12-16 20:41:37 +08:00
parent 1a1be01dbb
commit b1370d2124
18 changed files with 538 additions and 118 deletions

View File

@@ -0,0 +1,53 @@
#ifndef DEBOUNCER_H
#define DEBOUNCER_H
#include <cstdint>
typedef uint8_t millis_t;
const millis_t DEBOUNCE_MS = 5;
/**
@brief Asymmetric debouncer
*/
class Debouncer {
public:
Debouncer();
void updateTime(millis_t delta);
bool sample(bool value);
private:
millis_t timeout;
};
template<typename T, T millis>
class Timeout {
public:
Timeout() {
timeout = 0;
}
void updateTime(millis_t delta) {
if (timeout > delta) {
timeout -= delta;
} else {
timeout = 0;
}
}
void expire() {
timeout = 0;
}
bool get() const {
return timeout == 0;
}
void reset() {
timeout = millis;
}
private:
uint16_t timeout;
};
#endif