diff options
Diffstat (limited to 'platformio/common/include/homekit')
-rw-r--r-- | platformio/common/include/homekit/logging.h | 20 | ||||
-rw-r--r-- | platformio/common/include/homekit/macros.h | 1 | ||||
-rw-r--r-- | platformio/common/include/homekit/stopwatch.h | 30 | ||||
-rw-r--r-- | platformio/common/include/homekit/util.h | 13 |
4 files changed, 64 insertions, 0 deletions
diff --git a/platformio/common/include/homekit/logging.h b/platformio/common/include/homekit/logging.h new file mode 100644 index 0000000..559ca33 --- /dev/null +++ b/platformio/common/include/homekit/logging.h @@ -0,0 +1,20 @@ +#ifndef COMMON_HOMEKIT_LOGGING_H +#define COMMON_HOMEKIT_LOGGING_H + +#include <stdlib.h> + +#ifdef DEBUG + +#define PRINTLN(s) Serial.println(s) +#define PRINT(s) Serial.print(s) +#define PRINTF(fmt, ...) Serial.printf(fmt, ##__VA_ARGS__) + +#else + +#define PRINTLN(s) +#define PRINT(s) +#define PRINTF(...) + +#endif + +#endif //COMMON_HOMEKIT_LOGGING_H
\ No newline at end of file diff --git a/platformio/common/include/homekit/macros.h b/platformio/common/include/homekit/macros.h new file mode 100644 index 0000000..7d3ad83 --- /dev/null +++ b/platformio/common/include/homekit/macros.h @@ -0,0 +1 @@ +#define ARRAY_SIZE(X) sizeof((X))/sizeof((X)[0])
\ No newline at end of file diff --git a/platformio/common/include/homekit/stopwatch.h b/platformio/common/include/homekit/stopwatch.h new file mode 100644 index 0000000..bac2fcc --- /dev/null +++ b/platformio/common/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 diff --git a/platformio/common/include/homekit/util.h b/platformio/common/include/homekit/util.h new file mode 100644 index 0000000..e0780d8 --- /dev/null +++ b/platformio/common/include/homekit/util.h @@ -0,0 +1,13 @@ +#pragma once + +namespace homekit { + +inline size_t otaGetMaxUpdateSize() { + return (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; +} + +inline void restart() { + ESP.restart(); +} + +}
\ No newline at end of file |