Rename send-kboot-reset.js to send-kboot-command.js and generalize it by allowing various KBOOT commands to be sent.
This commit is contained in:
35
packages/usb/send-kboot-command.js
Executable file
35
packages/usb/send-kboot-command.js
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env node
|
||||
const uhk = require('./uhk');
|
||||
const path = require('path');
|
||||
|
||||
function printUsage() {
|
||||
const scriptFilename = path.basename(process.argv[1]);
|
||||
const commands = Object.keys(uhk.kbootCommands).join(' | ');
|
||||
console.log(
|
||||
`Usage: ${scriptFilename} command i2cAddress
|
||||
command: ${commands}
|
||||
i2cAddress is not needed for the idle command`);
|
||||
}
|
||||
|
||||
const kbootCommand = process.argv[2];
|
||||
if (!kbootCommand) {
|
||||
console.log(`No command provided`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const kbootCommandId = uhk.kbootCommands[kbootCommand];
|
||||
if (!kbootCommandId) {
|
||||
console.log(`Invalid command provided`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const i2cAddress = process.argv[3];
|
||||
if (kbootCommand !== 'idle' && !i2cAddress) {
|
||||
console.log(`No i2cAddress provided`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const device = uhk.getUhkDevice();
|
||||
let transfer = new Buffer([uhk.usbCommands.sendKbootCommand, kbootCommandId, parseInt(i2cAddress)]);
|
||||
device.write(uhk.getTransferData(transfer));
|
||||
const response = Buffer.from(device.readSync());
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
const uhk = require('./uhk');
|
||||
|
||||
const device = uhk.getUhkDevice();
|
||||
let transfer = new Buffer([uhk.usbCommands.sendKbootCommand, 0x10]);
|
||||
device.write(uhk.getTransferData(transfer));
|
||||
const response = Buffer.from(device.readSync());
|
||||
@@ -86,6 +86,11 @@ exports = module.exports = moduleExports = {
|
||||
readUserConfig: 2,
|
||||
writeUserConfig: 3,
|
||||
},
|
||||
kbootCommands: {
|
||||
idle: 0,
|
||||
ping: 1,
|
||||
reset: 2,
|
||||
},
|
||||
leftLedDriverAddress: 0b1110100,
|
||||
rightLedDriverAddress: 0b1110111,
|
||||
sendLog: sendLog,
|
||||
|
||||
Reference in New Issue
Block a user