diff --git a/locales/en/messages.json b/locales/en/messages.json index 2ced5055..980168f3 100644 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -92,6 +92,10 @@ "analyticsOptOut": { "message": "Opt out of the anonymised collection of statistics data" }, + "connectionTimeout": { + "message": "Set connection timeout to allow longer initialisation on device plugin or reboot", + "description": "Change timeout on auto-connect and reboot so the bus has more time to initialize after being detected by the system" + }, "cordovaForceComputerUI": { "message": "Use computers interface instead of phones interface" }, diff --git a/src/css/tabs/options.css b/src/css/tabs/options.css index 5cdee88d..7ecf7eec 100644 --- a/src/css/tabs/options.css +++ b/src/css/tabs/options.css @@ -13,4 +13,5 @@ color: var(--defaultText); border: 1px solid var(--subtleAccent); border-radius: 3px; + width: fit-content; } diff --git a/src/js/port_handler.js b/src/js/port_handler.js index ee2fb171..91f6e917 100644 --- a/src/js/port_handler.js +++ b/src/js/port_handler.js @@ -174,9 +174,15 @@ PortHandler.detectPort = function(currentPorts) { if (GUI.auto_connect && !GUI.connecting_to && !GUI.connected_to) { // start connect procedure. We need firmware flasher protection over here if (GUI.active_tab !== 'firmware_flasher') { - GUI.timeout_add('auto-connect_timeout', function () { - $('div#header_btns a.connect').click(); - }, 100); // timeout so bus have time to initialize after being detected by the system + let connectionTimeout = 100; + 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 diff --git a/src/js/serial_backend.js b/src/js/serial_backend.js index 31e02755..c12e038d 100644 --- a/src/js/serial_backend.js +++ b/src/js/serial_backend.js @@ -827,26 +827,32 @@ function update_dataflash_global() { function reinitialiseConnection(originatorTab, callback) { GUI.log(i18n.getMessage('deviceRebooting')); + let connectionTimeout = 200; + ConfigStorage.get('connectionTimeout', function (result) { + if (result.connectionTimeout) { + connectionTimeout = result.connectionTimeout; + } - if (FC.boardHasVcp()) { // VCP-based flight controls may crash old drivers, we catch and reconnect - GUI.timeout_add('waiting_for_disconnect', function waiting_for_bootup() { - if (callback) { - callback(); - } - }, 200); - //TODO: Need to work out how to do a proper reconnect here. - // caveat: Timeouts set with `GUI.timeout_add()` are removed on disconnect. - } else { - GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() { - MSP.send_message(MSPCodes.MSP_STATUS, false, false, function() { - GUI.log(i18n.getMessage('deviceReady')); - originatorTab.initialize(false, $('#content').scrollTop()); - }); + if (FC.boardHasVcp()) { // VCP-based flight controls may crash old drivers, we catch and reconnect + GUI.timeout_add('waiting_for_disconnect', function waiting_for_bootup() { + if (callback) { + callback(); + } + }, connectionTimeout); + //TODO: Need to work out how to do a proper reconnect here. + // caveat: Timeouts set with `GUI.timeout_add()` are removed on disconnect. + } else { + GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() { + MSP.send_message(MSPCodes.MSP_STATUS, false, false, function() { + GUI.log(i18n.getMessage('deviceReady')); + originatorTab.initialize(false, $('#content').scrollTop()); + }); - if (callback) { - callback(); - } + if (callback) { + callback(); + } - }, 1500); // 1500 ms seems to be just the right amount of delay to prevent data request timeouts - } + }, connectionTimeout); // 1500 ms seems to be just the right amount of delay to prevent data request timeouts + } + }); } diff --git a/src/js/tabs/options.js b/src/js/tabs/options.js index d73b8a8f..9362651a 100644 --- a/src/js/tabs/options.js +++ b/src/js/tabs/options.js @@ -14,6 +14,7 @@ options.initialize = function (callback) { TABS.options.initCheckForConfiguratorUnstableVersions(); TABS.options.initAnalyticsOptOut(); TABS.options.initCliAutoComplete(); + TABS.options.initAutoConnectConnectionTimeout(); TABS.options.initCordovaForceComputerUI(); TABS.options.initDarkTheme(); @@ -105,6 +106,18 @@ options.initCliAutoComplete = function () { }).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.initCordovaForceComputerUI = function () { if (GUI.isCordova() && cordovaUI.canChangeUI) { ConfigStorage.get('cordovaForceComputerUI', function (result) { diff --git a/src/tabs/options.html b/src/tabs/options.html index 1bf9b0f4..1667ba4b 100644 --- a/src/tabs/options.html +++ b/src/tabs/options.html @@ -35,6 +35,17 @@ +