#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(const long baud_rate) const { if (sink == DEBUG_SINK_SERIAL) { Serial.begin(baud_rate); } } inline bool operator!() const { return !available(); }; inline bool available() const { if (sink == DEBUG_SINK_SERIAL) { return Serial.available(); } return false; }; size_t write(uint8_t value) const { if (sink == DEBUG_SINK_SERIAL) { Serial.write(value); } return value; } template inline void print(T t, int format = DEC) const { if (sink == DEBUG_SINK_SERIAL) { Serial.print(t, format); } }; template inline void print(const T *t) const { if (sink == DEBUG_SINK_SERIAL) { Serial.print(t); } }; template inline void print(T *t) const { if (sink == DEBUG_SINK_SERIAL) { Serial.print(t); } }; template inline void println(T t, int format = DEC) const { if (sink == DEBUG_SINK_SERIAL) { Serial.println(t, format); } }; template inline void println(const T *t) const { if (sink == DEBUG_SINK_SERIAL) { Serial.println(t); } }; template inline void println(T *t) const { if (sink == DEBUG_SINK_SERIAL) { Serial.println(t); } }; inline void println() const { if (sink == DEBUG_SINK_SERIAL) { Serial.println(); } }; inline void flush() { if (sink == DEBUG_SINK_SERIAL) { Serial.flush(); } }; }; #if DEBUG_SINK == 1 static const Debug debug; #elif DEBUG_SINK == 2 static const 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