diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-26 18:06:29 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-26 19:27:13 +0200 |
commit | afd694f05178c22b4f71f65143c4647ce912d980 (patch) | |
tree | bde5b59098c453a4355f63eaaabdf95f9e2679bb /Debug.h | |
parent | a64156388fc92da1d151a1094e25d9d89240bb38 (diff) | |
download | trygvisio_soil_moisture-afd694f05178c22b4f71f65143c4647ce912d980.tar.gz trygvisio_soil_moisture-afd694f05178c22b4f71f65143c4647ce912d980.tar.bz2 trygvisio_soil_moisture-afd694f05178c22b4f71f65143c4647ce912d980.tar.xz trygvisio_soil_moisture-afd694f05178c22b4f71f65143c4647ce912d980.zip |
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.
Diffstat (limited to 'Debug.h')
-rw-r--r-- | Debug.h | 173 |
1 files changed, 67 insertions, 106 deletions
@@ -12,138 +12,99 @@ enum DebugSink { template <enum DebugSink sink> 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<typename T> 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<typename T> inline - void print(const char *t); + void print(const T *t) const { + if (sink == DEBUG_SINK_SERIAL) { + Serial.print(t); + } + }; + template<typename T> inline - void print(const __FlashStringHelper *t); + void print(T *t) const { + if (sink == DEBUG_SINK_SERIAL) { + Serial.print(t); + } + }; template<typename T> 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<typename T> inline - void println(const T *t); + void println(const T *t) const { + if (sink == DEBUG_SINK_SERIAL) { + Serial.println(t); + } + }; + template<typename T> 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<enum DebugSink sink> -inline void Debug<sink>::begin(unsigned int baud_rate) { - if (sink == DEBUG_SINK_SERIAL) { - Serial.begin(baud_rate); - } -} - -template<enum DebugSink sink> -inline Debug<sink>::operator bool() { - if (sink == DEBUG_SINK_SERIAL) { - return Serial; - } - - return false; -} - -template<enum DebugSink sink> -inline bool Debug<sink>::available() { - if (sink == DEBUG_SINK_SERIAL) { - return Serial.available(); - } - - return false; -} - -template<enum DebugSink sink> -inline size_t Debug<sink>::write(uint8_t value) { - if (sink == DEBUG_SINK_SERIAL) { - return Serial.write(value); - } - - return 0; -} - -template<enum DebugSink sink> -template<typename T> -inline -void Debug<sink>::print(T t, int format) { - if (sink == DEBUG_SINK_SERIAL) { - Serial.print(t, format); - } -} - -template<enum DebugSink sink> -inline -void Debug<sink>::print(const char *t) { - if (sink == DEBUG_SINK_SERIAL) { - Serial.print(t); - } -} -template<enum DebugSink sink> -inline -void Debug<sink>::print(const __FlashStringHelper *t) { - if (sink == DEBUG_SINK_SERIAL) { - Serial.print(t); - } -} - -template<enum DebugSink sink> -template<typename T> -inline -void Debug<sink>::println(T t, int format) { - if (sink == DEBUG_SINK_SERIAL) { - Serial.println(t, format); - } -} - -template<enum DebugSink sink> -template<typename T> -inline -void Debug<sink>::println(const T *t) { - if (sink == DEBUG_SINK_SERIAL) { - Serial.println(t); - } -} - -template<enum DebugSink sink> -inline -void Debug<sink>::println(const __FlashStringHelper *t) { - if (sink == DEBUG_SINK_SERIAL) { - Serial.println(t); - } -} - -template<enum DebugSink sink> -inline -void Debug<sink>::println() { - if (sink == DEBUG_SINK_SERIAL) { - Serial.println(); - } -} - #if DEBUG_SINK == 1 -static Debug<DEBUG_SINK_VOID> debug; +static const Debug<DEBUG_SINK_VOID> debug; #elif DEBUG_SINK == 2 -static Debug<DEBUG_SINK_SERIAL> debug; +static const Debug<DEBUG_SINK_SERIAL> 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. |