diff --git a/packages/usb/shared.js b/packages/usb/shared.js index cac78513..0e2a1771 100644 --- a/packages/usb/shared.js +++ b/packages/usb/shared.js @@ -1,22 +1,5 @@ require('shelljs/global'); -function checkFirmwareImage(imagePath, extension) { - if (!imagePath) { - echo('No firmware image specified.'); - exit(1); - } - - if (!imagePath.endsWith(extension)) { - echo(`Firmware image extension is not ${extension}`); - exit(1); - } - - if (!test('-f', imagePath)) { - echo('Firmware image does not exist.'); - exit(1); - } -} - function getBlhostCmd(pid) { let blhostPath; switch (process.platform) { @@ -55,7 +38,6 @@ function execRetry(command) { } const exp = { - checkFirmwareImage, getBlhostCmd, execRetry, } diff --git a/packages/usb/uhk.js b/packages/usb/uhk.js index 60b727f8..73ce2b91 100644 --- a/packages/usb/uhk.js +++ b/packages/usb/uhk.js @@ -62,6 +62,23 @@ function getBootloaderDevice() { return foundDevice; } +function checkFirmwareImage(imagePath, extension) { + if (!imagePath) { + echo('No firmware image specified.'); + exit(1); + } + + if (!imagePath.endsWith(extension)) { + echo(`Firmware image extension is not ${extension}`); + exit(1); + } + + if (!test('-f', imagePath)) { + echo('Firmware image does not exist.'); + exit(1); + } +} + let configBufferIds = { hardwareConfig: 0, stagingUserConfig: 1, @@ -135,6 +152,7 @@ exports = module.exports = moduleExports = { getBootloaderDevice, getTransferData, checkModuleSlot, + checkFirmwareImage, reenumerate, usbCommands: { getDeviceProperty : 0x00, diff --git a/packages/usb/update-device-firmware.js b/packages/usb/update-device-firmware.js index dd22bcd5..9c950ea1 100755 --- a/packages/usb/update-device-firmware.js +++ b/packages/usb/update-device-firmware.js @@ -15,7 +15,7 @@ const firmwareImage = program.args[0]; const usbDir = `${__dirname}`; const blhost = getBlhostCmd(uhk.enumerationNameToProductId.bootloader); -checkFirmwareImage(firmwareImage, extension); +uhk.checkFirmwareImage(firmwareImage, extension); (async function() { config.verbose = true; diff --git a/packages/usb/update-module-firmware.js b/packages/usb/update-module-firmware.js index f0b3904e..5d399a38 100755 --- a/packages/usb/update-module-firmware.js +++ b/packages/usb/update-module-firmware.js @@ -15,7 +15,7 @@ let moduleSlot = program.args[0]; const i2cAddress = uhk.checkModuleSlot(moduleSlot, uhk.moduleSlotToI2cAddress); const firmwareImage = program.args[1]; -checkFirmwareImage(firmwareImage, extension); +uhk.checkFirmwareImage(firmwareImage, extension); const usbDir = `${__dirname}`; const blhostUsb = getBlhostCmd(uhk.enumerationNameToProductId.buspal);