-
Notifications
You must be signed in to change notification settings - Fork 4
/
debug.h
63 lines (42 loc) · 1.3 KB
/
debug.h
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
#ifndef DEBUG_H
#define DEBUG_H
#include <Arduino.h>
#include <Streaming.h>
#define __DEBUG__ 1
#if __DEBUG__ || _DEBUG
class DebugStackClass {
typedef const __FlashStringHelper* pgmptr;
pgmptr _fn;
const char * _func;
public:
DebugStackClass(pgmptr fn, const char * func, int l) {
_fn = strrchr_P(fn, '\\');
_func = func;
Serial << (">Begin: ") << _fn << ":" << _func << ":" << l << endl;
};
~DebugStackClass() {
Serial << ("<End: ") << _fn << ":" << _func << endl;
};
static const pgmptr strrchr_P(pgmptr ptr, char c) {
PGM_P t = NULL;
PGM_P buf = (PGM_P)ptr;
for (char tmpchar = 0; tmpchar = pgm_read_byte((PGM_P)buf); buf++) {
if (tmpchar == c)
t = buf;
}
//#ifndef PGMPTR
//#define PGMPTR( pgm_ptr ) ( reinterpret_cast< pgmptr >( pgm_ptr ) )
//#endif
//return PGMPTR(t);
return (reinterpret_cast<pgmptr>(t));
}
};
#define DEBUG_PRINT(x) Serial << DebugStackClass::strrchr_P(F(__FILE__), '\\') << ":" << __FUNCTION__ << ":" << __LINE__ << ": " << x << endl
#define DEBUG_STACK() DebugStackClass __DebugStack(F(__FILE__), __FUNCTION__, __LINE__)
#define DEBUG_STACK_PRINT(x) DebugStackClass __DebugStack(F(__FILE__), __FUNCTION__, __LINE__); Serial << x << endl
#else
#define DEBUG_PRINT(x)
#define DEBUG_STACK
#define DEBUG_STACK_PRINT(x)
#endif
#endif //DEBUG_H