From d317fdb0c737e6b1994da3f01c39937292c1e56f Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 25 Jul 2015 05:12:59 +0200 Subject: o Adding a Debug class that delegates to Serial to control where the debug output goes. --- Debug.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Debug.h (limited to 'Debug.h') 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 +class DebugImpl { +public: + template + static inline + void print(T t, int format = DEC); + + template + static inline + void print(const T *t); + + template + static inline + void println(T t, int format = DEC); + + template + static inline + void println(const T *t); + + static inline + void println(); +}; + +template +template +inline +void DebugImpl::print(T t, int format) { + if (enable) { + Serial.print(t, format); + } +} + +template +template +inline +void DebugImpl::print(const T *t) { + if (enable) { + Serial.print(t); + } +} + +template +template +inline +void DebugImpl::println(T t, int format) { + if (enable) { + Serial.println(t, format); + } +} + +template +template +inline +void DebugImpl::println(const T *t) { + if (enable) { + Serial.println(t); + } +} + +template +inline +void DebugImpl::println() { + if (enable) { + Serial.println(); + } +} + +#if ENABLE_DEBUG_LOG == 1 +typedef DebugImpl Debug; +#else +typedef DebugImpl Debug; +#endif + +#endif -- cgit v1.2.3