Skip to content

Commit

Permalink
fix(usb-connection): update usb driver error message, conditionally r…
Browse files Browse the repository at this point in the history
…equire discovery code
  • Loading branch information
HipsterBrown committed Aug 10, 2017
1 parent 8925746 commit 8078136
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
7 changes: 5 additions & 2 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ var semver = require('semver');

// Internal
var CrashReporter = require('./crash-reporter');
var discover = require('./discover');
var init = require('./init');
var installer = require('./installer');
var log = require('./log');
var Menu = require('./menu');
var updates = require('./update-fetch');
var provision = require('./tessel/provision');
var Tessel = require('./tessel/tessel');
var provision = require('./tessel/provision');

var controller = {
// This will be assigned with the Tessel that is found or selected.
Expand Down Expand Up @@ -86,6 +85,8 @@ controller.setupLocal = function(opts) {


Tessel.list = function(opts) {
var discover = require('./discover');

return new Promise(function(resolve, reject) {
// Grab all attached Tessels
log.info('Searching for nearby Tessels...');
Expand Down Expand Up @@ -181,6 +182,8 @@ Tessel.list = function(opts) {
};

Tessel.get = function(options) {
var discover = require('./discover');

return new Promise((resolve, reject) => {
log.info('Looking for your Tessel...');
// Collection variable as more Tessels are found
Expand Down
26 changes: 19 additions & 7 deletions lib/usb-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var Duplex = stream.Duplex;
var Emitter = events.EventEmitter;

// Third Party Dependencies
// ...
const tags = require('common-tags');

// Internal
var DFU = require('./dfu');
Expand All @@ -22,14 +22,26 @@ function debugCommands(message) {
log.debug(`(commands:usb) ${message}`);
}

var haveusb = true;
var isUSBAvailable = true;
try {
var usb = require('usb');
var VENDOR_REQ_OUT = usb.LIBUSB_REQUEST_TYPE_VENDOR | usb.LIBUSB_RECIPIENT_DEVICE | usb.LIBUSB_ENDPOINT_OUT;
// var VENDOR_REQ_IN = usb.LIBUSB_REQUEST_TYPE_VENDOR | usb.LIBUSB_RECIPIENT_DEVICE | usb.LIBUSB_ENDPOINT_IN;
} catch (e) {
haveusb = false;
log.error('WARNING: No USB controller found on this system. Please run npm install -g t2-cli to compile USB drivers for your version of node');
} catch (error) {
isUSBAvailable = false;

// do not exit the process during tests because usb is not needed to run them
if (!global.IS_TEST_ENV) {
log.error('Node version mismatch for USB drivers.');
log.info(tags.stripIndent`
To correct this issue, please run the following command:
npm rebuild --update-binary usb
This will rebuild the USB drivers for your version of Node.js
`);
process.exit(1);
}
}

var Daemon = require('./usb/usb-daemon');
Expand Down Expand Up @@ -408,15 +420,15 @@ USB.Scanner.prototype.start = function() {
}
};

if (haveusb) {
if (isUSBAvailable) {
usb.getDeviceList().forEach(deviceInspector);

usb.on('attach', deviceInspector);
}
};

USB.Scanner.prototype.stop = function() {
if (haveusb) {
if (isUSBAvailable) {
usb.removeAllListeners('attach');
}
};
Expand Down

0 comments on commit 8078136

Please # to comment.