Query the combined ConfigSizes device property. Remove the deprecated HardwareConfigSize and UserConfigSize device properties.
This commit is contained in:
@@ -35,13 +35,10 @@ export enum ConfigBufferId {
|
|||||||
validatedUserConfig = 2
|
validatedUserConfig = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum SystemPropertyIds {
|
export enum DevicePropertyIds {
|
||||||
UsbProtocolVersion = 0,
|
DeviceProtocolVersion = 0,
|
||||||
BridgeProtocolVersion = 1,
|
ProtocolVersions = 1,
|
||||||
DataModelVersion = 2,
|
ConfigSizes = 2
|
||||||
FirmwareVersion = 3,
|
|
||||||
HardwareConfigSize = 4,
|
|
||||||
MaxUserConfigSize = 5
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum EnumerationModes {
|
export enum EnumerationModes {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import * as fs from 'fs';
|
|||||||
import { UhkBlhost } from './uhk-blhost';
|
import { UhkBlhost } from './uhk-blhost';
|
||||||
import { UhkHidDevice } from './uhk-hid-device';
|
import { UhkHidDevice } from './uhk-hid-device';
|
||||||
import { snooze } from './util';
|
import { snooze } from './util';
|
||||||
import { convertBufferToIntArray, getTransferBuffers, SystemPropertyIds, UsbCommand, ConfigBufferId
|
import { convertBufferToIntArray, getTransferBuffers, DevicePropertyIds, UsbCommand, ConfigBufferId
|
||||||
} from '../index';
|
} from '../index';
|
||||||
import { LoadConfigurationsResult } from './models/load-configurations-result';
|
import { LoadConfigurationsResult } from './models/load-configurations-result';
|
||||||
|
|
||||||
@@ -68,15 +68,8 @@ export class UhkOperations {
|
|||||||
public async loadConfigurations(): Promise<LoadConfigurationsResult> {
|
public async loadConfigurations(): Promise<LoadConfigurationsResult> {
|
||||||
try {
|
try {
|
||||||
await this.device.waitUntilKeyboardBusy();
|
await this.device.waitUntilKeyboardBusy();
|
||||||
const userConfiguration = await this.loadConfiguration(
|
const userConfiguration = await this.loadConfiguration(ConfigBufferId.validatedUserConfig);
|
||||||
SystemPropertyIds.MaxUserConfigSize,
|
const hardwareConfiguration = await this.loadConfiguration(ConfigBufferId.hardwareConfig);
|
||||||
ConfigBufferId.validatedUserConfig,
|
|
||||||
'user configuration');
|
|
||||||
|
|
||||||
const hardwareConfiguration = await this.loadConfiguration(
|
|
||||||
SystemPropertyIds.HardwareConfigSize,
|
|
||||||
ConfigBufferId.hardwareConfig,
|
|
||||||
'hardware configuration');
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
userConfiguration,
|
userConfiguration,
|
||||||
@@ -91,15 +84,15 @@ export class UhkOperations {
|
|||||||
* Return with the actual user / hardware fonfiguration from UHK Device
|
* Return with the actual user / hardware fonfiguration from UHK Device
|
||||||
* @returns {Promise<Buffer>}
|
* @returns {Promise<Buffer>}
|
||||||
*/
|
*/
|
||||||
public async loadConfiguration(
|
public async loadConfiguration(configBufferId: ConfigBufferId): Promise<string> {
|
||||||
property: SystemPropertyIds,
|
|
||||||
configBufferId: ConfigBufferId ,
|
|
||||||
configName: string): Promise<string> {
|
|
||||||
let response = [];
|
let response = [];
|
||||||
|
|
||||||
|
const configBufferIdToName = ['HardwareConfig', 'StagingUserConfig', 'ValidatedUserConfig'];
|
||||||
|
const configName = configBufferIdToName[configBufferId];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.logService.debug(`[DeviceOperation] USB[T]: Read ${configName} size from keyboard`);
|
this.logService.debug(`[DeviceOperation] USB[T]: Read ${configName} size from keyboard`);
|
||||||
let configSize = await this.getConfigSizeFromKeyboard(property);
|
let configSize = await this.getConfigSizeFromKeyboard(configBufferId);
|
||||||
const originalConfigSize = configSize;
|
const originalConfigSize = configSize;
|
||||||
this.logService.debug(`[DeviceOperation] getConfigSize() configSize: ${configSize}`);
|
this.logService.debug(`[DeviceOperation] getConfigSize() configSize: ${configSize}`);
|
||||||
const chunkSize = 63;
|
const chunkSize = 63;
|
||||||
@@ -140,11 +133,15 @@ export class UhkOperations {
|
|||||||
* Return the user / hardware configuration size from the UHK Device
|
* Return the user / hardware configuration size from the UHK Device
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
public async getConfigSizeFromKeyboard(property: SystemPropertyIds): Promise<number> {
|
public async getConfigSizeFromKeyboard(configBufferId: ConfigBufferId): Promise<number> {
|
||||||
const buffer = await this.device.write(new Buffer([UsbCommand.GetProperty, property]));
|
const buffer = await this.device.write(new Buffer([UsbCommand.GetProperty, DevicePropertyIds.ConfigSizes]));
|
||||||
this.device.close();
|
this.device.close();
|
||||||
const configSize = buffer[1] + (buffer[2] << 8);
|
const hardwareConfigSize = buffer[1] + (buffer[2] << 8);
|
||||||
this.logService.debug('[DeviceOperation] User config size:', configSize);
|
const userConfigSize = buffer[3] + (buffer[4] << 8);
|
||||||
|
const isHardwareConfig = configBufferId === ConfigBufferId.hardwareConfig;
|
||||||
|
const configSize = isHardwareConfig ? hardwareConfigSize : userConfigSize;
|
||||||
|
const configString = isHardwareConfig ? 'Hardware' : 'User';
|
||||||
|
this.logService.debug(`[DeviceOperation] ${configString} config size:`, configSize);
|
||||||
return configSize;
|
return configSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const uhk = require('./uhk');
|
const uhk = require('./uhk');
|
||||||
|
|
||||||
const isHardwareConfig = process.argv[2] === 'h';
|
|
||||||
|
|
||||||
const device = uhk.getUhkDevice();
|
const device = uhk.getUhkDevice();
|
||||||
const sendData = new Buffer([uhk.usbCommands.getProperty,
|
const sendData = new Buffer([uhk.usbCommands.getProperty, uhk.devicePropertyIds.configSizes]);
|
||||||
isHardwareConfig ?
|
|
||||||
uhk.systemPropertyIds.hardwareConfigSize
|
|
||||||
: uhk.systemPropertyIds.userConfigSize]);
|
|
||||||
|
|
||||||
device.write(uhk.getTransferData(sendData));
|
device.write(uhk.getTransferData(sendData));
|
||||||
const response = Buffer.from(device.readSync());
|
const response = Buffer.from(device.readSync());
|
||||||
console.log(response[1] + (response[2]<<8));
|
|
||||||
|
const hardwareConfigMaxSize = response[1] + (response[2]<<8);
|
||||||
|
const userConfigMaxSize = response[3] + (response[4]<<8);
|
||||||
|
|
||||||
|
console.log(`hardwareConfigMaxSize: ${hardwareConfigMaxSize}`);
|
||||||
|
console.log(`userConfigMaxSize: ${userConfigMaxSize}`);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ let counter = 1;
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
console.log(`hidapi sync test ${counter++}`);
|
console.log(`hidapi sync test ${counter++}`);
|
||||||
const sendData = new Buffer([uhk.usbCommands.getProperty, uhk.systemPropertyIds.hardwareConfigSize]);
|
const sendData = new Buffer([uhk.usbCommands.getProperty, uhk.devicePropertyIds.configSizes]);
|
||||||
device.write(uhk.getTransferData(sendData));
|
device.write(uhk.getTransferData(sendData));
|
||||||
device.readSync()
|
device.readSync()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,22 +6,18 @@ const chunkSize = 63;
|
|||||||
|
|
||||||
let isHardwareConfig = process.argv[2] === 'h';
|
let isHardwareConfig = process.argv[2] === 'h';
|
||||||
let configTypeString = isHardwareConfig ? 'hardware' : 'user';
|
let configTypeString = isHardwareConfig ? 'hardware' : 'user';
|
||||||
let configSize;
|
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
let configBuffer = new Buffer(0);
|
let configBuffer = new Buffer(0);
|
||||||
let chunkSizeToRead;
|
let chunkSizeToRead;
|
||||||
|
|
||||||
const payload = new Buffer([
|
const payload = new Buffer([uhk.usbCommands.getProperty, uhk.devicePropertyIds.configSizes]);
|
||||||
uhk.usbCommands.getProperty,
|
|
||||||
isHardwareConfig
|
|
||||||
? uhk.systemPropertyIds.hardwareConfigSize
|
|
||||||
: uhk.systemPropertyIds.userConfigSize
|
|
||||||
]);
|
|
||||||
|
|
||||||
device.write(uhk.getTransferData(payload));
|
device.write(uhk.getTransferData(payload));
|
||||||
|
|
||||||
let buffer = Buffer.from(device.readSync());
|
let buffer = Buffer.from(device.readSync());
|
||||||
configSize = buffer[1] + (buffer[2]<<8);
|
const hardwareConfigMaxSize = buffer[1] + (buffer[2]<<8);
|
||||||
|
const userConfigMaxSize = buffer[3] + (buffer[4]<<8);
|
||||||
|
const configMaxSize = isHardwareConfig ? hardwareConfigMaxSize : userConfigMaxSize;
|
||||||
|
const configSize = Math.min(configMaxSize, configBuffer.length);
|
||||||
|
|
||||||
console.log(`${configTypeString}configSize:`, configSize);
|
console.log(`${configTypeString}configSize:`, configSize);
|
||||||
while (offset < configSize) {
|
while (offset < configSize) {
|
||||||
const configBufferId = isHardwareConfig ? uhk.configBufferIds.hardwareConfig : uhk.configBufferIds.validatedUserConfig;
|
const configBufferId = isHardwareConfig ? uhk.configBufferIds.hardwareConfig : uhk.configBufferIds.validatedUserConfig;
|
||||||
|
|||||||
@@ -96,13 +96,10 @@ exports = module.exports = moduleExports = {
|
|||||||
compatibleKeyboard: 0x6123,
|
compatibleKeyboard: 0x6123,
|
||||||
},
|
},
|
||||||
vendorId: 0x1D50,
|
vendorId: 0x1D50,
|
||||||
systemPropertyIds: {
|
devicePropertyIds: {
|
||||||
usbProtocolVersion: 0,
|
deviceProtocolVersion: 0,
|
||||||
bridgeProtocolVersion: 1,
|
protocolVersions: 1,
|
||||||
dataModelVersion: 2,
|
configSizes: 2,
|
||||||
firmwareVersion: 3,
|
|
||||||
hardwareConfigSize: 4,
|
|
||||||
userConfigSize: 5,
|
|
||||||
},
|
},
|
||||||
configBufferIds,
|
configBufferIds,
|
||||||
eepromOperations,
|
eepromOperations,
|
||||||
|
|||||||
@@ -19,21 +19,18 @@ const configBin = program.args[0];
|
|||||||
const chunkSize = 60;
|
const chunkSize = 60;
|
||||||
const isHardwareConfig = program.hardwareConfig;
|
const isHardwareConfig = program.hardwareConfig;
|
||||||
const configTypeString = isHardwareConfig ? 'hardware' : 'user';
|
const configTypeString = isHardwareConfig ? 'hardware' : 'user';
|
||||||
let configSize;
|
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
let configBuffer = fs.readFileSync(configBin);
|
let configBuffer = fs.readFileSync(configBin);
|
||||||
let chunkSizeToRead;
|
let chunkSizeToRead;
|
||||||
|
|
||||||
const payload = new Buffer([
|
const payload = new Buffer([uhk.usbCommands.getProperty, uhk.devicePropertyIds.configSizes]);
|
||||||
uhk.usbCommands.getProperty,
|
|
||||||
isHardwareConfig
|
|
||||||
? uhk.systemPropertyIds.hardwareConfigSize
|
|
||||||
: uhk.systemPropertyIds.userConfigSize
|
|
||||||
]);
|
|
||||||
|
|
||||||
device.write(uhk.getTransferData(payload));
|
device.write(uhk.getTransferData(payload));
|
||||||
let buffer = Buffer.from(device.readSync());
|
let buffer = Buffer.from(device.readSync());
|
||||||
configSize = Math.min(buffer[1] + (buffer[2]<<8), configBuffer.length);
|
const hardwareConfigMaxSize = buffer[1] + (buffer[2]<<8);
|
||||||
|
const userConfigMaxSize = buffer[3] + (buffer[4]<<8);
|
||||||
|
const configMaxSize = isHardwareConfig ? hardwareConfigMaxSize : userConfigMaxSize;
|
||||||
|
const configSize = Math.min(configMaxSize, configBuffer.length);
|
||||||
|
|
||||||
while (offset < configSize) {
|
while (offset < configSize) {
|
||||||
const usbCommand = isHardwareConfig ? uhk.usbCommands.writeHardwareConfig : uhk.usbCommands.writeStagingUserConfig;
|
const usbCommand = isHardwareConfig ? uhk.usbCommands.writeHardwareConfig : uhk.usbCommands.writeStagingUserConfig;
|
||||||
|
|||||||
Reference in New Issue
Block a user