-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebug.cpp
More file actions
86 lines (70 loc) · 1.82 KB
/
Debug.cpp
File metadata and controls
86 lines (70 loc) · 1.82 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
#include "Debug.h"
#ifdef DEBUG
void Debug::init(unsigned long timeoutMs) {
waitForSerial(timeoutMs);
}
void Debug::waitForSerial(unsigned long timeoutMs) {
unsigned long startTime = millis();
while (!Serial && (millis() - startTime) < timeoutMs) {
;
}
}
void Debug::printTimestamp() {
unsigned long t = millis();
unsigned int ms = t % 1000;
unsigned long totalSeconds = t / 1000;
unsigned int seconds = totalSeconds % 60;
unsigned int minutes = (totalSeconds / 60) % 60;
unsigned int hours = totalSeconds / 3600;
Serial.print("[");
if (hours < 10) Serial.print('0');
Serial.print(hours);
Serial.print(':');
if (minutes < 10) Serial.print('0');
Serial.print(minutes);
Serial.print(':');
if (seconds < 10) Serial.print('0');
Serial.print(seconds);
Serial.print('.');
if (ms < 100) Serial.print('0');
if (ms < 10) Serial.print('0');
Serial.print(ms);
Serial.print("] ");
}
void Debug::printString(const char* str) {
printTimestamp();
Serial.println(str);
}
void Debug::printNameValuePair(const char* name, int value) {
printTimestamp();
Serial.print(name);
Serial.print(": ");
Serial.println(value);
}
void Debug::printNameValuePair(const char* name, const char* value) {
printTimestamp();
Serial.print(name);
Serial.print(": ");
Serial.println(value);
}
#else
void Debug::init(unsigned long timeoutMs) {
(void)timeoutMs;
}
void Debug::waitForSerial(unsigned long timeoutMs) {
(void)timeoutMs;
}
void Debug::printTimestamp() {
}
void Debug::printString(const char* str) {
(void)str;
}
void Debug::printNameValuePair(const char* name, int value) {
(void)name;
(void)value;
}
void Debug::printNameValuePair(const char* name, const char* value) {
(void)name;
(void)value;
}
#endif