Skip to content

Commit 3ffdac1

Browse files
committed
Replacing enum class DebugLevel with constants
1 parent 1c2320e commit 3ffdac1

File tree

5 files changed

+32
-35
lines changed

5 files changed

+32
-35
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ This class provides functionality useful for debugging sketches via `printf`-sty
55

66
# How-To-Use Basic
77
ArduinoDebugUtils has 6 different debug levels (described descending from highest to lowest priority):
8-
* `DebugLevel::None` - no debug output is shown
9-
* `DebugLevel::Error` - critical errors
10-
* `DebugLevel::Warning` - non-critical errors
11-
* `DebugLevel::Info` - information
12-
* `DebugLevel::Debug` - more information
13-
* `DebugLevel::Verbose` - most information
8+
* `DEBUG_LVL_NONE` - no debug output is shown
9+
* `DEBUG_LVL_ERROR` - critical errors
10+
* `DEBUG_LVL_WARNING` - non-critical errors
11+
* `DEBUG_LVL_INFO` - information
12+
* `DEBUG_LVL_DEBUG` - more information
13+
* `DEBUG_LVL_VERBOSE` - most information
1414

1515
The desired debug level can be set via `setDebugLevel(DebugLevel::Warning)`.
1616

@@ -20,7 +20,7 @@ Example:
2020
```C++
2121
int i = 1;
2222
float pi = 3.1459;
23-
ArduinoDebugUtils.debugPrint(DebugLevel::Verbose, "i = %d, pi = %f, i, pi);
23+
ArduinoDebugUtils.debugPrint(DEBUG_LVL_VERBOSE, "i = %d, pi = %f, i, pi);
2424
```
2525
2626
If desired timestamps can be prefixed to the debug message. Timestamp output can be enabled and disabled via `timestampOn` and `timestampOff`.

examples/Arduino_Debug_Basic/Arduino_Debug_Basic.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ int i = 0;
1111

1212
void loop() {
1313

14-
ArduinoDebugUtils.debugPrint(DebugLevel::Info, "i = %d", i);
14+
ArduinoDebugUtils.debugPrint(DEBUG_LVL_INFO, "i = %d", i);
1515
i++;
1616
delay(1000);
1717
}

keywords.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ debugPrint KEYWORD2
2222
# Constants (LITERAL1)
2323
#######################################
2424

25-
DebugLevel LITERAL1
26-
None LITERAL1
27-
Error LITERAL1
28-
Warning LITERAL1
29-
Info LITERAL1
30-
Debug LITERAL1
31-
Verbose LITERAL1
25+
DEBUG_LVL_NONE LITERAL1
26+
DEBUG_LVL_ERROR LITERAL1
27+
DEBUG_LVL_WARNING LITERAL1
28+
DEBUG_LVL_INFO LITERAL1
29+
DEBUG_LVL_DEBUG LITERAL1
30+
DEBUG_LVL_VERBOSE LITERAL1

src/ArduinoDebugUtils.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace impl
3232
CONSTANTS
3333
******************************************************************************/
3434

35-
static DebugLevel const DEFAULT_DEBUG_LEVEL = DebugLevel::Info;
36-
static Stream * DEFAULT_OUTPUT_STREAM = &Serial;
35+
static int const DEFAULT_DEBUG_LEVEL = DEBUG_LVL_INFO;
36+
static Stream * DEFAULT_OUTPUT_STREAM = &Serial;
3737

3838
/******************************************************************************
3939
CTOR/DTOR
@@ -50,7 +50,7 @@ ArduinoDebugUtils::ArduinoDebugUtils()
5050
PUBLIC MEMBER FUNCTIONS
5151
******************************************************************************/
5252

53-
void ArduinoDebugUtils::setDebugLevel(DebugLevel const debug_level)
53+
void ArduinoDebugUtils::setDebugLevel(int const debug_level)
5454
{
5555
_debug_level = debug_level;
5656
}
@@ -70,10 +70,10 @@ void ArduinoDebugUtils::timestampOff()
7070
_timestamp_on = false;
7171
}
7272

73-
void ArduinoDebugUtils::debugPrint(DebugLevel const debug_level, const char * fmt, ...)
73+
void ArduinoDebugUtils::debugPrint(int const debug_level, const char * fmt, ...)
7474
{
75-
if (debug_level >= DebugLevel::Error &&
76-
debug_level <= DebugLevel::Verbose &&
75+
if (debug_level >= DEBUG_LVL_ERROR &&
76+
debug_level <= DEBUG_LVL_VERBOSE &&
7777
debug_level <= _debug_level)
7878
{
7979
if(_timestamp_on)

src/ArduinoDebugUtils.h

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,15 @@
2727
#include <stdarg.h>
2828

2929
/******************************************************************************
30-
TYPEDEF
30+
CONSTANTS
3131
******************************************************************************/
3232

33-
enum class DebugLevel : int {
34-
None = -1,
35-
Error = 0,
36-
Warning = 1,
37-
Info = 2,
38-
Debug = 3,
39-
Verbose = 4
40-
};
33+
static int const DEBUG_LVL_NONE = -1;
34+
static int const DEBUG_LVL_ERROR = 0;
35+
static int const DEBUG_LVL_WARNING = 1;
36+
static int const DEBUG_LVL_INFO = 2;
37+
static int const DEBUG_LVL_DEBUG = 3;
38+
static int const DEBUG_LVL_VERBOSE = 4;
4139

4240
/******************************************************************************
4341
NAMESPACE
@@ -57,20 +55,20 @@ class ArduinoDebugUtils
5755

5856
ArduinoDebugUtils();
5957

60-
void setDebugLevel(DebugLevel const debug_level);
58+
void setDebugLevel(int const debug_level);
6159
void setDebugOutputStream(Stream * stream);
6260

6361
void timestampOn();
6462
void timestampOff();
6563

66-
void debugPrint(DebugLevel const debug_level, const char * fmt, ...);
64+
void debugPrint(int const debug_level, const char * fmt, ...);
6765

6866

6967
private:
7068

71-
bool _timestamp_on;
72-
DebugLevel _debug_level;
73-
Stream * _debug_output_stream;
69+
bool _timestamp_on;
70+
int _debug_level;
71+
Stream * _debug_output_stream;
7472

7573
void vDebugPrint(char const * fmt, va_list args);
7674

0 commit comments

Comments
 (0)