Make jump-to-bootloader.js able to reenumerate the UHK as BusPal proxy.

This commit is contained in:
László Monda
2017-10-17 01:27:01 +02:00
parent 75e3995276
commit f7cdbbb5e0
2 changed files with 16 additions and 1 deletions

View File

@@ -6,6 +6,9 @@ let pollingIntervalMs = 100;
let bootloaderTimeoutMs = 5000;
let jumped = false;
console.log(process.argv[2])
let enumerationMode = process.argv[2] === 'buspal' ? uhk.enumerationModes.busPal : uhk.enumerationModes.bootloader;
console.log('Trying to jump to the bootloader...');
setInterval(() => {
timeoutMs -= pollingIntervalMs;
@@ -26,8 +29,14 @@ setInterval(() => {
if (device && !jumped) {
console.log('UHK found, jumping to bootloader');
let t = bootloaderTimeoutMs;
device.write(uhk.getTransferData(new Buffer([uhk.usbCommands.jumpToBootloader, 0, t&0xff, (t&0xff<<8)>>8, (t&0xff<<16)>>16, (t&0xff<<24)>>24])));
let message = new Buffer([uhk.usbCommands.jumpToBootloader, enumerationMode, t&0xff, (t&0xff<<8)>>8, (t&0xff<<16)>>16, (t&0xff<<24)>>24]);
console.log(message);
device.write(uhk.getTransferData(message));
jumped = true;
if (enumerationMode == uhk.enumerationModes.busPal) {
process.exit();
}
}
}, pollingIntervalMs);