#ifndef DEBUG_H #define DEBUG_H #include "config-check.h" enum DebugSink { DEBUG_SINK_SERIAL, DEBUG_SINK_SOFTWARE_SERIAL, DEBUG_SINK_VOID, }; template class Debug { public: inline void begin(unsigned int baud_rate); inline operator bool(); inline bool available(); size_t write(uint8_t); template inline void print(T t, int format = DEC); inline void print(const char *t); inline void print(const __FlashStringHelper *t); template inline void println(T t, int format = DEC); template inline void println(const T *t); inline void println(const __FlashStringHelper *t); inline void println(); inline void flush(); }; template inline void Debug::begin(unsigned int baud_rate) { if (sink == DEBUG_SINK_SERIAL) { Serial.begin(baud_rate); } } template inline Debug::operator bool() { if (sink == DEBUG_SINK_SERIAL) { return Serial; } return false; } template inline bool Debug::available() { if (sink == DEBUG_SINK_SERIAL) { return Serial.available(); } return false; } template inline size_t Debug::write(uint8_t value) { if (sink == DEBUG_SINK_SERIAL) { return Serial.write(value); } return 0; } template template inline void Debug::print(T t, int format) { if (sink == DEBUG_SINK_SERIAL) { Serial.print(t, format); } } template inline void Debug::print(const char *t) { if (sink == DEBUG_SINK_SERIAL) { Serial.print(t); } } template inline void Debug::print(const __FlashStringHelper *t) { if (sink == DEBUG_SINK_SERIAL) { Serial.print(t); } } template template inline void Debug::println(T t, int format) { if (sink == DEBUG_SINK_SERIAL) { Serial.println(t, format); } } template template inline void Debug::println(const T *t) { if (sink == DEBUG_SINK_SERIAL) { Serial.println(t); } } template inline void Debug::println(const __FlashStringHelper *t) { if (sink == DEBUG_SINK_SERIAL) { Serial.println(t); } } template inline void Debug::println() { if (sink == DEBUG_SINK_SERIAL) { Serial.println(); } } #if DEBUG_SINK == 1 static Debug debug; #elif DEBUG_SINK == 2 static Debug debug; #else #error Invalid value for DEBUG_SINK, must be one of 1 (for no output), 2 for serial port // , or 3 for software serial. #endif #endif