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,32 +1,17 @@
#!/usr/bin/env node
let fs = require('fs');
let uhk = require('./uhk');
const uhk = require('./uhk');
let eepromTransferType = process.argv[2];
let eepromTransferId = uhk.eepromTransfer[eepromTransferType];
const eepromTransferType = process.argv[2];
const eepromTransferId = uhk.eepromTransfer[eepromTransferType];
if (eepromTransferId === undefined) {
console.error(`Gotta provide one of ${Object.keys(uhk.eepromTransfer).join(', ')}`);
process.exit(1);
}
let isFirstSend = true;
let isFirstReceive = true;
let isEepromBusy = true;
uhk.sendUsbPacketsByCallback(() => {
if (isFirstSend) {
isFirstSend = false;
return new Buffer([uhk.usbCommands.launchEepromTransfer, eepromTransferId]);
} else {
return isEepromBusy ? new Buffer([uhk.usbCommands.getKeyboardState]) : null;
}
});
uhk.registerReceiveCallback((buffer) => {
if (isFirstReceive) {
isFirstReceive = false;
} else {
isEepromBusy = buffer[1] === 1;
}
});
const device = uhk.getUhkDevice();
device.write(uhk.getTransferData(new Buffer([uhk.usbCommands.launchEepromTransfer, eepromTransferId])));
const buffer = Buffer.from(device.readSync());
if(buffer[1] === 1) {
device.write(uhk.getTransferData(new Buffer([uhk.usbCommands.getKeyboardState])));
}