Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usb/bootloader: cleanup detection of bootloader mode. add user-facing instructions for installing zadig on windows #1052

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions lib/usb-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};

Expand All @@ -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'));
});
};
Expand Down