Make {get,set}-variable.js expect variable name and use async/await.

This commit is contained in:
László Monda
2018-07-25 02:08:36 +02:00
parent a04fa67446
commit b8859f7b64
3 changed files with 28 additions and 12 deletions

View File

@@ -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]]);
})();