-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.h
106 lines (94 loc) · 2.86 KB
/
Logger.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
#ifndef LOGGER_H
#define LOGGER_H
#include "Arduino.h"
class Logger {
public:
// Accessor methods
static Logger& readComputerInstance();
static Logger& readOnboardInstance();
static Logger& readXbeeInstance();
// Instance constructor
Logger(HardwareSerial& _output, bool _enabled);
// Regular method headers
void enable();
void disable();
bool isEnabled();
// Logging methods (MUST go in header)
template <typename First>
void logOne(const First& first) {
if (!enabled) {
return;
}
output.print(String(first));
output.print(", ");
output.println(millis());
}
template <typename First, typename Second>
void logTwo(const First& first, const Second& second) {
if (!enabled) {
return;
}
output.print(String(first));
output.print(", ");
output.print(String(second));
output.print(", ");
output.println(millis());
}
template <typename First, typename Second, typename Third>
void logThree(const First& first, const Second& second, const Third& third) {
if (!enabled) {
return;
}
output.print(String(first));
output.print(", ");
output.print(String(second));
output.print(", ");
output.print(String(third));
output.print(", ");
output.println(millis());
}
template <typename First, typename Second, typename Third, typename Fourth>
void logFour(const First& first, const Second& second, const Third& third, const Fourth& fourth) {
if (!enabled) {
return;
}
output.print(String(first));
output.print(", ");
output.print(String(second));
output.print(", ");
output.print(String(third));
output.print(", ");
output.print(String(fourth));
output.print(", ");
output.println(millis());
}
template <typename First, typename Second, typename Third, typename Fourth, typename Fifth>
void logFive(const First& first, const Second& second, const Third& third, const Fourth& fourth, const Fifth& fifth) {
if (!enabled) {
return;
}
output.print(String(first));
output.print(", ");
output.print(String(second));
output.print(", ");
output.print(String(third));
output.print(", ");
output.print(String(fourth));
output.print(", ");
output.print(String(fifth));
output.print(", ");
output.println(millis());
}
private:
// Accessor variables
static Logger *computerInstance;
static Logger *onboardInstance;
static Logger *xbeeInstance;
// Instance variables
HardwareSerial& output;
bool enabled;
};
Logger& Computer();
Logger& Onboard();
Logger& Xbee();
#endif // LOGGER_H