diff --git a/packages/usb/shared.js b/packages/usb/shared.js index eefca488..bdf718d9 100644 --- a/packages/usb/shared.js +++ b/packages/usb/shared.js @@ -1,22 +1,6 @@ require('shelljs/global'); -function execRetry(command) { - let firstRun = true; - let remainingRetries = 3; - let code; - do { - if (!firstRun) { - console.log(`Retrying ${command}`) - } - config.fatal = !remainingRetries; - code = exec(command).code; - config.fatal = true; - firstRun = false; - } while(code && --remainingRetries); -} - const exp = { - execRetry, } Object.keys(exp).forEach(function (cmd) { diff --git a/packages/usb/uhk.js b/packages/usb/uhk.js index b8dd1a76..1c512dc3 100644 --- a/packages/usb/uhk.js +++ b/packages/usb/uhk.js @@ -101,6 +101,21 @@ function getBlhostCmd(pid) { return `${__dirname}/blhost/${blhostPath} --usb 0x1d50,0x${pid.toString(16)}`; } +function execRetry(command) { + let firstRun = true; + let remainingRetries = 3; + let code; + do { + if (!firstRun) { + console.log(`Retrying ${command}`) + } + config.fatal = !remainingRetries; + code = exec(command).code; + config.fatal = true; + firstRun = false; + } while(code && --remainingRetries); +} + let configBufferIds = { hardwareConfig: 0, stagingUserConfig: 1, @@ -176,6 +191,7 @@ exports = module.exports = moduleExports = { checkModuleSlot, checkFirmwareImage, getBlhostCmd, + execRetry, reenumerate, usbCommands: { getDeviceProperty : 0x00, diff --git a/packages/usb/update-module-firmware.js b/packages/usb/update-module-firmware.js index 5fff18a8..fb718adb 100755 --- a/packages/usb/update-module-firmware.js +++ b/packages/usb/update-module-firmware.js @@ -26,12 +26,12 @@ 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`); +uhk.execRetry(`${blhostBuspal} get-property 1`); exec(`${blhostBuspal} flash-erase-all-unsecure`); exec(`${blhostBuspal} write-memory 0x0 ${firmwareImage}`); exec(`${blhostUsb} reset`); exec(`${usbDir}/reenumerate.js normalKeyboard`); -execRetry(`${usbDir}/send-kboot-command-to-module.js reset ${moduleSlot}`); +uhk.execRetry(`${usbDir}/send-kboot-command-to-module.js reset ${moduleSlot}`); exec(`${usbDir}/send-kboot-command-to-module.js idle`); config.verbose = false;