Skip to content

Commit

Permalink
chore: wait for devices in usb script
Browse files Browse the repository at this point in the history
  • Loading branch information
ert78gb committed Dec 14, 2024
1 parent 0b37c90 commit 68ce574
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/usb/factory-update-uhk80.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import {
getDeviceFirmwarePath,
getFirmwarePackageJson,
TmpFirmware,
snooze,
UhkHidDevice,
UhkOperations,
UsbVariables,
waitForDevices,
waitForUhkDeviceConnected,
} from 'uhk-usb';

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions packages/usb/factory-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getFirmwarePackageJson,
getModuleFirmwarePath,
isUhkDeviceConnected,
waitForDevices,
waitForUhkDeviceConnected,
} from 'uhk-usb';

Expand Down Expand Up @@ -80,6 +81,7 @@ const devicesOptions = getDevicesOptions(DEVICES);

const { operations } = Uhk(argv);
await operations.updateDeviceFirmware(rightFirmwarePath, uhkDeviceProduct);
await waitForDevices(uhkDeviceProduct.keyboard);
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.`);
Expand Down
1 change: 1 addition & 0 deletions packages/usb/wait-for-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ while (new Date().getTime() - startTime.getTime() < timeout && !found) {
}

if (found) {
await snooze(1000);
process.exit(0);
}
else {
Expand Down

0 comments on commit 68ce574

Please sign in to comment.