Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intermittent connect failure #3515

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

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