From 482cff3d3b50a5bd6e894ad0db4a2ad7c7400380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Tue, 30 Jan 2018 23:44:25 +0100 Subject: [PATCH] Extract sendKbootCommandToModule() from send-kboot-command-to-module.js to uhk.js --- packages/usb/send-kboot-command-to-module.js | 6 +++--- packages/usb/uhk.js | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/usb/send-kboot-command-to-module.js b/packages/usb/send-kboot-command-to-module.js index a98f6874..fe1ada79 100755 --- a/packages/usb/send-kboot-command-to-module.js +++ b/packages/usb/send-kboot-command-to-module.js @@ -33,6 +33,6 @@ if (kbootCommand !== 'idle') { } const device = uhk.getUhkDevice(); -let transfer = new Buffer([uhk.usbCommands.sendKbootCommandToModule, kbootCommandId, parseInt(i2cAddress)]); -device.write(uhk.getTransferData(transfer)); -const response = Buffer.from(device.readSync()); +(async function() { + await uhk.sendKbootCommandToModule(device, kbootCommandId, i2cAddress); +})(); diff --git a/packages/usb/uhk.js b/packages/usb/uhk.js index 06ec6138..5936bc10 100644 --- a/packages/usb/uhk.js +++ b/packages/usb/uhk.js @@ -196,6 +196,10 @@ function reenumerate(enumerationMode) { }) }; +async function sendKbootCommandToModule(device, kbootCommandId, i2cAddress) { + return await uhk.writeDevice(device, [uhk.usbCommands.sendKbootCommandToModule, kbootCommandId, parseInt(i2cAddress)]) +}; + uhk = exports = module.exports = moduleExports = { bufferToString, getUint16, @@ -211,6 +215,7 @@ uhk = exports = module.exports = moduleExports = { execRetry, updateDeviceFirmware, reenumerate, + sendKbootCommandToModule, usbCommands: { getDeviceProperty : 0x00, reenumerate : 0x01,