check every 100ms for DFU mode

10.8-maintenance
ctzsnooze 2022-02-27 14:39:31 +11:00
parent 1c94c65641
commit 249345beda
1 changed files with 20 additions and 4 deletions

View File

@ -114,10 +114,26 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
const onDisconnect = disconnectionResult => { const onDisconnect = disconnectionResult => {
if (disconnectionResult) { if (disconnectionResult) {
// delay to allow board to boot in bootloader mode // wait until board boots into bootloader mode
// required to detect if a DFU device appears // MacOs may need 5 seconds delay
// MacOs seems to need about 5 seconds delay function waitForDfu() {
setTimeout(startFlashing, GUI.operating_system === 'MacOS' ? 5000 : 1000); if (PortHandler.dfu_available) {
console.log(`DFU available after ${failedAttempts / 10} seconds`);
clearInterval(dfuWaitInterval);
startFlashing();
} else {
failedAttempts++;
if (failedAttempts > 100) {
clearInterval(dfuWaitInterval);
console.log(`failed to get DFU connection, gave up after 10 seconds`);
GUI.log(i18n.getMessage('serialPortOpenFail'));
GUI.connect_lock = false;
}
}
}
let failedAttempts = 0;
const dfuWaitInterval = setInterval(waitForDfu, 100);
} else { } else {
GUI.connect_lock = false; GUI.connect_lock = false;
} }