Make {get,set}-variable.js expect variable name and use async/await.
This commit is contained in:
@@ -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]);
|
||||
})();
|
||||
|
||||
@@ -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]]);
|
||||
})();
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user