diff --git a/packages/usb/shared.js b/packages/usb/shared.js index 0e2a1771..eefca488 100644 --- a/packages/usb/shared.js +++ b/packages/usb/shared.js @@ -1,27 +1,5 @@ require('shelljs/global'); -function getBlhostCmd(pid) { - let blhostPath; - switch (process.platform) { - case 'linux': - const arch = exec('uname -m', {silent:true}).stdout.trim(); - blhostPath = `linux/${arch}/blhost`; - break; - case 'darwin': - blhostPath = 'mac/blhost'; - break; - case 'win32': - blhostPath = 'win/blhost.exe'; - break; - default: - echo('Your operating system is not supported.'); - exit(1); - break; - } - - return `${__dirname}/blhost/${blhostPath} --usb 0x1d50,0x${pid.toString(16)}`; -} - function execRetry(command) { let firstRun = true; let remainingRetries = 3; @@ -38,7 +16,6 @@ function execRetry(command) { } const exp = { - getBlhostCmd, execRetry, } diff --git a/packages/usb/uhk.js b/packages/usb/uhk.js index 73ce2b91..b8dd1a76 100644 --- a/packages/usb/uhk.js +++ b/packages/usb/uhk.js @@ -79,6 +79,28 @@ function checkFirmwareImage(imagePath, extension) { } } +function getBlhostCmd(pid) { + let blhostPath; + switch (process.platform) { + case 'linux': + const arch = exec('uname -m', {silent:true}).stdout.trim(); + blhostPath = `linux/${arch}/blhost`; + break; + case 'darwin': + blhostPath = 'mac/blhost'; + break; + case 'win32': + blhostPath = 'win/blhost.exe'; + break; + default: + echo('Your operating system is not supported.'); + exit(1); + break; + } + + return `${__dirname}/blhost/${blhostPath} --usb 0x1d50,0x${pid.toString(16)}`; +} + let configBufferIds = { hardwareConfig: 0, stagingUserConfig: 1, @@ -153,6 +175,7 @@ exports = module.exports = moduleExports = { getTransferData, checkModuleSlot, checkFirmwareImage, + getBlhostCmd, reenumerate, usbCommands: { getDeviceProperty : 0x00, diff --git a/packages/usb/update-device-firmware.js b/packages/usb/update-device-firmware.js index 9c950ea1..9f78bb9a 100755 --- a/packages/usb/update-device-firmware.js +++ b/packages/usb/update-device-firmware.js @@ -13,7 +13,7 @@ program const firmwareImage = program.args[0]; const usbDir = `${__dirname}`; -const blhost = getBlhostCmd(uhk.enumerationNameToProductId.bootloader); +const blhost = uhk.getBlhostCmd(uhk.enumerationNameToProductId.bootloader); uhk.checkFirmwareImage(firmwareImage, extension); diff --git a/packages/usb/update-module-firmware.js b/packages/usb/update-module-firmware.js index 5d399a38..5fff18a8 100755 --- a/packages/usb/update-module-firmware.js +++ b/packages/usb/update-module-firmware.js @@ -18,7 +18,7 @@ const firmwareImage = program.args[1]; uhk.checkFirmwareImage(firmwareImage, extension); const usbDir = `${__dirname}`; -const blhostUsb = getBlhostCmd(uhk.enumerationNameToProductId.buspal); +const blhostUsb = uhk.getBlhostCmd(uhk.enumerationNameToProductId.buspal); const blhostBuspal = `${blhostUsb} --buspal i2c,${i2cAddress}`; config.verbose = true;