forked from pa-pa/AskSinPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Debug.h
118 lines (95 loc) · 3.29 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------
#ifndef __DEBUG_H__
#define __DEBUG_H__
#ifdef ARDUINO
#include "Arduino.h"
#endif
// #define NDEBUG
#ifdef NDEBUG
#include <stdint.h>
#define DPRINT(str)
#define DPRINTLN(str)
#define DHEX(b...)
#define DHEXLN(b)
#define DDEC(b)
#define DDECLN(b)
#define DINIT(baudrate,msg)
#define DDEVINFO(dev)
#else
#ifdef ARDUINO
// can be used to move the debug output to Serial1 (useful on STM32 BluePill)
// must be defined in main .ino before any eader inclusion!
#ifndef DSERIAL
#define DSERIAL Serial
#endif
template <class T>
inline void DPRINT(T str) { DSERIAL.print(str); }
template <class T>
inline void DPRINTLN(T str) { DPRINT(str); DPRINT(F("\n")); }
inline void DHEX(uint8_t b) {
if( b<0x10 ) DSERIAL.print('0');
DSERIAL.print(b,HEX);
}
inline void DHEX(uint16_t b) {
if( b<0x10 ) DSERIAL.print(F("000"));
else if( b<0x100 ) DSERIAL.print(F("00"));
else if( b<0x1000 ) DSERIAL.print(F("0"));
DSERIAL.print(b,HEX);
}
inline void DHEX(uint32_t b) {
if( b<0x10 ) DSERIAL.print(F("0000000"));
else if( b<0x100 ) DSERIAL.print(F("000000"));
else if( b<0x1000 ) DSERIAL.print(F("00000"));
else if( b<0x10000 ) DSERIAL.print(F("0000"));
else if( b<0x100000 ) DSERIAL.print(F("000"));
else if( b<0x1000000 ) DSERIAL.print(F("00"));
else if( b<0x10000000 ) DSERIAL.print(F("0"));
DSERIAL.print(b,HEX);
}
template<typename TYPE>
inline void DDEC(TYPE b) {
DSERIAL.print(b,DEC);
}
#define DINIT(baudrate,msg) \
DSERIAL.begin(baudrate); \
DPRINTLN(msg);
#define DDEVINFO(dev) \
HMID devid; \
dev.getDeviceID(devid); \
DPRINT(F("ID: "));devid.dump(); \
uint8_t serial[11]; \
dev.getDeviceSerial(serial); \
serial[10]=0; \
DPRINT(F(" Serial: "));DPRINTLN((char*)serial);
#else
#include <iostream>
#include <iomanip>
#ifndef F
#define F(str) str
#endif
template <class T>
inline void DPRINT(T str) { std::cout << str << std::flush; }
template <class T>
inline void DPRINTLN(T str) { std::cout << str << std::endl; }
inline void DHEX(uint8_t b) { std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)b; }
inline void DHEX(uint16_t b) { std::cout << std::setw(4) << std::setfill('0') << std::hex << (int)b; }
inline void DHEX(uint32_t b) { std::cout << std::setw(8) << std::setfill('0') << std::hex << (int)b; }
template<typename TYPE>
inline void DDEC(TYPE b) { std::cout << std::dec << (int)b; }
#endif // ARDUINO
inline void DHEX(const uint8_t* b,uint8_t l) {
for( int i=0; i<l; i++, b++) {
DHEX(*b); DPRINT(F(" "));
}
}
inline void DHEXLN(uint8_t b) { DHEX(b); DPRINT(F("\n")); }
inline void DHEXLN(uint16_t b) { DHEX(b); DPRINT(F("\n")); }
inline void DHEXLN(uint32_t b) { DHEX(b); DPRINT(F("\n")); }
template<typename TYPE>
inline void DDECLN(TYPE b) { DDEC(b); DPRINT(F("\n")); }
inline void DHEXLN(const uint8_t* b,uint8_t l) { DHEX(b,l); DPRINT(F("\n")); }
#endif
#endif