-
Notifications
You must be signed in to change notification settings - Fork 8
/
pjlink.js
1284 lines (1161 loc) · 32.1 KB
/
pjlink.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
/* eslint-disable no-useless-escape */
import { combineRgb, Regex, TCPHelper } from '@companion-module/base'
import { runEntrypoint, InstanceBase, InstanceStatus } from '@companion-module/base'
import crypto from 'crypto'
import * as CONFIG from './choices.js'
import { UpgradeScripts } from './upgrades.js'
function ar2obj(a) {
return a.map((e, i) => ({ id: `${i}`, label: e }))
}
function stamp() {
const d = new Date()
return `${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`
}
class PJInstance extends InstanceBase {
constructor(internal) {
super(internal)
}
async init(config) {
this.startup(config)
}
async configUpdated(config) {
// stop everything and reset
this.destroy(true)
this.startup(config)
}
// When module gets deleted
destroy(restart) {
if (this.socket !== undefined) {
this.socket.destroy()
delete this.socket
}
if (this.poll_interval !== undefined) {
clearInterval(this.poll_interval)
delete this.poll_interval
}
if (this.restartTimer !== undefined) {
clearInterval(this.restartTimer)
delete this.restartTimer
}
if (!restart) {
this.log('debug', `Destroy ${this.id}`)
}
}
startup(config) {
this.config = config
this.DebugLevel = process.env.DEVELOPER || this.config.debug ? 2 : 0
this.projector = {}
this.projector.lamps = []
for (let i = 1; i <= 8; i++) {
this.projector.lamps.push({
lamp: i,
hours: '',
on: 'off',
})
}
// Laser projectors return an error when asking
// for lamp hours
this.projector.isLaser = false
this.badPassword = false
this.projector.freezeState = '0'
this.projector.muteState = '00'
this.projector.inputNames = CONFIG.INPUTS
this.needInputs = true
this.commands = []
this.init_variables()
this.init_feedbacks()
this.buildActions() // export actions
this.init_tcp()
}
check_auth(data, cb) {
let code = []
let restart = 15000
if ('PJLINK ERRA' == data.toUpperCase()) {
if ('ok' == this.lastStatus.split(';')[0]) {
//projector reset its own digest
restart = 1000
} else if (this.lastStatus != InstanceStatus.ConnectionFailure + ';Auth') {
this.log('error', 'Authentication error. Password not accepted by projector')
this.updateStatus(InstanceStatus.ConnectionFailure, 'Authentication error')
this.lastStatus = InstanceStatus.ConnectionFailure + ';Auth'
restart = 15000
}
this.commands.length = 0
this.pjConnected = false
this.badPassword = true
this.authOK = false
this.passwordstring = ''
if (this.socket) {
this.socket.destroy()
}
delete this.socket
this.restartSocket(restart)
} else {
if ('PJLINK 0' == data.toUpperCase()) {
this.log('debug', 'Projector does not need password')
this.passwordstring = ''
this.authOK = true
} else if ((code = data.match(/^PJLINK 1 (\S+)/i))) {
let digest = code[1] + this.config.password
let hasher = crypto.createHash('md5')
this.passwordstring = hasher.update(digest, 'utf-8').digest('hex')
this.authOK = true
}
if (this.lastStatus != InstanceStatus.Ok + ';Auth') {
this.updateStatus(InstanceStatus.Ok, 'Auth OK')
this.lastStatus = InstanceStatus.Ok + ';Auth'
}
// send first command with (or without) auth password
this.lastCmd = '%1POWR ?'
this.socket?.send(this.passwordstring + this.lastCmd + '\r').then(() => {
this.getProjectorDetails()
if (this.poll_interval) {
delete this.poll_interval
}
this.pollTime = this.config.pollTime ? this.config.pollTime * 1000 : 10000
this.poll_interval = setInterval(this.poll.bind(this), this.pollTime) //ms for poll
this.poll()
})
}
if (typeof cb == 'function') {
cb()
}
}
restartSocket(waitTime = 5000) {
if (this.restartTimer) {
clearInterval(this.restartTimer)
delete this.restartTimer
}
this.restartTimer = setInterval(() => {
// don't restart if connected
if (this.socket === undefined || !this.socket.isConnected) {
this.updateStatus(InstanceStatus.ConnectionFailure, 'Retrying connection')
this.init_tcp()
}
}, waitTime)
}
init_tcp(cb) {
let receivebuffer = ''
this.passwordstring = ''
let args
let cmd
let err
let resp
let res
let projClass
if (this.socketTimer) {
clearInterval(this.socketTimer)
delete this.socketTimer
}
if (this.poll_interval) {
clearInterval(this.poll_interval)
delete this.poll_interval
}
if (this.socket !== undefined) {
this.socket.destroy()
delete this.socket
}
if (this.config.host) {
this.authOK = true
this.commands = []
const port = this.config.port || 4352
this.socket = new TCPHelper(this.config.host, port)
this.socket.on('error', (err) => {
if (err.code == 'EPIPE') {
// not really connected, yet
return
}
if (this.lastStatus != InstanceStatus.Error + ';' + err.name) {
this.updateStatus(InstanceStatus.Error, 'Network ' + err.message)
this.lastStatus = InstanceStatus.Error + ';' + err.name
this.log('error', 'Network ' + err.message)
}
this.pjConnected = false
this.authOK = false
this.commands = []
if (this.socketTimer) {
clearInterval(this.socketTimer)
delete this.socketTimer
}
if (this.socket !== undefined && this.socket.destroy !== undefined) {
this.socket.destroy()
delete this.socket
}
this.restartSocket()
})
this.socket.on('connect', () => {
receivebuffer = ''
this.connect_time = Date.now()
if (this.lastStatus != InstanceStatus.Connecting) {
this.updateStatus(InstanceStatus.Connecting, 'Authorizing')
this.log('info', 'Authorizing')
this.lastStatus = InstanceStatus.Connecting
}
this.pjConnected = true
if (this.restartTimer !== undefined) {
clearInterval(this.restartTimer)
delete this.restartTimer
}
this.authOK = false
})
this.socket.on('end', () => {
this.pjConnected = false
this.authOK = false
if (this.lastStatus != InstanceStatus.Error + ';Disc') {
this.log('error', 'Projector Disconnected')
this.updateStatus(InstanceStatus.Error, 'Disconnected')
this.lastStatus = InstanceStatus.Error + ';Disc'
}
// set timer to retry connection in 30 secs
if (this.socketTimer) {
clearInterval(this.socketTimer)
delete this.socketTimer
}
if (this.socket !== undefined && this.socket.destroy !== undefined) {
this.socket.destroy()
delete this.socket
}
this.log('debug', 'Disconnected')
this.restartSocket()
})
this.socket.on('data', (chunk) => {
// separate buffered stream into lines with responses
let i = 0,
line = '',
offset = 0
receivebuffer += chunk
while ((i = receivebuffer.indexOf('\r', offset)) !== -1) {
line = receivebuffer.slice(offset, i)
offset = i + 1
this.socket?.emit('receiveline', line.toString())
}
receivebuffer = receivebuffer.slice(offset)
})
this.socket.on('receiveline', async (data) => {
this.connect_time = Date.now()
if (this.DebugLevel > 1) {
this.log('debug', `PJLINK: < ${stamp()} ${data}`)
}
// auth password setup
if (data.match(/^PJLINK*/i)) {
this.check_auth(data, cb)
return
}
if ((args = data.match(/^(%(\d).+)=ERR(\d)/i))) {
let errorText = 'Unknown error'
let newState = 'warn'
let newStatus = InstanceStatus.UnknownWarning
cmd = args[1].toUpperCase()
projClass = parseInt(args[2])
err = args[3].toUpperCase()
switch (err) {
case '1':
if (cmd == '%1LAMP') {
errorText = 'Projector reports no lamp, disabling lamp check for Laser'
this.projector.isLaser = true
} else {
if (projClass === this.projector.class) {
errorText = 'Undefined command: ' + cmd
} else {
errorText = 'Command for different Protocol Class: ' + cmd
// downgrade to Class 1
this.projector.class = 1
}
}
break
case '2':
errorText = 'Projector reported ' + cmd
if (cmd.slice(2) == 'INPT') {
errorText += ': No such input'
} else {
errorText += ': Out of parameter'
}
break
case '3':
errorText = 'Projector Busy/Offline'
break
case '4':
errorText = 'Projector/Display failure'
newState = 'error'
newStatus = InstanceStatus.Error
break
}
if (cmd == '%2INNM' || (this.projector.powerState != '1' && err == '3')) {
// ignore. some PJ do not report input names
} else {
if (this.lastStatus != newStatus + ';' + err) {
this.log(newState, errorText)
this.updateStatus(newStatus, errorText)
this.lastStatus = newStatus + ';' + err
}
this.log('debug', `PJLINK ERROR: ${errorText}`)
}
} else if (data.match(/^PJLINK*/i)) {
// auth password setup
this.check_auth(data, cb)
} else {
let cmd = data.slice(0, 6).toUpperCase()
let resp = data.slice(7) // leave case alone for labels
// PJ returns 'OK' when command is accepted
// we need the status response
if ('OK' == resp) {
return
}
switch (cmd) {
case '%1CLSS':
this.projector.class = resp
this.setVariableValues({ projectorClass: resp })
this.socket.emit('projectorClass')
break
case '%1NAME':
this.projector.name = resp
this.setVariableValues({ projectorName: resp })
break
case '%1INF1':
this.projector.make = resp
this.setVariableValues({ projectorMake: resp })
break
case '%1INF2':
this.projector.model = resp
this.setVariableValues({ projectorModel: resp })
break
case '%1INFO':
this.projector.other = resp
this.setVariableValues({ projectorOther: resp })
break
case '%2RLMP':
this.projector.lampReplacement = resp
this.setVariableValues({ lampReplacement: resp })
break
case '%2RFIL':
this.projector.filterReplacement = resp
this.setVariableValues({ filterReplacement: resp })
break
case '%1INST':
this.projector.availInputs = resp.split(' ')
// class 1 does not report names
// so re-build a generic input list for this PJ
let classCount = new Array(Object.keys(CONFIG.INPUT_CLASS).length).fill(0)
this.projector.inputNames.length = 0
for (let p of this.projector.availInputs) {
let classNum = p[0]
let inClass = CONFIG.INPUT_CLASS[classNum]
classCount[classNum] += 1
this.projector.inputNames.push({
id: p,
label: `${inClass}-${classCount[classNum]} (${p})`,
})
}
this.updateActions = true
this.needInputs = false
break
case '%2INST':
this.needInputs = false
this.projector.availInputs = resp.split(' ')
// get input names from PJ
this.getInputName(this.projector.availInputs)
break
case '%2INNM':
if (this.projector.inputNames.length > this.haveNames) {
let idx = this.projector.inputNames.findIndex((o) => o.label === null)
let num = this.projector.inputNames[idx].id
this.projector.inputNames[idx].label = `${resp} (${num})`
this.haveNames += 1
this.updateActions = this.projector.inputNames.length == this.haveNames
}
break
case '%1POWR':
let powerTransition = this.projector.powerState + resp
this.badPassword = false
this.projector.powerState = resp
this.setVariableValues({ powerState: CONFIG.POWER_STATE[resp] })
this.checkFeedbacks('powerState')
// reset warining (if any)
if (resp == '1' && this.lastStatus != InstanceStatus.Ok + ';Auth') {
this.updateStatus(InstanceStatus.Ok, 'Auth OK')
this.lastStatus = InstanceStatus.Ok + ';Auth'
} else if (resp == '0' && this.lastStatus != InstanceStatus.Ok + ';Off') {
this.updateStatus(InstanceStatus.Ok, 'PJ Standby')
this.lastStatus = InstanceStatus.Ok + ';Off'
} else if (resp == '2' && this.lastStatus != InstanceStatus.Ok + ';Cool') {
this.updateStatus(InstanceStatus.Ok, 'PJ Cooling')
this.lastStatus = InstanceStatus.Ok + ';Cool'
} else if (resp == '3' && this.lastStatus != InstanceStatus.Ok + ';Warm') {
this.updateStatus(InstanceStatus.Ok, 'PJ Warmup')
this.lastStatus = InstanceStatus.Ok + ';Warm'
}
// PJ went from off/warm to powered on, initial Query Mute Status and input
if (['01', '31'].includes(powerTransition)) {
this.sendCmd('%1AVMT ?')
this.sendCmd(`%${this.projector.class}INPT ?`)
}
break
case '%1INPT':
case '%2INPT':
let iName = this.projector.inputNames.find((o) => o.id == resp)?.label
if (!iName) {
iName = CONFIG.INPUT_CLASS[resp[0]] + ' (' + resp + ')'
this.projector.inputNames.push({ id: resp, label: iName })
}
if (resp != this.projector.inputNum) {
this.projector.inputNum = resp
this.setVariableValues({ projectorInput: iName })
this.checkFeedbacks('projectorInput')
// only check input res when input changes
if (cmd[1] == '2') {
this.sendCmd('%2IRES ?')
}
}
break
case '%1LAMP':
let stat = resp.split(' ')
for (let i = 0; i < stat.length; i += 2) {
let thisLamp = Math.floor(i / 2)
let lampHours = stat[i]
let onState = stat[i + 1] == '1' ? 'On' : 'Off'
this.projector.lamps[thisLamp] = { lamp: thisLamp, hours: lampHours, on: onState }
this.setVariableValues({
[`lamp${thisLamp + 1}Hrs`]: lampHours,
[`lamp${thisLamp + 1}On`]: onState,
})
}
// fill table for unused lamps
for (let i = stat.length; i < 16; i += 2) {
let thisLamp = Math.floor(i / 2)
this.projector.lamps[thisLamp] = { lamp: thisLamp, hours: 0, on: 'Off' }
this.setVariableValues({
[`lamp${thisLamp + 1}Hrs`]: '',
[`lamp${thisLamp + 1}On`]: 'N/A',
})
}
this.checkFeedbacks('lampHour')
break
case '%2IRES':
res = resp.split('x')
this.projector.inputHorzRes = res[0]
this.projector.inputVertRes = res[1]
this.setVariableValues({
inputHorzRes: res[0],
inputVertRes: res[1],
})
break
case '%2RRES':
res = resp.split('x')
this.projector.recHorzRes = res[0]
this.projector.recVertRes = res[1]
this.setVariableValues({
recHorzRes: res[0],
recVertRes: res[1],
})
break
case '%1ERST':
const errs = resp.split('')
this.projector.errorFan = errs[0]
this.projector.errorLamp = errs[1]
this.projector.errorTemp = errs[2]
this.projector.errorCover = errs[3]
this.projector.errorFilter = errs[4]
this.projector.errorOther = errs[5]
this.setVariableValues({
errorFan: CONFIG.ERROR_STATE[errs[0]],
errorLamp: CONFIG.ERROR_STATE[errs[1]],
errorTemp: CONFIG.ERROR_STATE[errs[2]],
errorCover: CONFIG.ERROR_STATE[errs[3]],
errorFilter: CONFIG.ERROR_STATE[errs[4]],
errorOther: CONFIG.ERROR_STATE[errs[5]],
})
this.checkFeedbacks('errors')
break
case '%1AVMT':
this.projector.muteState = resp
let tmp = CONFIG.MUTE_ITEM[resp[0]]
tmp = tmp + ' ' + CONFIG.ON_OFF_STATE[resp[1]]
this.setVariableValues({ muteState: tmp })
this.checkFeedbacks('muteState')
break
case '%2FREZ':
this.projector.freezeState = resp
this.setVariableValues({ freezeState: CONFIG.ON_OFF_STATE[resp] })
this.checkFeedbacks('freezeState')
break
case '%2SNUM':
this.projector.serialNumber = resp
this.setVariableValues({ serialNumber: resp })
break
case '%2SVER':
this.projector.softwareVer = resp
this.setVariableValues({ softwareVer: resp })
break
case '%2FILT':
this.projector.filterUsageTime = resp
this.setVariableValues({ filterUsageTime: resp })
break
}
}
if (this.commands.length) {
if (this.lastCmd != data.slice(0, 6)) {
this.log('debug', `Response mismatch, expected ${this.lastCmd}`)
}
let nextCmd = this.commands.shift()
if (this.DebugLevel >= 1) {
this.log('debug', `PJLINK: > ${nextCmd}`)
}
this.lastCmd = nextCmd.slice(0, 6)
await this.socket?.send(this.passwordstring + nextCmd + '\r')
} else {
if (this.socketTimer) {
clearInterval(this.socketTimer)
delete this.socketTimer
}
this.socketTimer = setInterval(async () => {
// socket isn't connected, abort
if (this.socket === undefined || !this.socket?.isConnected) {
return
}
if (this.commands.length > 0) {
let cmd = this.commands.shift()
this.connect_time = Date.now()
this.lastCmd = cmd.slice(0, 6)
await this.socket.send(this.passwordstring + cmd + '\r')
clearInterval(this.socketTimer)
delete this.socketTimer
}
// istnv: an old version of the documentation stated 4 seconds.
// Reading through version 1.04 and version 2.00,
// idle time is 30 seconds
if (Date.now() - this.connect_time > 30000) {
if (this.socketTimer) {
clearInterval(this.socketTimer)
delete this.socketTimer
}
if (this.socket !== undefined && this.socket.destroy !== undefined) {
this.socket.destroy()
}
delete this.socket
this.pjConnected = false
this.authOK = false
this.log('debug', 'disconnecting per protocol defintion :(')
}
}, 100)
}
})
this.socket.connect()
}
}
async sendCmd(cmd) {
let sent = true
if (this.DebugLevel >= 1) {
this.log('debug', `PJLINK: >> ${stamp()} ${cmd}`)
}
if (this.DebugLevel >= 2) {
if (this.commands.length > 0) {
this.log('debug', `this.commands is ${this.commands}`)
}
}
if (this.badPassword) {
return
} else if (!this.authOK) {
sent = false
} else if (this.pjConnected) {
try {
await this.socket.send(this.passwordstring + cmd + '\r')
} catch (error) {
// connected but not ready :/
if (error.code == 'EPIPE') {
sent = false
}
}
}
if (!sent && !this.commands.includes(cmd)) {
this.commands.push(cmd)
}
}
// Return config fields for web config
getConfigFields() {
return [
{
type: 'textinput',
id: 'host',
label: 'Target IP',
width: 6,
regex: Regex.IP,
},
{
type: 'textinput',
id: 'password',
label: 'PJLink password (empty for none)',
width: 6,
},
{
type: 'number',
id: 'pollTime',
label: 'Enter polling time in seconds',
default: 10,
},
{
type: 'checkbox',
id: 'debug',
label: 'Enable extra debugging information',
default: false,
},
]
}
/**
* Setup actions for this module
*
* @since 2.0.0
*/
buildActions() {
let actions = {
powerState: {
name: 'Change Projector Power State',
options: [
{
type: 'dropdown',
label: 'Select Power State',
id: 'opt',
default: '1',
choices: ar2obj(CONFIG.ON_OFF_TOGGLE),
},
],
},
muteState: {
name: 'Change Projector Mute State ',
options: [
{
type: 'dropdown',
label: 'Select Mute',
id: 'item',
default: '3',
choices: ar2obj(CONFIG.MUTE_ITEM),
},
{
type: 'dropdown',
label: 'Select State',
id: 'opt',
default: '0',
choices: ar2obj(CONFIG.ON_OFF_TOGGLE),
},
],
},
freezeState: {
name: 'Change Projector Freeze State',
options: [
{
type: 'dropdown',
label: 'Select Freeze State',
id: 'opt',
default: '0',
choices: ar2obj(CONFIG.ON_OFF_TOGGLE),
},
],
},
inputToggle: {
name: 'Switch Projector Input',
options: [
{
type: 'dropdown',
label: 'Select input',
id: 'inputNum',
//default: this.projector.inputNames[0],
choices: this.projector.inputNames,
},
],
},
}
for (let cmd in actions) {
actions[cmd].callback = async (action, context) => {
this.doAction(action)
}
}
this.setActionDefinitions(actions)
}
doAction(action) {
let opt = action.options
let cmd = null
function setToggle(curVal, opt) {
return 2 == parseInt(opt) ? 1 - parseInt(curVal) : parseInt(opt)
}
switch (action.actionId) {
case 'powerState':
// don't send if warming/cooling
if ('01'.includes(this.projector.powerState)) {
cmd = '%1POWR ' + setToggle(this.projector.powerState, opt.opt)
}
break
case 'muteState':
cmd = '%1AVMT '
// toggle
if ('2' == opt.opt) {
var was = opt.item & (this.projector.muteState[0] * this.projector.muteState[1])
cmd += opt.item + (was == 0 ? '1' : '0')
} else {
// simple on/off
cmd += opt.item + opt.opt
}
break
case 'freezeState':
cmd = '%2FREZ ' + setToggle(this.projector.freezeState, opt.opt)
break
case 'inputToggle':
cmd = '%1INPT ' + opt.inputNum
break
}
if (cmd !== null) {
if (this.DebugLevel >= 1) {
this.log('debug', `sending ${cmd} to ${this.config.host}`)
}
// reset warining (if any)
if (this.lastStatus != InstanceStatus.Ok + ';Auth') {
this.updateStatus(InstanceStatus.Ok, 'Auth OK')
this.lastStatus = InstanceStatus.Ok + ';Auth'
}
this.sendCmd(cmd)
// follow up with a status update
this.sendCmd(cmd.slice(0, 7) + '?')
}
// log('debug','action():', action);
}
init_variables() {
var variables = []
variables.push({
name: 'Projector Class',
variableId: 'projectorClass',
})
variables.push({
name: 'Projector Name',
variableId: 'projectorName',
})
variables.push({
name: 'Projector Manufacturer',
variableId: 'projectorMake',
})
variables.push({
name: 'Projector Product Name',
variableId: 'projectorModel',
})
variables.push({
name: 'Projector Other Info',
variableId: 'projectorOther',
})
variables.push({
name: 'Error Status - Fan',
variableId: 'errorFan',
})
variables.push({
name: 'Error Status - Lamp',
variableId: 'errorLamp',
})
variables.push({
name: 'Error Status - Temp',
variableId: 'errorTemp',
})
variables.push({
name: 'Error Status - Cover',
variableId: 'errorCover',
})
variables.push({
name: 'Error Status - Filter',
variableId: 'errorFilter',
})
variables.push({
name: 'Error Status - Other',
variableId: 'errorOther',
})
variables.push({
name: 'Freeze Status',
variableId: 'freezeState',
})
variables.push({
name: 'Input Horizontal Resolution',
variableId: 'inputHorzRes',
})
variables.push({
name: 'Recommended Vertical Resolution',
variableId: 'recVertRes',
})
variables.push({
name: 'Recommended Horizontal Resolution',
variableId: 'recHorzRes',
})
variables.push({
name: 'Input Vertical Resolution',
variableId: 'inputVertRes',
})
variables.push({
name: 'Lamp 1 Hours',
variableId: 'lamp1Hrs',
})
variables.push({
name: 'Lamp 2 Hours',
variableId: 'lamp2Hrs',
})
variables.push({
name: 'Lamp 3 Hours',
variableId: 'lamp3Hrs',
})
variables.push({
name: 'Lamp 4 Hours',
variableId: 'lamp4Hrs',
})
variables.push({
name: 'Lamp 5 Hours',
variableId: 'lamp5Hrs',
})
variables.push({
name: 'Lamp 6 Hours',
variableId: 'lamp6Hrs',
})
variables.push({
name: 'Lamp 7 Hours',
variableId: 'lamp7Hrs',
})
variables.push({
name: 'Lamp 8 Hours',
variableId: 'lamp8Hrs',
})
variables.push({
name: 'Lamp 1 On',
variableId: 'lamp1On',
})
variables.push({
name: 'Lamp 2 On',
variableId: 'lamp2On',
})
variables.push({
name: 'Lamp 3 On',
variableId: 'lamp3On',
})
variables.push({
name: 'Lamp 4 On',
variableId: 'lamp4On',
})
variables.push({
name: 'Lamp 5 On',
variableId: 'lamp5On',
})
variables.push({
name: 'Lamp 6 On',
variableId: 'lamp6On',
})
variables.push({
name: 'Lamp 7 On',
variableId: 'lamp7On',
})
variables.push({
name: 'Lamp 8 On',
variableId: 'lamp8On',
})
variables.push({
name: 'Serial Number',
variableId: 'serialNumber',
})
variables.push({
name: 'Software Version',
variableId: 'softwareVer',
})
variables.push({
name: 'Filter Usage Time',
variableId: 'filterUsageTime',
})
variables.push({
name: 'Filter Replacment Model Number',
variableId: 'filterReplacement',
})
variables.push({
name: 'Lamp Replacment Model Number',
variableId: 'lampReplacement',
})
variables.push({
name: 'Mute Status',
variableId: 'muteState',
})
variables.push({
name: 'Projector Power Status',
variableId: 'powerState',
})
variables.push({
name: 'Projector Input',
variableId: 'projectorInput',
})
this.setVariableDefinitions(variables)
this.setVariableValues({
freezeState: 'N/A',
serialNumber: 'N/A',
softwareVer: 'N/A',
lampReplacement: 'N/A',
filterReplacement: 'N/A',
filterUsageTime: 'N/A',
inputHorzRes: 'N/A',
inputVertRes: 'N/A',
recHorzRes: 'N/A',
recVertRes: 'N/A',
})
}
init_feedbacks() {