mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-19 06:15:13 +03:00
Make connection timeout dynamic
This commit is contained in:
parent
989816a2e1
commit
f8371afca2
4 changed files with 22 additions and 46 deletions
|
@ -830,6 +830,8 @@ function update_dataflash_global() {
|
|||
function reinitializeConnection(originatorTab, callback) {
|
||||
|
||||
// Close connection gracefully if it still exists.
|
||||
const previousTimeStamp = connectionTimestamp;
|
||||
|
||||
if (serial.connectionId) {
|
||||
if (GUI.connected_to || GUI.connecting_to) {
|
||||
$('a.connect').trigger('click');
|
||||
|
@ -840,19 +842,25 @@ function reinitializeConnection(originatorTab, callback) {
|
|||
|
||||
GUI.log(i18n.getMessage('deviceRebooting'));
|
||||
|
||||
let connectionTimeout = 200;
|
||||
const result = ConfigStorage.get('connectionTimeout');
|
||||
let attempts = 0;
|
||||
const reconnect = setInterval(waitforSerial, 100);
|
||||
|
||||
if (result.connectionTimeout) {
|
||||
connectionTimeout = result.connectionTimeout;
|
||||
function waitforSerial() {
|
||||
if (connectionTimestamp !== previousTimeStamp && CONFIGURATOR.connectionValid) {
|
||||
console.log(`Serial connection available after ${attempts / 10} seconds`);
|
||||
clearInterval(reconnect);
|
||||
MSP.promise(MSPCodes.MSP_STATUS).then(() => {
|
||||
GUI.log(i18n.getMessage('deviceReady'));
|
||||
originatorTab.initialize(false, $('#content').scrollTop());
|
||||
callback?.();
|
||||
});
|
||||
} else {
|
||||
attempts++;
|
||||
if (attempts > 100) {
|
||||
clearInterval(reconnect);
|
||||
console.log(`failed to get serial connection, gave up after 10 seconds`);
|
||||
GUI.log(i18n.getMessage('serialPortOpenFail'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
MSP.send_message(MSPCodes.MSP_STATUS, false, false, () => {
|
||||
GUI.log(i18n.getMessage('deviceReady'));
|
||||
originatorTab.initialize(false, $('#content').scrollTop());
|
||||
});
|
||||
|
||||
callback?.();
|
||||
}, connectionTimeout);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue