refactor(usb): Use hid-api instead of lib-usb (#404)

* refactor(usb): Rewrite jump-to-bootloder to node-hid

* refactor(usb): Rewrite the whole usb packages to HID-API

* refactor(usb): Deleted not valid usb command files

* refactor(usb): Deleted not supported usb commands

* Remove obsolete script.

* Remove obsolete script.

* Fix script.

* Fix script.

* No need to assign the silent property because it has been removed.

* This workaround may work on other platforms, but it certainly doesn't work on Linux. It makes some scripts not work, so I'm commenting it out.

* Fix bootloader VID and PID.
This commit is contained in:
Róbert Kiss
2017-09-06 14:32:58 +02:00
committed by László Monda
parent 3cbd3bb5ea
commit 30c74c06d3
23 changed files with 953 additions and 814 deletions

View File

@@ -1,39 +1,38 @@
#!/usr/bin/env node
let fs = require('fs');
let uhk = require('./uhk');
const fs = require('fs');
const uhk = require('./uhk');
const device = uhk.getUhkDevice();
const chunkSize = 60;
let isHardwareConfig = process.argv[2] === 'h';
let configTypeString = isHardwareConfig ? 'hardware' : 'user';
let isFirstSend = true;
let isFirstReceive = true;
const isHardwareConfig = process.argv[2] === 'h';
const configTypeString = isHardwareConfig ? 'hardware' : 'user';
let configSize;
let offset = 0;
let configBuffer = fs.readFileSync(`${configTypeString}-config.write`);
let chunkSizeToRead;
uhk.sendUsbPacketsByCallback(() => {
if (isFirstSend) {
isFirstSend = false;
return new Buffer([uhk.usbCommands.getProperty, isHardwareConfig ? uhk.systemPropertyIds.hardwareConfigSize : uhk.systemPropertyIds.userConfigSize]);
} else {
chunkSizeToRead = Math.min(chunkSize, configSize - offset)
let usbCommand = isHardwareConfig ? uhk.usbCommands.writeHardwareConfig : uhk.usbCommands.writeUserConfig;
let buffer = Buffer.concat([
new Buffer([usbCommand, chunkSizeToRead, offset & 0xff, offset >> 8]),
configBuffer.slice(offset, offset+chunkSizeToRead)
]);
let bufferOrNull = offset >= configSize ? null : buffer;
offset += chunkSizeToRead;
return bufferOrNull;
}
});
const payload = new Buffer([
uhk.usbCommands.getProperty,
isHardwareConfig
? uhk.systemPropertyIds.hardwareConfigSize
: uhk.systemPropertyIds.userConfigSize
]);
uhk.registerReceiveCallback((buffer) => {
if (isFirstReceive) {
isFirstReceive = false;
configSize = buffer[1] + (buffer[2]<<8);
console.log(`${configTypeString}configSize:`, configSize);
}
});
device.write(uhk.getTransferData(payload));
let buffer = Buffer.from(device.readSync());
configSize = buffer[1] + (buffer[2]<<8);
console.log(`${configTypeString}configSize:`, configSize);
while (offset < configSize){
const usbCommand = isHardwareConfig ? uhk.usbCommands.writeHardwareConfig : uhk.usbCommands.writeUserConfig;
chunkSizeToRead = Math.min(chunkSize, configSize - offset);
buffer = Buffer.concat([
new Buffer([usbCommand, chunkSizeToRead, offset & 0xff, offset >> 8]),
configBuffer.slice(offset, offset+chunkSizeToRead)
]);
console.log('write-config-chunk:', uhk.bufferToString(buffer));
device.write(uhk.getTransferData(buffer));
device.readSync();
offset += chunkSizeToRead;
}