diff --git a/Code/devterm_keyboard/state.h b/Code/devterm_keyboard/state.h index 8d65173..4b5b6a1 100644 --- a/Code/devterm_keyboard/state.h +++ b/Code/devterm_keyboard/state.h @@ -5,13 +5,51 @@ #include #include -#include "debouncer.h" - enum class TrackballMode : uint8_t { Wheel, Mouse, }; +template +class Timeout +{ +public: + Timeout() + { + timeout = 0; + } + + void updateTime(uint8_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: + T timeout; +}; + class State { public: diff --git a/Code/devterm_keyboard/state.ino b/Code/devterm_keyboard/state.ino index b0fc330..fd85a81 100644 --- a/Code/devterm_keyboard/state.ino +++ b/Code/devterm_keyboard/state.ino @@ -11,7 +11,7 @@ State::State() { } -void State::tick(millis_t delta) +void State::tick(uint8_t delta) { middleClickTimeout.updateTime(delta); }