Skip to content

Commit

Permalink
Fix intermittent connect failure
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Jul 17, 2023
1 parent 4d42a8f commit 0c69452
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ export function reinitializeConnection(callback) {
clearInterval(reconnect);
gui_log(i18n.getMessage('deviceReady'));

if (callback === typeof('function')) {
if (typeof callback === 'function') {
callback();
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import FC from '../fc';
import MSP from '../msp';
import MSPCodes from '../msp/MSPCodes';
import PortHandler, { usbDevices } from '../port_handler';
import CONFIGURATOR, { API_VERSION_1_39, API_VERSION_1_45 } from '../data_storage';
import { API_VERSION_1_39, API_VERSION_1_45 } from '../data_storage';
import serial from '../serial';
import STM32DFU from '../protocols/stm32usbdfu';
import { gui_log } from '../gui_log';
Expand Down Expand Up @@ -581,6 +581,7 @@ firmware_flasher.initialize = function (callback) {

function onFinishClose() {
MSP.clearListeners();
MSP.disconnect_cleanup();
}

function onClose(success) {
Expand All @@ -589,7 +590,6 @@ firmware_flasher.initialize = function (callback) {
}

serial.disconnect(onFinishClose);
MSP.disconnect_cleanup();
}

function onFinish() {
Expand Down Expand Up @@ -646,6 +646,7 @@ firmware_flasher.initialize = function (callback) {
console.log(`Requesting board information`);
MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, () => {
gui_log(i18n.getMessage('apiVersionReceived', FC.CONFIG.apiVersion));

if (FC.CONFIG.apiVersion.includes('null')) {
onClose(false); // not supported
} else if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_39)) {
Expand Down Expand Up @@ -684,8 +685,7 @@ firmware_flasher.initialize = function (callback) {
if (!(serial.connected || serial.connectionId)) {
serial.connect(port, {bitrate: baud}, onConnect);
} else {
console.warn('Attempting to connect while there still is a connection', serial.connected, serial.connectionId);
serial.disconnect();
console.warn('Attempting to connect while there still is a connection', serial.connected, serial.connectionId, serial.openCanceled);
}
} else {
console.log('Releases not loaded yet');
Expand Down
10 changes: 2 additions & 8 deletions src/js/tabs/ports.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import semver from 'semver';
import { i18n } from "../localization";
import GUI, { TABS } from '../gui';
import { tracking } from "../Analytics";
import { reinitializeConnection } from '../serial_backend';
import { mspHelper } from '../msp/MSPHelper';
import FC from '../fc';
import MSP from '../msp';
Expand Down Expand Up @@ -296,8 +295,7 @@ ports.initialize = function (callback) {

const pheripheralsSelectElement = $('select[name="function-peripherals"]');
pheripheralsSelectElement.on('change', function() {
let vtxControlSelected = undefined;
let mspControlSelected = undefined;
let vtxControlSelected, mspControlSelected;

pheripheralsSelectElement.each(function(index, element) {
const value = $(element).val();
Expand Down Expand Up @@ -476,11 +474,7 @@ ports.initialize = function (callback) {
}

function save_to_eeprom() {
mspHelper.writeConfiguration(function() {
GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection);
});
});
mspHelper.writeConfiguration(true);
}
}
};
Expand Down

0 comments on commit 0c69452

Please sign in to comment.