-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
94 lines (80 loc) · 2.79 KB
/
index.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
var instance_skel = require('../../instance_skel');
const MarshallCamera = require('./visca/lib/Marshall/MarshallCamera');
const commands = require('./visca/lib/Marshall/commands')
const { Range, List } = require('./visca/lib/Parameters');
class instance extends instance_skel {
constructor(system, id, config) {
super(system, id, config)
this.initActions()
}
init() {
this.camera = new MarshallCamera(this.config.host)
}
updateConfig(config) {
if (this.config.host !== config.host) {
this.camera = new MarshallCamera(config.host)
}
this.config = config
}
destroy() {
}
config_fields() {
return [
{
type: 'text',
id: 'info',
width: 12,
label: 'Information',
value: 'This will establish a TCP connection to the device'
},
{
type: 'textinput',
id: 'host',
label: 'Target IP',
width: 6,
regex: this.REGEX_IP
}
]
}
initActions() {
let actions = {}
let commandsArray = Object.values(commands)
for (const command of commandsArray) {
const pattern = command.pattern
const parameters = pattern.getParameters()
let options = []
for (const parameter of parameters) {
let option = {
id: parameter.name,
label: parameter.name,
}
option.tooltip = parameter.comment
switch (parameter.constructor) {
case Range:
option.type = 'number',
option.min = parameter.min,
option.max = parameter.max,
option.default = parameter.min
option.required = true
break
case List:
option.type = 'dropdown',
option.choices = parameter.itemNameArray.map(itemName => ({ id: itemName, label: itemName}))
option.default = parameter.itemNameArray[0]
break
}
options.push(option)
}
const fullName = command.familyName ? `${command.familyName} - ${command.name}` : command.name
actions[fullName] = {
label: fullName,
options: options,
callback: ((action, _) => {
this.camera.sendCommand(command, action.options)
})
}
}
this.setActions(actions)
}
}
exports = module.exports = instance;