summaryrefslogtreecommitdiff
path: root/include/pio/include/homekit/stopwatch.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/pio/include/homekit/stopwatch.h')
-rw-r--r--include/pio/include/homekit/stopwatch.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/include/pio/include/homekit/stopwatch.h b/include/pio/include/homekit/stopwatch.h
new file mode 100644
index 0000000..bac2fcc
--- /dev/null
+++ b/include/pio/include/homekit/stopwatch.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <Arduino.h>
+
+namespace homekit {
+
+class StopWatch {
+private:
+ unsigned long time;
+
+public:
+ StopWatch() : time(0) {};
+
+ inline void save() {
+ time = millis();
+ }
+
+ inline bool elapsed(unsigned long ms) {
+ unsigned long now = millis();
+ if (now < time) {
+ // rollover?
+ time = now;
+ } else if (now - time >= ms) {
+ return true;
+ }
+ return false;
+ }
+};
+
+} \ No newline at end of file