Make reenumerate() more reliable.

This commit is contained in:
László Monda
2018-01-31 04:26:49 +01:00
parent 5c618869a2
commit 8650fef7ae

View File

@@ -29,6 +29,9 @@ function uint32ToArray(value) {
function writeDevice(device, data, options={}) { function writeDevice(device, data, options={}) {
device.write(getTransferData(new Buffer(data))); device.write(getTransferData(new Buffer(data)));
if (options.noRead) {
return Promise.resolve();
}
return util.promisify(device.read.bind(device))(); return util.promisify(device.read.bind(device))();
} }
@@ -164,7 +167,7 @@ function reenumerate(enumerationMode) {
} }
console.log(`Trying to reenumerate as ${enumerationMode}...`); console.log(`Trying to reenumerate as ${enumerationMode}...`);
const intervalId = setInterval(() => { const intervalId = setInterval(async function() {
pollingTimeoutMs -= pollingIntervalMs; pollingTimeoutMs -= pollingIntervalMs;
const foundDevice = HID.devices().find(device => const foundDevice = HID.devices().find(device =>
@@ -187,8 +190,7 @@ function reenumerate(enumerationMode) {
let device = exports.getUhkDevice(); let device = exports.getUhkDevice();
if (device && !jumped) { if (device && !jumped) {
console.log(`UHK found, reenumerating as ${enumerationMode}`); console.log(`UHK found, reenumerating as ${enumerationMode}`);
let message = new Buffer([exports.usbCommands.reenumerate, enumerationModeId, ...uint32ToArray(bootloaderTimeoutMs)]); await writeDevice(device, [exports.usbCommands.reenumerate, enumerationModeId, ...uint32ToArray(bootloaderTimeoutMs)], {noRead:true});
device.write(getTransferData(message));
jumped = true; jumped = true;
} }