Skip to content

Commit

Permalink
Merge pull request #2758 from haslinghuis/fix_reboot
Browse files Browse the repository at this point in the history
Fix reboot
  • Loading branch information
McGiverGim authored Feb 25, 2022
2 parents 7f59ed0 + e7ca4dc commit f7eb0e8
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 130 deletions.
2 changes: 1 addition & 1 deletion src/js/backup_restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ function configuration_restore(callback) {
GUI.log(i18n.getMessage('eeprom_saved_ok'));

GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitialiseConnection('setup', _callback));
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection('setup', _callback));
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/js/msp.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,10 @@ const MSP = {
return;
}

if (code === undefined) {
if (code === undefined || !serial.connectionId) {
return;
}

let bufferOut;
if (code <= 254) {
bufferOut = this.encode_message_v1(code, data);
Expand Down
3 changes: 2 additions & 1 deletion src/js/protocols/stm32.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
if (disconnectionResult) {
// delay to allow board to boot in bootloader mode
// required to detect if a DFU device appears
setTimeout(startFlashing, 1000);
// MacOs seems to need about 5 seconds delay
setTimeout(startFlashing, GUI.operating_system === 'MacOS' ? 5000 : 1000);
} else {
GUI.connect_lock = false;
}
Expand Down
167 changes: 85 additions & 82 deletions src/js/protocols/stm32usbdfu.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/js/serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ const serial = {
if (GUI.connected_to || GUI.connecting_to) {
$('a.connect').trigger('click');
} else {
self.disconnect();
serial.disconnect();
}
},
};
56 changes: 26 additions & 30 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

let mspHelper;
let connectionTimestamp;
let clicks = false;

function initializeSerialBackend() {
GUI.updateManualPortVisibility = function(){
Expand Down Expand Up @@ -43,11 +44,8 @@ function initializeSerialBackend() {
$('div.connect_controls a.connect').click(function () {
if (GUI.connect_lock != true) { // GUI control overrides the user control

const thisElement = $(this);
const clicks = thisElement.data('clicks');

const toggleStatus = function() {
thisElement.data("clicks", !clicks);
clicks = !clicks;
};

GUI.configuration_loaded = false;
Expand Down Expand Up @@ -336,7 +334,7 @@ function abortConnect() {
$('div#port-picker #port, div#port-picker #baud, div#port-picker #delay').prop('disabled', false);

// reset data
$('div#connectbutton a.connect').data("clicks", false);
clicks = false;
}

function processBoardInfo() {
Expand Down Expand Up @@ -829,34 +827,32 @@ function update_dataflash_global() {
}
}

function reinitialiseConnection(originatorTab, callback) {
function reinitializeConnection(originatorTab, callback) {

// Close connection gracefully if it still exists.
if (serial.connectionId) {
if (GUI.connected_to || GUI.connecting_to) {
$('a.connect').trigger('click');
} else {
serial.disconnect();
}
}

GUI.log(i18n.getMessage('deviceRebooting'));

let connectionTimeout = 200;
ConfigStorage.get('connectionTimeout', function (result) {
if (result.connectionTimeout) {
connectionTimeout = result.connectionTimeout;
}
const result = ConfigStorage.get('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();
}
}, 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 (result.connectionTimeout) {
connectionTimeout = result.connectionTimeout;
}

if (callback) {
callback();
}
setTimeout(() => {
MSP.send_message(MSPCodes.MSP_STATUS, false, false, () => {
GUI.log(i18n.getMessage('deviceReady'));
originatorTab.initialize(false, $('#content').scrollTop());
});

}, connectionTimeout); // 1500 ms seems to be just the right amount of delay to prevent data request timeouts
}
});
callback?.();
}, connectionTimeout);
}
2 changes: 1 addition & 1 deletion src/js/tabs/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ TABS.cli.read = function (readInfo) {
CONFIGURATOR.cliActive = false;
CONFIGURATOR.cliValid = false;
GUI.log(i18n.getMessage('cliReboot'));
reinitialiseConnection(self);
reinitializeConnection(self);
}

}
Expand Down
3 changes: 1 addition & 2 deletions src/js/tabs/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,7 @@ TABS.configuration.initialize = function (callback) {
GUI.log(i18n.getMessage('configurationEepromSaved'));

GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false);
reinitialiseConnection(self);
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(self));
});
}

Expand Down
3 changes: 1 addition & 2 deletions src/js/tabs/failsafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,7 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
GUI.log(i18n.getMessage('configurationEepromSaved'));

GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false);
reinitialiseConnection(self);
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(self));
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/tabs/motors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ TABS.motors.initialize = function (callback) {

function reboot() {
GUI.log(i18n.getMessage('configurationEepromSaved'));
MSP.promise(MSPCodes.MSP_SET_REBOOT, false, false).then(() => reinitialiseConnection());
MSP.promise(MSPCodes.MSP_SET_REBOOT, false, false).then(() => reinitializeConnection(self));
}

function showDialogMixerReset(message) {
Expand Down
3 changes: 1 addition & 2 deletions src/js/tabs/onboard_logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ TABS.onboard_logging.initialize = function (callback) {
GUI.log(i18n.getMessage('configurationEepromSaved'));

GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false);
reinitialiseConnection(self);
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(self));
});
}

Expand Down
3 changes: 1 addition & 2 deletions src/js/tabs/ports.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ TABS.ports.initialize = function (callback, scrollPosition) {
GUI.log(i18n.getMessage('configurationEepromSaved'));

GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false);
reinitialiseConnection(self);
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(self));
});
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/js/tabs/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ TABS.receiver.initialize = function (callback) {
GUI.log(i18n.getMessage('configurationEepromSaved'));
if (boot) {
GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false);
reinitialiseConnection(tab);
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(tab));
});
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/js/tabs/transponder.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ TABS.transponder.initialize = function(callback, scrollPosition) {
GUI.log(i18n.getMessage('transponderEepromSaved'));
if ( $(_this).hasClass('reboot') ) {
GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false);
reinitialiseConnection(self);
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(self));
});
}
});
Expand Down

0 comments on commit f7eb0e8

Please sign in to comment.