|
25 | 25 | NAMESPACE
|
26 | 26 | ******************************************************************************/
|
27 | 27 |
|
28 |
| -namespace impl |
29 |
| -{ |
| 28 | +namespace impl { |
30 | 29 |
|
31 |
| -/****************************************************************************** |
32 |
| - CONSTANTS |
33 |
| - ******************************************************************************/ |
| 30 | + /****************************************************************************** |
| 31 | + CONSTANTS |
| 32 | + ******************************************************************************/ |
34 | 33 |
|
35 |
| -static int const DEFAULT_DEBUG_LEVEL = DEBUG_LVL_INFO; |
36 |
| -static Stream * DEFAULT_OUTPUT_STREAM = &Serial; |
| 34 | + static int const DEFAULT_DEBUG_LEVEL = DEBUG_LVL_INFO; |
| 35 | + static Stream * DEFAULT_OUTPUT_STREAM = &Serial; |
37 | 36 |
|
38 |
| -/****************************************************************************** |
39 |
| - CTOR/DTOR |
40 |
| - ******************************************************************************/ |
| 37 | + /****************************************************************************** |
| 38 | + CTOR/DTOR |
| 39 | + ******************************************************************************/ |
41 | 40 |
|
42 |
| -ArduinoDebugUtils::ArduinoDebugUtils() |
43 |
| -{ |
44 |
| - timestampOff(); |
45 |
| - setDebugLevel(DEFAULT_DEBUG_LEVEL); |
46 |
| - setDebugOutputStream(DEFAULT_OUTPUT_STREAM); |
47 |
| -} |
| 41 | + ArduinoDebugUtils::ArduinoDebugUtils() { |
| 42 | + timestampOff(); |
| 43 | + setDebugLevel(DEFAULT_DEBUG_LEVEL); |
| 44 | + setDebugOutputStream(DEFAULT_OUTPUT_STREAM); |
| 45 | + } |
48 | 46 |
|
49 |
| -/****************************************************************************** |
50 |
| - PUBLIC MEMBER FUNCTIONS |
51 |
| - ******************************************************************************/ |
| 47 | + /****************************************************************************** |
| 48 | + PUBLIC MEMBER FUNCTIONS |
| 49 | + ******************************************************************************/ |
52 | 50 |
|
53 |
| -void ArduinoDebugUtils::setDebugLevel(int const debug_level) |
54 |
| -{ |
55 |
| - _debug_level = debug_level; |
56 |
| -} |
57 |
| - |
58 |
| -void ArduinoDebugUtils::setDebugOutputStream(Stream * stream) |
59 |
| -{ |
60 |
| - _debug_output_stream = stream; |
61 |
| -} |
62 |
| - |
63 |
| -void ArduinoDebugUtils::timestampOn() |
64 |
| -{ |
65 |
| - _timestamp_on = true; |
66 |
| -} |
67 |
| - |
68 |
| -void ArduinoDebugUtils::timestampOff() |
69 |
| -{ |
70 |
| - _timestamp_on = false; |
71 |
| -} |
72 |
| - |
73 |
| -void ArduinoDebugUtils::debugPrint(int const debug_level, const char * fmt, ...) |
74 |
| -{ |
75 |
| - if (debug_level >= DEBUG_LVL_ERROR && |
76 |
| - debug_level <= DEBUG_LVL_VERBOSE && |
77 |
| - debug_level <= _debug_level) |
78 |
| - { |
79 |
| - if(_timestamp_on) |
80 |
| - { |
81 |
| - char timestamp[20]; |
82 |
| - snprintf(timestamp, 20, "[ %lu ] ", millis()); |
83 |
| - _debug_output_stream->print(timestamp); |
84 |
| - } |
| 51 | + void ArduinoDebugUtils::setDebugLevel(int const debug_level) { |
| 52 | + _debug_level = debug_level; |
| 53 | + } |
85 | 54 |
|
86 |
| - va_list args; |
87 |
| - va_start(args, fmt); |
88 |
| - vDebugPrint(fmt, args); |
89 |
| - va_end(args); |
| 55 | + void ArduinoDebugUtils::setDebugOutputStream(Stream * stream) { |
| 56 | + _debug_output_stream = stream; |
90 | 57 | }
|
91 |
| -} |
92 | 58 |
|
93 |
| -/****************************************************************************** |
94 |
| - PRIVATE MEMBER FUNCTIONS |
95 |
| - ******************************************************************************/ |
| 59 | + void ArduinoDebugUtils::timestampOn() { |
| 60 | + _timestamp_on = true; |
| 61 | + } |
96 | 62 |
|
97 |
| -void ArduinoDebugUtils::vDebugPrint(char const * fmt, va_list args) |
98 |
| -{ |
99 |
| - static size_t const MSG_BUF_SIZE = 120; |
100 |
| - char msg_buf[MSG_BUF_SIZE] = {0}; |
| 63 | + void ArduinoDebugUtils::timestampOff() { |
| 64 | + _timestamp_on = false; |
| 65 | + } |
101 | 66 |
|
102 |
| - vsnprintf(msg_buf, MSG_BUF_SIZE, fmt, args); |
| 67 | + void ArduinoDebugUtils::debugPrint(int const debug_level, const char * fmt, ...) { |
| 68 | + if (debug_level >= DEBUG_LVL_ERROR && |
| 69 | + debug_level <= DEBUG_LVL_VERBOSE && |
| 70 | + debug_level <= _debug_level) { |
| 71 | + if (_timestamp_on) { |
| 72 | + char timestamp[20]; |
| 73 | + snprintf(timestamp, 20, "[ %lu ] ", millis()); |
| 74 | + _debug_output_stream->print(timestamp); |
| 75 | + } |
| 76 | + |
| 77 | + va_list args; |
| 78 | + va_start(args, fmt); |
| 79 | + vDebugPrint(fmt, args); |
| 80 | + va_end(args); |
| 81 | + } |
| 82 | + } |
103 | 83 |
|
104 |
| - _debug_output_stream->println(msg_buf); |
105 |
| -} |
| 84 | + /****************************************************************************** |
| 85 | + PRIVATE MEMBER FUNCTIONS |
| 86 | + ******************************************************************************/ |
106 | 87 |
|
107 |
| -/****************************************************************************** |
108 |
| - NAMESPACE |
109 |
| - ******************************************************************************/ |
| 88 | + void ArduinoDebugUtils::vDebugPrint(char const * fmt, va_list args) { |
| 89 | + static size_t const MSG_BUF_SIZE = 120; |
| 90 | + char msg_buf[MSG_BUF_SIZE] = {0}; |
| 91 | + |
| 92 | + vsnprintf(msg_buf, MSG_BUF_SIZE, fmt, args); |
| 93 | + |
| 94 | + _debug_output_stream->println(msg_buf); |
| 95 | + } |
| 96 | + |
| 97 | + /****************************************************************************** |
| 98 | + NAMESPACE |
| 99 | + ******************************************************************************/ |
110 | 100 |
|
111 | 101 | } /* impl */
|
112 | 102 |
|
|
0 commit comments