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