Files
agent/usb/jump-to-bootloader.js
2017-02-28 01:23:56 +01:00

29 lines
699 B
JavaScript
Executable File

#!/usr/bin/env node
let uhk = require('./uhk');
let timeoutMs = 10000;
let pollingIntervalMs = 100;
let jumped = false;
console.log('Trying to jump to the bootloader...');
setInterval(() => {
timeoutMs -= pollingIntervalMs;
if (uhk.getBootloaderDevice()) {
console.log('Bootloader is up');
process.exit(0);
}
if (timeoutMs <= 0) {
console.log("Couldn't jump to the bootloader");
process.exit(1);
}
if (uhk.getUhkDevice() && !jumped) {
console.log('UHK found, jumping to bootloader');
uhk.sendUsbPacket(new Buffer([uhk.usbCommands.jumpToBootloader]), {noReceive:true});
jumped = true;
}
}, pollingIntervalMs);