/**************************************************** Simple Debug class to improve debugging in Arduino Written after some very stressful debugging sessions by Alessandro Tornago, free license to everyone. ****************************************************/ #if !defined(DEBUG_H) #define DEBUG_H // comment/uncomment this directive to activate/deactivate debugging // the value corresponds to the pin number associated // with push button for BRK debug command #define DEBUG 17 #if defined(DEBUG) class Debug { private: uint8_t stopPin; // attach a push button on this pin to stop execution until pressed void stop(void); public: Debug(uint8_t StopPin=255) { stopPin = StopPin; if(stopPin!=255) pinMode(stopPin,INPUT_PULLUP); }; void begin(uint16_t speed); void D(const char *txt) { Serial.println(txt); }; void D(const char *txt,const char *t2) { Serial.print(txt); Serial.print(" "); Serial.println(t2); }; void D(const char *txt,int32_t n) { Serial.print(txt); Serial.print(" "); Serial.println(n); }; void D(const char *txt,int32_t s, const uint8_t *buf); void S(void) { stop(); }; void S(const char *txt) { D(txt); stop(); }; void S(const char *t1,const char *t2) { D(t1,t2); stop(); }; void S(const char *t1,int32_t n) { D(t1,n); stop(); }; void S(const char *txt,int32_t s, const uint8_t *buf) { D(txt,s,buf); stop(); } }; extern Debug dd; #define DBGBEGIN(s) dd.begin(s) #define DBGREF Serial.print(__FILE__),Serial.print(":"),Serial.print(__FUNCTION__),Serial.print(":"),Serial.print(__LINE__),Serial.print(" => ") #define BRK(...) DBGREF,dd.S(__VA_ARGS__) #define DBG(...) DBGREF,dd.D(__VA_ARGS__) #else #define DBG(...) #define BRK(...) #define DBGBEGIN(s) #endif // DEBUG #endif // DEBUG_H