Skip to content

Commit d49fb9b

Browse files
authored
Merge pull request #18 from whyameye/master
add "newlineOn" and "newlineOff" methods
2 parents f84108b + 270c73e commit d49fb9b

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Diff for: README.md

+20
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ Debug.timestampOff();
7878
Debug.print(DBG_VERBOSE, "i = %d", i); //Output looks like : i = 21
7979
```
8080

81+
### Debug.newlineOn() :
82+
Calling this function ensures that a newline will be sent at the end of the `Debug.print()` function call;
83+
By default, a newline is sent
84+
Return type: void.
85+
86+
Example:
87+
```
88+
Debug.newlineOn();
89+
```
90+
91+
### Debug.newlineOff() :
92+
Calling this function ensure that a newline will NOT be sent at the end of the `Debug.print()` function call;
93+
By default a newline is sent. Call this to shut that functionality off.
94+
Return type: void.
95+
96+
Example:
97+
```
98+
Debug.timestampOff();
99+
```
100+
81101

82102
### Debug.print(int const debug_level, const char * fmt, ...);
83103
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 <= (<DBG_LEVEL> that has been set using `setDebugLevel()` function).

Diff for: src/Arduino_DebugUtils.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static Stream * DEFAULT_OUTPUT_STREAM = &Serial;
3434

3535
Arduino_DebugUtils::Arduino_DebugUtils() {
3636
timestampOff();
37+
newlineOn();
3738
setDebugLevel(DEFAULT_DEBUG_LEVEL);
3839
setDebugOutputStream(DEFAULT_OUTPUT_STREAM);
3940
}
@@ -50,6 +51,14 @@ void Arduino_DebugUtils::setDebugOutputStream(Stream * stream) {
5051
_debug_output_stream = stream;
5152
}
5253

54+
void Arduino_DebugUtils::newlineOn() {
55+
_newline_on = true;
56+
}
57+
58+
void Arduino_DebugUtils::newlineOff() {
59+
_newline_on = false;
60+
}
61+
5362
void Arduino_DebugUtils::timestampOn() {
5463
_timestamp_on = true;
5564
}
@@ -98,7 +107,11 @@ void Arduino_DebugUtils::vPrint(char const * fmt, va_list args) {
98107

99108
vsnprintf(msg_buf, MSG_BUF_SIZE, fmt, args);
100109

101-
_debug_output_stream->println(msg_buf);
110+
if (_newline_on) {
111+
_debug_output_stream->println(msg_buf);
112+
} else {
113+
_debug_output_stream->print(msg_buf);
114+
}
102115
}
103116

104117
void Arduino_DebugUtils::printTimestamp()

Diff for: src/Arduino_DebugUtils.h

+4
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ class Arduino_DebugUtils {
5656
void timestampOn();
5757
void timestampOff();
5858

59+
void newlineOn();
60+
void newlineOff();
61+
5962
void print(int const debug_level, const char * fmt, ...);
6063
void print(int const debug_level, const __FlashStringHelper * fmt, ...);
6164

6265

6366
private:
6467

6568
bool _timestamp_on;
69+
bool _newline_on;
6670
int _debug_level;
6771
Stream * _debug_output_stream;
6872

0 commit comments

Comments
 (0)