* add write-hca.js * refactor: Move config serializer into the uhk-common package * refactor: Move getTransferBuffers into the uhk-usb package * refactor: delete obsoleted classes * build: add uhk-usb build command * refactor: move eeprom transfer to uhk-usb package * fix: Fix write-hca.js * feat: load hardware config from the device and * style: fix ts lint errors * build: fix rxjs dependency resolve * test: Add jasmine unit test framework to the tet serializer * fix(user-config): A "type": "basic", properties to the "keystroke" action types * feat(usb): set chmod+x on write-hca.js * feat(usb): Create USB logger * style: Fix type * build: Add chalk to dependencies. Chalk will colorize the output
58 lines
1.7 KiB
JavaScript
Executable File
58 lines
1.7 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
const {HardwareConfiguration, UhkBuffer} = require('uhk-common');
|
|
const {EepromTransfer, UhkHidDevice, UsbCommand} = require('uhk-usb');
|
|
const Logger = require('./logger');
|
|
|
|
if (process.argv.length < 3) {
|
|
console.log(`use: write-hca <layout> <manufactureId>
|
|
|
|
- layout: iso or ansi
|
|
- manufactureId: max 32 bit integer
|
|
`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const layout = process.argv[2];
|
|
if (layout !== 'iso' && layout !== 'ansi') {
|
|
console.log('Invalid layout. Layout should be on of: iso, ansi');
|
|
process.exit(1);
|
|
}
|
|
|
|
const uuid = Number.parseInt(process.argv[3]);
|
|
|
|
if (isNaN(uuid)) {
|
|
console.log('Manufacture Id is not a integer');
|
|
process.exit(1);
|
|
}
|
|
const hardwareConfig = new HardwareConfiguration();
|
|
|
|
hardwareConfig.signature = 'UHK';
|
|
hardwareConfig.dataModelVersion = 0;
|
|
hardwareConfig.hardwareId = 0;
|
|
hardwareConfig.uuid = uuid;
|
|
hardwareConfig.brandId = 0;
|
|
hardwareConfig.isIso = layout === 'iso';
|
|
hardwareConfig.hasBacklighting = false;
|
|
|
|
const logger = new Logger();
|
|
|
|
async function writeHca() {
|
|
const device = new UhkHidDevice(logger);
|
|
const hardwareBuffer = new UhkBuffer();
|
|
hardwareConfig.toBinary(hardwareBuffer);
|
|
const buffer = hardwareBuffer.buffer.slice(0, 60);
|
|
const fragments = UhkHidDevice.getTransferBuffers(UsbCommand.WriteHardwareConfig, buffer);
|
|
logger.debug('USB[T]: Write hardware configuration to keyboard');
|
|
for (const fragment of fragments) {
|
|
await device.write(fragment);
|
|
}
|
|
|
|
logger.debug('USB[T]: Write hardware configuration to EEPROM');
|
|
await device.writeConfigToEeprom(EepromTransfer.WriteHardwareConfig);
|
|
}
|
|
|
|
writeHca()
|
|
.catch((err)=>{
|
|
console.error(err);
|
|
});
|