-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDbg.cpp
70 lines (59 loc) · 1.25 KB
/
Dbg.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
#include "Dbg.h"
#ifdef DEBUG_ENABLED
#define DBG_MAX_LENGTH 80
//Dbg::Dbg() {
//}
void Dbg::begin(int serial, long int rate, byte maxlevel)
{
switch(serial) {
case 1:
m_serial = &Serial;
break;
#if defined(__AVR_ATmega1280__) || defined (__AVR_ATmega2560__)
case 2:
m_serial = &Serial1;
break;
case 3:
m_serial = &Serial2;
break;
case 4:
m_serial = &Serial3;
break;
#endif
default:
m_serial = &Serial;
break;
}
m_serial->begin(rate);
debug_level = maxlevel;
}
void Dbg::log(byte level, const char *fmt, ...)
{
if(debug_level >= level){
char buf[DBG_MAX_LENGTH];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, (DBG_MAX_LENGTH - 1), fmt, ap);
va_end(ap);
switch(level){
case LEVELFATAL:
m_serial->print("@@@");
break;
case LEVELERROR:
m_serial->print("***");
break;
case LEVELWARN:
m_serial->print("???");
break;
case LEVELINFO:
m_serial->print("%%%");
break;
case LEVELDEBUG:
m_serial->print("&&&");
break;
}
m_serial->println(buf);
}
}
#endif
Dbg Debug;