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
|
#!/usr/bin/env node
|
||||||
const path = require('path');
|
|
||||||
const uhk = require('./uhk');
|
const uhk = require('./uhk');
|
||||||
const device = uhk.getUhkDevice();
|
const device = uhk.getUhkDevice();
|
||||||
|
|
||||||
let buffer = new Buffer([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.i2cBaudRate]);
|
(async function() {
|
||||||
//console.log(buffer);
|
let response = await uhk.writeDevice(device, [uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.i2cBaudRate]);
|
||||||
device.write(uhk.getTransferData(buffer));
|
let requestedBaudRate = uhk.getUint32(response, 2);
|
||||||
let response = device.readSync();
|
let actualBaudRate = uhk.getUint32(response, 6);
|
||||||
//console.log(Buffer.from(response));
|
console.log(`requestedBaudRate:${requestedBaudRate} | actualBaudRate:${actualBaudRate} | I2C0_F:0b${response[1].toString(2).padStart(8, '0')}`)
|
||||||
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 HID = require('node-hid');
|
||||||
// const debug = process.env.DEBUG;
|
// const debug = process.env.DEBUG;
|
||||||
const debug = true;
|
const debug = true;
|
||||||
@@ -26,6 +27,11 @@ function uint32ToArray(value) {
|
|||||||
return [(value >> 0) & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, (value >> 24) & 0xff];
|
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() {
|
function getUhkDevice() {
|
||||||
const foundDevice = HID.devices().find(device =>
|
const foundDevice = HID.devices().find(device =>
|
||||||
device.vendorId === 0x1d50 && device.productId === 0x6122 &&
|
device.vendorId === 0x1d50 && device.productId === 0x6122 &&
|
||||||
@@ -72,6 +78,7 @@ exports = module.exports = moduleExports = {
|
|||||||
getUint16,
|
getUint16,
|
||||||
getUint32,
|
getUint32,
|
||||||
uint32ToArray,
|
uint32ToArray,
|
||||||
|
writeDevice,
|
||||||
getUhkDevice,
|
getUhkDevice,
|
||||||
getBootloaderDevice,
|
getBootloaderDevice,
|
||||||
getTransferData,
|
getTransferData,
|
||||||
|
|||||||
Reference in New Issue
Block a user