Rename jump-to-bootloader.js to reenumerate.js and make it able to reenumerate as any UHK USB product ID.
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
let uhk = require('./uhk');
|
||||
|
||||
let timeoutMs = 10000;
|
||||
let pollingIntervalMs = 100;
|
||||
let bootloaderTimeoutMs = 5000;
|
||||
let jumped = false;
|
||||
|
||||
let enumerationMode = process.argv[2] === 'buspal' ? uhk.enumerationModes.busPal : uhk.enumerationModes.bootloader;
|
||||
|
||||
console.log('Trying to jump to the bootloader...');
|
||||
setInterval(() => {
|
||||
timeoutMs -= pollingIntervalMs;
|
||||
|
||||
let device = uhk.getBootloaderDevice();
|
||||
|
||||
if (device) {
|
||||
console.log('Bootloader is up');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (timeoutMs <= 0) {
|
||||
console.log("Couldn't jump to the bootloader");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
device = uhk.getUhkDevice();
|
||||
if (device && !jumped) {
|
||||
console.log('UHK found, jumping to bootloader');
|
||||
let t = bootloaderTimeoutMs;
|
||||
let message = new Buffer([uhk.usbCommands.jumpToBootloader, enumerationMode, t&0xff, (t&0xff<<8)>>8, (t&0xff<<16)>>16, (t&0xff<<24)>>24]);
|
||||
device.write(uhk.getTransferData(message));
|
||||
jumped = true;
|
||||
|
||||
if (enumerationMode == uhk.enumerationModes.busPal) {
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
}, pollingIntervalMs);
|
||||
20
packages/usb/package-lock.json
generated
20
packages/usb/package-lock.json
generated
@@ -1,11 +1,14 @@
|
||||
{
|
||||
"requires": true,
|
||||
"name": "agent-usb",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@types/node": {
|
||||
"version": "8.0.28",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.28.tgz",
|
||||
"integrity": "sha512-HupkFXEv3O3KSzcr3Ylfajg0kaerBg1DyaZzRBBQfrU3NN1mTBRE7sCveqHwXLS5Yrjvww8qFzkzYQQakG9FuQ=="
|
||||
"integrity": "sha512-HupkFXEv3O3KSzcr3Ylfajg0kaerBg1DyaZzRBBQfrU3NN1mTBRE7sCveqHwXLS5Yrjvww8qFzkzYQQakG9FuQ==",
|
||||
"dev": true
|
||||
},
|
||||
"ansi-styles": {
|
||||
"version": "3.2.0",
|
||||
@@ -38,6 +41,11 @@
|
||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
|
||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
|
||||
},
|
||||
"commander": {
|
||||
"version": "2.11.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz",
|
||||
"integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ=="
|
||||
},
|
||||
"escape-string-regexp": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
||||
@@ -689,10 +697,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "0.10.31",
|
||||
"bundled": true
|
||||
},
|
||||
"string-width": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
@@ -702,6 +706,10 @@
|
||||
"strip-ansi": "3.0.1"
|
||||
}
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "0.10.31",
|
||||
"bundled": true
|
||||
},
|
||||
"stringstream": {
|
||||
"version": "0.0.5",
|
||||
"bundled": true
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "2.1.0",
|
||||
"commander": "^2.11.0",
|
||||
"node-hid": "0.5.4",
|
||||
"uhk-common": "1.0.0",
|
||||
"uhk-usb": "1.0.0"
|
||||
|
||||
52
packages/usb/reenumerate.js
Executable file
52
packages/usb/reenumerate.js
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env node
|
||||
const HID = require('node-hid');
|
||||
let uhk = require('./uhk');
|
||||
var program = require('commander');
|
||||
|
||||
program
|
||||
.option('-dt, --polling-timeout <n>', 'Polling timeout (ms)')
|
||||
.option('-bt, --bootloader-timeout <n>', 'Bootloader timeout (ms)')
|
||||
.option('-f, --force', 'Force reenumeration')
|
||||
.parse(process.argv);
|
||||
|
||||
let pollingTimeoutMs = 10000;
|
||||
const pollingIntervalMs = 100;
|
||||
const bootloaderTimeoutMs = 5000;
|
||||
let jumped = false;
|
||||
|
||||
const enumerationMode = program.args[0];
|
||||
const enumerationModeId = uhk.enumerationModes[enumerationMode];
|
||||
|
||||
if (enumerationModeId === undefined) {
|
||||
const enumerationModes = Object.keys(uhk.enumerationModes).join(', ');
|
||||
console.log(`Invalid enumeration mode '${enumerationMode}' is not one of: ${enumerationModes}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Trying to reenumerate as ${enumerationMode}...`);
|
||||
setInterval(() => {
|
||||
pollingTimeoutMs -= pollingIntervalMs;
|
||||
|
||||
const foundDevice = HID.devices().find(device =>
|
||||
device.vendorId === uhk.vendorId && device.productId === uhk.enumerationModeIdToProductId[enumerationModeId]);
|
||||
|
||||
if (foundDevice) {
|
||||
console.log(`${enumerationMode} is up`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (pollingTimeoutMs <= 0) {
|
||||
console.log(`Couldn't reenumerate as ${enumerationMode}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let device = uhk.getUhkDevice();
|
||||
if (device && !jumped) {
|
||||
console.log(`UHK found, reenumerating as ${enumerationMode}`);
|
||||
let t = bootloaderTimeoutMs;
|
||||
let message = new Buffer([uhk.usbCommands.reenumerate, enumerationModeId, t&0xff, (t&0xff<<8)>>8, (t&0xff<<16)>>16, (t&0xff<<24)>>24]);
|
||||
device.write(uhk.getTransferData(message));
|
||||
jumped = true;
|
||||
}
|
||||
|
||||
}, pollingIntervalMs);
|
||||
@@ -51,7 +51,7 @@ exports = module.exports = moduleExports = {
|
||||
getTransferData,
|
||||
usbCommands: {
|
||||
getProperty: 0,
|
||||
jumpToBootloader: 1,
|
||||
reenumerate: 1,
|
||||
setTestLed: 2,
|
||||
writeUserConfig: 8,
|
||||
applyConfig: 9,
|
||||
@@ -68,10 +68,17 @@ exports = module.exports = moduleExports = {
|
||||
},
|
||||
enumerationModes: {
|
||||
bootloader: 0,
|
||||
busPal: 1,
|
||||
buspal: 1,
|
||||
normalKeyboard: 2,
|
||||
compatibleKeyboard: 3,
|
||||
},
|
||||
enumerationModeIdToProductId: {
|
||||
'0': 0x6120,
|
||||
'1': 0x6121,
|
||||
'2': 0x6122,
|
||||
'3': 0x6123,
|
||||
},
|
||||
vendorId: 0x1D50,
|
||||
systemPropertyIds: {
|
||||
usbProtocolVersion: 0,
|
||||
bridgeProtocolVersion: 1,
|
||||
|
||||
Reference in New Issue
Block a user