From 0aba139aeff8ff80757c5d36502413299a0b449e Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Thu, 11 May 2023 04:18:08 +0300 Subject: mqtt, esp: add new esp8266-based device --- platformio/temphum/src/stopwatch.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 platformio/temphum/src/stopwatch.h (limited to 'platformio/temphum/src/stopwatch.h') diff --git a/platformio/temphum/src/stopwatch.h b/platformio/temphum/src/stopwatch.h new file mode 100644 index 0000000..bac2fcc --- /dev/null +++ b/platformio/temphum/src/stopwatch.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +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 -- cgit v1.2.3