@@ -58,21 +58,34 @@ void Arduino_DebugUtils::timestampOff() {
58
58
_timestamp_on = false ;
59
59
}
60
60
61
- void Arduino_DebugUtils::print (int const debug_level, const char * fmt, ...) {
62
- if (debug_level >= DBG_ERROR &&
63
- debug_level <= DBG_VERBOSE &&
64
- debug_level <= _debug_level) {
65
- if (_timestamp_on) {
66
- char timestamp[20 ];
67
- snprintf (timestamp, 20 , " [ %lu ] " , millis ());
68
- _debug_output_stream->print (timestamp);
69
- }
70
-
71
- va_list args;
72
- va_start (args, fmt);
73
- vPrint (fmt, args);
74
- va_end (args);
75
- }
61
+ void Arduino_DebugUtils::print (int const debug_level, const char * fmt, ...)
62
+ {
63
+ if (!shouldPrint (debug_level))
64
+ return ;
65
+
66
+ if (_timestamp_on)
67
+ printTimestamp ();
68
+
69
+ va_list args;
70
+ va_start (args, fmt);
71
+ vPrint (fmt, args);
72
+ va_end (args);
73
+ }
74
+
75
+ void Arduino_DebugUtils::print (int const debug_level, const __FlashStringHelper * fmt, ...)
76
+ {
77
+ if (!shouldPrint (debug_level))
78
+ return ;
79
+
80
+ if (_timestamp_on)
81
+ printTimestamp ();
82
+
83
+ String fmt_str (fmt);
84
+
85
+ va_list args;
86
+ va_start (args, fmt_str.c_str ());
87
+ vPrint (fmt_str.c_str (), args);
88
+ va_end (args);
76
89
}
77
90
78
91
/* *****************************************************************************
@@ -88,6 +101,18 @@ void Arduino_DebugUtils::vPrint(char const * fmt, va_list args) {
88
101
_debug_output_stream->println (msg_buf);
89
102
}
90
103
104
+ void Arduino_DebugUtils::printTimestamp ()
105
+ {
106
+ char timestamp[20 ];
107
+ snprintf (timestamp, 20 , " [ %lu ] " , millis ());
108
+ _debug_output_stream->print (timestamp);
109
+ }
110
+
111
+ bool Arduino_DebugUtils::shouldPrint (int const debug_level) const
112
+ {
113
+ return ((debug_level >= DBG_ERROR) && (debug_level <= DBG_VERBOSE) && (debug_level <= _debug_level));
114
+ }
115
+
91
116
/* *****************************************************************************
92
117
CLASS INSTANTIATION
93
118
******************************************************************************/
0 commit comments