From 1b22a2e739ed32d34608b70c3f694ad62b64468a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Mon, 23 Oct 2017 01:13:36 +0200 Subject: [PATCH] Rename send-kboot-reset.js to send-kboot-command.js and generalize it by allowing various KBOOT commands to be sent. --- packages/usb/send-kboot-command.js | 35 ++++++++++++++++++++++++++++++ packages/usb/send-kboot-reset.js | 7 ------ packages/usb/uhk.js | 5 +++++ 3 files changed, 40 insertions(+), 7 deletions(-) create mode 100755 packages/usb/send-kboot-command.js delete mode 100755 packages/usb/send-kboot-reset.js diff --git a/packages/usb/send-kboot-command.js b/packages/usb/send-kboot-command.js new file mode 100755 index 00000000..aa5c87cc --- /dev/null +++ b/packages/usb/send-kboot-command.js @@ -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()); diff --git a/packages/usb/send-kboot-reset.js b/packages/usb/send-kboot-reset.js deleted file mode 100755 index 60c84c50..00000000 --- a/packages/usb/send-kboot-reset.js +++ /dev/null @@ -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()); diff --git a/packages/usb/uhk.js b/packages/usb/uhk.js index 9bef1427..3cf14814 100755 --- a/packages/usb/uhk.js +++ b/packages/usb/uhk.js @@ -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,