Add the async uhk.writeDevice() and use it in get-i2c-baud-rate.js
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
const path = require('path');
|
||||
const uhk = require('./uhk');
|
||||
const device = uhk.getUhkDevice();
|
||||
|
||||
let buffer = new Buffer([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.i2cBaudRate]);
|
||||
//console.log(buffer);
|
||||
device.write(uhk.getTransferData(buffer));
|
||||
let response = device.readSync();
|
||||
//console.log(Buffer.from(response));
|
||||
let requestedBaudRate = uhk.getUint32(response, 2);
|
||||
let actualBaudRate = uhk.getUint32(response, 6);
|
||||
console.log(`requestedBaudRate:${requestedBaudRate} | actualBaudRate:${actualBaudRate} | I2C0_F:0b${response[1].toString(2).padStart(8, '0')}`)
|
||||
(async function() {
|
||||
let response = await uhk.writeDevice(device, [uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.i2cBaudRate]);
|
||||
let requestedBaudRate = uhk.getUint32(response, 2);
|
||||
let actualBaudRate = uhk.getUint32(response, 6);
|
||||
console.log(`requestedBaudRate:${requestedBaudRate} | actualBaudRate:${actualBaudRate} | I2C0_F:0b${response[1].toString(2).padStart(8, '0')}`)
|
||||
})();
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user