-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
261 lines (223 loc) · 5.94 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
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
// NovaStar-VX6S
var tcp = require('../../tcp');
var instance_skel = require('../../instance_skel');
var debug;
var log;
function instance(system, id, config) {
var self = this;
// super-constructor
instance_skel.apply(this, arguments);
self.actions(); // export actions
return self;
}
instance.prototype.CHOICES_INPUTS = [
{ id: '0', label: 'HDMI 1' },
{ id: '1', label: 'HDMI 2' },
{ id: '2', label: 'SDI 1' },
{ id: '3', label: 'SDI 2' },
{ id: '4', label: 'DVI 1' },
{ id: '5', label: 'DVI 2' },
{ id: '6', label: 'USB' }
]
instance.prototype.CHOICES_DISPLAY_MODES = [
{ id: '0', label: 'Normal' },
{ id: '1', label: 'Freeze' },
{ id: '2', label: 'Black' }
]
instance.prototype.updateConfig = function(config) {
var self = this;
self.config = config;
self.init_tcp();
}
instance.prototype.init = function() {
var self = this;
debug = self.debug;
log = self.log;
self.init_tcp();
}
instance.prototype.init_tcp = function() {
var self = this;
if (self.socket !== undefined) {
self.socket.destroy();
delete self.socket;
}
if (self.config.port === undefined) {
self.config.port = 5200;
}
if (self.config.host) {
self.socket = new tcp(self.config.host, self.config.port);
self.socket.on('status_change', function (status, message) {
self.status(status, message);
});
self.socket.on('error', function (err) {
debug('Network error', err);
self.log('error','Network error: ' + err.message);
});
self.socket.on('connect', function () {
let cmd = new Buffer([0x55,0xAA,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x00,0x57,0x56]);
self.socket.send(cmd);
debug('Connected');
});
// if we get any data, display it to stdout
self.socket.on('data', function(buffer) {
//var indata = buffer.toString('hex');
//future feedback can be added here
//console.log(indata);
console.log('Buffer:', buffer);
});
}
};
// Return config fields for web config
instance.prototype.config_fields = function () {
var self = this;
return [
{
type: 'text',
id: 'info',
width: 12,
label: 'Information',
value: 'This module will connect to a NovaStar VX6S LED Processor.'
},
{
type: 'textinput',
id: 'host',
label: 'IP Address',
width: 6,
default: '192.168.0.1',
regex: self.REGEX_IP
}
]
};
// When module gets deleted
instance.prototype.destroy = function() {
var self = this;
if (self.socket !== undefined) {
self.socket.destroy();
}
debug('destroy', self.id);
}
instance.prototype.actions = function() {
var self = this;
self.system.emit('instance_actions', self.id, {
'change_input': {
label: 'Change Input',
options:
[
{
type: 'dropdown',
label: 'Input',
id: 'input',
default: '0',
choices: self.CHOICES_INPUTS
}
]
},
'change_display_mode': {
label: 'Change Display Mode',
options:
[
{
type: 'dropdown',
label: 'Display Mode',
id: 'display_mode',
default: '0',
choices: self.CHOICES_DISPLAY_MODES
}
]
},
'pip_onoff': {
label: 'Turn Picture In Picture (PIP) On or Off',
options:
[
{
type: 'dropdown',
label: 'On/Off',
id: 'value',
default: '0',
choices:
[
{ id: '0', label: 'Off' },
{ id: '1', label: 'On' }
]
}
]
}
});
}
instance.prototype.action = function(action) {
var self = this;
var cmd;
var options = action.options;
var lf = '\u000a';
switch(action.action) {
case 'change_input':
switch(options.input) {
case '0':
//HDMI1
cmd = new Buffer([0x55,0xAA,0x00,0x88,0xFE,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x12,0x00,0x02,0x13,0x03,0x00,0x00,0x00,0x11,0x17,0x57]);
break;
case '1':
//HDMI2
cmd = new Buffer([0x55,0xAA,0x00,0xA8,0xFE,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x12,0x00,0x02,0x13,0x03,0x00,0x01,0x00,0x12,0x39,0x57]);
break;
case '2':
//SDI1
cmd = new Buffer([0x55,0xAA,0x00,0xC4,0xFE,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x12,0x00,0x02,0x13,0x03,0x00,0x02,0x00,0x31,0x75,0x57]);
break;
case '3':
//SDI2
cmd = new Buffer([0x55,0xAA,0x00,0xD4,0xFE,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x12,0x00,0x02,0x13,0x03,0x00,0x03,0x00,0x32,0x87,0x57]);
break;
case '4':
//DVI1
cmd = new Buffer([0x55,0xAA,0x00,0xD6,0xFE,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x12,0x00,0x02,0x13,0x03,0x00,0x04,0x00,0x01,0x59,0x57]);
break;
case '5':
//DVI2
cmd = new Buffer([0x55,0xAA,0x00,0xD7,0xFE,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x12,0x00,0x02,0x13,0x03,0x00,0x06,0x00,0x02,0x5d,0x57]);
break;
case '6':
//USB
cmd = new Buffer([0x55,0xAA,0x00,0xD9,0xFE,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x12,0x00,0x02,0x13,0x03,0x00,0x07,0x00,0x00,0x54,0x57]);
break;
}
break;
case 'change_display_mode':
switch(options.display_mode) {
case '0':
//Normal
cmd = new Buffer([0x55,0xAA,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x50,0x00,0x20,0x02,0x01,0x00,0x02,0xC7,0x56]);
break;
case '1':
//Freeze
cmd = new Buffer([0x55,0xAA,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x50,0x00,0x20,0x02,0x01,0x00,0x02,0xC8,0x56]);
break;
case '2':
//Black
cmd = new Buffer([0x55,0xAA,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x50,0x00,0x20,0x02,0x01,0x00,0x02,0xC9,0x56]);
break;
}
break;
case 'pip_onoff':
switch(options.value) {
case '0':
//Off
cmd = new Buffer([0x55,0xAA,0x00,0x00,0xFE,0xFF,0x00,0x00,0x00,0x00,0x01,0x00,0x30,0x00,0x20,0x02,0x01,0x00,0x00,0xA6,0x57]);
break;
case '1':
//On
cmd = new Buffer([0x55,0xAA,0x00,0x00,0xFE,0xFF,0x00,0x00,0x00,0x00,0x01,0x00,0x30,0x00,0x20,0x02,0x01,0x00,0x01,0xA7,0x57]);
break;
}
break;
}
if (cmd !== undefined) {
if (self.socket !== undefined && self.socket.connected) {
self.socket.send(cmd);
} else {
debug('Socket not connected :(');
}
}
};
instance_skel.extendedBy(instance);
exports = module.exports = instance;