diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-25 05:12:59 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-25 06:08:19 +0200 |
commit | d317fdb0c737e6b1994da3f01c39937292c1e56f (patch) | |
tree | 665b0744c1bbab4cde2c03321845173366dfdf3a /Debug.h | |
parent | 44c35350f8131e9998274ce4b3194d116250d379 (diff) | |
download | trygvisio_soil_moisture-d317fdb0c737e6b1994da3f01c39937292c1e56f.tar.gz trygvisio_soil_moisture-d317fdb0c737e6b1994da3f01c39937292c1e56f.tar.bz2 trygvisio_soil_moisture-d317fdb0c737e6b1994da3f01c39937292c1e56f.tar.xz trygvisio_soil_moisture-d317fdb0c737e6b1994da3f01c39937292c1e56f.zip |
o Adding a Debug class that delegates to Serial to control where the debug output goes.
Diffstat (limited to 'Debug.h')
-rw-r--r-- | Debug.h | 79 |
1 files changed, 79 insertions, 0 deletions
@@ -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 |