3-phase PV router
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1
12#ifndef DEBUG_H
13#define DEBUG_H
14
15// #define ENABLE_DEBUG
16// #define DEBUG_PORT Serial
17
18#define TEXTIFY(A) #A
19#define ESCAPEQUOTE(A) TEXTIFY(A)
20
21#ifdef ARDUINO
22
23#ifndef DEBUG_USE_PRINT_P
24#if defined(ESP8266)
25#define DEBUG_USE_PRINT_P 1
26#else
27#define DEBUG_USE_PRINT_P 0
28#endif // ESP8266
29#endif // DEBUG_USE_PRINT_P
30
31#ifdef ENABLE_DEBUG
32
33// Use os_printf, works but also outputs additional dubug if not using Serial
34//#define DEBUG_BEGIN(speed) DEBUG_PORT.begin(speed);
35// DEBUG_PORT.setDebugOutput(true) #define DBUGF(format, ...)
36// os_printf(PSTR(format "\n"), ##__VA_ARGS__)
37
38#define DEBUG_BEGIN(speed) DEBUG_PORT.begin(speed)
39
40#if DEBUG_USE_PRINT_P
41// Serial.printf_P needs Git version of Arduino Core
42#define DBUGF(format, ...) DEBUG_PORT.printf_P(PSTR(format "\n"), ##__VA_ARGS__)
43#else
44#define DBUGF(format, ...) DEBUG_PORT.printf(format "\n", ##__VA_ARGS__)
45#endif
46
47#define DBUG(...) DEBUG_PORT.print(__VA_ARGS__)
48#define DBUGLN(...) DEBUG_PORT.println(__VA_ARGS__)
49#define DBUGVAR(x, ...) \
50 do \
51 { \
52 DEBUG_PORT.print(F(ESCAPEQUOTE(x) " = ")); \
53 DEBUG_PORT.println(x, ##__VA_ARGS__); \
54 } while (false)
55
56#else // ENABLE_DEBUG
57
58#define DEBUG_BEGIN(speed) DEBUG_PORT.begin(speed)
59#define DBUGF(...)
60#define DBUG(...)
61#define DBUGLN(...)
62#define DBUGVAR(...)
63
64#endif // ENABLE_DEBUG
65
66#ifdef DEBUG_SERIAL1
67#error DEBUG_SERIAL1 defiend, please use -DDEBUG_PORT=Serial1 instead
68#endif
69
70#ifndef DEBUG_PORT
71#ifdef EMONESP
72#include <SoftwareSerial.h>
73inline SoftwareSerial mySerial(2, 3); // RX, TX
74
75#define DEBUG_PORT mySerial
76#else
77#define DEBUG_PORT Serial
78#endif
79#endif
80#define DEBUG DEBUG_PORT
81
82#else // ARDUINO
83
84#define DEBUG_BEGIN(speed)
85
86#ifdef ENABLE_DEBUG
87
88#define DBUGF(format, ...) printf(format "\n", ##__VA_ARGS__)
89#define DBUG(...)
90#define DBUGLN(...)
91#define DBUGVAR(...)
92
93#else
94
95#define DBUGF(...)
96#define DBUG(...)
97#define DBUGLN(...)
98#define DBUGVAR(...)
99
100#endif // DEBUG
101
102#endif // ARDUINO
103
104#endif // DEBUG_H