diff --git a/lib/usb-connection.js b/lib/usb-connection.js index 15269539..a9dc3f99 100644 --- a/lib/usb-connection.js +++ b/lib/usb-connection.js @@ -312,18 +312,24 @@ USB.Connection.prototype._waitUntilInBootloader = function() { var retry = () => { this._findBootedDeviceBySerialNumber(this.device.deviceDescriptor.iSerialNumber) // A Tessel was found! - .then(function(bootedDevice) { + .then(bootedDevice => { // Make sure it's in the proper mode if (bootedDevice) { return resolve(bootedDevice); } // It didn't find it - }, function(err) { + }, error => { if (--retryCount > 0) { return setTimeout(retry, retryTimeout); - } else { - reject(err); } + + if (process.platform.startsWith('win')) { + log.info('Placeholder for zadig installation instructions.'); + } + + + // No tries left... + reject(error); }); }; @@ -333,22 +339,25 @@ USB.Connection.prototype._waitUntilInBootloader = function() { // Looks through all attached USB devices for a Tessel in bootloader mode USB.Connection.prototype._findBootedDeviceBySerialNumber = function(serialNumber) { - return new Promise(function(resolve, reject) { + return new Promise((resolve, reject) => { + var found; // Fetch all attached USB devices if (usb) { - var list = usb.getDeviceList(); - - for (var i = 0; i < list.length; i++) { - var device = list[i]; - // Make sure this is a Tessel - if ((device.deviceDescriptor.idVendor === TESSEL_VID) && (device.deviceDescriptor.idProduct === TESSEL_PID) && (device.deviceDescriptor.iSerialNumber === serialNumber)) { - // Make sure it's in bootloader mode - if (device.deviceDescriptor.bcdDevice >> 8 === 0) { - return resolve(device); - } + found = usb.getDeviceList().find(device => { + if ((device.deviceDescriptor.idVendor === TESSEL_VID) && + (device.deviceDescriptor.idProduct === TESSEL_PID) && + (device.deviceDescriptor.iSerialNumber === serialNumber) && + (device.deviceDescriptor.bcdDevice >> 8 === 0)) { + // Shift bcdDevice bits rightward 8 bits to check that + // the device is in bootloader mode. + return device; } - } + }); } + + if (found) { + return resolve(found); + } return reject(new Error('No device found in bootloader mode')); }); };