-
Notifications
You must be signed in to change notification settings - Fork 0
/
Debug.cpp
78 lines (70 loc) · 1.97 KB
/
Debug.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "Debug.h"
/**
* Sends a string to the Serial port with a debug level, only if it is lower than the setted one.
* The debug level will be sent only if it's a new line.
* @param st String to print.
* @param level Debug level.
*/
void SerialDebug::print(String st, Levels level) {
if (level <= this->level) {
String toPrint = "";
if (ended) toPrint += getLevel(level);
toPrint += st;
serial->print(toPrint);
ended = st.endsWith("\n");
}
}
/**
* Sends a line to the serial port with a debug level, only if it is lower than the setted one.
* The debug level will be sent only if it's a new line.
* @param st String to print.
* @param level Debug level.
*/
void SerialDebug::println(String st, Levels level) {
print(st+"\n", level);
}
/**
* Sends a debug string to the serial port, only debug is accepted.
* The debug level will be sent only if it's a new line.
* @param st String to print.
*/
void SerialDebug::print(String st) {
print(st, Levels::DEBUG);
}
/**
* Sends a debug line to the serial port, only debug is accepted.
* The debug level will be sent only if it's a new line.
* @param st String to print.
*/
void SerialDebug::println(String st) {
println(st, Levels::DEBUG);
}
/**
* Delay used only in debug. This should be used to avoid errors while running in competition.
* @param t Time to wait in microseconds.
*/
void SerialDebug::delayd(int t) {
if(level>=Levels::DEBUG) delay(t);
}
/**
* Sets the level to be used for the debug.
* @param lvl Debug level.
*/
void SerialDebug::setLevel(Levels level) {
this->level = level;
}
/**
* Get the string corresponding the actual debug level.
* @param level Debug level.
* @return The string representing the level.
*/
String SerialDebug::getLevel(Levels level) {
switch (level) {
case Levels::DEBUG: return "debug ";
case Levels::INFO: return "information ";
case Levels::WARN: return "warning ";
default: return "";
}
}
// creation of the default instance
SerialDebug Debug;