Move waitForKbootIdle() to uhk.js
This commit is contained in:
@@ -204,6 +204,35 @@ async function jumpToModuleBootloader(device, moduleSlotId) {
|
|||||||
await uhk.writeDevice(device, [uhk.usbCommands.jumpToModuleBootloader, moduleSlotId]);
|
await uhk.writeDevice(device, [uhk.usbCommands.jumpToModuleBootloader, moduleSlotId]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function waitForKbootIdle(device) {
|
||||||
|
const intervalMs = 100;
|
||||||
|
const pingMessageInterval = 500;
|
||||||
|
let timeoutMs = 10000;
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const intervalId = setInterval(async function() {
|
||||||
|
const response = await uhk.writeDevice(device, [uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.currentKbootCommand]);
|
||||||
|
const currentKbootCommand = response[1];
|
||||||
|
if (currentKbootCommand == 0) {
|
||||||
|
console.log('Bootloader pinged.');
|
||||||
|
resolve();
|
||||||
|
clearInterval(intervalId);
|
||||||
|
return;
|
||||||
|
} else if (timeoutMs % pingMessageInterval === 0) {
|
||||||
|
console.log("Cannot ping the bootloader. Please reconnect the left keyboard half. It probably needs several tries, so keep reconnecting until you see this message.");
|
||||||
|
};
|
||||||
|
|
||||||
|
timeoutMs -= intervalMs;
|
||||||
|
|
||||||
|
if (timeoutMs < 0) {
|
||||||
|
reject();
|
||||||
|
clearInterval(intervalId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}, intervalMs);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
uhk = exports = module.exports = moduleExports = {
|
uhk = exports = module.exports = moduleExports = {
|
||||||
bufferToString,
|
bufferToString,
|
||||||
getUint16,
|
getUint16,
|
||||||
@@ -221,6 +250,7 @@ uhk = exports = module.exports = moduleExports = {
|
|||||||
reenumerate,
|
reenumerate,
|
||||||
sendKbootCommandToModule,
|
sendKbootCommandToModule,
|
||||||
jumpToModuleBootloader,
|
jumpToModuleBootloader,
|
||||||
|
waitForKbootIdle,
|
||||||
usbCommands: {
|
usbCommands: {
|
||||||
getDeviceProperty : 0x00,
|
getDeviceProperty : 0x00,
|
||||||
reenumerate : 0x01,
|
reenumerate : 0x01,
|
||||||
|
|||||||
@@ -1,37 +1,7 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const uhk = require('./uhk');
|
const uhk = require('./uhk');
|
||||||
|
|
||||||
let intervalMs = 100;
|
|
||||||
let pingMessageInterval = 500;
|
|
||||||
|
|
||||||
async function waitForKbootIdle(device) {
|
|
||||||
let timeoutMs = 10000;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const intervalId = setInterval(async function() {
|
|
||||||
const response = await uhk.writeDevice(device, [uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.currentKbootCommand]);
|
|
||||||
const currentKbootCommand = response[1];
|
|
||||||
if (currentKbootCommand == 0) {
|
|
||||||
console.log('Bootloader pinged.');
|
|
||||||
resolve();
|
|
||||||
clearInterval(intervalId);
|
|
||||||
return;
|
|
||||||
} else if (timeoutMs % pingMessageInterval === 0) {
|
|
||||||
console.log("Cannot ping the bootloader. Please reconnect the left keyboard half. It probably needs several tries, so keep reconnecting until you see this message.");
|
|
||||||
};
|
|
||||||
|
|
||||||
timeoutMs -= intervalMs;
|
|
||||||
|
|
||||||
if (timeoutMs < 0) {
|
|
||||||
reject();
|
|
||||||
clearInterval(intervalId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}, intervalMs);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const device = uhk.getUhkDevice();
|
const device = uhk.getUhkDevice();
|
||||||
|
|
||||||
(async function() {
|
(async function() {
|
||||||
await waitForKbootIdle(device);
|
await uhk.waitForKbootIdle(device);
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user