-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiPresets.js
More file actions
473 lines (440 loc) · 16.6 KB
/
MultiPresets.js
File metadata and controls
473 lines (440 loc) · 16.6 KB
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
/* Camera Preserts Version 1.2 Frank Reijn
This SOFTWARE PRODUCT is provided "as is" and "with all faults."
There is no representations or warranties of any kind concerning the safety,
suitability, lack of viruses, inaccuracies, typographical errors,or
other harmful components of this SOFTWARE PRODUCT. There are inherent
dangers in the use of any software, and you are solely responsible for
determining whether this SOFTWARE PRODUCT is compatible with your equipment
and other software installed on your equipment.
You are also solely responsible for the protection of your equipment
and backup of your data, and THE PROVIDER will not be liable for any damages
you may suffer in connection with using, modifying, or distributing this SOFTWARE PRODUCT.
- How to : Speakertrack wil be de-activate when GUI is activated and does STAY de-activated!
Longpress a number does store the current active camera position , focus and zoom.
Focus WhiteBalance Brightness.. Easy I hope
EasterEgg, press the Smiley button. Position the camera for a wide view.
Longpress the Smily to store the positions. Find a suggestion position in the settings tab.
in the Settings there is a button for a suggestion camera position.
*/
const xapi = require('xapi');
const CAMERAID_CAMERA_LEFT = 1;
const CAMERAID_CAMERA_RIGHT = 2;
const CAMERACONNECTORID_CAMERA_LEFT = 1;
const CAMERACONNECTORID_CAMERA_RIGHT = 2;
// Long Press times values
const everysecond = 1500; // In milliseconds
var longp = 0; //longpress flag
var timerId= 0;
let camera1active = true;
let camera2active = false;
let camno =0;
// focus var's
let focuslevel = 4200;
let focusstepper = 100;
let focusstr = '10';
//Brightness
let Brightval = 20;
//WhiteBalance
let WBval = 1;
let initstate = 0; // only zero at first time !
let Easteregg = false; // enter easteregg mode
xapi.event.on('UserInterface Extensions Page Action', (event) => {
if(event.PageId == 'CamPresets'){
if(event.Type == 'Opened'){
if (initstate ==0){
initstate = 10;
setGuiValue('Autofocus', 'on');
xapi.Command.UserInterface.Extensions.Widget.SetValue({
WidgetId: 'brtext',
Value: 'A',
});
setGuiValue('bright', 'on');
setGuiValue('Whitebalance', 'on');
setGuiValue('standby', 'on');
xapi.Command.UserInterface.Extensions.Widget.SetValue({
WidgetId: 'wbtext',
Value: 'A',
});
//disable SpeakerTrack to avoid a runaway!
xapi.status.get('Cameras SpeakerTrack Status').then((pstatus) => {
if(pstatus == 'Active') {alert('', 'Please note : SpeakerTrack is now deactivated!!! ', 5)}});
xapi.command('Cameras SpeakerTrack Deactivate');
}
}
}
//Focus page pressed
if(event.PageId == 'Focus'){
if(event.Type == 'Opened'){
//xStatus Cameras Camera 1 Position Focus
//grab current focus value
camera1active &&xapi.status
.get('Cameras Camera 1 Position Focus')
.then((level) => {
focuslevel=level;
});
camera2active &&xapi.status
.get('Cameras Camera 2 Position Focus')
.then((level) => {
focuslevel = level;
});
}
}
});
// Cam zoom in out
xapi.event.on('UserInterface Extensions Widget Action', (event) => {
if(event.WidgetId == 'Zoom'){
if(event.Type == 'pressed'){
switch(event.Value){
case 'increment':
camera1active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_LEFT, Zoom: 'In', ZoomSpeed : '15'});
camera2active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_RIGHT, Zoom: 'In', ZoomSpeed : '15'});
break;
case 'decrement':
camera1active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_LEFT, Zoom: 'Out', ZoomSpeed : '15'});
camera2active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_RIGHT, Zoom: 'Out', ZoomSpeed : '15'});
break;
}
}
else if(event.Type == 'released'){
camera1active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_LEFT, Zoom: 'Stop'});
camera2active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_RIGHT,Zoom: 'Stop'});
}
}
// Enable disable AutoFocus
if(event.WidgetId == 'Autofocus'){
if(event.Type == 'changed'){
if (event.Value == "on"){
xapi.config.set('Cameras Camera 1 Focus Mode','Auto');
xapi.config.set('Cameras Camera 2 Focus Mode','Auto');
} else {
xapi.config.set('Cameras Camera 1 Focus Mode','Manual');
xapi.config.set('Cameras Camera 2 Focus Mode','Manual');
}
}
}
// Set Focus inc/dec speed 100x 10x 1x
if(event.WidgetId == 'fspeed'){
if(event.Type == 'pressed'){
focusstepper = parseInt(event.Value);
}
}
//set focus distance + or -
if(event.WidgetId == 'Focusset'){
if(event.Type == 'pressed'){
switch(event.Value){
case 'increment':
focuslevel = focuslevel +focusstepper;
focusstr=`${focuslevel}`;
break;
case 'decrement':
focuslevel = focuslevel -focusstepper;
focusstr=`${focuslevel}`;
break;
}
camera1active && xapi.command("Camera PositionSet", {CameraId: CAMERAID_CAMERA_LEFT,Focus:focusstr});
camera2active && xapi.command("Camera PositionSet", {CameraId: CAMERAID_CAMERA_RIGHT,Focus:focusstr});
}
else if(event.Type == 'released'){
// update the value to the Gui
xapi.Command.UserInterface.Extensions.Widget.SetValue({
WidgetId: 'Focusset',
Value: focuslevel,
});
}
}
// Enable disable Brightness
if(event.WidgetId == 'bright'){
if(event.Type == 'changed'){
if (event.Value == "on"){
xapi.config.set('Cameras Camera 1 Brightness Mode','Auto');
xapi.config.set('Cameras Camera 2 Brightness Mode','Auto');
xapi.Command.UserInterface.Extensions.Widget.SetValue({
WidgetId: 'brtext',
Value: 'A',
});
} else {
xapi.config.set('Cameras Camera 1 Brightness Mode','Manual');
xapi.config.set('Cameras Camera 2 Brightness Mode','Manual');
xapi.Command.UserInterface.Extensions.Widget.SetValue({
WidgetId: 'brtext',
Value: '20',
});
xapi.Command.UserInterface.Extensions.Widget.SetValue({
WidgetId: 'brightset',
Value: '255',
});
}
}
}
//set Brightness slider
if(event.WidgetId == 'brightset'){
if(event.Type == 'pressed'){
//none
}
else if(event.Type == 'released'){
Brightval = parseInt(Math.floor((event.Value * 0.1)));
camera1active && xapi.config.set('Cameras Camera 1 Brightness DefaultLevel',Brightval);
camera1active && xapi.config.set('Cameras Camera 2 Brightness DefaultLevel',Brightval);
// update the value to the Gui
xapi.Command.UserInterface.Extensions.Widget.SetValue({
WidgetId: 'brtext',
Value: Brightval,
});
}
}
// Enable disable WhiteBalance
if(event.WidgetId == 'Whitebalance'){
if(event.Type == 'changed'){
if (event.Value == "on"){
xapi.config.set('Cameras Camera 1 Whitebalance Mode','Auto');
xapi.config.set('Cameras Camera 2 Whitebalance Mode','Auto');
xapi.Command.UserInterface.Extensions.Widget.SetValue({
WidgetId: 'wbtext',
Value: 'A',
});
} else {
xapi.config.set('Cameras Camera 1 Whitebalance Mode','Manual');
xapi.config.set('Cameras Camera 2 Whitebalance Mode','Manual');
xapi.Command.UserInterface.Extensions.Widget.SetValue({
WidgetId: 'wbset',
Value: '255',
});
xapi.Command.UserInterface.Extensions.Widget.SetValue({
WidgetId: 'wbtext',
Value: '16',
});
}
}
}
//set WhiteBalance slider
if(event.WidgetId == 'wbset'){
if(event.Type == 'pressed'){
//none
}
else if(event.Type == 'released'){
WBval = parseInt(Math.floor((event.Value * 0.064)));
camera1active && xapi.config.set('Cameras Camera 1 Whitebalance Level',WBval);
camera2active && xapi.config.set('Cameras Camera 2 Whitebalance Level',WBval);
// update the value to the Gui
xapi.Command.UserInterface.Extensions.Widget.SetValue({
WidgetId: 'wbtext',
Value: WBval,
});
}
}
//cam position left right up down
if(event.WidgetId == 'NESW'){
if(event.Type == 'pressed'){
//start timer for long press check
timerId = setInterval(longpress, everysecond);
switch(event.Value){
case 'right':
if(camera1active && camera2active){
//noop
}
else{
camera1active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_LEFT, Pan: 'Right'});
camera2active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_RIGHT, Pan: 'Right'});
}
break;
case 'left':
if(camera1active && camera2active){
//noop
}
else{
camera1active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_LEFT, Pan: 'Left'});
camera2active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_RIGHT, Pan: 'Left'});
}
break;
case 'up':
camera1active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_LEFT, Tilt: 'Up'});
camera2active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_RIGHT, Tilt: 'Up'});
break;
case 'down':
camera1active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_LEFT, Tilt: 'Down'});
camera2active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_RIGHT, Tilt: 'Down'});
break;
case 'center':
//Set crazy wide view ( easter egg )
//camera1active = true;
//camera2active = true;
break;
default:
console.log(`Unhandled Navigation`);
}
}
else if(event.Type == 'released'){
camera1active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_LEFT, Tilt: 'Stop',Pan: 'Stop'});
camera2active && xapi.command("Camera Ramp", {CameraId: CAMERAID_CAMERA_RIGHT,Tilt: 'Stop',Pan: 'Stop'});
//Long Press stuff
clearInterval(timerId); //stop the timer
if (longp==1){
longp=0; //clear long flag
if (event.Value == 'center'){
xapi.command("Camera Preset Store", {PresetId: '14', CameraId: CAMERAID_CAMERA_LEFT });
xapi.command("Camera Preset Store", {PresetId: '13', CameraId: CAMERAID_CAMERA_RIGHT });
alert('', 'EasterEgg Preset positions Saved', 3);
}
}
else {
if (event.Value == 'center'){
Easteregg = !Easteregg;
if (Easteregg){ // Show Egg Text on GUI
setGuiValue('eggtext', 'EggM');
}
else{
setGuiValue('eggtext', '');
}
xapi.command("Camera Preset Activate",{PresetId: '13'});
xapi.command("Camera Preset Activate",{PresetId: '14'});
xapi.command("Video Input SetMainVideoSource", {ConnectorId: [CAMERACONNECTORID_CAMERA_LEFT, CAMERACONNECTORID_CAMERA_RIGHT]});
//xapi.command("Video Input SetMainVideoSource", {ConnectorId: [CAMERACONNECTORID_CAMERA_RIGHT, CAMERACONNECTORID_CAMERA_LEFT]});
}
}
}
}
// set active cam
if(event.WidgetId == 'CamSelect'){
if(event.Type == 'pressed'){
switch(event.Value){
case 'Cam1':
if (!Easteregg){
xapi.command("Video Input SetMainVideoSource", {ConnectorId: CAMERACONNECTORID_CAMERA_LEFT});
}
camera1active = true;
camera2active = false;
break;
case 'Cam2':
if (!Easteregg){
xapi.command("Video Input SetMainVideoSource", {ConnectorId: CAMERACONNECTORID_CAMERA_RIGHT});
}
camera2active = true;
camera1active = false;
default:
console.log(`Unhandled Navigation`);
}
}
}
// Enable Selfview
if(event.WidgetId == 'SelfView'){
if(event.Type == 'changed'){
if (event.Value == "on"){
xapi.command("Video Selfview Set", {Mode: 'On', FullscreenMode: 'On', OnMonitorRole: 'First'});
} else {
xapi.command("Video Selfview Set", {Mode: 'On', FullscreenMode: 'Off', OnMonitorRole: 'First'});
}
}
}
// Clear all presets
if(event.WidgetId == 'ClearAll'){
if(event.Type == 'pressed'){
xapi.command('Userinterface Message Prompt Display', {
Title: 'Camera Presets',
Text: 'Erease ALL presets?',
feedbackId: 'prompt0',
'Option.1': 'Yes Please !!',
'Option.2': 'No No No Cancel',
});
}
}
// Get or store preset button
if(event.WidgetId == 'Preset'){
if(event.Type == 'pressed'){
timerId = setInterval(longpress, everysecond);
switch(event.Value){
default:
//nop
}
}
else if(event.Type == 'released'){
clearInterval(timerId); //stop the timer
if (longp==1){
longp=0; //clear long flag
//store the active camera settings in a preset button.
camera1active && xapi.command("Camera Preset Store", {PresetId: event.Value, CameraId: CAMERAID_CAMERA_LEFT });
camera2active && xapi.command("Camera Preset Store", {PresetId: event.Value , CameraId: CAMERAID_CAMERA_RIGHT });
alert('', 'Preset position Saved', 3);
}
else {
// get camera in position of this preset
xapi.command("Camera Preset Activate",{PresetId: event.Value });
}
}
}
// Get or store preset button
if(event.WidgetId == 'eggsuggestion'){
if(event.Type == 'pressed'){
if(Easteregg){
xapi.command("Camera PositionSet", {CameraId: CAMERAID_CAMERA_LEFT,Tilt: '10',Pan: '4500',Zoom: '8500'});
xapi.command("Camera PositionSet", {CameraId: CAMERAID_CAMERA_RIGHT,Tilt: '130',Pan: '-3700',Zoom: '8500'});
}
else {
alert('', 'Please Activate EasterEgg mode first!!', 3);
}
}
}
// Enable disable auto Standby
if(event.WidgetId == 'standby'){
if(event.Type == 'changed'){
if (event.Value == "on"){
xapi.config.set('Standby Control:','On');
} else {
xapi.config.set('Standby Control:','Off');
}
}
}
});
// Debug utils
function listenToGui() {
xapi.Event.UserInterface.Extensions.on((event) => {
const msg = JSON.stringify(event);
alertBigScreen('UI Extensions event', msg);
console.log(msg);
});
}
function alertBigScreen(title, text, duration = 5) {
xapi.Command.UserInterface.Message.Alert.Display({
Title: title,
Text: text,
Duration: duration,
});
}
//listenToGui(); //remove comment to get debug output
// end of debug utils
// used and abused to sent notification to Tough10 and big screen
function alert(Title, Text, Duration = 5) {
xapi.Command.UserInterface.Message.Alert.Display({ Title, Text, Duration });
}
// only to set the longpress flag :-) from the timer
function longpress (){
longp =1; // set longpress flag
}
// update the Gui
async function setGuiValue(id, value) {
try {
await xapi.Command.UserInterface.Extensions.Widget.SetValue({
WidgetId: id,
Value: value,
})
} catch (error) {
console.error('Not able to set GUI value', id, value);
}
}
xapi.event.on('UserInterface Message Prompt Response', (event) => {
switch (event.FeedbackId + event.OptionId) {
case 'prompt0' + '1':
//xCommand Camera Preset Remove PresetId: PresetId
xapi.command("Camera Preset Remove", {PresetId: '5'});
xapi.command("Camera Preset Remove", {PresetId: '6'});
xapi.command("Camera Preset Remove", {PresetId: '7'});
xapi.command("Camera Preset Remove", {PresetId: '8'});
xapi.command("Camera Preset Remove", {PresetId: '9'});
xapi.command("Camera Preset Remove", {PresetId: '10'});
xapi.command("Camera Preset Remove", {PresetId: '11'});
xapi.command("Camera Preset Remove", {PresetId: '12'});
xapi.command("Camera Preset Remove", {PresetId: '13'});
xapi.command("Camera Preset Remove", {PresetId: '14'});
alert('', 'All Preset setting cleared ', 3);
break;
}
});