aboutsummaryrefslogtreecommitdiff
path: root/Debug.h
diff options
context:
space:
mode:
Diffstat (limited to 'Debug.h')
-rw-r--r--Debug.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/Debug.h b/Debug.h
new file mode 100644
index 0000000..1fee5db
--- /dev/null
+++ b/Debug.h
@@ -0,0 +1,79 @@
+#ifndef DEBUG_H
+#define DEBUG_H
+
+#include "config.h"
+
+template <bool enable>
+class DebugImpl {
+public:
+ template<typename T>
+ static inline
+ void print(T t, int format = DEC);
+
+ template<typename T>
+ static inline
+ void print(const T *t);
+
+ template<typename T>
+ static inline
+ void println(T t, int format = DEC);
+
+ template<typename T>
+ static inline
+ void println(const T *t);
+
+ static inline
+ void println();
+};
+
+template<bool enable>
+template<typename T>
+inline
+void DebugImpl<enable>::print(T t, int format) {
+ if (enable) {
+ Serial.print(t, format);
+ }
+}
+
+template<bool enable>
+template<typename T>
+inline
+void DebugImpl<enable>::print(const T *t) {
+ if (enable) {
+ Serial.print(t);
+ }
+}
+
+template<bool enable>
+template<typename T>
+inline
+void DebugImpl<enable>::println(T t, int format) {
+ if (enable) {
+ Serial.println(t, format);
+ }
+}
+
+template<bool enable>
+template<typename T>
+inline
+void DebugImpl<enable>::println(const T *t) {
+ if (enable) {
+ Serial.println(t);
+ }
+}
+
+template<bool enable>
+inline
+void DebugImpl<enable>::println() {
+ if (enable) {
+ Serial.println();
+ }
+}
+
+#if ENABLE_DEBUG_LOG == 1
+typedef DebugImpl<false> Debug;
+#else
+typedef DebugImpl<true> Debug;
+#endif
+
+#endif