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