-
Notifications
You must be signed in to change notification settings - Fork 1
/
4_shutter_list.ino
82 lines (68 loc) · 1.55 KB
/
4_shutter_list.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
const int stepDelay = shutterRoundTime * 10;
class ShutterList {
public:
Shutter *list[shuttersSize];
ShutterList() {
list[0] = new Shutter(0, "left", RELAY_LEFT_UP, RELAY_LEFT_DOWN);
list[1] = new Shutter(1, "middle", RELAY_MIDDLE_UP, RELAY_MIDDLE_DOWN);
list[2] = new Shutter(2, "right", RELAY_RIGHT_UP, RELAY_RIGHT_DOWN);
}
Shutter *find(char* label) {
for (int i = 0; i < shuttersSize; i++) {
if (list[i]->label == String(label)) {
return list[i];
}
}
Serial.print("Invalid shutter label: ");
Serial.println(label);
}
void setup() {
for (int i = 0; i < shuttersSize; i++) {
list[i]->setup();
}
}
void loop() {
if (noSteps()) {
return;
}
delay(stepDelay);
afterStep();
}
void onMqttConnected() {
subscribe();
publishMqtt();
}
void subscribe() {
for (int i = 0; i < shuttersSize; i++) {
list[i]->subscribe();
}
}
void setPosition(char * label, String newPosition) {
find(label)->setPosition(newPosition);
}
void publishSerial() {
for (int i = 0; i < shuttersSize; i++) {
list[i]->publishSerial();
}
}
void publishMqtt() {
for (int i = 0; i < shuttersSize; i++) {
list[i]->publishMqtt();
}
}
private:
bool noSteps() {
for (int i = 0; i < shuttersSize; i++) {
if (list[i]->steps() != 0) {
return false;
}
}
return true;
}
void afterStep() {
for (int i = 0; i < shuttersSize; i++) {
list[i]->afterStep();
}
}
};
ShutterList shutters;