diff --git a/packages/usb/factory-update.ts b/packages/usb/factory-update-uhk60.ts similarity index 67% rename from packages/usb/factory-update.ts rename to packages/usb/factory-update-uhk60.ts index 00b9b8e5380..1b9e9a7d990 100755 --- a/packages/usb/factory-update.ts +++ b/packages/usb/factory-update-uhk60.ts @@ -3,11 +3,9 @@ import * as path from 'path'; import * as fs from 'fs'; import { - FIRMWARE_UPGRADE_METHODS, LEFT_HALF_MODULE, UHK_60_DEVICE, UHK_60_V2_DEVICE, - UHK_80_DEVICE_LEFT, } from 'uhk-common'; import { getCurrentUhkDeviceProduct, @@ -15,8 +13,7 @@ import { getDeviceUserConfigPath, getFirmwarePackageJson, getModuleFirmwarePath, - isUhkDeviceConnected, - waitForUhkDeviceConnected, + waitForDevices, } from 'uhk-usb'; import Uhk, { errorHandler, getUhkDeviceProductFromArg, getDevicesOptions, yargs } from './src/index.js'; @@ -30,7 +27,7 @@ const devicesOptions = getDevicesOptions(DEVICES); (async function () { try { const argv = yargs - .scriptName('./factory-update.ts') + .scriptName('./factory-update-uhk60.ts') .usage(`Usage: $0 {${devicesOptions} {iso|ansi}`) .demandCommand(3) .option('set-serial-number', { @@ -57,10 +54,7 @@ const devicesOptions = getDevicesOptions(DEVICES); process.exit(1); } - - const leftFirmwarePath = uhkDeviceProduct.firmwareUpgradeMethod === FIRMWARE_UPGRADE_METHODS.MCUBOOT - ? getDeviceFirmwarePath(UHK_80_DEVICE_LEFT, packageJson) - : getModuleFirmwarePath(LEFT_HALF_MODULE, packageJson); + const leftFirmwarePath = getModuleFirmwarePath(LEFT_HALF_MODULE, packageJson); if (!fs.existsSync(leftFirmwarePath)) { console.error('Left firmware path not found!'); @@ -80,26 +74,11 @@ const devicesOptions = getDevicesOptions(DEVICES); const { operations } = Uhk(argv); await operations.updateDeviceFirmware(rightFirmwarePath, uhkDeviceProduct); - if (uhkDeviceProduct.firmwareUpgradeMethod === FIRMWARE_UPGRADE_METHODS.MCUBOOT) { - if (!(await isUhkDeviceConnected(UHK_80_DEVICE_LEFT))) { - console.log(`[DeviceService] Please connect your ${UHK_80_DEVICE_LEFT.logName} keyboard with USB cable.`); - } - await waitForUhkDeviceConnected(UHK_80_DEVICE_LEFT); - - await operations.updateFirmwareWithMcuManager(leftFirmwarePath, UHK_80_DEVICE_LEFT); - - if (!(await isUhkDeviceConnected(uhkDeviceProduct))) { - console.log(`[DeviceService] Please connect your ${uhkDeviceProduct.logName} keyboard with USB cable.`); - } - await waitForUhkDeviceConnected(uhkDeviceProduct); - } - else { - await operations.updateLeftModuleWithKboot(leftFirmwarePath, uhkDeviceProduct); - } + await waitForDevices(uhkDeviceProduct.keyboard); + await operations.updateLeftModuleWithKboot(leftFirmwarePath, uhkDeviceProduct); const configBuffer = fs.readFileSync(userConfigPath) as any; await operations.saveUserConfiguration(configBuffer); await operations.saveHardwareConfiguration(layout === 'iso', deviceId, argv.setSerialNumber); - await operations.switchKeymap('TES'); console.log('All done!'); } catch (error) { await errorHandler(error); diff --git a/packages/usb/factory-update-uhk80.ts b/packages/usb/factory-update-uhk80.ts index 697ded38e27..a5b0bf7f182 100755 --- a/packages/usb/factory-update-uhk80.ts +++ b/packages/usb/factory-update-uhk80.ts @@ -17,10 +17,10 @@ import { getDeviceFirmwarePath, getFirmwarePackageJson, TmpFirmware, - snooze, UhkHidDevice, UhkOperations, UsbVariables, + waitForDevices, waitForUhkDeviceConnected, } from 'uhk-usb'; @@ -71,7 +71,10 @@ try { // just wait until devices be ready. After the reenumeration the halves start to communicate with each other // give them some time to finish - await snooze(5000); + await Promise.all([ + waitForDevices(UHK_80_DEVICE.keyboard), + waitForDevices(UHK_80_DEVICE_LEFT.keyboard), + ]); // Need to reload hid devices because after the reenumeration maybe the HID device path changed connectedDevices = await getHidDevices(); diff --git a/packages/usb/wait-for-device.ts b/packages/usb/wait-for-device.ts index fce32c8ae4a..e0600e95e8f 100755 --- a/packages/usb/wait-for-device.ts +++ b/packages/usb/wait-for-device.ts @@ -105,6 +105,7 @@ while (new Date().getTime() - startTime.getTime() < timeout && !found) { } if (found) { + await snooze(1000); process.exit(0); } else {