Add the -u, or --overwrite-user-config argument to update-all-firmwares.js and make write-config.js able to read a specified config file.
This commit is contained in:
@@ -11,6 +11,7 @@ require('shelljs/global');
|
||||
|
||||
program
|
||||
.usage(`firmwarePath`)
|
||||
.option('-u, --overwrite-user-config', 'Overwrite the user configuration with the one that is bundled with the firmware')
|
||||
.parse(process.argv);
|
||||
|
||||
if (program.args.length == 0) {
|
||||
@@ -30,6 +31,11 @@ require('shelljs/global');
|
||||
exec(`${__dirname}/update-device-firmware.js ${firmwarePath}/devices/uhk60-right/firmware.hex`);
|
||||
exec(`${__dirname}/reenumerate.js normalKeyboard`);
|
||||
exec(`${__dirname}/update-module-firmware.js leftHalf ${firmwarePath}/modules/uhk60-left.bin`);
|
||||
|
||||
if (program.overwriteUserConfig) {
|
||||
exec(`${__dirname}/write-config.js ${firmwarePath}/devices/uhk60-right/config.bin`);
|
||||
}
|
||||
|
||||
config.verbose = false;
|
||||
} catch(exception) {
|
||||
console.error(exception.message);
|
||||
|
||||
@@ -1,15 +1,27 @@
|
||||
#!/usr/bin/env node
|
||||
const program = require('commander');
|
||||
const fs = require('fs');
|
||||
const uhk = require('./uhk');
|
||||
const device = uhk.getUhkDevice();
|
||||
require('shelljs/global');
|
||||
|
||||
program
|
||||
.usage(`config.bin`)
|
||||
.option('-h, --hardware-config', 'Write the hardware config instead of the user config')
|
||||
.parse(process.argv);
|
||||
|
||||
if (program.args.length == 0) {
|
||||
console.error('No binary config file specified.');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const configBin = program.args[0];
|
||||
const chunkSize = 60;
|
||||
|
||||
const isHardwareConfig = process.argv[2] === 'h';
|
||||
const isHardwareConfig = program.hardwareConfig;
|
||||
const configTypeString = isHardwareConfig ? 'hardware' : 'user';
|
||||
let configSize;
|
||||
let offset = 0;
|
||||
let configBuffer = fs.readFileSync(`${configTypeString}-config.write`);
|
||||
let configBuffer = fs.readFileSync(configBin);
|
||||
let chunkSizeToRead;
|
||||
|
||||
const payload = new Buffer([
|
||||
@@ -21,17 +33,21 @@ const payload = new Buffer([
|
||||
|
||||
device.write(uhk.getTransferData(payload));
|
||||
let buffer = Buffer.from(device.readSync());
|
||||
configSize = buffer[1] + (buffer[2]<<8);
|
||||
console.log(`${configTypeString}configSize:`, configSize);
|
||||
configSize = Math.min(buffer[1] + (buffer[2]<<8), configBuffer.length);
|
||||
|
||||
while (offset < configSize) {
|
||||
const usbCommand = isHardwareConfig ? uhk.usbCommands.writeHardwareConfig : uhk.usbCommands.writeStagingUserConfig;
|
||||
chunkSizeToRead = Math.min(chunkSize, configSize - offset);
|
||||
|
||||
if (chunkSizeToRead === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
buffer = Buffer.concat([
|
||||
new Buffer([usbCommand, chunkSizeToRead, offset & 0xff, offset >> 8]),
|
||||
configBuffer.slice(offset, offset+chunkSizeToRead)
|
||||
]);
|
||||
console.log('write-config-chunk:', uhk.bufferToString(buffer));
|
||||
|
||||
device.write(uhk.getTransferData(buffer));
|
||||
device.readSync();
|
||||
offset += chunkSizeToRead;
|
||||
|
||||
Reference in New Issue
Block a user