Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion packages/uhk-agent/src/services/device.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -488,6 +489,8 @@ export class DeviceService {
}

let firmwarePathData: TmpFirmware;
let shouldEnableFirmwareVersionCheck = false;
let uhkDeviceProduct: UhkDeviceProduct;

try {
await this.stopPollUhkDevice();
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions packages/uhk-usb/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export enum UsbVariables {
LedAudioRegisters = 6,
ShellEnabled = 7,
ShellBuffer = 8,
FirmwareVersionCheckEnabled = 9,
}

// TODO: use the LayerName enum instead of this array
Expand Down
12 changes: 12 additions & 0 deletions packages/uhk-usb/src/uhk-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ export class UhkOperations {
await this.device.write(transfer);
}

public async disableFirmwareVersionCheck(): Promise<void> {
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<void> {
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<void> {
this.logService.usbOps(`[UhkHidDevice] USB[T]: Jump to bootloader. Module: ${ModuleSlotToId[module].toString()}`);
const transfer = Buffer.from([UsbCommand.JumpToModuleBootloader, module]);
Expand Down
Loading