Browse Source

remove state.h dependency on debouncer.h

Daniel Zanco 1 year ago
parent
commit
7c93eac0bb
2 changed files with 41 additions and 3 deletions
  1. 40 2
      Code/devterm_keyboard/state.h
  2. 1 1
      Code/devterm_keyboard/state.ino

+ 40 - 2
Code/devterm_keyboard/state.h

@@ -5,13 +5,51 @@
 #include <array>
 #include <USBComposite.h>
 
-#include "debouncer.h"
-
 enum class TrackballMode : uint8_t {
   Wheel,
   Mouse,
 };
 
+template <typename T, T millis>
+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:

+ 1 - 1
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);
 }