-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAVController.ino
317 lines (279 loc) · 7.27 KB
/
AVController.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/*
Project : AV & Dataton WatchOut Controller
Author : Eddy Yanto
Created : 28 November 2012
Description : A system interface for an iOS device and button control panel
to control amplifier (using IR LED), computers (using relay),
WatchOut cluster and projectors (using TCP sockets)
Change notes :
- 2015-02-10 : Changed IR interace to ethernet control for Marantz amplifier for better reliability
- 2015-03-11 : Added another physical button for trigger Duo show
*/
#include <SPI.h>
#include <Ethernet.h>
#include <IRremote.h>
// Change to 0 to enable logging on serial monitor
int enableLog = 0;
// Keep track of uptime
long currentMillis = 0;
// Local ethernet IP and mac setting
byte localMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte localIp[] = { 192, 168, 1, 48 };
// Local server: used to receive commands from iOS device
EthernetServer localServer = EthernetServer(3038);
EthernetClient connectedClient;
// Watchout cluster master
byte watchOutServer[] = { 192, 168, 1, 51 };
const int watchOutPort = 3039;
EthernetClient sharedClient;
// Projectors list
// Note: projectors and WatchOut share the same EthernetClient (sharedClient)
byte projectors[][4] = {
{ 192, 168, 1, 1 },
{ 192, 168, 1, 2 },
{ 192, 168, 1, 3 },
{ 192, 168, 1, 4 },
{ 192, 168, 1, 5 },
{ 192, 168, 1, 6 },
{ 192, 168, 1, 7 },
{ 192, 168, 1, 8 }
};
const int projectorPort = 4352;
// Amplifier
IRsend irsend;
byte marantzAmplifier[] = { 192, 168, 1, 10 };
const int marantzAmplifierPort = 23;
// Keep track of computers and amplifier status
int isDevicesOn = 0;
void setup()
{
Serial.begin(9600);
// Relay
pinMode(2, OUTPUT);
// IR led
// defaults to pin 3
// 4 buttons
pinMode(4, INPUT); // Ophir Duo show — button
pinMode(5, OUTPUT); // Ophir Duo show — led
pinMode(6, INPUT); // System OFF — button
pinMode(7, OUTPUT); // System OFF — led
pinMode(8, INPUT); // Marina One show — button
pinMode(9, OUTPUT); // Marina One show — led
pinMode(A2, INPUT); // System ON — button
pinMode(A3, OUTPUT); // System ON — led
Ethernet.begin(localMac, localIp);
localServer.begin();
_log("Control started.");
}
void loop()
{
// If iOS device connects, read the command and trigger
connectedClient = localServer.available();
if (connectedClient == true) {
char incoming = connectedClient.read();
_log("Connected client: " + connectedClient);
switch(incoming){
case 'A': // Turn OFF system
_log("Received A: Turn OFF.");
turnOffAll();
delay(100);
break;
case 'B': // Turn ON system
_log("Received B: Turn ON.");
turnOnAll();
delay(100);
break;
case 'C':
_log("Received C: Trigger Marina One show.");
triggerOneShow();
delay(100);
case 'd':
_log("Received D: Trigger Ophir Duo Show.");
triggerDuoShow();
default:
break;
}
// Close connected client so that they don't build up (only 4 max concurrent connection is allowed by Ethernet Shield)
// connectedClient.stop(); // Taken care on iOS side
}
// ON Button (GREEN)
if(digitalRead(A2) == HIGH){
digitalWrite(A3, HIGH);
turnOnAll();
delay(100);
}
else{
digitalWrite(A3, LOW);
}
// OFF button (RED)
if(digitalRead(6) == HIGH){
digitalWrite(7, HIGH);
turnOffAll();
delay(100);
}
else{
digitalWrite(7, LOW);
}
// PLAY Button (BLUE)
if(digitalRead(8) == HIGH){
digitalWrite(9, HIGH);
_log("Marina One button triggered.");
triggerOneShow();
delay(5000);
}
else{
digitalWrite(9, LOW);
}
// Duo Button (BLUE)
if(digitalRead(4) == HIGH){
digitalWrite(5, HIGH);
_log("Ophir Duo button triggered.");
triggerDuoShow();
delay(5000);
}
else{
digitalWrite(5, LOW);
}
}
void triggerOneShow(){
EthernetClient externalClient;
if(sharedClient.connect(watchOutServer, watchOutPort)){
delay(100);
sharedClient.flush();
sharedClient.println("\r");
sharedClient.println("authenticate 1\r\n");
delay(100);
sharedClient.println("gotoControlCue \"one\"\r\n");
sharedClient.println("run\r\n");
delay(100);
_log("WatchOut command sent");
}
else{
_log("WatchOut connection failed");
}
sharedClient.flush();
sharedClient.stop();
}
void triggerDuoShow(){
EthernetClient externalClient;
if(sharedClient.connect(watchOutServer, watchOutPort)){
delay(100);
sharedClient.flush();
sharedClient.println("\r");
sharedClient.println("authenticate 1\r\n");
delay(100);
sharedClient.println("gotoControlCue \"duo\"\r\n");
sharedClient.println("run\r\n");
delay(100);
_log("WatchOut command sent");
}
else{
_log("WatchOut connection failed");
}
sharedClient.flush();
sharedClient.stop();
}
void turnOnAll(){
isDevicesOn = 1;
turnOnProjectors();
turnOnAmplifier();
}
void turnOffAll(){
isDevicesOn = 0;
turnOffProjectors();
turnOffAmplifier();
}
// This function is phased out and replaced with
// turnOnAmplifier and turnOffAmplifier which uses Ethernet control
//void turnOnOffAmplifier(){
// irsend.sendRC5(0x40C, 12); //amplifier
// irsend.sendRC5(0x40C, 12); //amplifier
//}
void turnOnOffComputer(){
digitalWrite(2, HIGH);
delay(500); // Adjust accordingly since we're simulating power button push
digitalWrite(2, LOW);
}
void turnOnAmplifier(){
_log("Turning ON Amplifier started.");
if(sharedClient.connect(marantzAmplifier, marantzAmplifierPort)){
delay(200);
sharedClient.println("SIDVD");
sharedClient.stop();
_log(" success");
}
else{
_log(" failed");
sharedClient.flush();
sharedClient.stop();
}
_log("Turning ON amplifier ended.");
}
void turnOffAmplifier(){
_log("Turning OFF Amplifier started.");
if(sharedClient.connect(marantzAmplifier, marantzAmplifierPort)){
delay(200);
sharedClient.println("PWSTANDBY");
delay(1000);
sharedClient.stop();
delay(1000);
_log(" success");
}
else{
_log(" failed");
sharedClient.flush();
sharedClient.stop();
}
_log("Turning OFF amplifier ended.");
}
void turnOnProjectors(){
_log("Turning ON projectors started.");
for(int i = 0; i < 8; i++){
if(sharedClient.connect(projectors[i], projectorPort)){
delay(200);
sharedClient.println("%1POWR 1\r");
delay(1000);
sharedClient.stop();
delay(1000);
_log(String(i) + " success");
}
else{
_log(String(i) + " failed");
sharedClient.flush();
sharedClient.stop();
}
}
_log("Turning ON projectors ended.");
}
void turnOffProjectors(){
_log("Turning OFF projectors started.");
for(int i = 0; i < 8; i++){
if(sharedClient.connect(projectors[i], projectorPort)){
delay(200);
sharedClient.println("%1POWR 0\r");
delay(1000);
sharedClient.flush();
sharedClient.stop();
delay(1000);
_log(String(i) + " success");
}
else{
_log(String(i) + " failed");
sharedClient.flush();
sharedClient.stop();
}
}
_log("Turning OFF projectors ended.");
}
void _log(String message){
if(enableLog){
Serial.println(message);
}
}
void serialEvent() {
while (Serial.available()) {
enableLog = 1;
Serial.println("Serial logging enabled.");
Serial.read();
}
}