-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path__dd_misc_debug.h
More file actions
110 lines (108 loc) · 3.44 KB
/
__dd_misc_debug.h
File metadata and controls
110 lines (108 loc) · 3.44 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
101
102
103
104
105
106
107
108
#ifndef DD_NO_DEBUG_INTERFACE
class DrawTextDDDebugInterface: public DDDebugInterface {
public:
void setConnectionType(const char* connectionType) {
this->connectionType = connectionType;
}
public:
virtual void logConnectionState(DDDebugConnectionState connectionState) {
const char* state = NULL;
switch (connectionState) {
case DDDebugConnectionState::DEBUG_NOT_CONNECTED:
state = "NCed";
break;
case DDDebugConnectionState::DEBUG_CONNECTING:
state = "Cing ";
break;
case DDDebugConnectionState::DEBUG_CONNECTED:
state = "Ced ";
break;
case DDDebugConnectionState::DEBUG_RECONNECTING:
state = "RCing";
break;
case DDDebugConnectionState::DEBUG_RECONNECTED:
state = "RCed ";
break;
}
if (state != NULL) {
if (true) {
String s = state;
if (connectionType != NULL) {
s = String(connectionType) + ":" + s;
}
drawText(s.c_str(), false);
} else {
drawText(state, false);
}
}
}
virtual void logError(const String& errMsg) {
drawText("Err", true);
}
protected:
virtual void drawText(const char* text, bool isError) {
}
protected:
const char* connectionType;
};
class ToSerialDDDebugInterface: public DDDebugInterface {
public:
virtual void logConnectionState(DDDebugConnectionState connectionState) {
switch (connectionState) {
case DDDebugConnectionState::DEBUG_NOT_CONNECTED:
Serial.println("* DebugConnection: not connected");
break;
case DDDebugConnectionState::DEBUG_CONNECTING:
Serial.println("* DebugConnection: connecting");
break;
case DDDebugConnectionState::DEBUG_CONNECTED:
Serial.println("* DebugConnection: connected");
break;
case DDDebugConnectionState::DEBUG_RECONNECTING:
Serial.println("* DebugConnection: reconnecting");
break;
case DDDebugConnectionState::DEBUG_RECONNECTED:
Serial.println("* DebugConnection: reconnected");
break;
}
}
virtual void logError(const String& errMsg) {
Serial.print("XXX Error: ");
Serial.println(errMsg);
}
};
class LedDDDebugInterface: public DDDebugInterface {
public:
LedDDDebugInterface(uint8_t ledPin) {
this->ledPin = ledPin;
pinMode(ledPin, OUTPUT);
}
virtual void logSendCommand(int state) {
digitalWrite(ledPin, state == 1 ? HIGH : LOW);
}
private:
uint8_t ledPin;
};
class CompositeDDDebugInterface: public DDDebugInterface {
public:
CompositeDDDebugInterface(DDDebugInterface* debug1, DDDebugInterface* debug2){
this->debug1 = debug1;
this->debug2 = debug2;
}
virtual void logConnectionState(DDDebugConnectionState connectionState) {
if (debug1 != NULL) debug1->logConnectionState(connectionState);
if (debug2 != NULL) debug2->logConnectionState(connectionState);
}
virtual void logSendCommand(int state) {
if (debug1 != NULL) debug1->logSendCommand(state);
if (debug2 != NULL) debug2->logSendCommand(state);
}
virtual void logError(const String& errMsg) {
if (debug1 != NULL) debug1->logError(errMsg);
if (debug2 != NULL) debug2->logError(errMsg);
}
private:
DDDebugInterface* debug1;
DDDebugInterface* debug2;
};
#endif