diff --git a/packages/usb/uhk.js b/packages/usb/uhk.js index 1156f10d..999d7cf9 100644 --- a/packages/usb/uhk.js +++ b/packages/usb/uhk.js @@ -102,6 +102,7 @@ exports = module.exports = moduleExports = { deviceProtocolVersion: 0, protocolVersions: 1, configSizes: 2, + currentKbootCommand: 3, }, modulePropertyIds: { protocolVersions: 0, diff --git a/packages/usb/update-module-firmware.js b/packages/usb/update-module-firmware.js index 2778174f..10401c3a 100755 --- a/packages/usb/update-module-firmware.js +++ b/packages/usb/update-module-firmware.js @@ -24,6 +24,7 @@ const blhostBuspal = `${blhostUsb} --buspal i2c,${i2cAddress},100k`; config.verbose = true; exec(`${usbDir}/send-kboot-command-to-module.js ping ${moduleSlot}`); exec(`${usbDir}/jump-to-module-bootloader.js ${moduleSlot}`); +exec(`${usbDir}/wait-for-kboot-idle.js`); exec(`${usbDir}/reenumerate.js buspal`); execRetry(`${blhostBuspal} get-property 1`); exec(`${blhostBuspal} flash-erase-all-unsecure`); diff --git a/packages/usb/wait-for-kboot-idle.js b/packages/usb/wait-for-kboot-idle.js new file mode 100755 index 00000000..846ce884 --- /dev/null +++ b/packages/usb/wait-for-kboot-idle.js @@ -0,0 +1,22 @@ +#!/usr/bin/env node +const uhk = require('./uhk'); + +function getCurrentKbootCommand() { + device.write(uhk.getTransferData(new Buffer([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.currentKbootCommand]))); + const response = Buffer.from(device.readSync()); + const currentKbootCommand = response[1]; + if (currentKbootCommand == 0) { + console.log('Bootloader pinged.'); + process.exit(0); + } else { + console.log("Cannot ping the bootloader. Please reconnect the left keyboard half. It probably needs several tries, so keep reconnecting until you see this message."); + } +} + +const device = uhk.getUhkDevice(); + +getCurrentKbootCommand(); + +setInterval(() => { + getCurrentKbootCommand(); +}, 500);