Extract getUsbEndpoints() to util.js. Use ES6 features in led_pwm.js
This commit is contained in:
23
usb/util.js
23
usb/util.js
@@ -1,4 +1,27 @@
|
||||
var usb = require('usb');
|
||||
|
||||
exports = module.exports = {
|
||||
getUsbEndpoints: function() {
|
||||
var vid = 0x16d3;
|
||||
var pid = 0x05ea;
|
||||
|
||||
var device = usb.findByIds(vid, pid);
|
||||
device.open();
|
||||
|
||||
var usbInterface = device.interface(0);
|
||||
|
||||
// https://github.com/tessel/node-usb/issues/147
|
||||
// The function 'isKernelDriverActive' is not available on Windows and not even needed.
|
||||
if (process.platform !== 'win32' && usbInterface.isKernelDriverActive()) {
|
||||
usbInterface.detachKernelDriver();
|
||||
}
|
||||
usbInterface.claim();
|
||||
|
||||
var endpointIn = usbInterface.endpoints[0];
|
||||
var endpointOut = usbInterface.endpoints[1];
|
||||
return [endpointIn, endpointOut];
|
||||
},
|
||||
|
||||
bufferToString: function(buffer) {
|
||||
var str = '';
|
||||
for (var i = 0; i < buffer.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user