-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAPI.ino
135 lines (110 loc) · 2.27 KB
/
API.ino
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// ----- API -----
void log(String message) {
Serial.print("log " + message + "\n");
}
int mazeWidth() {
return getInteger("mazeWidth");
}
int mazeHeight() {
return getInteger("mazeHeight");
}
bool wallFront() {
return getBoolean("wallFront");
}
bool wallRight() {
return getBoolean("wallRight");
}
bool wallLeft() {
return getBoolean("wallLeft");
}
bool moveForward() {
return getAck("moveForward");
}
void turnRight() {
getAck("turnRight");
}
void turnLeft() {
getAck("turnLeft");
}
void setWall(int x, int y, char direction) {
Serial.print(
"setWall "
+ String(x) + " "
+ String(y) + " "
+ String(direction) + "\n"
);
}
void clearWall(int x, int y, char direction) {
Serial.print(
"clearWall "
+ String(x) + " "
+ String(y) + " "
+ String(direction) + "\n"
);
}
void setColor(int x, int y, char color) {
Serial.print(
"setColor "
+ String(x) + " "
+ String(y) + " "
+ String(color) + "\n"
);
}
void clearColor(int x, int y) {
Serial.print(
"clearColor "
+ String(x) + " "
+ String(y) + "\n"
);
}
void clearAllColor() {
Serial.print("clearAllColor\n");
}
void setText(int x, int y, String text) {
Serial.print(
"setText "
+ String(x) + " "
+ String(y) + " "
+ text + "\n"
);
}
void clearText(int x, int y) {
Serial.print(
"clearText "
+ String(x) + " "
+ String(y) + "\n"
);
}
void clearAllText() {
Serial.print("clearAllText\n");
}
bool wasReset() {
return getBoolean("wasReset");
}
void ackReset() {
getAck("ackReset");
}
// ----- Helpers -----
String readline() {
String response = "";
while (response == "") {
response = Serial.readStringUntil('\n');
}
return response;
}
String communicate(String command) {
Serial.print(command + "\n");
return readline();
}
bool getAck(String command) {
String response = communicate(command);
return response == "ack";
}
bool getBoolean(String command) {
String response = communicate(command);
return response == "true";
}
int getInteger(String command) {
String response = communicate(command);
return response.toInt();
}