diff --git a/packages/usb/apply-config.js b/packages/usb/apply-config.js index 51f296d7..218038e8 100755 --- a/packages/usb/apply-config.js +++ b/packages/usb/apply-config.js @@ -1,8 +1,7 @@ #!/usr/bin/env node const uhk = require('./uhk'); -const device = uhk.getUhkDevice(); -const sendData = new Buffer([uhk.usbCommands.applyConfig]); -device.write(uhk.getTransferData(sendData)); -const response = Buffer.from(device.readSync()); -console.log(response); +(async function() { + const device = uhk.getUhkDevice(); + uhk.applyConfig(device); +})(); diff --git a/packages/usb/get-module-state.js b/packages/usb/get-module-state.js index b2c493fb..4013b8bf 100755 --- a/packages/usb/get-module-state.js +++ b/packages/usb/get-module-state.js @@ -1,14 +1,7 @@ #!/usr/bin/env node const uhk = require('./uhk'); -const device = uhk.getUhkDevice(); -function getModuleState() { - const payload = new Buffer([uhk.usbCommands.getModuleProperty, 1]); - console.log('Sending ', uhk.bufferToString(payload)); - device.write(uhk.getTransferData(payload)); - const receivedBuffer = device.readSync(); - console.log('Received', uhk.bufferToString(receivedBuffer)); - setTimeout(getModuleState, 500) -} - -getModuleState(); +(async function() { + const device = uhk.getUhkDevice(); + await uhk.getModuleProperty(device, 1, uhk.modulePropertyIds.protocolVersions); +})(); diff --git a/packages/usb/uhk.js b/packages/usb/uhk.js index 06b9c27f..14625f6b 100644 --- a/packages/usb/uhk.js +++ b/packages/usb/uhk.js @@ -366,6 +366,10 @@ async function writeHca(device, isIso) { await uhk.launchEepromTransfer(device, uhk.eepromOperations.write, uhk.eepromTransfer.writeHardwareConfig); } +async function getModuleProperty(device, slotId, moduleProperty) { + await writeDevice(device, [uhk.usbCommands.getModuleProperty, slotId, moduleProperty]); +} + uhk = exports = module.exports = moduleExports = { bufferToString, getUint16, @@ -392,6 +396,7 @@ uhk = exports = module.exports = moduleExports = { launchEepromTransfer, writeUca, writeHca, + getModuleProperty, usbCommands: { getDeviceProperty : 0x00, reenumerate : 0x01,