diff --git a/README.md b/README.md index 5156760..8f08544 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,26 @@ Debug.timestampOff(); Debug.print(DBG_VERBOSE, "i = %d", i); //Output looks like : i = 21 ``` +### Debug.newlineOn() : +Calling this function ensures that a newline will be sent at the end of the `Debug.print()` function call; +By default, a newline is sent +Return type: void. + +Example: +``` +Debug.newlineOn(); +``` + +### Debug.newlineOff() : +Calling this function ensure that a newline will NOT be sent at the end of the `Debug.print()` function call; +By default a newline is sent. Call this to shut that functionality off. +Return type: void. + +Example: +``` +Debug.timestampOff(); +``` + ### Debug.print(int const debug_level, const char * fmt, ...); This function prints the message if parameter `debug_level` in the `Debug.print(debug_level, ...)` function call belongs to the range: DBG_ERROR <= debug_level <= ( that has been set using `setDebugLevel()` function). diff --git a/src/Arduino_DebugUtils.cpp b/src/Arduino_DebugUtils.cpp index c467a78..b1e3e75 100644 --- a/src/Arduino_DebugUtils.cpp +++ b/src/Arduino_DebugUtils.cpp @@ -34,6 +34,7 @@ static Stream * DEFAULT_OUTPUT_STREAM = &Serial; Arduino_DebugUtils::Arduino_DebugUtils() { timestampOff(); + newlineOn(); setDebugLevel(DEFAULT_DEBUG_LEVEL); setDebugOutputStream(DEFAULT_OUTPUT_STREAM); } @@ -50,6 +51,14 @@ void Arduino_DebugUtils::setDebugOutputStream(Stream * stream) { _debug_output_stream = stream; } +void Arduino_DebugUtils::newlineOn() { + _newline_on = true; +} + +void Arduino_DebugUtils::newlineOff() { + _newline_on = false; +} + void Arduino_DebugUtils::timestampOn() { _timestamp_on = true; } @@ -98,7 +107,11 @@ void Arduino_DebugUtils::vPrint(char const * fmt, va_list args) { vsnprintf(msg_buf, MSG_BUF_SIZE, fmt, args); - _debug_output_stream->println(msg_buf); + if (_newline_on) { + _debug_output_stream->println(msg_buf); + } else { + _debug_output_stream->print(msg_buf); + } } void Arduino_DebugUtils::printTimestamp() diff --git a/src/Arduino_DebugUtils.h b/src/Arduino_DebugUtils.h index a44b5ac..b759534 100644 --- a/src/Arduino_DebugUtils.h +++ b/src/Arduino_DebugUtils.h @@ -56,6 +56,9 @@ class Arduino_DebugUtils { void timestampOn(); void timestampOff(); + void newlineOn(); + void newlineOff(); + void print(int const debug_level, const char * fmt, ...); void print(int const debug_level, const __FlashStringHelper * fmt, ...); @@ -63,6 +66,7 @@ class Arduino_DebugUtils { private: bool _timestamp_on; + bool _newline_on; int _debug_level; Stream * _debug_output_stream;