From 148dd8d36133a6719324a0ef8e3f6911ae959ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Mon, 2 Apr 2018 17:25:35 +0200 Subject: [PATCH] Rewrite writeHca() using the JavaScript USB API instead of TypeScript because the latter couldn't reopen the USB device. --- packages/usb/factory-update.js | 46 ++++++++++++++++------------------ packages/usb/uhk.js | 15 ++++------- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/packages/usb/factory-update.js b/packages/usb/factory-update.js index 8e8b945e..0a859047 100755 --- a/packages/usb/factory-update.js +++ b/packages/usb/factory-update.js @@ -5,33 +5,29 @@ const uhk = require('./uhk') require('shelljs/global'); (async function() { - try { - config.fatal = true; + config.fatal = true; - program - .usage(`firmwarePath`) - .parse(process.argv); + program + .usage(`firmwarePath`) + .parse(process.argv); - if (program.args.length == 0) { - 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); + if (program.args.length == 0) { + 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); + + await uhk.writeHca(device, false); + config.verbose = false; })(); diff --git a/packages/usb/uhk.js b/packages/usb/uhk.js index 2644dfab..127c02f8 100644 --- a/packages/usb/uhk.js +++ b/packages/usb/uhk.js @@ -330,7 +330,7 @@ async function launchEepromTransfer(device, operation, configBuffer) { } while (isBusy); }; -async function writeHca(isIso) { +async function writeHca(device, isIso) { const hardwareConfig = new HardwareConfiguration(); hardwareConfig.signature = 'UHK'; @@ -344,19 +344,14 @@ async function writeHca(isIso) { hardwareConfig.isIso = isIso; const logger = new Logger(); - - const device = new UhkHidDevice(logger); const hardwareBuffer = new UhkBuffer(); hardwareConfig.toBinary(hardwareBuffer); 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'); - await device.writeConfigToEeprom(ConfigBufferId.hardwareConfig); + console.log('write hardware config') + 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 = {