Skip to content

Commit b388c08

Browse files
authored
Merge pull request #31 from arduino-libraries/fix-29
Provide debug macros for debug prints.
2 parents 4ac1bf3 + 7b46868 commit b388c08

File tree

6 files changed

+44
-13
lines changed

6 files changed

+44
-13
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode/
2+

Diff for: README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Example:
2424
```C++
2525
int i = 1;
2626
float pi = 3.1459;
27-
Debug.print(DBG_VERBOSE, "i = %d, pi = %f", i, pi);
27+
DEBUG_VERBOSE("i = %d, pi = %f", i, pi);
2828
```
2929
**Note**: The output of floating point numbers (`%f`) does NOT work on [ArduinoCore-avr](https://github.com/arduino/ArduinoCore-avr).
3030
@@ -43,7 +43,7 @@ Parameter debug_level in order of lowest to highest priority are : `DBG_NONE`, `
4343
Return type: void.
4444
4545
Example:
46-
```
46+
```C++
4747
Debug.setDebugLevel(DBG_VERBOSE);
4848
```
4949
### Debug.setDebugOutputStream(Stream * stream) :
@@ -52,7 +52,7 @@ By default, Output Stream is Serial. In advanced cases other objects could be ot
5252
Return type: void.
5353

5454
Example:
55-
```
55+
```C++
5656
SoftwareSerial mySerial(10, 11); // RX, TX
5757
Debug.setDebugOutputStream(&mySerial);
5858
```
@@ -63,9 +63,9 @@ By default, printing timestamp is off, unless turned on using this function call
6363
Return type: void.
6464
6565
Example:
66-
```
66+
```C++
6767
Debug.timestampOn();
68-
Debug.print(DBG_VERBOSE, "i = %d", i); //Output looks like : [ 21007 ] i = 21
68+
DBG_VERBOSE("i = %d", i); //Output looks like : [ 21007 ] i = 21
6969
```
7070

7171
### Debug.timestampOff() :
@@ -74,9 +74,9 @@ Calling this function switches off the timestamp in the `Debug.print()` function
7474
Return type: void.
7575

7676
Example:
77-
```
77+
```C++
7878
Debug.timestampOff();
79-
Debug.print(DBG_VERBOSE, "i = %d", i); //Output looks like : i = 21
79+
DEBUG_VERBOSE("i = %d", i); //Output looks like : i = 21
8080
```
8181
8282
### Debug.newlineOn() :
@@ -85,7 +85,7 @@ By default, a newline is sent
8585
Return type: void.
8686
8787
Example:
88-
```
88+
```C++
8989
Debug.newlineOn();
9090
```
9191

@@ -95,7 +95,7 @@ By default a newline is sent. Call this to shut that functionality off.
9595
Return type: void.
9696

9797
Example:
98-
```
98+
```C++
9999
Debug.timestampOff();
100100
```
101101

@@ -106,8 +106,8 @@ This function prints the message if parameter `debug_level` in the `Debug.print(
106106
Return type: void.
107107

108108
Example:
109-
```
109+
```C++
110110
Debug.setDebugLevel(DBG_VERBOSE);
111111
int i = 0;
112-
Debug.print(DBG_VERBOSE, "DBG_VERBOSE i = %d", i);
112+
DEBUG_VERBOSE("DBG_VERBOSE i = %d", i);
113113
```

Diff for: examples/Arduino_Debug_Advance/Arduino_Debug_Advance.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void setup() {
2424
int i = 0;
2525

2626
void loop() {
27-
Debug.print(DBG_VERBOSE, "i = %d", i);
27+
DEBUG_VERBOSE("i = %d", i);
2828
i++;
2929
delay(1000);
3030
}

Diff for: examples/Arduino_Debug_Basic/Arduino_Debug_Basic.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void setup() {
88
int i = 0;
99

1010
void loop() {
11-
Debug.print(DBG_INFO, "i = %d", i);
11+
DEBUG_INFO("i = %d", i);
1212
i++;
1313
delay(1000);
1414
}

Diff for: keywords.txt

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ setDebugOutputStream KEYWORD2
1717
timestampOn KEYWORD2
1818
timestampOff KEYWORD2
1919
print KEYWORD2
20+
DEBUG_ERROR KEYWORD2
21+
DEBUG_WARNING KEYWORD2
22+
DEBUG_INFO KEYWORD2
23+
DEBUG_DEBUG KEYWORD2
24+
DEBUG_VERBOSE KEYWORD2
2025

2126
#######################################
2227
# Constants (LITERAL1)

Diff for: src/Arduino_DebugUtils.h

+24
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,28 @@ class Arduino_DebugUtils {
9393

9494
extern Arduino_DebugUtils Debug;
9595

96+
/**************************************************************************************
97+
* DEFINE
98+
**************************************************************************************/
99+
100+
#ifndef DEBUG_ERROR
101+
# define DEBUG_ERROR(fmt, ...) Debug.print(DBG_ERROR, fmt, ## __VA_ARGS__)
102+
#endif
103+
104+
#ifndef DEBUG_WARNING
105+
# define DEBUG_WARNING(fmt, ...) Debug.print(DBG_WARNING, fmt, ## __VA_ARGS__)
106+
#endif
107+
108+
#ifndef DEBUG_INFO
109+
# define DEBUG_INFO(fmt, ...) Debug.print(DBG_INFO, fmt, ## __VA_ARGS__)
110+
#endif
111+
112+
#ifndef DEBUG_DEBUG
113+
# define DEBUG_DEBUG(fmt, ...) Debug.print(DBG_DEBUG, fmt, ## __VA_ARGS__)
114+
#endif
115+
116+
#ifndef DEBUG_VERBOSE
117+
# define DEBUG_VERBOSE(fmt, ...) Debug.print(DBG_VERBOSE, fmt, ## __VA_ARGS__)
118+
#endif
119+
96120
#endif /* ARDUINO_DEBUG_UTILS_H_ */

0 commit comments

Comments
 (0)