-
Notifications
You must be signed in to change notification settings - Fork 719
Expand file tree
/
Copy pathSimpleFOCDebug.h
More file actions
101 lines (81 loc) · 3.21 KB
/
Copy pathSimpleFOCDebug.h
File metadata and controls
101 lines (81 loc) · 3.21 KB
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
#ifndef __SIMPLEFOCDEBUG_H__
#define __SIMPLEFOCDEBUG_H__
#include "Arduino.h"
/**
* SimpleFOCDebug class
*
* This class is used to print debug messages to a chosen output.
* Currently, Print instances are supported as targets, e.g. serial port.
*
* Activate debug output globally by calling enable(), optionally passing
* in a Print instance. If none is provided "Serial" is used by default.
*
* To produce debug output, use the macro SIMPLEFOC_DEBUG:
* SIMPLEFOC_DEBUG("Debug message!");
* SIMPLEFOC_DEBUG("a float value:", 123.456f);
* SIMPLEFOC_DEBUG("an integer value: ", 123);
*
* Keep debugging output short and simple. Some of our MCUs have limited
* RAM and limited serial output capabilities.
*
* By default, the SIMPLEFOC_DEBUG macro uses the flash string helper to
* help preserve memory on Arduino boards.
*
* You can also disable debug output completely. In this case all debug output
* and the SimpleFOCDebug class is removed from the compiled code.
* Add -DSIMPLEFOC_DISABLE_DEBUG to your compiler flags to disable debug in
* this way.
*
**/
// #define SIMPLEFOC_DISABLE_DEBUG
#ifdef SIMPLEFOC_DISABLE_DEBUG
class SimpleFOCDebug {
public:
inline static void enable(Print* debugPrint){}
inline static void println(const __FlashStringHelper* msg){}
inline static void println(const StringSumHelper msg){}
inline static void println(const char* msg){}
inline static void println(const __FlashStringHelper* msg, float val){}
inline static void println(const char* msg, float val){}
inline static void println(const __FlashStringHelper* msg, int val){}
inline static void println(const char* msg, int val){}
inline static void println(const char* msg, char val){}
inline static void println(){}
inline static void println(int val){}
inline static void println(float val){}
inline static void print(const char* msg){}
inline static void print(const __FlashStringHelper* msg){}
inline static void print(const StringSumHelper msg){}
inline static void print(int val){}
inline static void print(float val){}
static void printf(const char* msg, ...){}
};
#define SIMPLEFOC_DEBUG(msg, ...)
#else
class SimpleFOCDebug {
public:
static void enable(Print* debugPrint = &Serial);
static void println(const __FlashStringHelper* msg);
static void println(const StringSumHelper msg);
static void println(const char* msg);
static void println(const __FlashStringHelper* msg, float val);
static void println(const char* msg, float val);
static void println(const __FlashStringHelper* msg, int val);
static void println(const char* msg, int val);
static void println(const char* msg, char val);
static void println();
static void println(int val);
static void println(float val);
static void print(const char* msg);
static void print(const __FlashStringHelper* msg);
static void print(const StringSumHelper msg);
static void print(int val);
static void print(float val);
static void printf(const char* msg, ...);
protected:
static Print* _debugPrint;
};
#define SIMPLEFOC_DEBUG(msg, ...) \
SimpleFOCDebug::println(F(msg), ##__VA_ARGS__)
#endif //ifndef SIMPLEFOC_DISABLE_DEBUG
#endif