Extract uhk.applyConfig() and uhk.launchEepromTransfer()
This commit is contained in:
@@ -9,23 +9,5 @@ if (eepromTransfer === undefined) {
|
||||
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);
|
||||
}
|
||||
// const buffer = await uhk.writeDevice(device, [uhk.usbCommands.launchEepromTransfer, eepromTransfer.operation, eepromTransfer.configBuffer]);
|
||||
|
||||
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();
|
||||
|
||||
@@ -276,7 +276,7 @@ async function updateFirmwares(firmwarePath) {
|
||||
await uhk.updateModuleFirmware(uhk.moduleSlotToI2cAddress.leftHalf, uhk.moduleSlotToId.leftHalf, `${firmwarePath}/modules/uhk60-left.bin`);
|
||||
}
|
||||
|
||||
async function writeUserConfig(device, configBuffer, isHardwareConfig) {
|
||||
async function writeConfig(device, configBuffer, isHardwareConfig) {
|
||||
const chunkSize = 60;
|
||||
let offset = 0;
|
||||
let chunkSizeToRead;
|
||||
@@ -303,6 +303,19 @@ async function writeUserConfig(device, configBuffer, isHardwareConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
async function applyConfig(device) {
|
||||
await uhk.writeDevice(device, [uhk.usbCommands.applyConfig]);
|
||||
}
|
||||
|
||||
async function launchEepromTransfer(device, operation, configBuffer) {
|
||||
const buffer = await uhk.writeDevice(device, [uhk.usbCommands.launchEepromTransfer, operation, configBuffer]);
|
||||
isBusy = true;
|
||||
do {
|
||||
const buffer = uhk.writeDevice(device, [uhk.usbCommands.getDeviceState]);
|
||||
isBusy = buffer[1] === 1;
|
||||
} while (isBusy);
|
||||
};
|
||||
|
||||
uhk = exports = module.exports = moduleExports = {
|
||||
bufferToString,
|
||||
getUint16,
|
||||
@@ -324,7 +337,9 @@ uhk = exports = module.exports = moduleExports = {
|
||||
waitForKbootIdle,
|
||||
updateModuleFirmware,
|
||||
updateFirmwares,
|
||||
writeUserConfig,
|
||||
writeConfig,
|
||||
applyConfig,
|
||||
launchEepromTransfer,
|
||||
usbCommands: {
|
||||
getDeviceProperty : 0x00,
|
||||
reenumerate : 0x01,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
const fs = require('fs');
|
||||
const program = require('commander');
|
||||
const tmp = require('tmp');
|
||||
const decompress = require('decompress');
|
||||
@@ -32,9 +33,11 @@ require('shelljs/global');
|
||||
await uhk.updateFirmwares(firmwarePath);
|
||||
|
||||
if (program.overwriteUserConfig) {
|
||||
exec(`${__dirname}/write-config.js ${firmwarePath}/devices/uhk60-right/config.bin`);
|
||||
exec(`${__dirname}/apply-config.js`);
|
||||
exec(`${__dirname}/eeprom.js writeUserConfig`);
|
||||
const device = uhk.getUhkDevice();
|
||||
const configBuffer = fs.readFileSync(`${firmwarePath}/devices/uhk60-right/config.bin`);
|
||||
await uhk.writeConfig(device, configBuffer, false);
|
||||
await uhk.applyConfig(device);
|
||||
await uhk.launchEepromTransfer(device, uhk.eepromOperations.write, uhk.eepromTransfer.writeUserConfig);
|
||||
}
|
||||
|
||||
config.verbose = false;
|
||||
|
||||
@@ -20,7 +20,7 @@ const uhk = require('./uhk');
|
||||
const configBin = program.args[0];
|
||||
const isHardwareConfig = program.hardwareConfig;
|
||||
const configTypeString = isHardwareConfig ? 'hardware' : 'user';
|
||||
let configBuffer = fs.readFileSync(configBin);
|
||||
const configBuffer = fs.readFileSync(configBin);
|
||||
|
||||
await uhk.writeUserConfig(device, configBuffer, isHardwareConfig);
|
||||
})();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user