-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.js
53 lines (44 loc) · 1.11 KB
/
controller.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
'use strict';
const SerialPort = require('serialport')
const powerOn = [0x02, 0x30, 0x35, 0x03]
const powerOff = [0x02, 0x30, 0x36, 0x03]
const input1 = [0x02, 0x32, 0x31, 0x03]
const input2 = [0x02, 0x32, 0x32, 0x03]
const input3 = [0x02, 0x32, 0x33, 0x03]
const input4 = [0x02, 0x32, 0x34, 0x03]
var port = new SerialPort('/dev/ttyUSB1', {
baudRate: 9600
})
port.on('error', function(err) {
console.log('Error: ', err.message);
})
function sendCommand(cmd) {
port.write(cmd, function(err) {
if (err) {
print("Error", err)
}
})
}
module.exports.onButtonPressed = function onButtonPressed(name) {
console.log(`[CONTROLLER] ${name} button pressed`);
switch (name) {
case 'POWER ON':
sendCommand(powerOn);
break;
case 'POWER OFF':
sendCommand(powerOff);
break;
case 'INPUT 1':
sendCommand(input1);
break;
case 'INPUT 2':
sendCommand(input2);
break;
case 'INPUT 3':
sendCommand(input3);
break;
case 'INPUT 4':
sendCommand(input4);
break;
}
};