diff --git a/packages/usb/get-variable.js b/packages/usb/get-variable.js index 0d43a38f..38653bca 100755 --- a/packages/usb/get-variable.js +++ b/packages/usb/get-variable.js @@ -1,11 +1,16 @@ #!/usr/bin/env node - const uhk = require('./uhk'); -const device = uhk.getUhkDevice(); -const sendData = new Buffer([uhk.usbCommands.getVariable, +process.argv[2]]); -console.log(sendData); -device.write(uhk.getTransferData(sendData)); -const receivedBuffer = Buffer.from(device.readSync()); -console.log(receivedBuffer[1]); +(async function() { + const device = uhk.getUhkDevice(); + const variableName = process.argv[2]; + const variableId = uhk.variableNameToId[variableName]; + if (variableId === undefined) { + console.log(`The specified variable does not exist. Specify one of ${Object.keys(uhk.variableNameToId).join(', ')}`); + process.exit(1); + } + + const receivedBuffer = await uhk.writeDevice(device, [uhk.usbCommands.getVariable, variableId]); + console.log(receivedBuffer[1]); +})(); diff --git a/packages/usb/set-variable.js b/packages/usb/set-variable.js index 340d2dda..96449913 100755 --- a/packages/usb/set-variable.js +++ b/packages/usb/set-variable.js @@ -1,10 +1,15 @@ #!/usr/bin/env node - const uhk = require('./uhk'); -const device = uhk.getUhkDevice(); -const sendData = new Buffer([uhk.usbCommands.setVariable, +process.argv[2], +process.argv[3]]); -console.log(sendData); -device.write(uhk.getTransferData(sendData)); +(async function() { + const device = uhk.getUhkDevice(); + const variableName = process.argv[2]; + const variableId = uhk.variableNameToId[variableName]; + if (variableId === undefined) { + console.log(`The specified variable does not exist. Specify one of ${Object.keys(uhk.variableNameToId).join(', ')}`); + process.exit(1); + } + await uhk.writeDevice(device, [uhk.usbCommands.setVariable, variableId, +process.argv[3]]); +})(); diff --git a/packages/usb/uhk.js b/packages/usb/uhk.js index 9044b1ca..c957a612 100644 --- a/packages/usb/uhk.js +++ b/packages/usb/uhk.js @@ -477,6 +477,12 @@ uhk = exports = module.exports = moduleExports = { normalKeyboard: 0x6122, compatibleKeyboard: 0x6123, }, + variableNameToId: { + testSwitches: 0, + testUsbStack: 1, + debounceTimePress: 2, + debounceTimeRelease: 3, + }, vendorId: 0x1D50, devicePropertyIds: { deviceProtocolVersion: 0,