Extract getUsbEndpoints() to util.js. Use ES6 features in led_pwm.js

This commit is contained in:
László Monda
2017-01-15 01:00:55 +01:00
parent 180d40a7a5
commit 199030effb
2 changed files with 31 additions and 28 deletions

View File

@@ -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++) {