-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathusb-peripheral.js
38 lines (32 loc) · 1.03 KB
/
usb-peripheral.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
var usb = require('usb');
var UsbPeripheral = function() {
this.monitorWr = function(startRower, stopRower) {
var wrUsbEvent = function(device) {
if (!device) {
return false;
}
console.log('[USB] Device, ' +
'Vendor id: ' + device.deviceDescriptor.idVendor +
', Product id: ', device.deviceDescriptor.idProduct);
var idProduct = device.deviceDescriptor.idProduct;
if (device.deviceDescriptor.idVendor === 0x04d8 &&
device.deviceDescriptor.idProduct === 0x000a) {
return true;
}
return false;
};
usb.on('attach', function(device) {
if (wrUsbEvent(device)) {
console.log('[Init] WaterRower-S4.2 Connected to USB hub controller');
startRower();
}
});
usb.on('detach', function(device) {
if (wrUsbEvent(device)) {
console.log('[End] WaterRower-S4.2 Disconnected from USB hub controller');
stopRower();
}
});
};
};
module.exports.UsbPeripheral = UsbPeripheral;