-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrainer.c
1162 lines (958 loc) · 38.2 KB
/
trainer.c
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
// Petr Vanek
// LGPL
#include <ncurses.h> /* ncurses.h includes stdio.h */
//#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#ifndef WIN32
#include <glob.h> //find /dev/files
#include <termios.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#else
#include <winsock2.h>
//#include <windows.h>
#include "serialport.c" //includes windows.h
#include <io.h>
#endif
#include <time.h>
#include <getopt.h>
#include <errno.h>
#include <artnet/artnet.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#define INFO 0x14
#define RDM_UID 0x24
#define PACKET_START 0xA5
#define SEND_DMX 6
#define STOP_DMX_RDM 8
#define DMX_IN 4
#define SNIFFER 0x34
#ifndef WIN32
struct termios oldtio,newtio;
#endif
unsigned char buffer[1024];
int size;
int fd=-1;
#ifdef WIN32
HANDLE h; //serial port
#endif
#define ARTNET
//#define DEBUG
int calib[8][4]; // calibration values
int a,b; // helpers to init calib
int menu_r=0; // cursor position row
int menu_c=0; // cursor position column
WINDOW *w=NULL;
enum fixtures
{
NONE,
DLX,
DLS,
DLF
};
enum fixtures fixture = NONE;
int serial_port;
unsigned char serial_alias[42]="...searching...";
char serial_name[40];
int uid=0; //is DEVICE detected?
const char* fixtures_print[] = {
"press c to configure fixture",
"DL(4)X",
"DL(4)S",
"DL(4)F"
};
float fade_time;
int program_step = 0;
int current_step = 0;
int current_program = 0;
int program_length;
unsigned long tstart;
unsigned long tend;
unsigned long tallend;
unsigned long t;
int sum=0;
int tsum=0;
#ifndef DEBUG
int verbose = 0;
#else
int verbose = 1;
#endif
int MAXCHANNELS=512;
static artnet_node node;
unsigned char dmx[512]; //dmx array
// program,step,values
static int program[5][32][78]={
//first step is defining #of steps in program and delay time in ms for each step
//test program, pan/tilt movement
{}
,
{//DLX M1 The OFF 8000 4200 3200 2700 ON 8000 5600 4200 OFF 5600
{30,40,40,40,10,100,10,10,100,10,10,60,10,10,60,10,40,10,60,10,10,60,10,10,60,10,60,10,60,10,40}, //number of steps, delay for each step
{0,0,0,0,0,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//8000K WhitePoint ON (shutter off, 3sec)
{0,0,0,0,0,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//RGBW mixing ON (shutter off, 3sec),,
{0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//Theater mode OFF (3sec),,,
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,560,561,562,563,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//8000K calibration,,,
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,560,561,562,563,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,,,
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,560,561,562,563,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,,,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,520,521,522,523,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//4200K calibration,,,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,520,521,522,523,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,,,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,520,521,522,523,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,,,
{0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,510,511,512,513,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//3200K calibration,,,
{0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,510,511,512,513,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,,,
{0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,510,511,512,513,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,,,
{0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,500,501,502,503,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//2700K calibration,,,
{0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,500,501,502,503,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,,,
{0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,500,501,502,503,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,,,
{0,0,0,0,0,241,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//Theater mode ON (3sec),,,
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,570,571,572,573,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//8000K theater calibration,
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,570,571,572,573,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,,,
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,570,571,572,573,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,,,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,550,551,552,553,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//5600K theater calibration,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,550,551,552,553,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,,,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,550,551,552,553,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,,,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,530,531,532,533,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//4200K theater calibration
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,530,531,532,533,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,,,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,530,531,532,533,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,,,
{0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//Theater mode OFF (3sec),,,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,540,541,542,543,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//5600K calibration,,,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,540,541,542,543,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,,,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,540,541,542,543,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,,,
{128,0,128,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,540,541,542,543,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}//end,,,,
},
{//DLS
{30,40,40,40,10,20,10,10,20,10,10,20,10,10,20,10,40,10,20,10,10,20,10,10,20,10,40,10,20,10,40}, //number of steps, delay for each step
{0,0,0,0,0,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//8000K WhitePoint ON (shutter off, 3sec)
{0,0,0,0,0,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//RGBW mixing ON (shutter off, 3sec)
{0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//Theater mode OFF (3sec),
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,560,561,562,563,0},//8000K calibration,
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,560,561,562,563,0},//SAVE calibrations,
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,560,561,562,563,0},//back to 0 ,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,520,521,522,523,0},//4200K calibration,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,520,521,522,523,0},//SAVE calibrations,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,520,521,522,523,0},//back to 0 ,
{0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,510,511,512,513,0},//3200K calibration,
{0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,510,511,512,513,0},//SAVE calibrations,
{0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,510,511,512,513,0},//back to 0 ,
{0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,500,501,502,503,0},//2700K calibration,
{0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,500,501,502,503,0},//SAVE calibrations,
{0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,500,501,502,503,0},//back to 0 ,
{0,0,0,0,0,241,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//Theater mode ON (3sec),
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,570,571,572,573,0},//8000K theater calibration,
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,570,571,572,573,0},//SAVE calibrations,
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,570,571,572,573,0},//back to 0 ,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,550,551,552,553,0},//5600K theater calibration,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,550,551,552,553,0},//SAVE calibrations,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,550,551,552,553,0},//back to 0 ,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,530,531,532,533,0},//4200K theater calibration,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,530,531,532,533,0},//SAVE calibrations,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,530,531,532,533,0},//back to 0 ,
{0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//Theater mode OFF (3sec),
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,540,541,542,543,0},//5600K calibration,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,540,541,542,543,0},//SAVE calibrations,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,540,541,542,543,0},//back to 0 ,
{128,0,128,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,540,541,542,543,0}//end
},
{//DLF
{30,40,40,40,10,40,10,10,40,10,10,40,10,10,40,10,40,10,40,10,10,40,10,10,40,10,40,10,40,10,40}, //number of steps, delay for each step
{0,0,0,0,0,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//8000K WhitePoint ON (shutter off, 3sec)
{0,0,0,0,0,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//RGBW mixing ON (shutter off, 3sec)
{0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//Theater mode OFF (3sec)
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,560,561,562,563,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//8000K calibration
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,560,561,562,563,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,560,561,562,563,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,520,521,522,523,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//4200K calibration,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,520,521,522,523,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,520,521,522,523,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,
{0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,510,511,512,513,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//3200K calibration,
{0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,510,511,512,513,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,
{0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,510,511,512,513,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,
{0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,500,501,502,503,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//2700K calibration,
{0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,500,501,502,503,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,
{0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,500,501,502,503,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,
{0,0,0,0,0,241,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//Theater mode ON (3sec),
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,570,571,572,573,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//8000K theater calibration,
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,570,571,572,573,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,
{0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,570,571,572,573,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,550,551,552,553,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//5600K theater calibration,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,550,551,552,553,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,550,551,552,553,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,530,531,532,533,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//4200K theater calibration,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,530,531,532,533,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,
{0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,530,531,532,533,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,
{0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//Theater mode OFF (3sec),
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,540,541,542,543,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//5600K calibration,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,540,541,542,543,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//SAVE calibrations,
{0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,540,541,542,543,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//back to 0 ,
{128,0,128,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,540,541,542,543,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}//back to 0 ,
}
,
{
{5,20,20,20,20,20},//number of steps, delay for each step
{0,0},
{121,0,128,0},
{254,0,255,0},
{122,0,128,0},
{0,0}
}
};
// color temperatures labels
const char *c_temp[] = {
"2700 ",
"3200 ",
"4200 ",
"4200 Theatre",
"5600 ",
"5600 Theatre",
"8000 ",
"8000 Theatre",
};
void dmxusb_mute_dmx(){
buffer[0]=PACKET_START;
buffer[1]=STOP_DMX_RDM;
buffer[2]=0;
buffer[3]=0;
buffer[4]=buffer[0]+buffer[1]+buffer[2]+buffer[3];
buffer[5]=buffer[4]+buffer[4];
#ifndef WIN32
write(fd,buffer,6);
#else
writeToSerialPort(h,buffer,6);
#endif
}
void dmxusb_open_port(char *serial_name){
#ifndef WIN32
fd=open(serial_name,O_RDWR | O_NOCTTY);
if (fd<0) {
//chyba otevreni portu
#ifdef DEBUG
printf("chyba otevreni portu");
#endif
}
#else
//printf("inside open port: %s",serial_name);
h = openSerialPort(serial_name,B19200,one,off);
//h = openSerialPort(serial_name,B9600,one,off);
//Sleep(100);
#endif
#ifndef WIN32
#ifdef DEBUG
printf("port ready\n");
#endif
tcgetattr(fd,&oldtio);
memset(&newtio,0,sizeof(newtio));
newtio.c_iflag=0;
newtio.c_oflag=~OPOST;
newtio.c_cflag=CS8 | CSTOPB | CLOCAL | CREAD;
newtio.c_lflag=0;
newtio.c_cc[VTIME]=0;
newtio.c_cc[VMIN]=0;
if (tcsetattr(fd,TCSANOW,&newtio)==-1) {
//close(fd); //OSX failure, temporarily disabled
#ifdef DEBUG
printf("port setting error\n");
#endif
}
tcflush(fd,TCIFLUSH);
tcflush(fd,TCOFLUSH);
#ifdef DEBUG
printf("port settings done\n");
#endif
#endif
}
int file_exist (char *filename)
{
struct stat status;
return (stat(filename, &status) == 0);
}
int get_uid(){
buffer[0]=PACKET_START;
buffer[1]=RDM_UID;
buffer[2]=0;
buffer[3]=0;
buffer[4]=buffer[0]+buffer[1]+buffer[2]+buffer[3];
buffer[5]=buffer[4]+buffer[4];
#ifndef WIN32
write(fd,buffer,6+size);
struct timespec tim, tim2;
tim.tv_sec = 0;
tim.tv_nsec = 100000000L;
nanosleep(&tim,&tim2);
#else
writeToSerialPort(h,buffer,size+6);
Sleep(100);
#endif
int success=0;
int bytes;
#ifndef WIN32
fd_set read_fds, write_fds, except_fds;
FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
FD_ZERO(&except_fds);
FD_SET(fd, &read_fds);
struct timeval timeout;
timeout.tv_sec = 1;
timeout.tv_usec = 0;
if (select(fd + 1, &read_fds, &write_fds, &except_fds, &timeout)>0)
{
//printf("select OK\n");
if (FD_ISSET(fd, &read_fds)) {
ioctl(fd, FIONREAD, &bytes);
unsigned char data[bytes];
//printf("bytes ready: %d\n",bytes);
read(fd,data,bytes);
//printf("read bytes: %d\n",read(fd,data,bytes));
if (data[0]==0xa5){
if (data[1]==0x25){
success=1;
if(data[7]==0x02){
sprintf(serial_alias,"RUNIT WTX");
}
else if(data[7]==0x01){
sprintf(serial_alias,"RUI");
}
}}
}
}
#else
bytes=11;
unsigned char data[bytes];
//printf("reding bytes ready: %d\n",bytes);
readFromSerialPort(h,data,bytes);
//printf("read bytes: %d\n",read(fd,data,bytes));
if (data[0]==0xa5){
if (data[1]==0x25){
success=1;
if(data[7]==0x02){
sprintf(serial_alias,"RUNIT WTX");
}
else if(data[7]==0x01){
sprintf(serial_alias,"RUI");
}
}}
#endif
// fd is ready for reading
else
{
// timeout or error
//printf("error\n");
}
return success;
}
void init_artnet()
{
char *ip_addr = NULL;
int optc, subnet_addr = 0, port_addr = 0;
int bcast_limit = 0;
int an_sd;
char error_msg[40];
/* set up artnet node */
node = artnet_new(ip_addr, verbose);;
if(node == NULL) {
sprintf(error_msg,"Error: Unable to start Art-Net");
mvwprintw(w,13,1," ");
mvwprintw(w,13,1,"%s",error_msg);
//return 1;
}
// set names and node type
artnet_set_short_name(node, "TRAINER");
artnet_set_long_name(node, "The calibRAtIoN submittER");
artnet_set_node_type(node, ARTNET_SRV);
artnet_set_subnet_addr(node, subnet_addr);
// enable the first input port (1 universe only)
artnet_set_port_type(node, 0, ARTNET_ENABLE_INPUT, ARTNET_PORT_DMX);
artnet_set_port_addr(node, 0, ARTNET_INPUT_PORT, port_addr);
artnet_set_bcast_limit(node, bcast_limit);
//start the node
//artnet_start(node);
if (artnet_start(node) != ARTNET_EOK) {
sprintf(error_msg,"Error: Failed to start Art-Net");
mvwprintw(w,13,1," ");
mvwprintw(w,13,1,"%s",error_msg);
//printf("Failed to start: %s\n", artnet_strerror() );
//goto error_destroy;
// return 1;
}
// store the sds
an_sd = artnet_get_sd(node); //all as per examples
}
void find_port(){
static int i=0; //port iterator
#ifdef WIN32
#define ITER 100
#else
#define ITER 1
#endif
if ((i<ITER) && (!uid)){
#ifdef WIN32
if (i<10){
sprintf(serial_name,"COM%d",i);
}else{
sprintf(serial_name,"\\\\.\\COM%d",i);
}
printf(".");
//printf("opening port %s\n",serial_name);
dmxusb_open_port(serial_name);
uid=get_uid();
if (uid){ //>0
#ifdef DEBUG
printf("\n");
printf("found port: %s\n", serial_name);
printf("found device: %s\n",serial_alias);
#endif
mvwprintw(w,13,1," ");
mvwprintw(w,13,1,"%s %s",uid ? serial_name:"", serial_alias);
// break;
}else{
//printf("UID failed");
}
#else
glob_t glob_result;
#ifdef __APPLE__
glob("/dev/cu.usbserial*",GLOB_TILDE,NULL,&glob_result);
#else
glob("/dev/ttyUSB*",GLOB_TILDE,NULL,&glob_result);
#endif
printf("number of serial ports: %d\n",glob_result.gl_pathc);
unsigned int j=0;
while (j<glob_result.gl_pathc){ //iterate fast on UNIX as we have stat and can fail quickly
sprintf(serial_name,"%s",glob_result.gl_pathv[j]);
j++;
if (file_exist(serial_name))
{
printf("opening port %s\n",serial_name);
dmxusb_open_port(serial_name);
uid=get_uid();
if (uid){ //>0
#ifdef DEBUG
printf("\n");
printf("found port: %s\n", serial_name);
printf("found device: %s\n",serial_alias);
#endif
mvwprintw(w,13,1," ");
mvwprintw(w,13,1,"%s %s",uid ? serial_name:"", serial_alias);
break;
}else{
//printf("UID failed");
}
}
}
#endif
i++;
}else{
if (!uid){ //uid should be 0 if no serial
#ifdef ARTNET
sprintf(serial_alias,"Enabling Art-Net Output");
mvwprintw(w,13,1," ");
mvwprintw(w,13,1,"%s",serial_alias);
init_artnet();
uid=10;
#else
sprintf(serial_alias,"No DMX device found and Art-Net disabled");
mvwprintw(w,13,1," ");
mvwprintw(w,13,1,"%s",serial_alias);
#endif
}
}
}
void dmxusb_send_dmx(){
int i;
int CRC=0;
size=MAXCHANNELS;
buffer[0]=PACKET_START;
buffer[1]=SEND_DMX;
buffer[2]=(size) & 0x00ff;
buffer[3]=((size) >> 8) & 0x00ff;
buffer[4]=buffer[0]+buffer[1]+buffer[2]+buffer[3];
memcpy(&buffer[5],dmx,size);
for (i=0;i<5+size;i++) CRC+=buffer[i];
buffer[5+size]=(CRC & 0x00ff);
#ifdef DEBUG
printf("dmx out writted: %d\n",write(fd,buffer,6+size));
#else
write(fd,buffer,6+size);
#endif
#ifndef WIN32
write(fd,buffer,6+size);
#else
writeToSerialPort(h,buffer,size+6);
#endif
}
void conf(){
//set correct fixture type
fixture++;
if (fixture>3){
fixture=1;
}
}
void fill_dmx()
{
//change DMX values - use values from our program and where needed, fill in calibration values from calib array
for(a=0; a<512; a++)
{
if (a<78) //really only analyze first 70 channels of each DMX packet
{
int cur_val=program[current_program][current_step][a]; //our program values. re-write them by calibration values where value is 500 - indicating the slot
if (cur_val>499){
if (cur_val < 510)
{
dmx[a]=calib[0][cur_val-500];
}else if (cur_val < 520)
{
dmx[a]=calib[1][cur_val-510];
}else if (cur_val < 530)
{
dmx[a]=calib[2][cur_val-520];
}else if (cur_val < 540)
{
dmx[a]=calib[3][cur_val-530];
}else if (cur_val < 550)
{
dmx[a]=calib[4][cur_val-540];
}else if (cur_val < 560)
{
dmx[a]=calib[5][cur_val-550];
}else if (cur_val < 570)
{
dmx[a]=calib[6][cur_val-560];
}else if (cur_val < 580)
{
dmx[a]=calib[7][cur_val-570];
}else if (cur_val < 590)
{
dmx[a]=calib[8][cur_val-580];
}
}else{
dmx[a]=program[current_program][current_step][a]; //for other DMX slots, use the program values
}
}
else
{
//dmx[a]=0x00; //above 70, we don't care about DMX values. Should be 0 by default.
}
}
}
void init_calib(){
//initialize all calibration values to 128
//int sample=0; //test sequence to initialize calibrations by sequence of numbers
for(a=0; a<8; a++)
{
for (b=0;b<4;b++)
{
calib[a][b]=255;
// calib[a][b]=sample;
// sample++;
}
}
}
void get_input(int r,int c,char * str,int msg) //get user input for each calibration value
{
nodelay(w,FALSE); //reenable getch
echo(); // print characters as typed
curs_set(2); // show cursor
mvwprintw(w,r+3,c+19+(c*4),"%s"," ");
move(r+3,c+21+(c*4));
getnstr(str,3); //get 3 characters
int delka=0;
int num;
num = atoi(str);
delka=strlen(str);
switch (delka){
case 0: //no user input
calib[menu_r][menu_c]=msg; //keep original value
menu_c=menu_c+1;
if(menu_c>3){
menu_c=0;
menu_r=menu_r+1;
if(menu_r>7){
menu_r=0;
}
}
break;
default:
if (num >=0 && num<256) //check for range
{
calib[menu_r][menu_c]=num; //new value
menu_c=menu_c+1;
if(menu_c>3){
menu_c=0;
menu_r=menu_r+1;
if(menu_r>7){
menu_r=0;
}
}
}
else
{
//not a valid input, repeat - stay in editable prompt
get_input(menu_r,menu_c,str,calib[menu_r][menu_c]);
}
break;
}
noecho(); //edit is over, set terminal back to non edit mode - catch single char in main loop
curs_set(0);
nodelay(w,TRUE); //reenable getch
}
void msleep(long time) {
#ifndef WIN32
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 1000000*time;
nanosleep(&ts, NULL);
#else
Sleep(time);
#endif
}
// returns the time in milliseconds
unsigned long timeGetTime() {
#ifndef WIN32
struct timeval tv;
gettimeofday(&tv, NULL);
return (unsigned long)tv.tv_sec*1000UL + (unsigned long)tv.tv_usec/1000;
#else
SYSTEMTIME st;
GetSystemTime(&st);
//return (unsigned long)st.wSecond*1000UL + (unsigned long)st.wMilliseconds;
return (unsigned long) st.wHour*3600*1000UL + st.wMinute*60*1000UL + st.wSecond*1000UL + (unsigned long)st.wMilliseconds;
#endif
}
int do_step() { //loop for DMX sending
if (current_program != 0) { //send DMX only if any program is active
if (program_step!=current_step){ //new step
float fadetime = (float)program[current_program][0][program_step];
current_step=program_step;
tstart=timeGetTime();
tend=tstart+(int)(fadetime*100.0);
t=tstart;
sum = 0;
for (int i = program_step; i < program_length+1; i++) {
sum += program[current_program][0][i];
}
tallend=tstart+(sum*100.0);
if (current_step==1)
tsum=(int)sum;
}
if (t<=tend) { //not a new step, keep sending until time is up
t=timeGetTime();
int final = (tallend-timeGetTime())/100;
if (final < 0)
{
final = 0;
}
//print program progress
//printf("pl: %d\n",program_length);
// move(14,0);
attron(COLOR_PAIR(1));
//int percent=((tsum/6)-final-(tend-timeGetTime())/60)*100/(int)(tsum/6);
//int percent=((tsum/6)-final)*100/(int)(tsum/6);
int percent=((tsum)-final)*100/tsum;
//int percent=((tsum)-final);
//mvwprintw(w,14,1,"%s, Step %02d of %02d (Time %03d of %03d) %03i", fixtures_print[fixture],current_step,program_length, (tend-timeGetTime())/60,final,percent);
//mvwprintw(w,14,1,"%s, Step %02d of %02d (Time %03d of %03d) %03i", fixtures_print[fixture],current_step,program_length, tsum,final,percent);
mvwprintw(w,14,1,"%s, Step %02d of %02d %03i%%", fixtures_print[fixture],current_step,program_length,percent);
move(14,0.42*percent);
chgat(42, COLOR_PAIR(1), 0, NULL);
fill_dmx(); //fill in
msleep(40); //sleep why? (as per example from artnet libs)
//send DMX
if (uid==10) { //10 is artnet identifier
#ifdef ARTNET
char error_msg[40];
if (artnet_send_dmx(node,0,MAXCHANNELS, dmx)){
//printf("failed to send: %s\n", artnet_strerror() );
sprintf(error_msg,"Error: Unable to send Art-Net data");
mvwprintw(w,13,1," ");
mvwprintw(w,13,1,"%s",error_msg);
}
#endif
}else{
if(uid){
dmxusb_send_dmx(dmx,MAXCHANNELS);
}
}
msleep(40); //sleep dtto
t=timeGetTime(); // get current time, because the last time is too old (due to the sleep)
} else{
//next step
program_step++;
if (program_step > program_length){ //end of program
current_program=0;
program_step=0;
current_step=0;
//nodelay(w,FALSE);
mvwprintw(w,14,1,"Finished ");
#ifndef ARTNET
dmxusb_mute_dmx();
#endif
}
}
}
return 0;
}
void draw_screen() { //draw user interface
int i=0,x,y,z;
// color schemas
init_pair(1, COLOR_WHITE, COLOR_YELLOW);
init_pair(2, COLOR_RED, COLOR_GREEN);
init_pair(3, COLOR_RED, COLOR_WHITE);
init_pair(4, COLOR_GREEN, COLOR_WHITE);
init_pair(5, COLOR_BLUE, COLOR_WHITE);
init_pair(6, COLOR_BLACK, COLOR_WHITE);
init_pair(7, 244, COLOR_WHITE);
init_pair(8, COLOR_CYAN,COLOR_BLACK) ;
init_pair(9, COLOR_GREEN, COLOR_BLACK);
attron(COLOR_PAIR(5));
mvwprintw(w,0,1,"%s", "TRAINER The calibration submitter v0.9");
attron(COLOR_PAIR(6));
attron(A_BOLD);
mvwprintw(w,0,11,"%s", "T");
mvwprintw(w,0,20,"%s", "ra");
mvwprintw(w,0,23,"%s", "i");
mvwprintw(w,0,25,"%s", "n");
mvwprintw(w,0,34,"%s", "er");
attron(COLOR_PAIR(8));
attron(A_BOLD);
mvwprintw(w,1,1, " ");
mvwprintw(w,1,(45-strlen(fixtures_print[fixture]))/2, "%s", fixtures_print[fixture]);
attroff(A_BOLD);
attron(COLOR_PAIR(9));
mvwprintw(w,2,1,"%s", " Color Temperature Red Green Blue White ");
for(y=0; y<sizeof(c_temp)/sizeof(*c_temp); y+=1) //calibration values array UI
{
move(y+3,1);
attron(COLOR_PAIR(6));
//attron(A_UNDERLINE);
addstr(" ");
addstr(c_temp[y]);
addstr(" ");
move(y+3,20);
for(z=0;z<4;z++)
{
attron(COLOR_PAIR(z+3));
if (z==menu_c && y==menu_r){
attron(COLOR_PAIR(2));
}
printw(" %03d ",calib[y][z]);
}
addstr(" ");
}
//attroff(A_UNDERLINE);
// bottom buttons
attron(COLOR_PAIR(8));
attron(A_BOLD);
mvwprintw(w,12,1,"%s", "Entr: Edit");
// attron(COLOR_PAIR(8));
//mvprintw(12,10,"%s", "");
// attron(COLOR_PAIR(8));
mvwprintw(w,12,12,"%s", "r: Run");
mvwprintw(w,12,19,"%s", "t: Test");
mvwprintw(w,12,27,"%s", "s: Stop");
// attron(COLOR_PAIR(8));
mvwprintw(w,12,35,"%s", "q: Quit");
attroff(A_BOLD);
}
void cleanup() { //on exit
if(w) {
resetty();
endwin();
}
#ifdef ARTNET
artnet_stop(node);
#else
dmxusb_mute_dmx();
#ifndef WIN32
tcsetattr(fd,TCSANOW,&oldtio);
#else
closeSerialPort(h);
#endif
#endif
}
int main()
{
find_port();
//dmxusb_open_port("\\\\.\\COM35");
//get_uid();
//mvwprintw(w,18,1,"hledam port");
int c = 0;
char strr[3];
atexit(cleanup);
/* init curses */
w = initscr();
if (!w) {
printf ("unable to open main-screen\n");
return 1;
}
curs_set(0);
savetty();
start_color();
//attron(COLOR_PAIR(8));
noecho();
raw();
keypad(w, TRUE);
mousemask(ALL_MOUSE_EVENTS, NULL); //accept mouse events
//cbreak();
MEVENT event;
init_calib(); //fill calibrations with 128s
draw_screen();//draw UI
char e=' ';
//nodelay(w,TRUE);
timeout(50); //prevent 100% cpu usage during idle loop
mvwprintw(w,13,1," ");
mvwprintw(w,13,1,"%s %s",uid ? serial_name:"",serial_alias);
/* main loop */
c=0;
while (c!='q') {
c=wgetch(w);
switch (c) { //user input, single character
case KEY_MOUSE:
if(getmouse(&event) == OK)
{ /* When the user clicks left mouse button */
if(event.bstate & BUTTON1_CLICKED)