-
-
Notifications
You must be signed in to change notification settings - Fork 370
/
content_leds.js
executable file
·2427 lines (2093 loc) · 85.4 KB
/
content_leds.js
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
var onLedLayoutTab = false;
var nonBlacklistLedArray = [];
var ledBlacklist = [];
var finalLedArray = [];
var conf_editor = null;
var blacklist_editor = null;
var aceEdt = null;
var imageCanvasNodeCtx;
var canvas_height;
var canvas_width;
var topLeftPoint = null;
var topRightPoint = null;
var bottomRightPoint = null;
var bottomLeftPoint = null;
var topLeft2topRight = null;
var topRight2bottomRight = null;
var bottomRight2bottomLeft = null;
var bottomLeft2topLeft = null;
var toggleKeystoneCorrectionArea = false;
var devSPI = ['apa102', 'apa104', 'ws2801', 'lpd6803', 'lpd8806', 'p9813', 'sk6812spi', 'sk6822spi', 'sk9822', 'ws2812spi'];
var devRPiPWM = ['ws281x'];
var devRPiGPIO = ['piblaster'];
var devNET = ['atmoorb', 'cololight', 'fadecandy', 'philipshue', 'nanoleaf', 'razer', 'tinkerforge', 'tpm2net', 'udpe131', 'udpartnet', 'udpddp', 'udph801', 'udpraw', 'wled', 'yeelight'];
var devSerial = ['adalight', 'dmx', 'atmo', 'sedu', 'tpm2', 'karate'];
var devHID = ['hyperionusbasp', 'lightpack', 'paintpack', 'rawhid'];
var infoTextDefault = '<span>' + $.i18n("conf_leds_device_info_log") + ' </span><a href="" onclick="SwitchToMenuItem(\'MenuItemLogging\')" style="cursor:pointer">' + $.i18n("main_menu_logging_token") + '</a>';
var configPanel = "text";
function round(number) {
var factor = Math.pow(10, 4);
var tempNumber = number * factor;
var roundedTempNumber = Math.round(tempNumber);
return roundedTempNumber / factor;
};
function createLedPreview(leds) {
if (configPanel == "classic") {
$('#previewcreator').html($.i18n('conf_leds_layout_preview_originCL'));
$('#leds_preview').css("padding-top", "56.25%");
}
else if (configPanel == "text") {
$('#previewcreator').html($.i18n('conf_leds_layout_preview_originTEXT'));
$('#leds_preview').css("padding-top", "56.25%");
}
else if (configPanel == "matrix") {
$('#previewcreator').html($.i18n('conf_leds_layout_preview_originMA'));
$('#leds_preview').css("padding-top", "100%");
}
$('#previewledcount').html($.i18n('conf_leds_layout_preview_totalleds', leds.length));
$('#previewledpower').html($.i18n('conf_leds_layout_preview_ledpower', ((leds.length * 0.06) * 1.1).toFixed(1)));
$('.st_helper').css("border", "8px solid grey");
canvas_height = $('#leds_preview').innerHeight();
canvas_width = $('#leds_preview').innerWidth();
imageCanvasNodeCtx = document.getElementById("image_preview").getContext("2d");
$('#image_preview').css({ "width": canvas_width, "height": canvas_height });
var leds_html = "";
for (var idx = leds.length - 1; idx >= 0; idx--) {
var led = leds[idx];
var led_id = 'ledc_' + [idx];
var bgcolor = "background-color:hsla(" + (idx * 360 / leds.length) + ",100%,50%,0.75);";
var pos = "left:" + (led.hmin * canvas_width) + "px;" +
"top:" + (led.vmin * canvas_height) + "px;" +
"width:" + ((led.hmax - led.hmin) * (canvas_width - 1)) + "px;" +
"height:" + ((led.vmax - led.vmin) * (canvas_height - 1)) + "px;";
leds_html += '<div id="' + led_id + '" class="led" style="' + bgcolor + pos + '" title="' + idx + '"><span id="' + led_id + '_num" class="led_prev_num">' + ((led.name) ? led.name : idx) + '</span></div>';
}
$('#leds_preview').html(leds_html);
$('#ledc_0').css({ "background-color": "black", "z-index": "12" });
$('#ledc_1').css({ "background-color": "grey", "z-index": "11" });
$('#ledc_2').css({ "background-color": "#A9A9A9", "z-index": "10" });
if ($('#leds_prev_toggle_num').hasClass('btn-success'))
$('.led_prev_num').css("display", "inline");
if (onLedLayoutTab && configPanel == "classic" && toggleKeystoneCorrectionArea) {
// Calculate corner size (min/max:10px/18px)
var size = Math.min(Math.max(canvas_width / 100 * 2, 10), 18);
var corner_size = "width:" + size + "px; height:" + size + "px;";
var corners =
'<div id="top_left_point" class="keystone_correction_corners cursor_nwse" style="' + corner_size + '"></div>' +
'<div id="top_right_point" class="keystone_correction_corners cursor_nesw" style="' + corner_size + '"></div>' +
'<div id="bottom_right_point" class="keystone_correction_corners cursor_nwse" style="' + corner_size + '"></div>' +
'<div id="bottom_left_point" class="keystone_correction_corners cursor_nesw" style="' + corner_size + '"></div>';
$('#keystone_correction_area').html(corners).css({ "width": canvas_width, "height": canvas_height });
var top_left_point = document.getElementById('top_left_point'),
top_right_point = document.getElementById('top_right_point'),
bottom_right_point = document.getElementById('bottom_right_point'),
bottom_left_point = document.getElementById('bottom_left_point');
var maxWidth = $('#keystone_correction_area').innerWidth(),
maxHeight = $('#keystone_correction_area').innerHeight();
// Deactivate build-in cursor
PlainDraggable.draggableCursor = false;
PlainDraggable.draggingCursor = false;
// Top Left Point
topLeftPoint = new PlainDraggable(top_left_point, {
containment: {
left: parseInt($('#keystone_correction_area').offset().left - size / 2),
top: parseInt($('#keystone_correction_area').offset().top - size / 2),
width: parseInt(maxWidth + $('#top_left_point').outerWidth()),
height: parseInt(maxHeight + $('#top_left_point').outerHeight()),
},
onMove: function (newPosition) {
var keystone_correction_area_offsets = $('#keystone_correction_area').offset();
var left = newPosition.left - keystone_correction_area_offsets.left + size / 2;
var top = newPosition.top - keystone_correction_area_offsets.top + size / 2;
var ptlh = Math.min(Math.max((((left * 1) / maxWidth).toFixed(2) * 100).toFixed(0), 0), 100);
var ptlv = Math.min(Math.max((((top * 1) / maxHeight).toFixed(2) * 100).toFixed(0), 0), 100);
$('#ip_cl_ptlh').val(ptlh);
$('#ip_cl_ptlv').val(ptlv);
$("#ip_cl_ptlh, #ip_cl_ptlv").trigger("change");
}
});
// Initialize position
topLeftPoint.left = $('#keystone_correction_area').offset().left + maxWidth / 100 * $('#ip_cl_ptlh').val() - size / 2;
topLeftPoint.top = $('#keystone_correction_area').offset().top + maxHeight / 100 * $('#ip_cl_ptlv').val() - size / 2;
// Top right point
topRightPoint = new PlainDraggable(top_right_point, {
containment: {
left: parseInt($('#keystone_correction_area').offset().left - $('#top_right_point').outerWidth() + size / 2),
top: parseInt($('#keystone_correction_area').offset().top - size / 2),
width: parseInt(maxWidth + $('#top_right_point').outerWidth()),
height: parseInt(maxHeight + $('#top_right_point').outerHeight())
},
onMove: function (newPosition) {
var keystone_correction_area_offsets = $('#keystone_correction_area').offset();
var left = newPosition.left - keystone_correction_area_offsets.left + $('#top_right_point').outerWidth() - size / 2;
var top = newPosition.top - keystone_correction_area_offsets.top + size / 2;
var ptrh = Math.min(Math.max((((left * 1) / maxWidth).toFixed(2) * 100).toFixed(0), 0), 100);
var ptrv = Math.min(Math.max((((top * 1) / maxHeight).toFixed(2) * 100).toFixed(0), 0), 100);
$('#ip_cl_ptrh').val(ptrh);
$('#ip_cl_ptrv').val(ptrv);
$("#ip_cl_ptrh, #ip_cl_ptrv").trigger("change");
}
});
// Initialize position
topRightPoint.left = $('#keystone_correction_area').offset().left + maxWidth / 100 * $('#ip_cl_ptrh').val() - size / 2;
topRightPoint.top = $('#keystone_correction_area').offset().top + maxHeight / 100 * $('#ip_cl_ptrv').val() - size / 2;
// Bottom right point
bottomRightPoint = new PlainDraggable(bottom_right_point, {
containment: {
left: parseInt($('#keystone_correction_area').offset().left - $('#bottom_right_point').outerWidth() + size / 2),
top: parseInt($('#keystone_correction_area').offset().top - $('#bottom_right_point').outerHeight() + size / 2),
width: parseInt(maxWidth + $('#bottom_right_point').outerWidth()),
height: parseInt(maxHeight + $('#bottom_right_point').outerHeight())
},
onMove: function (newPosition) {
var keystone_correction_area_offsets = $('#keystone_correction_area').offset();
var left = newPosition.left - keystone_correction_area_offsets.left + $('#bottom_right_point').outerWidth() - size / 2;
var top = newPosition.top - keystone_correction_area_offsets.top + $('#bottom_right_point').outerHeight() - size / 2;
var pbrh = Math.min(Math.max((((left * 1) / maxWidth).toFixed(2) * 100).toFixed(0), 0), 100);
var pbrv = Math.min(Math.max((((top * 1) / maxHeight).toFixed(2) * 100).toFixed(0), 0), 100);
$('#ip_cl_pbrh').val(pbrh);
$('#ip_cl_pbrv').val(pbrv);
$("#ip_cl_pbrh, #ip_cl_pbrv").trigger("change");
}
});
// Initialize position
bottomRightPoint.left = $('#keystone_correction_area').offset().left + maxWidth / 100 * $('#ip_cl_pbrh').val() - size / 2;
bottomRightPoint.top = $('#keystone_correction_area').offset().top + maxHeight / 100 * $('#ip_cl_pbrv').val() - size / 2;
// Bottom left point
bottomLeftPoint = new PlainDraggable(bottom_left_point, {
containment: {
left: parseInt($('#keystone_correction_area').offset().left - size / 2),
top: parseInt($('#keystone_correction_area').offset().top - $('#bottom_left_point').outerHeight() + size / 2),
width: parseInt(maxWidth + $('#bottom_left_point').outerWidth()),
height: parseInt(maxHeight + $('#bottom_left_point').outerHeight())
},
onMove: function (newPosition) {
var keystone_correction_area_offsets = $('#keystone_correction_area').offset();
var left = newPosition.left - keystone_correction_area_offsets.left + size / 2;
var top = newPosition.top - keystone_correction_area_offsets.top + $('#bottom_left_point').outerHeight() - size / 2;
var pblh = Math.min(Math.max((((left * 1) / maxWidth).toFixed(2) * 100).toFixed(0), 0), 100);
var pblv = Math.min(Math.max((((top * 1) / maxHeight).toFixed(2) * 100).toFixed(0), 0), 100);
$('#ip_cl_pblh').val(pblh);
$('#ip_cl_pblv').val(pblv);
$("#ip_cl_pblh, #ip_cl_pblv").trigger("change");
}
});
// Initialize position
bottomLeftPoint.left = $('#keystone_correction_area').offset().left + maxWidth / 100 * $('#ip_cl_pblh').val() - size / 2;
bottomLeftPoint.top = $('#keystone_correction_area').offset().top + maxHeight / 100 * $('#ip_cl_pblv').val() - size / 2;
// Remove existing lines
if (topLeft2topRight != null) {
topLeft2topRight.remove();
}
if (topRight2bottomRight != null) {
topRight2bottomRight.remove();
}
if (bottomRight2bottomLeft != null) {
bottomRight2bottomLeft.remove();
}
if (bottomLeft2topLeft != null) {
bottomLeft2topLeft.remove();
}
// Get border color from keystone correction corners
var lineColor = $(".keystone_correction_corners").css("border-color");
// Add lines
topLeft2topRight = new LeaderLine(LeaderLine.pointAnchor(top_left_point, { x: '50%', y: '50%' }), LeaderLine.pointAnchor(top_right_point, { x: '50%', y: '50%' }), { path: 'straight', size: 1, color: lineColor, endPlug: 'behind' });
topRight2bottomRight = new LeaderLine(LeaderLine.pointAnchor(top_right_point, { x: '50%', y: '50%' }), LeaderLine.pointAnchor(bottom_right_point, { x: '50%', y: '50%' }), { path: 'straight', size: 1, color: lineColor, endPlug: 'behind' });
bottomRight2bottomLeft = new LeaderLine(LeaderLine.pointAnchor(bottom_right_point, { x: '50%', y: '50%' }), LeaderLine.pointAnchor(bottom_left_point, { x: '50%', y: '50%' }), { path: 'straight', size: 1, color: lineColor, endPlug: 'behind' });
bottomLeft2topLeft = new LeaderLine(LeaderLine.pointAnchor(bottom_left_point, { x: '50%', y: '50%' }), LeaderLine.pointAnchor(top_left_point, { x: '50%', y: '50%' }), { path: 'straight', size: 1, color: lineColor, endPlug: 'behind' });
} else {
$('#keystone_correction_area').html("").css({ "width": 0, "height": 0 });
// Remove existing lines
if (topLeft2topRight != null) {
topLeft2topRight.remove();
topLeft2topRight = null;
}
if (topRight2bottomRight != null) {
topRight2bottomRight.remove();
topRight2bottomRight = null;
}
if (bottomRight2bottomLeft != null) {
bottomRight2bottomLeft.remove();
bottomRight2bottomLeft = null;
}
if (bottomLeft2topLeft != null) {
bottomLeft2topLeft.remove();
bottomLeft2topLeft = null;
}
}
// Change on window resize. Is this correct?
$(window).off("resize.createLedPreview");
$(window).on("resize.createLedPreview", (function () {
createLedPreview(leds);
}));
}
function createClassicLedLayoutSimple(ledstop, ledsleft, ledsright, ledsbottom, position, reverse) {
let params = {
ledstop: 0, ledsleft: 0, ledsright: 0, ledsbottom: 0,
ledsglength: 0, ledsgpos: 0, position: 0,
ledsHDepth: 0.08, ledsVDepth: 0.05, overlap: 0,
edgeVGap: 0,
ptblh: 0, ptblv: 1, ptbrh: 1, ptbrv: 1,
pttlh: 0, pttlv: 0, pttrh: 1, pttrv: 0,
reverse: false
};
params.ledstop = ledstop;
params.ledsleft = ledsleft;
params.ledsright = ledsright;
params.ledsbottom = ledsbottom;
params.position = position;
params.reverse = reverse;
return createClassicLedLayout(params);
}
function createClassicLedLayout(params) {
var edgeHGap = params.edgeVGap / (16 / 9);
var ledArray = [];
function createFinalArray(array) {
var finalLedArray = [];
for (var i = 0; i < array.length; i++) {
var hmin = array[i].hmin;
var hmax = array[i].hmax;
var vmin = array[i].vmin;
var vmax = array[i].vmax;
finalLedArray[i] = { "hmax": hmax, "hmin": hmin, "vmax": vmax, "vmin": vmin }
}
return finalLedArray;
}
function rotateArray(array, times) {
if (times > 0) {
while (times--) {
array.push(array.shift())
}
return array;
}
else {
while (times++) {
array.unshift(array.pop())
}
return array;
}
}
function valScan(val) {
if (val > 1)
return 1;
if (val < 0)
return 0;
return val;
}
function ovl(scan, val) {
if (scan == "+")
return valScan(val += params.overlap);
else
return valScan(val -= params.overlap);
}
function createLedArray(hmin, hmax, vmin, vmax) {
hmin = round(hmin);
hmax = round(hmax);
vmin = round(vmin);
vmax = round(vmax);
ledArray.push({ "hmin": hmin, "hmax": hmax, "vmin": vmin, "vmax": vmax });
}
function createTopLeds() {
var steph = (params.pttrh - params.pttlh - (2 * edgeHGap)) / params.ledstop;
var stepv = (params.pttrv - params.pttlv) / params.ledstop;
for (var i = 0; i < params.ledstop; i++) {
var hmin = ovl("-", params.pttlh + (steph * Number([i])) + edgeHGap);
var hmax = ovl("+", params.pttlh + (steph * Number([i + 1])) + edgeHGap);
var vmin = params.pttlv + (stepv * Number([i]));
var vmax = vmin + params.ledsHDepth;
createLedArray(hmin, hmax, vmin, vmax);
}
}
function createRightLeds() {
var steph = (params.ptbrh - params.pttrh) / params.ledsright;
var stepv = (params.ptbrv - params.pttrv - (2 * params.edgeVGap)) / params.ledsright;
for (var i = 0; i < params.ledsright; i++) {
var hmax = params.pttrh + (steph * Number([i + 1]));
var hmin = hmax - params.ledsVDepth;
var vmin = ovl("-", params.pttrv + (stepv * Number([i])) + params.edgeVGap);
var vmax = ovl("+", params.pttrv + (stepv * Number([i + 1])) + params.edgeVGap);
createLedArray(hmin, hmax, vmin, vmax);
}
}
function createBottomLeds() {
var steph = (params.ptbrh - params.ptblh - (2 * edgeHGap)) / params.ledsbottom;
var stepv = (params.ptbrv - params.ptblv) / params.ledsbottom;
for (var i = params.ledsbottom - 1; i > -1; i--) {
var hmin = ovl("-", params.ptblh + (steph * Number([i])) + edgeHGap);
var hmax = ovl("+", params.ptblh + (steph * Number([i + 1])) + edgeHGap);
var vmax = params.ptblv + (stepv * Number([i]));
var vmin = vmax - params.ledsHDepth;
createLedArray(hmin, hmax, vmin, vmax);
}
}
function createLeftLeds() {
var steph = (params.ptblh - params.pttlh) / params.ledsleft;
var stepv = (params.ptblv - params.pttlv - (2 * params.edgeVGap)) / params.ledsleft;
for (var i = params.ledsleft - 1; i > -1; i--) {
var hmin = params.pttlh + (steph * Number([i]));
var hmax = hmin + params.ledsVDepth;
var vmin = ovl("-", params.pttlv + (stepv * Number([i])) + params.edgeVGap);
var vmax = ovl("+", params.pttlv + (stepv * Number([i + 1])) + params.edgeVGap);
createLedArray(hmin, hmax, vmin, vmax);
}
}
//rectangle
createTopLeds();
createRightLeds();
createBottomLeds();
createLeftLeds();
//check led gap pos
if (params.ledsgpos + params.ledsglength > ledArray.length) {
var mpos = Math.max(0, ledArray.length - params.ledsglength);
//$('#ip_cl_ledsgpos').val(mpos);
ledsgpos = mpos;
}
//check led gap length
if (params.ledsglength >= ledArray.length) {
//$('#ip_cl_ledsglength').val(ledArray.length-1);
params.ledsglength = ledArray.length - params.ledsglength - 1;
}
if (params.ledsglength != 0) {
ledArray.splice(params.ledsgpos, params.ledsglength);
}
if (params.position != 0) {
rotateArray(ledArray, params.position);
}
if (params.reverse)
ledArray.reverse();
return createFinalArray(ledArray);
}
function createClassicLeds() {
//get values
let params = {
ledstop: parseInt($("#ip_cl_top").val()),
ledsbottom: parseInt($("#ip_cl_bottom").val()),
ledsleft: parseInt($("#ip_cl_left").val()),
ledsright: parseInt($("#ip_cl_right").val()),
ledsglength: parseInt($("#ip_cl_glength").val()),
ledsgpos: parseInt($("#ip_cl_gpos").val()),
position: parseInt($("#ip_cl_position").val()),
reverse: $("#ip_cl_reverse").is(":checked"),
//advanced values
ledsVDepth: parseInt($("#ip_cl_vdepth").val()) / 100,
ledsHDepth: parseInt($("#ip_cl_hdepth").val()) / 100,
edgeVGap: parseInt($("#ip_cl_edgegap").val()) / 100 / 2,
//cornerVGap : parseInt($("#ip_cl_cornergap").val())/100/2,
overlap: $("#ip_cl_overlap").val() / 100,
//trapezoid values % -> float
ptblh: parseInt($("#ip_cl_pblh").val()) / 100,
ptblv: parseInt($("#ip_cl_pblv").val()) / 100,
ptbrh: parseInt($("#ip_cl_pbrh").val()) / 100,
ptbrv: parseInt($("#ip_cl_pbrv").val()) / 100,
pttlh: parseInt($("#ip_cl_ptlh").val()) / 100,
pttlv: parseInt($("#ip_cl_ptlv").val()) / 100,
pttrh: parseInt($("#ip_cl_ptrh").val()) / 100,
pttrv: parseInt($("#ip_cl_ptrv").val()) / 100,
}
nonBlacklistLedArray = createClassicLedLayout(params);
finalLedArray = blackListLeds(nonBlacklistLedArray, ledBlacklist);
//check led gap pos
if (params.ledsgpos + params.ledsglength > finalLedArray.length) {
var mpos = Math.max(0, finalLedArray.length - params.ledsglength);
$('#ip_cl_ledsgpos').val(mpos);
}
//check led gap length
if (params.ledsglength >= finalLedArray.length) {
$('#ip_cl_ledsglength').val(finalLedArray.length - 1);
}
createLedPreview(finalLedArray);
aceEdt.set(finalLedArray);
}
function createMatrixLayout(ledshoriz, ledsvert, cabling, start, direction) {
// Big thank you to RanzQ (Juha Rantanen) from Github for this script
// https://raw.githubusercontent.com/RanzQ/hyperion-audio-effects/master/matrix-config.js
var parallel = false
var leds = []
var hblock = 1.0 / ledshoriz
var vblock = 1.0 / ledsvert
if (cabling == "parallel") {
parallel = true
}
/**
* Adds led to the hyperion config led array
* @param {Number} x Horizontal position in matrix
* @param {Number} y Vertical position in matrix
*/
function addLed(x, y) {
var hscanMin = x * hblock
var hscanMax = (x + 1) * hblock
var vscanMin = y * vblock
var vscanMax = (y + 1) * vblock
hscanMin = round(hscanMin);
hscanMax = round(hscanMax);
vscanMin = round(vscanMin);
vscanMax = round(vscanMax);
leds.push({
hmin: hscanMin,
hmax: hscanMax,
vmin: vscanMin,
vmax: vscanMax
})
}
var startYX = start.split('-')
var startX = startYX[1] === 'right' ? ledshoriz - 1 : 0
var startY = startYX[0] === 'bottom' ? ledsvert - 1 : 0
var endX = startX === 0 ? ledshoriz - 1 : 0
var endY = startY === 0 ? ledsvert - 1 : 0
var forward = startX < endX
var downward = startY < endY
var x, y
if (direction === 'vertical') {
for (x = startX; forward && x <= endX || !forward && x >= endX; x += forward ? 1 : -1) {
for (y = startY; downward && y <= endY || !downward && y >= endY; y += downward ? 1 : -1) {
addLed(x, y)
}
if (!parallel) {
downward = !downward
var tmp = startY
startY = endY
endY = tmp
}
}
} else {
for (y = startY; downward && y <= endY || !downward && y >= endY; y += downward ? 1 : -1) {
for (x = startX; forward && x <= endX || !forward && x >= endX; x += forward ? 1 : -1) {
addLed(x, y)
}
if (!parallel) {
forward = !forward
var tmp = startX
startX = endX
endX = tmp
}
}
}
return leds;
}
function createMatrixLeds() {
// Big thank you to RanzQ (Juha Rantanen) from Github for this script
// https://raw.githubusercontent.com/RanzQ/hyperion-audio-effects/master/matrix-config.js
//get values
var ledshoriz = parseInt($("#ip_ma_ledshoriz").val());
var ledsvert = parseInt($("#ip_ma_ledsvert").val());
var cabling = $("#ip_ma_cabling").val();
var direction = $("#ip_ma_direction").val();
var start = $("#ip_ma_start").val();
nonBlacklistLedArray = createMatrixLayout(ledshoriz, ledsvert, cabling, start, direction);
finalLedArray = blackListLeds(nonBlacklistLedArray, ledBlacklist);
createLedPreview(finalLedArray);
aceEdt.set(finalLedArray);
}
function blackListLeds(nonBlacklistLedArray, blackList) {
var blacklistedLedArray = [...nonBlacklistLedArray];
if (blackList && blackList.length > 0) {
for (let item of blackList) {
var start = item.start;
var num = item.num
var layoutSize = blacklistedLedArray.length;
//Only consider rules which are in rage of defined number of LEDs
if (start >= 0 && start < layoutSize) {
// If number of LEDs exceeds layoutSize, use apply number until layout size
if (start + num > layoutSize) {
num = layoutSize - start;
}
for (var i = 0; i < num; i++) {
blacklistedLedArray[start + i] = { hmax: 0, hmin: 0, vmax: 0, vmin: 0 };
}
}
}
}
return blacklistedLedArray;
}
function getLedConfig() {
var ledConfig = { classic: {}, matrix: {} };
var classicSchema = window.serverSchema.properties.ledConfig.properties.classic.properties;
for (var key in classicSchema) {
if (classicSchema[key].type === "boolean")
ledConfig.classic[key] = $('#ip_cl_' + key).is(':checked');
else if (classicSchema[key].type === "integer")
ledConfig.classic[key] = parseInt($('#ip_cl_' + key).val());
else
ledConfig.classic[key] = $('#ip_cl_' + key).val();
}
var matrixSchema = window.serverSchema.properties.ledConfig.properties.matrix.properties;
for (var key in matrixSchema) {
if (matrixSchema[key].type === "boolean")
ledConfig.matrix[key] = $('#ip_ma_' + key).is(':checked');
else if (matrixSchema[key].type === "integer")
ledConfig.matrix[key] = parseInt($('#ip_ma_' + key).val());
else
ledConfig.matrix[key] = $('#ip_ma_' + key).val();
}
ledConfig.ledBlacklist = blacklist_editor.getEditor("root.ledBlacklist").getValue();
return ledConfig;
}
function isEmpty(obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key))
return false;
}
return true;
}
$(document).ready(function () {
// translate
performTranslation();
// update instance listing
updateHyperionInstanceListing();
//add intros
if (window.showOptHelp) {
createHintH("intro", $.i18n('conf_leds_device_intro'), "leddevice_intro");
createHintH("intro", $.i18n('conf_leds_layout_intro'), "layout_intro");
$('#led_vis_help').html('<div><div class="led_ex" style="background-color:black;margin-right:5px;margin-top:3px"></div><div style="display:inline-block;vertical-align:top">' + $.i18n('conf_leds_layout_preview_l1') + '</div></div><div class="led_ex" style="background-color:grey;margin-top:3px;margin-right:2px"></div><div class="led_ex" style="background-color: rgb(169, 169, 169);margin-right:5px;margin-top:3px;"></div><div style="display:inline-block;vertical-align:top">' + $.i18n('conf_leds_layout_preview_l2') + '</div>');
}
//**************************************************
// Handle LED-Layout Configuration
//**************************************************
var slConfig = window.serverConfig.ledConfig;
//restore ledConfig - Classic
for (var key in slConfig.classic) {
if (typeof (slConfig.classic[key]) === "boolean")
$('#ip_cl_' + key).prop('checked', slConfig.classic[key]);
else
$('#ip_cl_' + key).val(slConfig.classic[key]);
}
//restore ledConfig - Matrix
for (var key in slConfig.matrix) {
if (typeof (slConfig.matrix[key]) === "boolean")
$('#ip_ma_' + key).prop('checked', slConfig.matrix[key]);
else
$('#ip_ma_' + key).val(slConfig.matrix[key]);
}
// check access level and adjust ui
if (storedAccess == "default") {
$('#texfield_panel').toggle(false);
$('#previewcreator').toggle(false);
}
// Wiki link
$('#leds_wl').append('<p style="font-weight:bold">' + $.i18n('general_wiki_moreto', $.i18n('conf_leds_nav_label_ledlayout')) + buildWL("user/advanced/Advanced.html#led-layout", "Wiki") + '</p>');
// bind change event to all inputs
$('.ledCLconstr').on("change", function () {
//Ensure Values are in min/max ranges
if ($(this).val() < $(this).attr('min') * 1) { $(this).val($(this).attr('min')); }
if ($(this).val() > $(this).attr('max') * 1) { $(this).val($(this).attr('max')); }
//top/bottom and left/right must not overlap
switch (this.id) {
case "ip_cl_ptlh":
var ptrh = parseInt($("#ip_cl_ptrh").val());
if (this.value > ptrh) {
$(this).val(ptrh);
}
var pbrh = parseInt($("#ip_cl_pbrh").val());
if (this.value > pbrh) {
$(this).val(pbrh);
}
break;
case "ip_cl_ptrh":
var ptlh = parseInt($("#ip_cl_ptlh").val());
if (this.value < ptlh) {
$(this).val(ptlh);
}
var pblh = parseInt($("#ip_cl_pblh").val());
if (this.value < pblh) {
$(this).val(pblh);
}
break;
case "ip_cl_pblh":
var pbrh = parseInt($("#ip_cl_pbrh").val());
if (this.value > pbrh) {
$(this).val(pbrh);
}
var ptrh = parseInt($("#ip_cl_ptrh").val());
if (this.value > ptrh) {
$(this).val(ptrh);
}
break;
case "ip_cl_pbrh":
var pblh = parseInt($("#ip_cl_pblh").val());
if (this.value < pblh) {
$(this).val(pblh);
}
var ptlh = parseInt($("#ip_cl_ptlh").val());
if (this.value < ptlh) {
$(this).val(ptlh);
}
break;
case "ip_cl_ptlv":
var pblv = parseInt($("#ip_cl_pblv").val());
if (this.value > pblv) {
$(this).val(pblv);
}
var pbrv = parseInt($("#ip_cl_pbrv").val());
if (this.value > pbrv) {
$(this).val(pbrv);
}
break;
case "ip_cl_pblv":
var ptrv = parseInt($("#ip_cl_ptrv").val());
if (this.value < ptrv) {
$(this).val(ptrv);
}
var ptlv = parseInt($("#ip_cl_ptlv").val());
if (this.value < ptlv) {
$(this).val(ptlv);
}
break;
case "ip_cl_ptrv":
var pbrv = parseInt($("#ip_cl_pbrv").val());
if (this.value > pbrv) {
$(this).val(pbrv);
}
var pblv = parseInt($("#ip_cl_pblv").val());
if (this.value > pblv) {
$(this).val(pblv);
}
break;
case "ip_cl_pbrv":
var ptrv = parseInt($("#ip_cl_ptrv").val());
if (this.value < ptrv) {
$(this).val(ptrv);
}
var ptlv = parseInt($("#ip_cl_ptlv").val());
if (this.value < ptlv) {
$(this).val(ptlv);
}
break;
case "ip_cl_top":
case "ip_cl_bottom":
case "ip_cl_left":
case "ip_cl_right":
case "ip_cl_glength":
case "ip_cl_gpos":
var ledstop = parseInt($("#ip_cl_top").val());
var ledsbottom = parseInt($("#ip_cl_bottom").val());
var ledsleft = parseInt($("#ip_cl_left").val());
var ledsright = parseInt($("#ip_cl_right").val());
var maxLEDs = ledstop + ledsbottom + ledsleft + ledsright;
var gpos = parseInt($("#ip_cl_gpos").val());
$("#ip_cl_gpos").attr({ 'max': maxLEDs - 1 });
var max = maxLEDs - gpos;
if (gpos == 0) {
--max;
}
$("#ip_cl_glength").attr({ 'max': max });
var glength = parseInt($("#ip_cl_glength").val());
if (glength + gpos >= maxLEDs) {
$("#ip_cl_glength").val($("#ip_cl_glength").attr('max'));
}
break;
default:
}
createClassicLeds();
});
$('.ledMAconstr').on("change", function () {
valValue(this.id, this.value, this.min, this.max);
createMatrixLeds();
});
$('#collapse1').on('shown.bs.collapse', function () {
configPanel = "classic";
$("#leds_prev_toggle_keystone_correction_area").show();
createClassicLeds();
});
$('#collapse2').on('shown.bs.collapse', function () {
configPanel = "matrix";
$("#leds_prev_toggle_keystone_correction_area").hide();
createMatrixLeds();
});
$('#collapse5').on('shown.bs.collapse', function () {
configPanel = "text";
$("#leds_prev_toggle_keystone_correction_area").hide();
createLedPreview(finalLedArray);
aceEdt.set(finalLedArray);
});
// Initialise from config and apply blacklist rules
nonBlacklistLedArray = window.serverConfig.leds;
ledBlacklist = window.serverConfig.ledConfig.ledBlacklist;
finalLedArray = blackListLeds(nonBlacklistLedArray, ledBlacklist);
var blacklistOptions = window.serverSchema.properties.ledConfig.properties.ledBlacklist;
blacklist_editor = createJsonEditor('editor_container_blacklist_conf', {
ledBlacklist: blacklistOptions,
});
blacklist_editor.getEditor("root.ledBlacklist").setValue(ledBlacklist);
// v4 of json schema with diff required assignment - remove when hyperion schema moved to v4
var ledschema = { "items": { "additionalProperties": false, "required": ["hmin", "hmax", "vmin", "vmax"], "properties": { "name": { "type": "string" }, "colorOrder": { "enum": ["rgb", "bgr", "rbg", "brg", "gbr", "grb"], "type": "string" }, "hmin": { "maximum": 1, "minimum": 0, "type": "number" }, "hmax": { "maximum": 1, "minimum": 0, "type": "number" }, "vmin": { "maximum": 1, "minimum": 0, "type": "number" }, "vmax": { "maximum": 1, "minimum": 0, "type": "number" } }, "type": "object" }, "type": "array" };
//create jsonace editor
aceEdt = new JSONACEEditor(document.getElementById("aceedit"), {
mode: 'code',
schema: ledschema,
onChange: function () {
var success = true;
try {
aceEdt.get();
}
catch (err) {
success = false;
}
if (success) {
$('#leds_custom_updsim').prop("disabled", false);
$('#leds_custom_save').prop("disabled", false);
}
else {
$('#leds_custom_updsim').prop("disabled", true);
$('#leds_custom_save').prop("disabled", true);
}
if (window.readOnlyMode) {
$('#leds_custom_save').prop('disabled', true);
}
}
}, finalLedArray);
//TODO: HACK! No callback for schema validation - Add it!
setInterval(function () {
if ($('#aceedit table').hasClass('jsoneditor-text-errors')) {
$('#leds_custom_updsim').prop("disabled", true);
$('#leds_custom_save').prop("disabled", true);
}
}, 1000);
$('.jsoneditor-menu').toggle();
// validate textfield and update preview
$("#leds_custom_updsim").off().on("click", function () {
nonBlacklistLedArray = aceEdt.get();
finalLedArray = blackListLeds(nonBlacklistLedArray, ledBlacklist);
createLedPreview(finalLedArray);
});
// save led layout, the generated textfield configuration always represents the latest layout
$("#btn_ma_save, #btn_cl_save, #btn_bl_save, #leds_custom_save").off().on("click", function () {
var hardwareLedCount = conf_editor.getEditor("root.generalOptions.hardwareLedCount").getValue();
var layoutLedCount = aceEdt.get().length;
if (hardwareLedCount < layoutLedCount) {
// Not enough hardware LEDs for configured layout
showInfoDialog('error', $.i18n("conf_leds_config_error"), $.i18n('conf_leds_error_hwled_lt_layout', hardwareLedCount, layoutLedCount));
} else {
saveLedConfig(false);
}
});
// toggle right icon on "Advanced Settings" click
$('#advanced_settings').on('click', function (e) {
$('#advanced_settings_right_icon').toggleClass('fa-angle-down fa-angle-up');
});
// toggle fullscreen button in led preview
$(".fullscreen-btn").mousedown(function (e) {
e.preventDefault();
});
$(".fullscreen-btn").click(function (e) {
e.preventDefault();
$(this).children('i')
.toggleClass('fa-expand')
.toggleClass('fa-compress');
$('#layout_type').toggle();
$('#layout_preview').toggleClass('col-lg-6 col-lg-12');
window.dispatchEvent(new Event('resize'));
});
// toggle led numbers
$('#leds_prev_toggle_num').off().on("click", function () {
$('.led_prev_num').toggle();
toggleClass('#leds_prev_toggle_num', "btn-danger", "btn-success");
});
// toggle live video
$('#leds_prev_toggle_live_video').off().on("click", function () {
setClassByBool('#leds_prev_toggle_live_video', window.imageStreamActive, "btn-success", "btn-danger");
if (onLedLayoutTab && window.imageStreamActive) {
imageCanvasNodeCtx.clear();
if (!$('#leds_toggle_live_video').hasClass("btn-success")) {
requestLedImageStop();
}
}
else {
requestLedImageStart();
}
});
// toggle keystone correction area
$('#leds_prev_toggle_keystone_correction_area').off().on("click", function () {
toggleKeystoneCorrectionArea = !toggleKeystoneCorrectionArea
toggleClass('#leds_prev_toggle_keystone_correction_area', "btn-success", "btn-danger");
window.dispatchEvent(new Event('resize'));
});
$(window.hyperion).on("cmd-ledcolors-imagestream-update", function (event) {
//Only update Image, if LED Layout Tab is visible
if (onLedLayoutTab && window.imageStreamActive) {
setClassByBool('#leds_prev_toggle_live_video', window.imageStreamActive, "btn-danger", "btn-success");
var imageData = (event.response.result.image);
var image = new Image();
image.onload = function () {
imageCanvasNodeCtx.drawImage(image, 0, 0, imageCanvasNodeCtx.canvas.width, imageCanvasNodeCtx.canvas.height);
};
image.src = imageData;
}
});
// open checklist
$('#leds_prev_checklist').off().on("click", function () {
var liList = [$.i18n('conf_leds_layout_checkp1'), $.i18n('conf_leds_layout_checkp3'), $.i18n('conf_leds_layout_checkp2'), $.i18n('conf_leds_layout_checkp4')];
var ul = document.createElement("ul");
ul.className = "checklist"
for (var i = 0; i < liList.length; i++) {
var li = document.createElement("li");
li.innerHTML = liList[i];
ul.appendChild(li);
}
showInfoDialog('checklist', "", ul);
});
// nav
$('#leds_cfg_nav a[data-toggle="tab"]').off().on('shown.bs.tab', function (e) {
var target = $(e.target).attr("href") // activated tab
if (target == "#menu_gencfg") {
onLedLayoutTab = true;
$('#leds_custom_updsim').trigger('click');
} else {
onLedLayoutTab = false;
window.dispatchEvent(new Event('resize')); // remove keystone correction lines
}
blacklist_editor.on('change', function () {
// only update preview, if config is valid
if (blacklist_editor.validate().length <= 0) {
ledBlacklist = blacklist_editor.getEditor("root.ledBlacklist").getValue();
finalLedArray = blackListLeds(nonBlacklistLedArray, ledBlacklist);
createLedPreview(finalLedArray);
aceEdt.set(finalLedArray);
}
// change save button state based on validation result
blacklist_editor.validate().length || window.readOnlyMode ? $('#btn_bl_save').prop('disabled', true) : $('#btn_bl_save').prop('disabled', false);
});
});
//**************************************************
// Handle LED-Device Configuration
//**************************************************
// External properties properties, 2-dimensional arry of [ledType][key]