Replace pushUint32() with uint32ToArray() and don't use it where not needed.
This commit is contained in:
@@ -3,7 +3,7 @@ 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.pushUint32([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.i2cBaudRate]));
|
let buffer = new Buffer([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.i2cBaudRate]);
|
||||||
//console.log(buffer);
|
//console.log(buffer);
|
||||||
device.write(uhk.getTransferData(buffer));
|
device.write(uhk.getTransferData(buffer));
|
||||||
let response = device.readSync();
|
let response = device.readSync();
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ function convertMs(milliseconds) {
|
|||||||
|
|
||||||
const device = uhk.getUhkDevice();
|
const device = uhk.getUhkDevice();
|
||||||
|
|
||||||
device.write(uhk.getTransferData(new Buffer(uhk.pushUint32([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.uptime]))));
|
device.write(uhk.getTransferData(new Buffer([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.uptime])));
|
||||||
let response = device.readSync();
|
let response = device.readSync();
|
||||||
let uptimeMs = uhk.getUint32(response, 1);
|
let uptimeMs = uhk.getUint32(response, 1);
|
||||||
let uptime = convertMs(uptimeMs);
|
let uptime = convertMs(uptimeMs);
|
||||||
console.log(`uptime: ${uptime.days}d ${String(uptime.hours).padStart(2, '0')}:${String(uptime.minutes).padStart(2, '0')}:${String(uptime.seconds).padStart(2, '0')}`)
|
console.log(`uptime: ${uptime.days}d ${String(uptime.hours).padStart(2, '0')}:${String(uptime.minutes).padStart(2, '0')}:${String(uptime.seconds).padStart(2, '0')}`)
|
||||||
|
|
||||||
device.write(uhk.getTransferData(new Buffer(uhk.pushUint32([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.i2cBaudRate]))));
|
device.write(uhk.getTransferData(new Buffer([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.i2cBaudRate])));
|
||||||
response = device.readSync();
|
response = device.readSync();
|
||||||
let requestedBaudRate = uhk.getUint32(response, 2);
|
let requestedBaudRate = uhk.getUint32(response, 2);
|
||||||
let actualBaudRate = uhk.getUint32(response, 6);
|
let actualBaudRate = uhk.getUint32(response, 6);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ function convertMs(milliseconds) {
|
|||||||
return {days, hours, minutes, seconds};
|
return {days, hours, minutes, seconds};
|
||||||
}
|
}
|
||||||
|
|
||||||
let buffer = new Buffer(uhk.pushUint32([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.uptime]));
|
let buffer = new Buffer([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.uptime]);
|
||||||
//console.log(buffer);
|
//console.log(buffer);
|
||||||
device.write(uhk.getTransferData(buffer));
|
device.write(uhk.getTransferData(buffer));
|
||||||
let response = device.readSync();
|
let response = device.readSync();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You're free to use any value in between and test the results.`);
|
|||||||
}
|
}
|
||||||
|
|
||||||
let bps = process.argv[2];
|
let bps = process.argv[2];
|
||||||
let buffer = new Buffer(uhk.pushUint32([uhk.usbCommands.setI2cBaudRate], +bps));
|
let buffer = new Buffer([uhk.usbCommands.setI2cBaudRate, ...uhk.uint32ToArray(+bps)]);
|
||||||
//console.log(buffer);
|
//console.log(buffer);
|
||||||
device.write(uhk.getTransferData(buffer));
|
device.write(uhk.getTransferData(buffer));
|
||||||
let response = device.readSync();
|
let response = device.readSync();
|
||||||
|
|||||||
+3
-7
@@ -22,12 +22,8 @@ function getUint32(buffer, offset) {
|
|||||||
return (buffer[offset]) + (buffer[offset+1] * 2**8) + (buffer[offset+2] * 2**16) + (buffer[offset+3] * 2**24);
|
return (buffer[offset]) + (buffer[offset+1] * 2**8) + (buffer[offset+2] * 2**16) + (buffer[offset+3] * 2**24);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pushUint32(array, value) {
|
function uint32ToArray(value) {
|
||||||
array.push((value >> 0) & 0xff);
|
return [(value >> 0) & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, (value >> 24) & 0xff];
|
||||||
array.push((value >> 8) & 0xff);
|
|
||||||
array.push((value >> 16) & 0xff);
|
|
||||||
array.push((value >> 24) & 0xff);
|
|
||||||
return array;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUhkDevice() {
|
function getUhkDevice() {
|
||||||
@@ -75,7 +71,7 @@ exports = module.exports = moduleExports = {
|
|||||||
bufferToString,
|
bufferToString,
|
||||||
getUint16,
|
getUint16,
|
||||||
getUint32,
|
getUint32,
|
||||||
pushUint32,
|
uint32ToArray,
|
||||||
getUhkDevice,
|
getUhkDevice,
|
||||||
getBootloaderDevice,
|
getBootloaderDevice,
|
||||||
getTransferData,
|
getTransferData,
|
||||||
|
|||||||
Reference in New Issue
Block a user