Skip to content

Provide debug macros for debug prints. #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode/

22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Example:
```C++
int i = 1;
float pi = 3.1459;
Debug.print(DBG_VERBOSE, "i = %d, pi = %f", i, pi);
DEBUG_VERBOSE("i = %d, pi = %f", i, pi);
```
**Note**: The output of floating point numbers (`%f`) does NOT work on [ArduinoCore-avr](https://github.com/arduino/ArduinoCore-avr).

Expand All @@ -43,7 +43,7 @@ Parameter debug_level in order of lowest to highest priority are : `DBG_NONE`, `
Return type: void.

Example:
```
```C++
Debug.setDebugLevel(DBG_VERBOSE);
```
### Debug.setDebugOutputStream(Stream * stream) :
Expand All @@ -52,7 +52,7 @@ By default, Output Stream is Serial. In advanced cases other objects could be ot
Return type: void.

Example:
```
```C++
SoftwareSerial mySerial(10, 11); // RX, TX
Debug.setDebugOutputStream(&mySerial);
```
Expand All @@ -63,9 +63,9 @@ By default, printing timestamp is off, unless turned on using this function call
Return type: void.

Example:
```
```C++
Debug.timestampOn();
Debug.print(DBG_VERBOSE, "i = %d", i); //Output looks like : [ 21007 ] i = 21
DBG_VERBOSE("i = %d", i); //Output looks like : [ 21007 ] i = 21
```

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

Example:
```
```C++
Debug.timestampOff();
Debug.print(DBG_VERBOSE, "i = %d", i); //Output looks like : i = 21
DEBUG_VERBOSE("i = %d", i); //Output looks like : i = 21
```

### Debug.newlineOn() :
Expand All @@ -85,7 +85,7 @@ By default, a newline is sent
Return type: void.

Example:
```
```C++
Debug.newlineOn();
```

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

Example:
```
```C++
Debug.timestampOff();
```

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

Example:
```
```C++
Debug.setDebugLevel(DBG_VERBOSE);
int i = 0;
Debug.print(DBG_VERBOSE, "DBG_VERBOSE i = %d", i);
DEBUG_VERBOSE("DBG_VERBOSE i = %d", i);
```
2 changes: 1 addition & 1 deletion examples/Arduino_Debug_Advance/Arduino_Debug_Advance.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void setup() {
int i = 0;

void loop() {
Debug.print(DBG_VERBOSE, "i = %d", i);
DEBUG_VERBOSE("i = %d", i);
i++;
delay(1000);
}
2 changes: 1 addition & 1 deletion examples/Arduino_Debug_Basic/Arduino_Debug_Basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void setup() {
int i = 0;

void loop() {
Debug.print(DBG_INFO, "i = %d", i);
DEBUG_INFO("i = %d", i);
i++;
delay(1000);
}
5 changes: 5 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ setDebugOutputStream KEYWORD2
timestampOn KEYWORD2
timestampOff KEYWORD2
print KEYWORD2
DEBUG_ERROR KEYWORD2
DEBUG_WARNING KEYWORD2
DEBUG_INFO KEYWORD2
DEBUG_DEBUG KEYWORD2
DEBUG_VERBOSE KEYWORD2

#######################################
# Constants (LITERAL1)
Expand Down
24 changes: 24 additions & 0 deletions src/Arduino_DebugUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,28 @@ class Arduino_DebugUtils {

extern Arduino_DebugUtils Debug;

/**************************************************************************************
* DEFINE
**************************************************************************************/

#ifndef DEBUG_ERROR
# define DEBUG_ERROR(fmt, ...) Debug.print(DBG_ERROR, fmt, ## __VA_ARGS__)
#endif

#ifndef DEBUG_WARNING
# define DEBUG_WARNING(fmt, ...) Debug.print(DBG_WARNING, fmt, ## __VA_ARGS__)
#endif

#ifndef DEBUG_INFO
# define DEBUG_INFO(fmt, ...) Debug.print(DBG_INFO, fmt, ## __VA_ARGS__)
#endif

#ifndef DEBUG_DEBUG
# define DEBUG_DEBUG(fmt, ...) Debug.print(DBG_DEBUG, fmt, ## __VA_ARGS__)
#endif

#ifndef DEBUG_VERBOSE
# define DEBUG_VERBOSE(fmt, ...) Debug.print(DBG_VERBOSE, fmt, ## __VA_ARGS__)
#endif

#endif /* ARDUINO_DEBUG_UTILS_H_ */