-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathatem-c201.ino
1362 lines (1176 loc) · 49.6 KB
/
atem-c201.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************
* Basis control for the SKAARHOJ C20x series devices
* This example is programmed for ATEM 1M/E versions
*
* This example also uses several custom libraries which you must install first.
* Search for "#include" in this file to find the libraries. Then download the libraries from http://skaarhoj.com/wiki/index.php/Libraries_for_Arduino
*
* Works with ethernet-enabled arduino devices (Arduino Ethernet or a model with Ethernet shield)
* Run the example sketch "ConfigEthernetAddresses" to set up Ethernet before installing this sketch.
*
* - kasper
*
*/
/*
* Dodano za digole serial - uporablja še vedno SoftwareSerial lib
*
* popravljene metode in klici
* ni vec command statusa
*
* - Ferbi
*/
/*
* Dodano čiščenje Value na selektorjih ter pomnenje User Button preseta
*
* - Anže
*/
// Including libraries:
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include "WebServer.h" // For web interface
#include <EEPROM.h> // For storing IP numbers
#include <MenuBackend.h> // Library for menu navigation. Must (for some reason) be included early! Otherwise compilation chokes.
#include <SkaarhojTools.h>
SkaarhojTools sTools(1);
static uint8_t default_ip[] = { // IP for Configuration Mode (192.168.0.99)
192, 168, 0, 99 };
uint8_t ip[4]; // Will hold the C201 IP address
uint8_t atem_ip[4]; // Will hold the ATEM IP address
uint8_t mac[6]; // Will hold the Arduino Ethernet shield/board MAC address (loaded from EEPROM memory, set with ConfigEthernetAddresses example sketch)
/* MEMORY USAGE:
* This can be used to track free memory.
* Include "MemoryFree.h" and use the following line
* Serial << F("freeMemory()=") << freeMemory() << "\n";
* in your code to see available memory.
*/
//#include <MemoryFree.h>
// No-cost stream operator as described at
// http://arduiniana.org/libraries/streaming/
template<class T> inline Print &operator <<(Print &obj, T arg)
{
obj.print(arg);
return obj;
}
// Include ATEM library and make an instance:
#include <ATEMext.h>
ATEMext AtemSwitcher;
// All related to library "SkaarhojBI8", which controls the buttons:
#include "Wire.h"
#include "MCP23017.h"
#include "PCA9685.h"
#include "SkaarhojBI8.h"
SkaarhojBI8 previewSelect;
SkaarhojBI8 programSelect;
SkaarhojBI8 cmdSelect;
SkaarhojBI8 extraButtons;
// All related to library "SkaarhojUtils". Used for rotary encoder and "T-bar" potentiometer:
#include "SkaarhojUtils.h"
SkaarhojUtils utils;
/*************************************************************
*
*
* LCD PANEL FUNCTIONS
*
*
**********************************************************/
//#include <SoftwareSerial.h>
//#define txPin 7
//SoftwareSerial LCD = SoftwareSerial(0, txPin);
// Since the LCD does not send data back to the Arduino, we should only define the txPin
#define _Digole_Serial_UART_
#define txPin 7
#include <DigoleSerial.h>
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(0, txPin); // RX, TX
//DigoleSerialDisp LCD(&mySerial, 9600);
DigoleSerialDisp LCD(&Serial2, 9600);
const int LCDdelay=2; // 10 is conservative, 2 actually works
void lcdPosition(int row, int col) {
LCD.setPrintPos(col, row);
delay(LCDdelay);
}
void clearLCD(){
LCD.clearScreen();
delay(LCDdelay);
}
void backlightOn() { //turns on the backlight
LCD.backLightOn();
delay(LCDdelay);
}
void backlightOff(){ //turns off the backlight
LCD.backLightOff();
delay(LCDdelay);
}
void lcdPrintValue(int number, uint8_t padding) {
LCD.setPrintPos(1, 0);
//LCD.print(" ");
LCD.print(number);
for(int i=String(number).length(); i<padding; i++) {
LCD.print(" ");
}
}
/*************************************************************
*
*
* MENU SYSTEM
*
*
**********************************************************/
uint8_t userButtonMode = 0; // 0-3
uint8_t setMenuValues = 0; //
uint8_t BUSselect = 0; // Preview/Program by default
uint8_t inputs[8] = {1,2,3,4,5,6,7,8};
unsigned long timeoutMillis = 0;
bool timeoutDone = true;
// Configuration of the menu items and hierarchi plus call-back functions:
MenuBackend menu = MenuBackend(menuUseEvent,menuChangeEvent);
// Beneath is list of menu items needed to build the menu
MenuItem menu_UP1 = MenuItem(menu, "< Exit", 1);
MenuItem menu_mediab1 = MenuItem(menu, "Media Bank 1", 1); // On Change: Show selected item/Value (2nd encoder rotates). On Use: N/A
MenuItem menu_mediab2 = MenuItem(menu, "Media Bank 2", 1); // (As Media Bank 1)
MenuItem menu_trans = MenuItem(menu, "Transitions", 1); // (As User Buttons)
MenuItem menu_trtype = MenuItem(menu, "Type", 2); // (As Media Bank 1)
MenuItem menu_trtime = MenuItem(menu, "Trans. Time", 2); // (As Media Bank 1)
MenuItem menu_ftb = MenuItem(menu, "Fade To Black", 1);
MenuItem menu_ftbtime = MenuItem(menu, "FTB Time", 2);
MenuItem menu_ftbexec = MenuItem(menu, "Do Fade to Black", 2);
MenuItem menu_aux1 = MenuItem(menu, "AUX 1", 1); // (As Media Bank 1)
//MenuItem menu_aux2 = MenuItem(menu, "AUX 2", 1); // (As Media Bank 1)
//MenuItem menu_aux3 = MenuItem(menu, "AUX 3", 1); // (As Media Bank 1)
MenuItem menu_network = MenuItem(menu, "Network", 1);
MenuItem menu_ownIP = MenuItem(menu, "Own IP", 2);
MenuItem menu_AtemIP = MenuItem(menu, "ATEM IP", 2);
MenuItem menu_UP2 = MenuItem(menu, "< Exit", 1);
// This function builds the menu and connects the correct items together
void menuSetup()
{
Serial << F("Setting up menu...");
// Add first to the menu root:
menu.getRoot().add(menu_mediab1);
// Setup the rest of menu items on level 1:
menu_mediab1.addBefore(menu_UP1);
menu_mediab1.addAfter(menu_mediab2);
menu_mediab2.addAfter(menu_trans);
menu_trans.addAfter(menu_ftb);
menu_ftb.addAfter(menu_aux1);
menu_aux1.addAfter(menu_UP2);
//menu_aux2.addAfter(menu_aux3);
//menu_aux3.addAfter(menu_UP2);
// Set up transition menu:
menu_trtype.addAfter(menu_trtime); // Chain subitems...
menu_trtime.addLeft(menu_trans); // Add parent item
menu_trans.addRight(menu_trtype); // Add the submenu to the parent - this will also see "left" for "menu_trtype"
// Set up fade-to-black menu:
menu_ftbtime.addAfter(menu_ftbexec); // Chain subitems...
menu_ftbexec.addLeft(menu_ftb); // Add parent item
menu_ftb.addRight(menu_ftbtime); // Add the submenu to the parent
}
/*
Here all use events are handled. Mainly these are used to navigate in to and out of menu items with the encoder button.
*/
void menuUseEvent(MenuUseEvent used)
{
setMenuValues=0;
if (used.item.getName()=="MenuRoot") {
menu.moveDown();
}
// Exit in upper level:
if (used.item.isEqual(menu_UP1) || used.item.isEqual(menu_UP2)) {
menu.toRoot();
}
// This will set the selected element as default when entering the menu again.
// PS: I don't know why I needed to put the "*" before "used.item.getLeft()" It was a lucky guess, or...?
if (used.item.getLeft()) {
used.item.addLeft(*used.item.getLeft());
}
// Using an element moves left or right depending on where there are elements.
// This works fine for a two level menu like this one.
if((bool)used.item.getRight()) {
menu.moveRight();
} else {
menu.moveLeft();
}
}
/*
Here we get a notification whenever the user changes the menu
That is, when the menu is navigated
*/
void menuChangeEvent(MenuChangeEvent changed)
{
setMenuValues=0;
if (changed.to.getName()=="MenuRoot") {
// Show default text.... status whatever....
clearLCD();
lcdPosition(0,0);
LCD.print(F(" MEDIA TEAM"));
lcdPosition(1,0);
LCD.print(F(" C201"));
setMenuValues=0;
} else {
// Show the item name in upper line:
lcdPosition(0,0);
LCD.print(changed.to.getName());
for(int i=strlen(changed.to.getName()); i<16; i++) {
LCD.print(F(" "));
}
if (strlen(changed.to.getName())>16) {
lcdPosition(1,0);
for(int i=16; i<strlen(changed.to.getName()); i++) {
LCD.print(changed.to.getName()[i]);
}
}
// If there are no menu items to the right, we assume its a value change:
if (!(bool)changed.to.getRight()) {
// Make settings as a consequence of menu selection:
if (changed.to.getName() == menu_mediab1.getName()) { setMenuValues=1; }
if (changed.to.getName() == menu_mediab2.getName()) { setMenuValues=2; }
if (changed.to.getName() == menu_aux1.getName()) { setMenuValues=3; }
//if (changed.to.getName() == menu_aux2.getName()) { setMenuValues=4; }
//if (changed.to.getName() == menu_aux3.getName()) { setMenuValues=5; }
if (changed.to.getName() == menu_trtype.getName()) { setMenuValues=10; }
if (changed.to.getName() == menu_trtime.getName()) { setMenuValues=11; }
if (changed.to.getName() == menu_ftbtime.getName()) { setMenuValues=20; }
if (changed.to.getName() == menu_ftbexec.getName()) { setMenuValues=21; }
// TODO: I HAVE to find another way to match the items here because two items with the same name will choke!!
if (changed.to.getName() == menu_UP1.getName()) {
lcdPosition(1,0);
LCD.print(F(" ")); // Arrow + Clear the line...
}
} else { // Just clear the displays second line if there are items to the right in the menu:
lcdPosition(0,15);
LCD.print(F(">")); // Arrow + Clear the line...
lcdPosition(1,0);
LCD.print(F(" ")); // Arrow + Clear the line...
}
}
}
// Interrupt functions for encoders:
void _enc0active() {
utils.encoders_interrupt(0);
}
void _enc1active() {
utils.encoders_interrupt(1);
}
/*************************************************************
*
*
* Webserver
*
*
**********************************************************/
#define PREFIX ""
WebServer webserver(PREFIX, 80);
void logoCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
/* this data was taken from a PNG file that was converted to a C data structure
* by running it through the directfb-csource application.
* (Alternatively by PHPSH script "HeaderGraphicsWebInterfaceInUnitsPNG8.phpsh")
*/
P(logoData) = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00,
0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x02, 0xa2,
0x00, 0x00, 0x00, 0x2b, 0x08, 0x03, 0x00, 0x00, 0x00, 0x94,
0xff, 0x1a, 0xf8, 0x00, 0x00, 0x00, 0x19, 0x74, 0x45, 0x58,
0x74, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x00,
0x41, 0x64, 0x6f, 0x62, 0x65, 0x20, 0x49, 0x6d, 0x61, 0x67,
0x65, 0x52, 0x65, 0x61, 0x64, 0x79, 0x71, 0xc9, 0x65, 0x3c,
0x00, 0x00, 0x00, 0x30, 0x50, 0x4c, 0x54, 0x45, 0xe6, 0xe6,
0xe6, 0x0d, 0x5c, 0xaf, 0x0c, 0x61, 0xbd, 0x57, 0x89, 0xcc,
0xd7, 0xe2, 0xf2, 0xfa, 0xfa, 0xfa, 0x85, 0xa8, 0xd9, 0xab,
0xc2, 0xe3, 0xc7, 0xd6, 0xec, 0x0b, 0x51, 0x9d, 0x36, 0x76,
0xc4, 0x23, 0x68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, 0xf5, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45,
0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 };
if (type == WebServer::POST)
{
// ignore POST data
server.httpFail();
return;
}
/* for a GET or HEAD, send the standard "it's all OK headers" but identify our data as a PNG file */
server.httpSuccess("image/png");
/* we don't output the body for a HEAD request */
if (type == WebServer::GET)
{
server.writeP(logoData, sizeof(logoData));
}
}
// commands are functions that get called by the webserver framework
// they can read any posted data from client, and they output to server
void webDefaultView(WebServer &server, WebServer::ConnectionType type)
{
P(htmlHead) =
"<html>"
"<head>"
"<title>SKAARHOJ Device Configuration</title>"
"<style type=\"text/css\">"
"BODY { font-family: sans-serif }"
"H1 { font-size: 14pt; }"
"P { font-size: 10pt; }"
"</style>"
"</head>"
"<body>"
"<img src='logo.png'><br/>";
int i;
server.httpSuccess();
server.printP(htmlHead);
server << "<div style='width:660px; margin-left:10px;'><form action='" PREFIX "/form' method='post'>";
// Panel IP:
server << "<h1>SKAARHOJ Device IP Address:</h1><p>";
for (i = 0; i <= 3; ++i)
{
server << "<input type='text' name='IP" << i << "' value='" << EEPROM.read(i+2) << "' id='IP" << i << "' size='4'>";
if (i<3) server << '.';
}
server << "<hr/>";
// ATEM Switcher Panel IP:
server << "<h1>ATEM Switcher IP Address:</h1><p>";
for (i = 0; i <= 3; ++i)
{
server << "<input type='text' name='ATEM_IP" << i << "' value='" << EEPROM.read(i+2+4) << "' id='ATEM_IP" << i << "' size='4'>";
if (i<3) server << '.';
}
server << "<hr/>";
server << "<h1>Input Assignment</h1>";
for (i = 0; i < 8; i++)
{
server << "Button " << i+1 << ":";
server << "<input type='text' name='INPUT" << i << "' value='" << EEPROM.read(i+20) << "' id='INPUT" << i << "' size='6'>";
server << "<br/>";
}
server << "For special inputs, please refer to <a href='https://github.com/sestg/atem-c201/blob/master/inputs.md#atem-inputs' target='_blank'>this</a> table.";
// End form and page:
server << "</br><input type='submit' value='Submit'/></form></div>";
server << "<br><i>(Reset / Pull the power after submitting the form successfully)</i>";
server << "</body></html>";
}
void formCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
if (type == WebServer::POST)
{
bool repeat;
char name[16], value[16];
do
{
repeat = server.readPOSTparam(name, 16, value, 16);
String Name = String(name);
// C201 Panel IP:
if (Name.startsWith("IP")) {
int addr = strtoul(name + 2, NULL, 10);
int val = strtoul(value, NULL, 10);
if (addr>=0 && addr <=3) {
EEPROM.write(addr+2, val); // IP address stored in bytes 0-3
}
}
// ATEM Switcher Panel IP:
if (Name.startsWith("ATEM_IP")) {
int addr = strtoul(name + 7, NULL, 10);
int val = strtoul(value, NULL, 10);
if (addr>=0 && addr <=3) {
EEPROM.write(addr+2+4, val); // IP address stored in bytes 4-7
}
}
// Input assignment:
if (Name.startsWith("INPUT")) {
int input = strtoul(name + 5, NULL, 10);
int val = strtoul(value, NULL, 10);
if (input>=0 && input <=7) {
EEPROM.write(input+20, val); // IP address stored in bytes 4-7
}
}
}
while (repeat);
server.httpSeeOther(PREFIX "/form");
}
else
webDefaultView(server, type);
}
void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
webDefaultView(server, type);
}
/*************************************************************
*
*
* MAIN PROGRAM CODE AHEAD
*
*
**********************************************************/
bool isConfigMode; // If set, the system will run the Web Configurator, not the normal program
bool shiftState=false;
void setup() {
Serial.begin(9600);
Serial << F("\n- - - - - - - -\nSerial Started\n");
// *********************************
// Start up BI8 boards and I2C bus:
// *********************************
// Always initialize Wire before setting up the SkaarhojBI8 class!
Wire.begin();
// Set up the SkaarhojBI8 boards:
previewSelect.begin(0,false);
programSelect.begin(2,false);
cmdSelect.begin(7,false);
extraButtons.begin(1,false);
// *********************************
// Mode of Operation (Normal / Configuration)
// *********************************
// Determine web config mode
// This is done by:
// - either flipping a switch connecting A1 to GND
// - Holding the CUT button during start up.
pinMode(A1,INPUT_PULLUP);
delay(100);
isConfigMode = cmdSelect.buttonIsPressed(1) || (analogRead(A1) > 100) ? true : false;
// *********************************
// INITIALIZE EEPROM memory:
// *********************************
// Check if EEPROM has ever been initialized, if not, install default IP
if (EEPROM.read(0) != 12 || EEPROM.read(1) != 232) { // Just randomly selected values which should be unlikely to be in EEPROM by default.
// Set these random values so this initialization is only run once!
EEPROM.write(0,12);
EEPROM.write(1,232);
// Set default IP address for Arduino/C100 panel (192.168.0.99)
EEPROM.write(2,192);
EEPROM.write(3,168);
EEPROM.write(4,0);
EEPROM.write(5,99); // Just some value I chose, probably below DHCP range?
// Set default IP address for ATEM Switcher (192.168.0.240):
EEPROM.write(6,192);
EEPROM.write(7,168);
EEPROM.write(8,0);
EEPROM.write(9,240);
//Set default user button mode
EEPROM.write(17,0);
//Set default button assignments
for (int i = 0; i < 8;i++) {
EEPROM.write(i+20, i+1);
}
}
// *********************************
// Setting up IP addresses, starting Ethernet
// *********************************
if (isConfigMode) {
// Setting the default ip address for configuration mode:
ip[0] = default_ip[0];
ip[1] = default_ip[1];
ip[2] = default_ip[2];
ip[3] = default_ip[3];
} else {
ip[0] = EEPROM.read(0+2);
ip[1] = EEPROM.read(1+2);
ip[2] = EEPROM.read(2+2);
ip[3] = EEPROM.read(3+2);
}
// Setting the ATEM IP address:
atem_ip[0] = EEPROM.read(0+2+4);
atem_ip[1] = EEPROM.read(1+2+4);
atem_ip[2] = EEPROM.read(2+2+4);
atem_ip[3] = EEPROM.read(3+2+4);
Serial << F("SKAARHOJ Device IP Address: ") << ip[0] << "." << ip[1] << "." << ip[2] << "." << ip[3] << "\n";
Serial << F("ATEM Switcher IP Address: ") << atem_ip[0] << "." << atem_ip[1] << "." << atem_ip[2] << "." << atem_ip[3] << "\n";
// Setting MAC address:
mac[0] = EEPROM.read(10);
mac[1] = EEPROM.read(11);
mac[2] = EEPROM.read(12);
mac[3] = EEPROM.read(13);
mac[4] = EEPROM.read(14);
mac[5] = EEPROM.read(15);
char buffer[18];
sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
Serial << F("SKAARHOJ Device MAC address: ") << buffer << F(" - Checksum: ")
<< ((mac[0]+mac[1]+mac[2]+mac[3]+mac[4]+mac[5]) & 0xFF);
if ((uint8_t)EEPROM.read(16)!=((mac[0]+mac[1]+mac[2]+mac[3]+mac[4]+mac[5]) & 0xFF)) {
Serial << F("MAC address not found in EEPROM memory!\n") <<
F("Please load example sketch ConfigEthernetAddresses to set it.\n") <<
F("The MAC address is found on the backside of your Ethernet Shield/Board\n (STOP)");
while(true);
}
for (int i = 0; i<8;i++) {
inputs[i] = EEPROM.read(20+i);
}
Ethernet.begin(mac, ip);
// ********************
// Start up LCD (has to be after Ethernet has been started!)
// ********************
pinMode(txPin, OUTPUT);
LCD.begin();
clearLCD();
lcdPosition(0,0);
LCD.disableCursor();
LCD.print(F(" MEDIA TEAM"));
lcdPosition(1,0);
LCD.print(F(" C201"));
backlightOn();
delay(4000);
// *********************************
// Final Setup based on mode
// *********************************
if (isConfigMode) {
// LCD IP info:
clearLCD();
lcdPosition(0,0);
LCD.print(F("CONFIG MODE, IP:"));
lcdPosition(1,0);
LCD.print(ip[0]);
LCD.print('.');
LCD.print(ip[1]);
LCD.print('.');
LCD.print(ip[2]);
LCD.print('.');
LCD.print(ip[3]);
// Red by default:
previewSelect.setDefaultColor(2);
programSelect.setDefaultColor(2);
cmdSelect.setDefaultColor(2);
extraButtons.setDefaultColor(2);
previewSelect.setButtonColorsToDefault();
programSelect.setButtonColorsToDefault();
cmdSelect.setButtonColorsToDefault();
extraButtons.setButtonColorsToDefault();
webserver.begin();
webserver.setDefaultCommand(&defaultCmd);
webserver.addCommand("form", &formCmd);
webserver.addCommand("logo.png", &logoCmd);
} else {
// LCD IP info:
clearLCD();
lcdPosition(0,0);
LCD.print(F("IP Address:"));
lcdPosition(1,0);
LCD.print(ip[0]);
LCD.print('.');
LCD.print(ip[1]);
LCD.print('.');
LCD.print(ip[2]);
LCD.print('.');
LCD.print(ip[3]);
//delay(1000);
// Colors of buttons:
previewSelect.setDefaultColor(0); // Off by default
programSelect.setDefaultColor(0); // Off by default
cmdSelect.setDefaultColor(0); // Off by default
extraButtons.setDefaultColor(0); // Off by default
//previewSelect.testSequence(10);
//programSelect.testSequence(10);
//cmdSelect.testSequence(10);
//extraButtons.testSequence(10);
// Initializing the slider:
utils.uniDirectionalSlider_init();
utils.uniDirectionalSlider_hasMoved();
// Initializing menu control:
utils.encoders_init();
attachInterrupt(1, _enc0active, RISING);
attachInterrupt(0, _enc1active, RISING);
menuSetup();
// Connect to an ATEM switcher on this address and using this local port:
// The port number is chosen randomly among high numbers.
clearLCD();
lcdPosition(0,0);
LCD.print(F("Connecting to:"));
lcdPosition(1,0);
LCD.print(atem_ip[0]);
LCD.print('.');
LCD.print(atem_ip[1]);
LCD.print('.');
LCD.print(atem_ip[2]);
LCD.print('.');
LCD.print(atem_ip[3]);
AtemSwitcher.begin(IPAddress(atem_ip[0],atem_ip[1],atem_ip[2],atem_ip[3]));
// AtemSwitcher.serialOutput(true);
AtemSwitcher.connect();
}
}
/*************************************************************
* Loop function (runtime loop)
*************************************************************/
// AtemOnline is true, if there is a connection to the ATEM switcher
bool AtemOnline = false;
// The loop function:
void loop() {
if (isConfigMode) {
webserver.processConnection();
} else {
// Check for packets, respond to them etc. Keeping the connection alive!
AtemSwitcher.runLoop();
menuNavigation();
menuValues();
// If connection is gone, try to reconnect:
//if (AtemSwitcher.hasInitialized()) {
// AtemSwitcher.connect();
// }
// If the switcher has been initialized, check for button presses as reflect status of switcher in button lights:
if (AtemSwitcher.hasInitialized()) {
if (!AtemOnline) {
AtemOnline = true;
timeoutMillis = millis() + 5000;
timeoutDone = false;
//Serial << "Got 'em at " << millis() << ", timeout set to " << timeoutMillis << " " << timeoutDone;
clearLCD();
lcdPosition(0,0);
LCD.print(F(" Connection OK! "));
lcdPosition(1,0);
LCD.print(F(" WELCOME! "));
previewSelect.setDefaultColor(0); // Dimmed by default
programSelect.setDefaultColor(0); // Dimmed by default
cmdSelect.setDefaultColor(0); // Dimmed by default
extraButtons.setDefaultColor(0); // Dimmed by default
previewSelect.setButtonColorsToDefault();
programSelect.setButtonColorsToDefault();
cmdSelect.setButtonColorsToDefault();
extraButtons.setButtonColorsToDefault();
}
setButtonColors();
AtemSwitcher.runLoop(); // Call here and there...
readingButtonsAndSendingCommands();
AtemSwitcher.runLoop(); // Call here and there...
extraButtonsCommands2();
AtemSwitcher.runLoop(); // Call here and there...
} else {
if (AtemOnline) {
AtemOnline = false;
//Serial << "Lost it at " << millis();
timeoutDone = true;
menu.toRoot();
clearLCD();
lcdPosition(0,0);
LCD.print(F("Connection Lost!"));
lcdPosition(1,0);
LCD.print(F("Reconnecting... "));
previewSelect.setDefaultColor(0); // Off by default
programSelect.setDefaultColor(0); // Off by default
cmdSelect.setDefaultColor(0); // Off by default
extraButtons.setDefaultColor(0); // Off by default
previewSelect.setButtonColorsToDefault();
programSelect.setButtonColorsToDefault();
cmdSelect.setButtonColorsToDefault();
extraButtons.setButtonColorsToDefault();
}
}
if (timeoutMillis < millis() && timeoutDone == false ) {
Serial << millis() << "\n" << timeoutDone << "\n" << timeoutMillis << "\n" ;
timeoutDone = true;
menu.toRoot();
}
}
}
/**********************************
* Navigation for the main menu:
***********************************/
void menuNavigation() {
int encValue = utils.encoders_state(0,1000);
switch(encValue) {
case 1:
menu.moveDown();
timeoutMillis = millis() + 15000;
timeoutDone = false;
break;
case -1: