From afd694f05178c22b4f71f65143c4647ce912d980 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 26 Jul 2015 18:06:29 +0200 Subject: o Much improved Debug class. - Inlining all definitions to make everything shorter and easier to read. - More const so even more can be inlined. o Adding some support for ATTiny85, still more work to be done. o Removing two unused battery characteristics. o Dynamically adding battery and temperature characteristics if their pipes are defined. --- Debug.h | 173 +++++++++++++++++++++++++--------------------------------------- 1 file changed, 67 insertions(+), 106 deletions(-) (limited to 'Debug.h') diff --git a/Debug.h b/Debug.h index 4485afd..a70a144 100644 --- a/Debug.h +++ b/Debug.h @@ -12,138 +12,99 @@ enum DebugSink { template class Debug { public: - inline void begin(unsigned int baud_rate); + inline void begin(const long baud_rate) const { + if (sink == DEBUG_SINK_SERIAL) { + Serial.begin(baud_rate); + } + } + + inline bool operator!() const { + return !available(); + }; - inline operator bool(); + inline bool available() const { + if (sink == DEBUG_SINK_SERIAL) { + return Serial.available(); + } - inline bool available(); + return false; + }; - size_t write(uint8_t); + 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); + void print(T t, int format = DEC) const { + if (sink == DEBUG_SINK_SERIAL) { + Serial.print(t, format); + } + }; + template inline - void print(const char *t); + void print(const T *t) const { + if (sink == DEBUG_SINK_SERIAL) { + Serial.print(t); + } + }; + template inline - void print(const __FlashStringHelper *t); + void print(T *t) const { + if (sink == DEBUG_SINK_SERIAL) { + Serial.print(t); + } + }; template inline - void println(T t, int format = DEC); + void println(T t, int format = DEC) const { + if (sink == DEBUG_SINK_SERIAL) { + Serial.println(t, format); + } + }; template inline - void println(const T *t); + void println(const T *t) const { + if (sink == DEBUG_SINK_SERIAL) { + Serial.println(t); + } + }; + template inline - void println(const __FlashStringHelper *t); + void println(T *t) const { + if (sink == DEBUG_SINK_SERIAL) { + Serial.println(t); + } + }; inline - void println(); + void println() const { + if (sink == DEBUG_SINK_SERIAL) { + Serial.println(); + } + }; inline - void flush(); + void flush() { + if (sink == DEBUG_SINK_SERIAL) { + Serial.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; +static const Debug debug; #elif DEBUG_SINK == 2 -static Debug debug; +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. -- cgit v1.2.3