mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-25 17:25:16 +03:00
Merge pull request #2838 from haslinghuis/dynamic_timeout
Make serial connection timeout dynamic
This commit is contained in:
commit
5b1845ff74
4 changed files with 22 additions and 46 deletions
|
@ -190,15 +190,7 @@ PortHandler.detectPort = function(currentPorts) {
|
||||||
if (GUI.auto_connect && !GUI.connecting_to && !GUI.connected_to) {
|
if (GUI.auto_connect && !GUI.connecting_to && !GUI.connected_to) {
|
||||||
// start connect procedure. We need firmware flasher protection over here
|
// start connect procedure. We need firmware flasher protection over here
|
||||||
if (GUI.active_tab !== 'firmware_flasher') {
|
if (GUI.active_tab !== 'firmware_flasher') {
|
||||||
let connectionTimeout = 100;
|
$('div#header_btns a.connect').click();
|
||||||
ConfigStorage.get('connectionTimeout', function (result) {
|
|
||||||
if (result.connectionTimeout) {
|
|
||||||
connectionTimeout = result.connectionTimeout;
|
|
||||||
}
|
|
||||||
GUI.timeout_add('auto-connect_timeout', function () {
|
|
||||||
$('div#header_btns a.connect').click();
|
|
||||||
}, connectionTimeout); // timeout so bus have time to initialize after being detected by the system
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// trigger callbacks
|
// trigger callbacks
|
||||||
|
|
|
@ -830,6 +830,8 @@ function update_dataflash_global() {
|
||||||
function reinitializeConnection(originatorTab, callback) {
|
function reinitializeConnection(originatorTab, callback) {
|
||||||
|
|
||||||
// Close connection gracefully if it still exists.
|
// Close connection gracefully if it still exists.
|
||||||
|
const previousTimeStamp = connectionTimestamp;
|
||||||
|
|
||||||
if (serial.connectionId) {
|
if (serial.connectionId) {
|
||||||
if (GUI.connected_to || GUI.connecting_to) {
|
if (GUI.connected_to || GUI.connecting_to) {
|
||||||
$('a.connect').trigger('click');
|
$('a.connect').trigger('click');
|
||||||
|
@ -840,19 +842,25 @@ function reinitializeConnection(originatorTab, callback) {
|
||||||
|
|
||||||
GUI.log(i18n.getMessage('deviceRebooting'));
|
GUI.log(i18n.getMessage('deviceRebooting'));
|
||||||
|
|
||||||
let connectionTimeout = 200;
|
let attempts = 0;
|
||||||
const result = ConfigStorage.get('connectionTimeout');
|
const reconnect = setInterval(waitforSerial, 100);
|
||||||
|
|
||||||
if (result.connectionTimeout) {
|
function waitforSerial() {
|
||||||
connectionTimeout = result.connectionTimeout;
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ options.initialize = function (callback) {
|
||||||
TABS.options.initCheckForConfiguratorUnstableVersions();
|
TABS.options.initCheckForConfiguratorUnstableVersions();
|
||||||
TABS.options.initAnalyticsOptOut();
|
TABS.options.initAnalyticsOptOut();
|
||||||
TABS.options.initCliAutoComplete();
|
TABS.options.initCliAutoComplete();
|
||||||
TABS.options.initAutoConnectConnectionTimeout();
|
|
||||||
TABS.options.initShowAllSerialDevices();
|
TABS.options.initShowAllSerialDevices();
|
||||||
TABS.options.initShowVirtualMode();
|
TABS.options.initShowVirtualMode();
|
||||||
TABS.options.initCordovaForceComputerUI();
|
TABS.options.initCordovaForceComputerUI();
|
||||||
|
@ -123,18 +122,6 @@ options.initCliAutoComplete = function () {
|
||||||
}).change();
|
}).change();
|
||||||
};
|
};
|
||||||
|
|
||||||
options.initAutoConnectConnectionTimeout = function () {
|
|
||||||
ConfigStorage.get('connectionTimeout', function (result) {
|
|
||||||
if (result.connectionTimeout) {
|
|
||||||
$('#connectionTimeoutSelect').val(result.connectionTimeout);
|
|
||||||
}
|
|
||||||
$('#connectionTimeoutSelect').on('change', function () {
|
|
||||||
const value = parseInt($(this).val());
|
|
||||||
ConfigStorage.set({'connectionTimeout': value});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
options.initShowAllSerialDevices = function() {
|
options.initShowAllSerialDevices = function() {
|
||||||
const showAllSerialDevicesElement = $('div.showAllSerialDevices input');
|
const showAllSerialDevicesElement = $('div.showAllSerialDevices input');
|
||||||
ConfigStorage.get('showAllSerialDevices', result => {
|
ConfigStorage.get('showAllSerialDevices', result => {
|
||||||
|
|
|
@ -35,17 +35,6 @@
|
||||||
</div>
|
</div>
|
||||||
<span class="freelabel" i18n="cliAutoComplete"></span>
|
<span class="freelabel" i18n="cliAutoComplete"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="connectionTimeout margin-bottom">
|
|
||||||
<select id="connectionTimeoutSelect">
|
|
||||||
<option value="100">100</option>
|
|
||||||
<option value="500">500</option>
|
|
||||||
<option value="1000">1000</option>
|
|
||||||
<option value="1500">1500</option>
|
|
||||||
<option value="2500">2500</option>
|
|
||||||
<option value="5000">5000</option>
|
|
||||||
</select>
|
|
||||||
<span class="freelabel" i18n="connectionTimeout"></span>
|
|
||||||
</div>
|
|
||||||
<div class="showAllSerialDevices margin-bottom">
|
<div class="showAllSerialDevices margin-bottom">
|
||||||
<div>
|
<div>
|
||||||
<input type="checkbox" class="toggle" />
|
<input type="checkbox" class="toggle" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue