Add the async uhk.writeDevice() and use it in get-i2c-baud-rate.js

This commit is contained in:
László Monda
2018-01-30 17:21:50 +01:00
parent 124c3ec29b
commit e0bb0bcca3
2 changed files with 13 additions and 9 deletions

View File

@@ -1,3 +1,4 @@
const util = require('util');
const HID = require('node-hid');
// const debug = process.env.DEBUG;
const debug = true;
@@ -26,6 +27,11 @@ function uint32ToArray(value) {
return [(value >> 0) & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, (value >> 24) & 0xff];
}
function writeDevice(device, data, options={}) {
device.write(getTransferData(new Buffer(data)));
return util.promisify(device.read.bind(device))();
}
function getUhkDevice() {
const foundDevice = HID.devices().find(device =>
device.vendorId === 0x1d50 && device.productId === 0x6122 &&
@@ -72,6 +78,7 @@ exports = module.exports = moduleExports = {
getUint16,
getUint32,
uint32ToArray,
writeDevice,
getUhkDevice,
getBootloaderDevice,
getTransferData,