Add set-i2c-baud-rate.js
This commit is contained in:
24
packages/usb/set-i2c-baud-rate.js
Executable file
24
packages/usb/set-i2c-baud-rate.js
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env node
|
||||
const path = require('path');
|
||||
const uhk = require('./uhk');
|
||||
const device = uhk.getUhkDevice();
|
||||
|
||||
let programName = path.basename(process.argv[1]);
|
||||
|
||||
if (process.argv.length !== 3) {
|
||||
console.log(`Usage: ${programName} <baud rate in Hz>
|
||||
Adjust the frequency of the main I2C bus via which the right keyboard half communicates with the left half and the add-on modules.
|
||||
Example values:
|
||||
* 400000 Hz - Highest speed. This will probably make communication unreliable. Not recommended.
|
||||
* 100000 Hz - Default speed. Should work in most cases.
|
||||
* 10000 Hz - Low speed. Should help when connection is spotty. It'll make initial LED display updates visibly slower.
|
||||
You're free to use any value in between and test the results.`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let bps = process.argv[2];
|
||||
let buffer = new Buffer(uhk.pushUint32([uhk.usbCommands.setI2cBaudRate], +bps));
|
||||
console.log(buffer);
|
||||
device.write(uhk.getTransferData(buffer));
|
||||
const response = Buffer.from(device.readSync());
|
||||
console.log(response);
|
||||
@@ -14,6 +14,22 @@ function bufferToString(buffer) {
|
||||
return str;
|
||||
}
|
||||
|
||||
function getUint16(buffer, offset) {
|
||||
return (buffer[offset]) + (buffer[offset+1] * 2**8);
|
||||
}
|
||||
|
||||
function getUint32(buffer, offset) {
|
||||
return (buffer[offset]) + (buffer[offset+1] * 2**8) + (buffer[offset+2] * 2**16) + (buffer[offset+3] * 2**24);
|
||||
}
|
||||
|
||||
function pushUint32(array, value) {
|
||||
array.push((value >> 0) & 0xff);
|
||||
array.push((value >> 8) & 0xff);
|
||||
array.push((value >> 16) & 0xff);
|
||||
array.push((value >> 24) & 0xff);
|
||||
return array;
|
||||
}
|
||||
|
||||
function getUhkDevice() {
|
||||
const foundDevice = HID.devices().find(device =>
|
||||
device.vendorId === 0x1d50 && device.productId === 0x6122 &&
|
||||
@@ -57,6 +73,9 @@ let eepromOperations = {
|
||||
|
||||
exports = module.exports = moduleExports = {
|
||||
bufferToString,
|
||||
getUint16,
|
||||
getUint32,
|
||||
pushUint32,
|
||||
getUhkDevice,
|
||||
getBootloaderDevice,
|
||||
getTransferData,
|
||||
@@ -78,6 +97,7 @@ exports = module.exports = moduleExports = {
|
||||
setLedPwmBrightness : 0x0d,
|
||||
getModuleProperty : 0x0e,
|
||||
getSlaveI2cErrors : 0x0f,
|
||||
setI2cBaudRate : 0x10,
|
||||
},
|
||||
enumerationModes: {
|
||||
bootloader: 0,
|
||||
|
||||
Reference in New Issue
Block a user