Rewrite writeHca() using the JavaScript USB API instead of TypeScript because the latter couldn't reopen the USB device.
This commit is contained in:
@@ -5,33 +5,29 @@ const uhk = require('./uhk')
|
|||||||
require('shelljs/global');
|
require('shelljs/global');
|
||||||
|
|
||||||
(async function() {
|
(async function() {
|
||||||
try {
|
config.fatal = true;
|
||||||
config.fatal = true;
|
|
||||||
|
|
||||||
program
|
program
|
||||||
.usage(`firmwarePath`)
|
.usage(`firmwarePath`)
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
if (program.args.length == 0) {
|
if (program.args.length == 0) {
|
||||||
console.error('No firmware path specified.');
|
console.error('No firmware path specified.');
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
config.verbose = true;
|
|
||||||
const firmwarePath = program.args[0];
|
|
||||||
await uhk.updateFirmwares(firmwarePath);
|
|
||||||
const device = uhk.getUhkDevice();
|
|
||||||
const configBuffer = fs.readFileSync(`${firmwarePath}/devices/uhk60-right/config.bin`);
|
|
||||||
console.log('write config');
|
|
||||||
await uhk.writeConfig(device, configBuffer, false);
|
|
||||||
console.log('apply config');
|
|
||||||
await uhk.applyConfig(device);
|
|
||||||
console.log('lanuch eeprom transfer');
|
|
||||||
await uhk.launchEepromTransfer(device, uhk.eepromOperations.write, uhk.eepromTransfer.writeUserConfig);
|
|
||||||
config.verbose = false;
|
|
||||||
|
|
||||||
} catch (exception) {
|
|
||||||
console.error(exception.message);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config.verbose = true;
|
||||||
|
const firmwarePath = program.args[0];
|
||||||
|
await uhk.updateFirmwares(firmwarePath);
|
||||||
|
const device = uhk.getUhkDevice();
|
||||||
|
const configBuffer = fs.readFileSync(`${firmwarePath}/devices/uhk60-right/config.bin`);
|
||||||
|
console.log('write config');
|
||||||
|
await uhk.writeConfig(device, configBuffer, false);
|
||||||
|
console.log('apply config');
|
||||||
|
await uhk.applyConfig(device);
|
||||||
|
console.log('lanuch eeprom transfer');
|
||||||
|
await uhk.launchEepromTransfer(device, uhk.eepromOperations.write, uhk.eepromTransfer.writeUserConfig);
|
||||||
|
|
||||||
|
await uhk.writeHca(device, false);
|
||||||
|
config.verbose = false;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ async function launchEepromTransfer(device, operation, configBuffer) {
|
|||||||
} while (isBusy);
|
} while (isBusy);
|
||||||
};
|
};
|
||||||
|
|
||||||
async function writeHca(isIso) {
|
async function writeHca(device, isIso) {
|
||||||
const hardwareConfig = new HardwareConfiguration();
|
const hardwareConfig = new HardwareConfiguration();
|
||||||
|
|
||||||
hardwareConfig.signature = 'UHK';
|
hardwareConfig.signature = 'UHK';
|
||||||
@@ -344,19 +344,14 @@ async function writeHca(isIso) {
|
|||||||
hardwareConfig.isIso = isIso;
|
hardwareConfig.isIso = isIso;
|
||||||
|
|
||||||
const logger = new Logger();
|
const logger = new Logger();
|
||||||
|
|
||||||
const device = new UhkHidDevice(logger);
|
|
||||||
const hardwareBuffer = new UhkBuffer();
|
const hardwareBuffer = new UhkBuffer();
|
||||||
hardwareConfig.toBinary(hardwareBuffer);
|
hardwareConfig.toBinary(hardwareBuffer);
|
||||||
const buffer = hardwareBuffer.getBufferContent();
|
const buffer = hardwareBuffer.getBufferContent();
|
||||||
const fragments = 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');
|
console.log('write hardware config')
|
||||||
await device.writeConfigToEeprom(ConfigBufferId.hardwareConfig);
|
await uhk.writeConfig(device, buffer, true);
|
||||||
|
console.log('lanuch eeprom transfer');
|
||||||
|
await uhk.launchEepromTransfer(device, uhk.eepromOperations.write, uhk.eepromTransfer.writeHardwareConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
uhk = exports = module.exports = moduleExports = {
|
uhk = exports = module.exports = moduleExports = {
|
||||||
|
|||||||
Reference in New Issue
Block a user