Extract waitForKbootIdle()
This commit is contained in:
@@ -1,22 +1,37 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const uhk = require('./uhk');
|
const uhk = require('./uhk');
|
||||||
|
|
||||||
function getCurrentKbootCommand() {
|
let intervalMs = 100;
|
||||||
device.write(uhk.getTransferData(new Buffer([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.currentKbootCommand])));
|
let pingMessageInterval = 500;
|
||||||
const response = Buffer.from(device.readSync());
|
|
||||||
const currentKbootCommand = response[1];
|
async function waitForKbootIdle(device) {
|
||||||
if (currentKbootCommand == 0) {
|
let timeoutMs = 10000;
|
||||||
console.log('Bootloader pinged.');
|
return new Promise((resolve, reject) => {
|
||||||
process.exit(0);
|
const intervalId = setInterval(async function() {
|
||||||
} else {
|
const response = await uhk.writeDevice(device, [uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.currentKbootCommand]);
|
||||||
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.");
|
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();
|
||||||
|
|
||||||
getCurrentKbootCommand();
|
(async function() {
|
||||||
|
await waitForKbootIdle(device);
|
||||||
setInterval(() => {
|
})();
|
||||||
getCurrentKbootCommand();
|
|
||||||
}, 500);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user