Skip to content

Commit b46cd4a

Browse files
committed
Update README.md with documentation for new features including module-specific debug levels
1 parent f5e4dc8 commit b46cd4a

File tree

1 file changed

+274
-2
lines changed

1 file changed

+274
-2
lines changed

Diff for: README.md

+274-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Arduino_DebugUtils
55
[![Compile Examples status](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/compile-examples.yml)
66
[![Spell Check status](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/spell-check.yml)
77

8-
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.
99

1010
# How-To-Use Basic
1111
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);
3030
3131
If desired, timestamps can be prefixed to the debug message. Timestamp output can be enabled and disabled via `timestampOn` and `timestampOff`.
3232
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.
37+
38+
```C++
39+
// Set debug level for a specific module (1-20)
40+
Debug.setDebugLevel(1, DBG_VERBOSE); // Module 1 gets verbose output
41+
Debug.setDebugLevel(2, DBG_WARNING); // Module 2 only shows warnings and errors
42+
43+
// Set a label for each module
44+
Debug.setModuleLabel(1, "WIFI");
45+
Debug.setModuleLabel(2, "SENSOR");
46+
47+
// Print debug message for a specific module
48+
Debug.print(1, DBG_INFO, "Connected to SSID: %s", ssid); // Module 1 (WIFI) info
49+
Debug.print(2, DBG_ERROR, "Sensor reading failed: %d", errorCode); // Module 2 (SENSOR) error
50+
```
51+
52+
## Runtime Configuration via Serial
53+
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+
3389
# How-To-Use Advanced
3490
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)`.
3591

3692
# Documentation
3793
### Debug :
3894
Arduino_DebugUtils Object that will be used for calling member functions.
3995

96+
## Basic Functions
97+
4098
### Debug.setDebugLevel(int const debug_level) :
99+
Sets the global debug level (module 0).
100+
41101
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`.
42102

43103
Return type: void.
@@ -46,6 +106,17 @@ Example:
46106
```C++
47107
Debug.setDebugLevel(DBG_VERBOSE);
48108
```
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+
49120
### Debug.setDebugOutputStream(Stream * stream) :
50121
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.
51122

@@ -56,6 +127,17 @@ Example:
56127
SoftwareSerial mySerial(10, 11); // RX, TX
57128
Debug.setDebugOutputStream(&mySerial);
58129
```
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+
59141
### Debug.timestampOn() :
60142
Calling this function switches on the timestamp in the `Debug.print()` function call;
61143
By default, printing timestamp is off, unless turned on using this function call.
@@ -79,6 +161,27 @@ Debug.timestampOff();
79161
DEBUG_VERBOSE("i = %d", i); //Output looks like : i = 21
80162
```
81163

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+
82185
### Debug.newlineOn() :
83186
Calling this function ensures that a newline will be sent at the end of the `Debug.print()` function call;
84187
By default, a newline is sent
@@ -96,9 +199,28 @@ Return type: void.
96199

97200
Example:
98201
```C++
99-
Debug.timestampOff();
202+
Debug.newlineOff();
100203
```
101204

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.
217+
218+
Return type: void.
219+
220+
Example:
221+
```C++
222+
Debug.debugLabelOff();
223+
```
102224

103225
### Debug.print(int const debug_level, const char * fmt, ...);
104226
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).
@@ -111,3 +233,153 @@ Debug.setDebugLevel(DBG_VERBOSE);
111233
int i = 0;
112234
DEBUG_VERBOSE("DBG_VERBOSE i = %d", i);
113235
```
236+
237+
## Module-Based Debug Functions
238+
239+
### Debug.setDebugLevel(int const module_id, int const debug_level) :
240+
Sets the debug level for a specific module.
241+
242+
Parameters:
243+
- module_id: The ID of the module (1-20)
244+
- debug_level: The debug level to set
245+
246+
Return type: void.
247+
248+
Example:
249+
```C++
250+
Debug.setDebugLevel(1, DBG_VERBOSE); // Set module 1 to verbose level
251+
```
252+
253+
### Debug.setDebugLevelAll(int const debug_level) :
254+
Sets the same debug level for all modules, including the global module.
255+
256+
Parameter:
257+
- debug_level: The debug level to set for all modules
258+
259+
Return type: void.
260+
261+
Example:
262+
```C++
263+
Debug.setDebugLevelAll(DBG_WARNING); // Set all modules to warning level
264+
```
265+
266+
### Debug.getDebugLevel(int const module_id) :
267+
Returns the current debug level for a specific module.
268+
269+
Parameter:
270+
- module_id: The ID of the module to query
271+
272+
Return type: int.
273+
274+
Example:
275+
```C++
276+
int moduleLevel = Debug.getDebugLevel(1);
277+
```
278+
279+
### Debug.setModuleLabel(int const module_id, const char* label) :
280+
Sets a descriptive label for a specific module.
281+
282+
Parameters:
283+
- module_id: The ID of the module (1-20)
284+
- label: A string label for the module (max 10 characters by default)
285+
286+
Return type: void.
287+
288+
Example:
289+
```C++
290+
Debug.setModuleLabel(1, "WIFI");
291+
Debug.setModuleLabel(2, "SENSOR");
292+
```
293+
294+
### Debug.getModuleLabel(int const module_id) :
295+
Returns the label for a specific module.
296+
297+
Parameter:
298+
- module_id: The ID of the module to query
299+
300+
Return type: String.
301+
302+
Example:
303+
```C++
304+
String label = Debug.getModuleLabel(1); // Returns "WIFI"
305+
```
306+
307+
### Debug.moduleLabelsOn() :
308+
Enables display of module labels in debug output.
309+
310+
Return type: void.
311+
312+
Example:
313+
```C++
314+
Debug.moduleLabelsOn();
315+
```
316+
317+
### Debug.moduleLabelsOff() :
318+
Disables display of module labels in debug output.
319+
320+
Return type: void.
321+
322+
Example:
323+
```C++
324+
Debug.moduleLabelsOff();
325+
```
326+
327+
### Debug.print(int const module_id, int const debug_level, const char * fmt, ...);
328+
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+
void loop() {
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.
370+
371+
Return type: void.
372+
373+
Example:
374+
```C++
375+
Debug.printDebugStatus();
376+
// Output looks like:
377+
// Debug Status:
378+
// Module Label Level
379+
// 0 GLOBAL VERBOSE
380+
// 1 WIFI INFO
381+
// 2 SENSOR WARNING
382+
// Show Level: on (toggle with L)
383+
// Timestamps: on (toggle with T)
384+
// New Lines : on (toggle with C)
385+
```

0 commit comments

Comments
 (0)