diff --git a/packages/uhk-agent/src/services/device.service.ts b/packages/uhk-agent/src/services/device.service.ts index 8f391df5..cabde6cf 100644 --- a/packages/uhk-agent/src/services/device.service.ts +++ b/packages/uhk-agent/src/services/device.service.ts @@ -1,5 +1,5 @@ import { ipcMain } from 'electron'; -import { ConfigurationReply, DeviceConnectionState, IpcEvents, IpcResponse, LogService } from 'uhk-common'; +import { ConfigurationReply, DeviceConnectionState, HardwareModules, IpcEvents, IpcResponse, LogService } from 'uhk-common'; import { snooze, UhkHidDevice, UhkOperations } from 'uhk-usb'; import { Observable } from 'rxjs/Observable'; import { Subscription } from 'rxjs/Subscription'; @@ -73,10 +73,15 @@ export class DeviceService { try { await this.device.waitUntilKeyboardBusy(); const result = await this.operations.loadConfigurations(); + const modules: HardwareModules = { + leftModuleInfo: await this.operations.getLeftModuleVersionInfo(), + rightModuleInfo: await this.operations.getRightModuleVersionInfo() + }; response = { success: true, - ...result + ...result, + modules }; } catch (error) { response = { diff --git a/packages/uhk-common/src/models/configuration-reply.ts b/packages/uhk-common/src/models/configuration-reply.ts index 0adb29e1..757e0ceb 100644 --- a/packages/uhk-common/src/models/configuration-reply.ts +++ b/packages/uhk-common/src/models/configuration-reply.ts @@ -1,6 +1,9 @@ +import { HardwareModules } from './hardware-modules'; + export interface ConfigurationReply { success: boolean; userConfiguration?: string; hardwareConfiguration?: string; + modules?: HardwareModules; error?: string; } diff --git a/packages/uhk-common/src/models/hardware-module-info.ts b/packages/uhk-common/src/models/hardware-module-info.ts new file mode 100644 index 00000000..59fac86c --- /dev/null +++ b/packages/uhk-common/src/models/hardware-module-info.ts @@ -0,0 +1,4 @@ +export interface HardwareModuleInfo { + firmwareVersion?: string; + moduleProtocolVersion?: string; +} diff --git a/packages/uhk-common/src/models/hardware-modules.ts b/packages/uhk-common/src/models/hardware-modules.ts new file mode 100644 index 00000000..03bd55f7 --- /dev/null +++ b/packages/uhk-common/src/models/hardware-modules.ts @@ -0,0 +1,6 @@ +import { HardwareModuleInfo } from './hardware-module-info'; + +export interface HardwareModules { + leftModuleInfo?: HardwareModuleInfo; + rightModuleInfo?: HardwareModuleInfo; +} diff --git a/packages/uhk-common/src/models/index.ts b/packages/uhk-common/src/models/index.ts index 4fee8211..b3738b43 100644 --- a/packages/uhk-common/src/models/index.ts +++ b/packages/uhk-common/src/models/index.ts @@ -5,3 +5,5 @@ export * from './app-start-info'; export * from './configuration-reply'; export * from './version-information'; export * from './device-connection-state'; +export * from './hardware-modules'; +export * from './hardware-module-info'; diff --git a/packages/uhk-usb/src/constants.ts b/packages/uhk-usb/src/constants.ts index 4d154b7a..71f2a235 100644 --- a/packages/uhk-usb/src/constants.ts +++ b/packages/uhk-usb/src/constants.ts @@ -22,7 +22,7 @@ export enum UsbCommand { GetDebugBuffer = 0x0b, GetAdcValue = 0x0c, SetLedPwmBrightness = 0x0d, - GetModuleProperties = 0x0e + GetModuleProperty = 0x0e } export enum EepromOperation { @@ -81,3 +81,7 @@ export enum KbootCommands { ping = 1, reset = 2 } + +export enum ModulePropertyId { + protocolVersions = 0 +} diff --git a/packages/uhk-usb/src/uhk-operations.ts b/packages/uhk-usb/src/uhk-operations.ts index c4b9534e..4f6d4ed3 100644 --- a/packages/uhk-usb/src/uhk-operations.ts +++ b/packages/uhk-usb/src/uhk-operations.ts @@ -1,5 +1,12 @@ -import { LogService } from 'uhk-common'; -import { EnumerationModes, EnumerationNameToProductId, KbootCommands, ModuleSlotToI2cAddress, ModuleSlotToId } from './constants'; +import { HardwareModuleInfo, LogService, UhkBuffer } from 'uhk-common'; +import { + EnumerationModes, + EnumerationNameToProductId, + KbootCommands, + ModulePropertyId, + ModuleSlotToI2cAddress, + ModuleSlotToId +} from './constants'; import * as path from 'path'; import * as fs from 'fs'; import { UhkBlhost } from './uhk-blhost'; @@ -193,6 +200,50 @@ export class UhkOperations { return false; } + public async getLeftModuleVersionInfo(): Promise { + try { + this.logService.debug('[DeviceOperation] USB[T]: Read left module version information'); + + const command = new Buffer([ + UsbCommand.GetModuleProperty, + ModuleSlotToId.leftHalf, + ModulePropertyId.protocolVersions + ]); + + const buffer = await this.device.write(command); + const uhkBuffer = UhkBuffer.fromArray(convertBufferToIntArray(buffer)); + // skip the first 2 byte + uhkBuffer.readUInt16(); + + return { + moduleProtocolVersion: `${uhkBuffer.readUInt16()}.${uhkBuffer.readUInt16()}.${uhkBuffer.readUInt16()}`, + firmwareVersion: `${uhkBuffer.readUInt16()}.${uhkBuffer.readUInt16()}.${uhkBuffer.readUInt16()}` + }; + } + catch (error) { + this.logService.error('[DeviceOperation] Could not read left module version information', error); + } + + return { + moduleProtocolVersion: '', + firmwareVersion: '' + }; + } + + public async getRightModuleVersionInfo(): Promise { + this.logService.debug('[DeviceOperation] USB[T]: Read right module version information'); + + const command = new Buffer([UsbCommand.GetProperty, DevicePropertyIds.ProtocolVersions]); + const buffer = await this.device.write(command); + const uhkBuffer = UhkBuffer.fromArray(convertBufferToIntArray(buffer)); + // skip the first byte + uhkBuffer.readUInt8(); + + return { + firmwareVersion: `${uhkBuffer.readUInt16()}.${uhkBuffer.readUInt16()}.${uhkBuffer.readUInt16()}` + }; + } + /** * IpcMain handler. Send the UserConfiguration to the UHK Device and send a response with the result. * @param {string} json - UserConfiguration in JSON format diff --git a/packages/uhk-web/src/app/components/device/firmware/device-firmware.component.html b/packages/uhk-web/src/app/components/device/firmware/device-firmware.component.html index c88f2cbe..c4aa951f 100644 --- a/packages/uhk-web/src/app/components/device/firmware/device-firmware.component.html +++ b/packages/uhk-web/src/app/components/device/firmware/device-firmware.component.html @@ -7,12 +7,19 @@ Firmware -

- Please note that the firmware update process may sometimes fail. If if fails then - simply retry until it succeeds. If the left half becomes unresponsive after a failed - update then retry and follow the instructions displayed during the update to fix it. - We'll make the firmware update process more robust. -

+

+ Firmware {{ hardwareModules.leftModuleInfo.firmwareVersion }} is running on the left keyboard half.
+ Firmware {{ hardwareModules.rightModuleInfo.firmwareVersion }} is running on the right keyboard half. +

+ +

+ + Please note that the firmware update process may sometimes fail. If if fails then + simply retry until it succeeds. If the left half becomes unresponsive after a failed + update then retry and follow the instructions displayed during the update to fix it. + We'll make the firmware update process more robust. + +