Replace UsbCommandId_ReadHardwareConfig and UsbCommandId_ReadUserConfig with UsbCommandId_ReadConfig.
This commit is contained in:
@@ -8,17 +8,22 @@ export namespace Constants {
|
||||
* UHK USB Communications command. All communication package should have start with a command code.
|
||||
*/
|
||||
export enum UsbCommand {
|
||||
GetProperty = 0,
|
||||
Reenumerate = 1,
|
||||
GetProperty = 0x00,
|
||||
Reenumerate = 0x01,
|
||||
JumpToModuleBootloader = 0x02,
|
||||
SendKbootCommandToModule = 0x03,
|
||||
ReadConfig = 0x04,
|
||||
UploadUserConfig = 8,
|
||||
ApplyConfig = 9,
|
||||
LaunchEepromTransfer = 12,
|
||||
ReadHardwareConfig = 13,
|
||||
WriteHardwareConfig = 14,
|
||||
ReadUserConfig = 15,
|
||||
GetKeyboardState = 16,
|
||||
JumpToModuleBootloader = 0x02,
|
||||
SendKbootCommandToModule = 0x03
|
||||
GetKeyboardState = 16
|
||||
}
|
||||
|
||||
export enum ConfigBufferId {
|
||||
hardwareConfig = 0,
|
||||
stagingUserConfig = 1,
|
||||
validatedUserConfig = 2
|
||||
}
|
||||
|
||||
export enum EepromTransfer {
|
||||
|
||||
@@ -5,7 +5,8 @@ import * as fs from 'fs';
|
||||
import { UhkBlhost } from './uhk-blhost';
|
||||
import { UhkHidDevice } from './uhk-hid-device';
|
||||
import { snooze } from './util';
|
||||
import { convertBufferToIntArray, EepromTransfer, getTransferBuffers, SystemPropertyIds, UsbCommand } from '../index';
|
||||
import { convertBufferToIntArray, EepromTransfer, getTransferBuffers, SystemPropertyIds, UsbCommand, ConfigBufferId
|
||||
} from '../index';
|
||||
import { LoadConfigurationsResult } from './models/load-configurations-result';
|
||||
|
||||
export class UhkOperations {
|
||||
@@ -69,12 +70,12 @@ export class UhkOperations {
|
||||
await this.device.waitUntilKeyboardBusy();
|
||||
const userConfiguration = await this.loadConfiguration(
|
||||
SystemPropertyIds.MaxUserConfigSize,
|
||||
UsbCommand.ReadUserConfig,
|
||||
ConfigBufferId.validatedUserConfig,
|
||||
'user configuration');
|
||||
|
||||
const hardwareConfiguration = await this.loadConfiguration(
|
||||
SystemPropertyIds.HardwareConfigSize,
|
||||
UsbCommand.ReadHardwareConfig,
|
||||
ConfigBufferId.hardwareConfig,
|
||||
'hardware configuration');
|
||||
|
||||
return {
|
||||
@@ -90,7 +91,10 @@ export class UhkOperations {
|
||||
* Return with the actual user / hardware fonfiguration from UHK Device
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async loadConfiguration(property: SystemPropertyIds, config: UsbCommand, configName: string): Promise<string> {
|
||||
public async loadConfiguration(
|
||||
property: SystemPropertyIds,
|
||||
configBufferId: ConfigBufferId ,
|
||||
configName: string): Promise<string> {
|
||||
let response = [];
|
||||
|
||||
try {
|
||||
@@ -106,12 +110,13 @@ export class UhkOperations {
|
||||
this.logService.debug(`[DeviceOperation] USB[T]: Read ${configName} from keyboard`);
|
||||
while (offset < configSize) {
|
||||
const chunkSizeToRead = Math.min(chunkSize, configSize - offset);
|
||||
const writeBuffer = Buffer.from([config, chunkSizeToRead, offset & 0xff, offset >> 8]);
|
||||
const writeBuffer = Buffer.from(
|
||||
[UsbCommand.ReadConfig, configBufferId, chunkSizeToRead, offset & 0xff, offset >> 8]);
|
||||
const readBuffer = await this.device.write(writeBuffer);
|
||||
configBuffer = Buffer.concat([configBuffer, new Buffer(readBuffer.slice(1, chunkSizeToRead + 1))]);
|
||||
offset += chunkSizeToRead;
|
||||
|
||||
if (firstRead && config === UsbCommand.ReadUserConfig) {
|
||||
if (firstRead && configBufferId !== ConfigBufferId.hardwareConfig) {
|
||||
firstRead = false;
|
||||
configSize = readBuffer[7] + (readBuffer[8] << 8);
|
||||
this.logService.debug(`[DeviceOperation] userConfigSize: ${configSize}`);
|
||||
|
||||
@@ -23,10 +23,10 @@ device.write(uhk.getTransferData(payload));
|
||||
let buffer = Buffer.from(device.readSync());
|
||||
configSize = buffer[1] + (buffer[2]<<8);
|
||||
console.log(`${configTypeString}configSize:`, configSize);
|
||||
while(offset < configSize) {
|
||||
const usbCommand = isHardwareConfig ? uhk.usbCommands.readHardwareConfig : uhk.usbCommands.readUserConfig;
|
||||
while (offset < configSize) {
|
||||
const configBufferId = isHardwareConfig ? uhk.configBufferIds.hardwareConfig : uhk.configBufferIds.validatedUserConfig;
|
||||
chunkSizeToRead = Math.min(chunkSize, configSize - offset);
|
||||
buffer = Buffer.from([usbCommand, chunkSizeToRead, offset & 0xff, offset >> 8]);
|
||||
buffer = Buffer.from([uhk.usbCommands.readConfig, configBufferId, chunkSizeToRead, offset & 0xff, offset >> 8]);
|
||||
console.log('write to keyboard', uhk.bufferToString(buffer));
|
||||
device.write(uhk.getTransferData(buffer));
|
||||
buffer = Buffer.from(device.readSync());
|
||||
|
||||
@@ -51,21 +51,20 @@ exports = module.exports = moduleExports = {
|
||||
getTransferData,
|
||||
checkModuleSlot,
|
||||
usbCommands: {
|
||||
getProperty: 0,
|
||||
reenumerate: 1,
|
||||
getProperty : 0x00,
|
||||
reenumerate : 0x01,
|
||||
jumpToModuleBootloader : 0x02,
|
||||
sendKbootCommandToModule: 0x03,
|
||||
readConfig : 0x04,
|
||||
setTestLed: 0x14,
|
||||
writeUserConfig: 8,
|
||||
applyConfig: 9,
|
||||
setLedPwmBrightness: 10,
|
||||
getAdcValue: 11,
|
||||
launchEepromTransferLegacy: 12,
|
||||
readHardwareConfig: 13,
|
||||
writeHardwareConfig: 14,
|
||||
readUserConfig: 15,
|
||||
getKeyboardState: 16,
|
||||
getDebugInfo: 17,
|
||||
jumpToModuleBootloader: 0x02,
|
||||
sendKbootCommandToModule: 0x03,
|
||||
},
|
||||
enumerationModes: {
|
||||
bootloader: 0,
|
||||
@@ -94,6 +93,11 @@ exports = module.exports = moduleExports = {
|
||||
hardwareConfigSize: 4,
|
||||
userConfigSize: 5,
|
||||
},
|
||||
configBufferIds: {
|
||||
hardwareConfig: 0,
|
||||
stagingUserConfig: 1,
|
||||
validatedUserConfig: 2,
|
||||
},
|
||||
eepromTransfer: {
|
||||
readHardwareConfig: 0,
|
||||
writeHardwareConfig: 1,
|
||||
|
||||
Reference in New Issue
Block a user