Files
agent/packages/usb/eeprom.js
László Monda 2702a74035 Finalize usb protocol (#515)
* Change UsbCommandId_SetTestLed from 0x02 to 0x14

* Change UsbCommandId_JumpToModuleBootloader from 0x12 to 0x02.

* Change UsbCommandId_SendKbootCommandToModule from 0x13 to 0x03.

* Replace UsbCommandId_ReadHardwareConfig and UsbCommandId_ReadUserConfig with UsbCommandId_ReadConfig.

* Change UsbCommandId_WriteHardwareConfig and UsbCommandId_WriteUserConfig to 0x05 and 0x06.

* Change UsbCommandId_ApplyConfig to 0x07.

* Change the arguments of UsbCommandId_LaunchEepromTransfer and its id to 0x08.

* Change the value of UsbCommandId_{GetDeviceState,SetTestLed,GetDebugBuffer,GetAdcValue,SetLedPwmBrightness}.

* Use firmware 6.0.0
2017-12-13 01:20:23 +01:00

32 lines
1011 B
JavaScript
Executable File

#!/usr/bin/env node
const uhk = require('./uhk');
const eepromTransferType = process.argv[2];
const eepromTransfer = uhk.eepromTransfer[eepromTransferType];
if (eepromTransfer === undefined) {
console.error(`Gotta provide one of ${Object.keys(uhk.eepromTransfer).join(', ')}`);
process.exit(1);
}
const device = uhk.getUhkDevice();
device.write(uhk.getTransferData(new Buffer([uhk.usbCommands.launchEepromTransfer, eepromTransfer.operation, eepromTransfer.configBuffer])));
const buffer = Buffer.from(device.readSync());
const responseCode = buffer[0];
if (responseCode !== 0) {
console.error(`Write user config to eeprom failed. Response code: ${responseCode}`);
process.exit(1);
}
function waitUntilKeyboardBusy() {
device.write(uhk.getTransferData(new Buffer([uhk.usbCommands.getDeviceState])));
const keyboardStateBuffer = Buffer.from(device.readSync());
if (keyboardStateBuffer[1] === 1) {
setTimeout(waitUntilKeyboardBusy, 200);
}
}
waitUntilKeyboardBusy();