Skip to content

Commit b9ea49b

Browse files
committed
Merge addmodules branch into master
2 parents 2620270 + b46cd4a commit b9ea49b

File tree

3 files changed

+773
-143
lines changed

3 files changed

+773
-143
lines changed

Diff for: README.md

+246-53
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Arduino_DebugUtils
22
==================
33

4-
[![Check Arduino status](https://github.com/robroypt/Arduino_DebugUtils/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/robroypt/Arduino_DebugUtils/actions/workflows/check-arduino.yml)
5-
[![Compile Examples status](https://github.com/robroypt/Arduino_DebugUtils/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/robroypt/Arduino_DebugUtils/actions/workflows/compile-examples.yml)
6-
[![Spell Check status](https://github.com/robroypt/Arduino_DebugUtils/actions/workflows/spell-check.yml/badge.svg)](https://github.com/robroypt/Arduino_DebugUtils/actions/workflows/spell-check.yml)
4+
[![Check Arduino status](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/check-arduino.yml)
5+
[![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)
6+
[![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):
@@ -16,7 +16,7 @@ Arduino_DebugUtils has 6 different debug levels (described descending from highe
1616
* `DBG_DEBUG` - more information
1717
* `DBG_VERBOSE` - most information
1818

19-
The desired debug level can be set in code via `setDebugLevel(DBG_WARNING)` or while the code is running using the Serial Monitor.
19+
The desired debug level can be set via `setDebugLevel(DBG_WARNING)`.
2020

2121
Debug messages are written via `print` which supports `printf`-style formatted output.
2222

@@ -30,41 +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-
# How-To-Use Advanced
34-
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-
36-
# Documentation
37-
## Code setup
33+
# New Features
3834
39-
### Include the Library
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.
4037
41-
Include the Arduino_DebugUtils library by adding
4238
```C++
43-
#include "Arduino_DebugUtils.h"
44-
```
45-
at the top of your code.
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");
4646
47-
### Setup the Serial Port
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+
```
4851

49-
By default, the Output Stream and input port for printing debug messages and receiving config commands is `Serial`.
52+
## Runtime Configuration via Serial
53+
You can now change debug settings at runtime through the same serial port used for debug output:
5054

51-
For minimal setup, just create the Serial object with a specified baud rate.
52-
```C++
53-
Serial.begin(9600); // Set baud rate here. Make sure you match the same baud rate in your terminal or monitor
5455
```
55-
In advanced cases you can use other serial ports (if available), or a Software Serial object. You can also (optionally) set a different Debug Level, turn on timestamps and debug labels.
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:
5683

5784
```C++
58-
mySerial.begin(9600); // Set baud rate here. Make sure you match the same baud rate in your terminal or monitor
59-
Debug.setDebugOutputStream(&mySerial);
60-
Debug.setDebugLevel(DBG_VERBOSE);
61-
Debug.timestampOn();
85+
// Format timestamps as [HH:MM:SS.mmm] instead of milliseconds
86+
Debug.formatTimestampOn();
6287
```
6388

64-
### Debug: object
65-
Arduino_DebugUtils Object that will be used for calling member functions is automatically instantiated when you include the library.
89+
# How-To-Use Advanced
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)`.
91+
92+
# Documentation
93+
### Debug :
94+
Arduino_DebugUtils Object that will be used for calling member functions.
95+
96+
## Basic Functions
6697

6798
### Debug.setDebugLevel(int const debug_level) :
99+
Sets the global debug level (module 0).
100+
68101
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`.
69102

70103
Return type: void.
@@ -73,6 +106,17 @@ Example:
73106
```C++
74107
Debug.setDebugLevel(DBG_VERBOSE);
75108
```
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+
76120
### Debug.setDebugOutputStream(Stream * stream) :
77121
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.
78122

@@ -83,6 +127,17 @@ Example:
83127
SoftwareSerial mySerial(10, 11); // RX, TX
84128
Debug.setDebugOutputStream(&mySerial);
85129
```
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+
86141
### Debug.timestampOn() :
87142
Calling this function switches on the timestamp in the `Debug.print()` function call;
88143
By default, printing timestamp is off, unless turned on using this function call.
@@ -106,26 +161,25 @@ Debug.timestampOff();
106161
DEBUG_VERBOSE("i = %d", i); //Output looks like : i = 21
107162
```
108163

109-
### Debug.debugLabelOn() :
110-
Calling this function switches on the Debug Label in the `Debug.print()` function call;
111-
By default, printing the debug label is off, unless turned on using this function call.
164+
### Debug.formatTimestampOn() :
165+
Calling this function enables formatted timestamps in the format [HH:MM:SS.mmm] instead of milliseconds.
112166

113167
Return type: void.
114168

115169
Example:
116170
```C++
117-
Debug.debugLabelOn();
171+
Debug.formatTimestampOn();
172+
DEBUG_VERBOSE("i = %d", i); //Output looks like : [ 00:01:35.421 ] i = 21
118173
```
119174
120-
### Debug.debugLabelOff() :
121-
Calling this function switches off the Debug Label in the `Debug.print()` function call;
122-
By default, printing the debug label is off, unless turned on using this function call.
175+
### Debug.formatTimestampOff() :
176+
Calling this function disables formatted timestamps, reverting to milliseconds display.
123177
124178
Return type: void.
125179
126180
Example:
127181
```C++
128-
Debug.debugLabelOff();
182+
Debug.formatTimestampOff();
129183
```
130184

131185
### Debug.newlineOn() :
@@ -148,6 +202,26 @@ Example:
148202
Debug.newlineOff();
149203
```
150204

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+
```
224+
151225
### Debug.print(int const debug_level, const char * fmt, ...);
152226
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).
153227

@@ -159,34 +233,153 @@ Debug.setDebugLevel(DBG_VERBOSE);
159233
int i = 0;
160234
DEBUG_VERBOSE("DBG_VERBOSE i = %d", i);
161235
```
162-
## Set Debug Settings at Runtime
163236
164-
While your code is running you can
165-
- set the current debug level
166-
- toggle the display of the prefixed Timestamp at the beginning of the `Debug.print()` function call
167-
- toggle the display of the debug label at the beginning of the `Debug.print()` function call
168-
- toggle the sending of a newline at the end of the `Debug.print()` function call
237+
## Module-Based Debug Functions
169238
170-
### Setup
239+
### Debug.setDebugLevel(int const module_id, int const debug_level) :
240+
Sets the debug level for a specific module.
171241
172-
Modify your `loop()` function to call `Debug.processDebugConfigCommand()` each time.
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.
173247
174248
Example:
175249
```C++
176-
int i = 0;
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.
177260

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++
178359
void loop() {
179-
DEBUG_VERBOSE("i = %d", i);
180-
i++;
360+
// Process any debug configuration commands
181361
Debug.processDebugConfigCommand();
182-
delay(1000); // See note on timing below
362+
363+
// Rest of your code
364+
// ...
183365
}
184366
```
185367

186-
### Timing
187-
- If you have a delay in your `loop()` (as is the case with the example code) this will also delay action on any entered commands, so for faster response call `processDebugConfigCommand()` more often.
368+
### Debug.printDebugStatus() :
369+
Displays the current debug configuration status, including module labels, debug levels, and toggle settings.
370+
371+
Return type: void.
188372

189-
### Trouble-shooting
190-
Check your monitor or terminal is configured:
191-
- to send a LF or CRLF Line Ending at the end of a message sent via the serial port.
192-
- to use the same baud rate specified when setting up the Serial object (9600 in the examples)
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)