You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This class provides functionality useful for debugging sketches via `printf`-style statements.
8
+
This class provides functionality useful for debugging sketches via `printf`-style statements with enhanced features including module-based debug levels and runtime configuration.
9
9
10
10
# How-To-Use Basic
11
11
Arduino_DebugUtils has 6 different debug levels (described descending from highest to lowest priority):
@@ -30,14 +30,74 @@ DEBUG_VERBOSE("i = %d, pi = %f", i, pi);
30
30
31
31
If desired, timestamps can be prefixed to the debug message. Timestamp output can be enabled and disabled via `timestampOn` and `timestampOff`.
32
32
33
+
# New Features
34
+
35
+
## Module-Based Debug Levels
36
+
This enhanced version supports up to 20 separate modules, each with its own debug level. This allows for more granular control over debugging output in complex applications.
You can now change debug settings at runtime through the same serial port used for debug output:
54
+
55
+
```
56
+
// Send these commands through serial monitor to change settings
57
+
VERBOSE // or V - Sets global debug level to VERBOSE
58
+
DEBUG // or D - Sets global debug level to DEBUG
59
+
INFO // or I - Sets global debug level to INFO
60
+
WARNING // or W - Sets global debug level to WARNING
61
+
ERROR // or E - Sets global debug level to ERROR
62
+
NONE // or N - Turns off global debug output
63
+
64
+
// Change debug level for a specific module
65
+
3V // Sets module 3's debug level to VERBOSE
66
+
5D // Sets module 5's debug level to DEBUG
67
+
7I // Sets module 7's debug level to INFO
68
+
10W // Sets module 10's debug level to WARNING
69
+
15E // Sets module 15's debug level to ERROR
70
+
20N // Sets module 20's debug level to NONE
71
+
72
+
// Toggle configuration settings
73
+
LABEL // or L - Toggle debug level labels
74
+
TIMESTAMP // or T - Toggle timestamps
75
+
NEWLINE // or C - Toggle newlines
76
+
77
+
// Display current debug status
78
+
STATUS // or S - Display current debug configuration
79
+
```
80
+
81
+
## Enhanced Timestamp Formatting
82
+
Timestamps can now be displayed in a more readable format:
83
+
84
+
```C++
85
+
// Format timestamps as [HH:MM:SS.mmm] instead of milliseconds
86
+
Debug.formatTimestampOn();
87
+
```
88
+
33
89
# How-To-Use Advanced
34
90
Normally all debug output is redirected to the primary serial output of each board (`Serial`). In case you want to redirect the output to another output stream you can make use of `setDebugOutputStream(&Serial2)`.
35
91
36
92
# Documentation
37
93
### Debug :
38
94
Arduino_DebugUtils Object that will be used for calling member functions.
39
95
96
+
## Basic Functions
97
+
40
98
### Debug.setDebugLevel(int const debug_level) :
99
+
Sets the global debug level (module 0).
100
+
41
101
Parameter debug_level in order of lowest to highest priority are : `DBG_NONE`, `DBG_ERROR`, `DBG_WARNING`, `DBG_INFO` (default), `DBG_DEBUG`, and `DBG_VERBOSE`.
42
102
43
103
Return type: void.
@@ -46,6 +106,17 @@ Example:
46
106
```C++
47
107
Debug.setDebugLevel(DBG_VERBOSE);
48
108
```
109
+
110
+
### Debug.getDebugLevel() :
111
+
Returns the current global debug level.
112
+
113
+
Return type: int.
114
+
115
+
Example:
116
+
```C++
117
+
int currentLevel = Debug.getDebugLevel();
118
+
```
119
+
49
120
### Debug.setDebugOutputStream(Stream * stream) :
50
121
By default, Output Stream is Serial. In advanced cases other objects could be other serial ports (if available), or can be a Software Serial object.
51
122
@@ -56,6 +127,17 @@ Example:
56
127
SoftwareSerial mySerial(10, 11); // RX, TX
57
128
Debug.setDebugOutputStream(&mySerial);
58
129
```
130
+
131
+
### Debug.setDebugIOStream(Stream * stream) :
132
+
Sets both the input and output stream for debug messages. This allows receiving configuration commands on the same stream used for debug output.
133
+
134
+
Return type: void.
135
+
136
+
Example:
137
+
```C++
138
+
Debug.setDebugIOStream(&Serial);
139
+
```
140
+
59
141
### Debug.timestampOn() :
60
142
Calling this function switches on the timestamp in the `Debug.print()` function call;
61
143
By default, printing timestamp is off, unless turned on using this function call.
@@ -79,6 +161,27 @@ Debug.timestampOff();
79
161
DEBUG_VERBOSE("i = %d", i); //Output looks like : i = 21
80
162
```
81
163
164
+
### Debug.formatTimestampOn() :
165
+
Calling this function enables formatted timestamps in the format [HH:MM:SS.mmm] instead of milliseconds.
166
+
167
+
Return type: void.
168
+
169
+
Example:
170
+
```C++
171
+
Debug.formatTimestampOn();
172
+
DEBUG_VERBOSE("i = %d", i); //Output looks like : [ 00:01:35.421 ] i = 21
173
+
```
174
+
175
+
### Debug.formatTimestampOff() :
176
+
Calling this function disables formatted timestamps, reverting to milliseconds display.
177
+
178
+
Return type: void.
179
+
180
+
Example:
181
+
```C++
182
+
Debug.formatTimestampOff();
183
+
```
184
+
82
185
### Debug.newlineOn() :
83
186
Calling this function ensures that a newline will be sent at the end of the `Debug.print()` function call;
84
187
By default, a newline is sent
@@ -96,9 +199,28 @@ Return type: void.
96
199
97
200
Example:
98
201
```C++
99
-
Debug.timestampOff();
202
+
Debug.newlineOff();
100
203
```
101
204
205
+
### Debug.debugLabelOn() :
206
+
Calling this function enables display of debug level labels (ERROR, WARNING, etc.) in the output.
207
+
208
+
Return type: void.
209
+
210
+
Example:
211
+
```C++
212
+
Debug.debugLabelOn();
213
+
```
214
+
215
+
### Debug.debugLabelOff() :
216
+
Calling this function disables display of debug level labels in the output.
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).
Prints a debug message for a specific module if the module's debug level is high enough.
329
+
330
+
Parameters:
331
+
- module_id: The ID of the module (1-20)
332
+
- debug_level: The debug level of this message
333
+
- fmt: Printf-style format string
334
+
- ...: Variable arguments for the format string
335
+
336
+
Return type: void.
337
+
338
+
Example:
339
+
```C++
340
+
Debug.print(1, DBG_INFO, "Connected to SSID: %s", ssid);
341
+
```
342
+
343
+
## Runtime Configuration
344
+
345
+
### Debug.processDebugConfigCommand() :
346
+
Checks for and processes any pending debug configuration commands from the input stream.
347
+
348
+
This function should be called regularly in your loop() function to enable runtime configuration. It allows you to change debug settings at runtime by sending commands through the serial monitor, including:
349
+
350
+
- Change global debug level with commands like `VERBOSE`, `DEBUG`, etc.
351
+
- Change module-specific debug levels with commands like `3V` (set module 3 to VERBOSE)
352
+
- Toggle configuration settings with commands like `LABEL`, `TIMESTAMP`, etc.
353
+
- Display current debug status with the `STATUS` command
354
+
355
+
Return type: void.
356
+
357
+
Example:
358
+
```C++
359
+
voidloop() {
360
+
// Process any debug configuration commands
361
+
Debug.processDebugConfigCommand();
362
+
363
+
// Rest of your code
364
+
// ...
365
+
}
366
+
```
367
+
368
+
### Debug.printDebugStatus() :
369
+
Displays the current debug configuration status, including module labels, debug levels, and toggle settings.
0 commit comments