summaryrefslogtreecommitdiff
path: root/platformio/common/include/homekit
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-05-17 04:06:18 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-05-17 04:06:18 +0300
commitc0111bf4d3dd91f54d27346970e4c6e0a1ce357e (patch)
treebeb15167412bc3ed60e3e11e9076d27ea6f437e5 /platformio/common/include/homekit
parent893e21cc83ee1ecf236a005f1bf4893448e9b3ea (diff)
pio: products refactoring
Diffstat (limited to 'platformio/common/include/homekit')
-rw-r--r--platformio/common/include/homekit/logging.h20
-rw-r--r--platformio/common/include/homekit/macros.h1
-rw-r--r--platformio/common/include/homekit/stopwatch.h30
-rw-r--r--platformio/common/include/homekit/util.h13
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