Skip to content

Commit 0b9bc1a

Browse files
committed
Extract common functionality 'printTimestamp' in order to reduce code duplication
1 parent 2194004 commit 0b9bc1a

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Diff for: src/Arduino_DebugUtils.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ void Arduino_DebugUtils::print(int const debug_level, const char * fmt, ...)
6565
debug_level <= _debug_level)
6666
{
6767
if (_timestamp_on)
68-
{
69-
char timestamp[20];
70-
snprintf(timestamp, 20, "[ %lu ] ", millis());
71-
_debug_output_stream->print(timestamp);
72-
}
68+
printTimestamp();
7369

7470
va_list args;
7571
va_start(args, fmt);
@@ -85,11 +81,7 @@ void Arduino_DebugUtils::print(int const debug_level, const __FlashStringHelper
8581
debug_level <= _debug_level)
8682
{
8783
if (_timestamp_on)
88-
{
89-
char timestamp[20];
90-
snprintf(timestamp, 20, "[ %lu ] ", millis());
91-
_debug_output_stream->print(timestamp);
92-
}
84+
printTimestamp();
9385

9486
String fmt_str(fmt);
9587

@@ -113,6 +105,13 @@ void Arduino_DebugUtils::vPrint(char const * fmt, va_list args) {
113105
_debug_output_stream->println(msg_buf);
114106
}
115107

108+
void Arduino_DebugUtils::printTimestamp()
109+
{
110+
char timestamp[20];
111+
snprintf(timestamp, 20, "[ %lu ] ", millis());
112+
_debug_output_stream->print(timestamp);
113+
}
114+
116115
/******************************************************************************
117116
CLASS INSTANTIATION
118117
******************************************************************************/

Diff for: src/Arduino_DebugUtils.h

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Arduino_DebugUtils {
6767
Stream * _debug_output_stream;
6868

6969
void vPrint(char const * fmt, va_list args);
70+
void printTimestamp();
7071

7172
};
7273

0 commit comments

Comments
 (0)