forked from bitfocus/companion-module-lectrosonics-aspen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
94 lines (74 loc) · 2.18 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
const InstanceSkel = require('../../instance_skel')
const configFields = require('./src/configFields')
const channelConfig = require('./src/channelConfig')
const tcp = require('./src/tcp')
const polling = require('./src/polling')
const actions = require('./src/actions')
const presets = require('./src/presets')
const feedbacks = require('./src/feedbacks')
class AspenInstance extends InstanceSkel {
constructor (system, id, config) {
super(system, id, config)
this.config = config
// Assign the methods from the listed files to this class
Object.assign(this, {
...configFields,
...channelConfig,
...tcp,
...polling,
...actions,
...presets,
...feedbacks
})
// Internal variables
this.data = {
deviceModel: null,
inputChannels: null,
outputChannels: null,
pollingInterval: null
}
// Internal device state
this.state = {}
}
init () {
this.status(this.STATUS_UNKNOWN)
// Init the actions
this.actions()
// Update the config
this.updateConfig()
}
updateConfig (config) {
if (config) {
this.config = config
}
// Quickly check if certain config values are present and continue setup
if (this.config.host && this.config.device_type) {
// Extract channelcount from Aspen model
const modelSpecs = /SPN(8|16|24)(12|24)/.exec(this.config.device_type)
this.data.deviceModel = modelSpecs[0]
this.data.inputChannels = Number(modelSpecs[1]) + 4 // 4 channels for testsignals
this.data.outputChannels = Number(modelSpecs[2])
// Update the channels and variables based on the selected model.
this.channelConfiguration()
// Update Variables
this.updateVariableDefinitions()
// Init the presets
this.presets()
// Init the TCP connection
this.initTCP()
// Start polling for settingvalues
this.initPolling()
// Init the feedbacks
this.feedbacks()
// Set status to OK
this.status(this.STATUS_OK)
}
}
destroy () {
if (this.socket !== undefined) {
this.socket.destroy()
}
this.debug('destroy', this.id)
}
}
module.exports = AspenInstance