diff --git a/packages/uhk-agent/src/services/device.service.ts b/packages/uhk-agent/src/services/device.service.ts index 4ddba48f996..fdc328228b6 100644 --- a/packages/uhk-agent/src/services/device.service.ts +++ b/packages/uhk-agent/src/services/device.service.ts @@ -2,6 +2,7 @@ import { ipcMain } from 'electron'; import { emptyDir } from 'fs-extra'; import { cloneDeep, isEqual } from 'lodash'; import os from 'os'; +import { UhkDeviceProduct } from 'uhk-common'; import { ALL_UHK_DEVICES, AreBleAddressesPairedIpcResponse, @@ -488,6 +489,8 @@ export class DeviceService { } let firmwarePathData: TmpFirmware; + let shouldEnableFirmwareVersionCheck = false; + let uhkDeviceProduct: UhkDeviceProduct; try { await this.stopPollUhkDevice(); @@ -506,7 +509,7 @@ export class DeviceService { event.sender.send(IpcEvents.device.updateFirmwareJson, packageJson); - const uhkDeviceProduct = await getCurrentUhkDeviceProduct(this.options); + uhkDeviceProduct = await getCurrentUhkDeviceProduct(this.options); checkFirmwareAndDeviceCompatibility(packageJson, uhkDeviceProduct); if (shouldUpgradeAgent(packageJson.userConfigVersion, this.disableAgentUpgrade)) { response.failReason = FirmwareUpgradeFailReason.UserConfigVersionNotSupported; @@ -592,6 +595,13 @@ export class DeviceService { await this.operations.updateDeviceFirmware(deviceFirmwarePath, uhkDeviceProduct); this.logService.misc('[DeviceService] Waiting for keyboard'); await waitForDevices(uhkDeviceProduct.keyboard); + + if (uhkDeviceProduct.id === UHK_DEVICE_IDS.UHK80_RIGHT) { + this.logService.misc('[DeviceService] Disable firmware version check.'); + await this.operations.disableFirmwareVersionCheck(); + shouldEnableFirmwareVersionCheck = true; + } + hardwareModules = await this.getHardwareModules(false); event.sender.send(IpcEvents.device.hardwareModulesLoaded, hardwareModules); @@ -767,6 +777,22 @@ export class DeviceService { await snooze(500); + try { + if (shouldEnableFirmwareVersionCheck) { + await waitForDevices(uhkDeviceProduct.keyboard); + this.logService.misc('[DeviceService] Enable firmware version check.'); + await this.operations.enableFirmwareVersionCheck(); + } + } + catch (error) { + const err = { message: error.message, stack: error.stack }; + this.logService.error('[DeviceService] error while enabling firmware version check', err); + + response.error = err; + } + + await snooze(500); + this.savedState = undefined; this.startPollUhkDevice(); await this.dongleZephyrLogService.enable(); diff --git a/packages/uhk-usb/src/constants.ts b/packages/uhk-usb/src/constants.ts index adb22f1613c..1627fd14b5a 100644 --- a/packages/uhk-usb/src/constants.ts +++ b/packages/uhk-usb/src/constants.ts @@ -112,6 +112,7 @@ export enum UsbVariables { LedAudioRegisters = 6, ShellEnabled = 7, ShellBuffer = 8, + FirmwareVersionCheckEnabled = 9, } // TODO: use the LayerName enum instead of this array diff --git a/packages/uhk-usb/src/uhk-operations.ts b/packages/uhk-usb/src/uhk-operations.ts index f02d7798fd7..631066fc89c 100644 --- a/packages/uhk-usb/src/uhk-operations.ts +++ b/packages/uhk-usb/src/uhk-operations.ts @@ -79,6 +79,18 @@ export class UhkOperations { await this.device.write(transfer); } + public async disableFirmwareVersionCheck(): Promise { + this.logService.usbOps('[UhkHidDevice] USB[T]: Disable firmware version check.'); + const transfer = Buffer.from([UsbCommand.SetVariable, UsbVariables.FirmwareVersionCheckEnabled, 0]); + await this.device.write(transfer); + } + + public async enableFirmwareVersionCheck(): Promise { + this.logService.usbOps('[UhkHidDevice] USB[T]: Enable firmware version check.'); + const transfer = Buffer.from([UsbCommand.SetVariable, UsbVariables.FirmwareVersionCheckEnabled, 1]); + await this.device.write(transfer); + } + public async jumpToBootloaderModule(module: ModuleSlotToId): Promise { this.logService.usbOps(`[UhkHidDevice] USB[T]: Jump to bootloader. Module: ${ModuleSlotToId[module].toString()}`); const transfer = Buffer.from([UsbCommand.JumpToModuleBootloader, module]);