1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-16 21:05:30 +03:00

Fix cli output

Fix rememberLastTab

Fix sonar issues
This commit is contained in:
Mark Haslinghuis 2022-07-26 16:56:56 +02:00
parent 1c775439a1
commit e85b706ad6
13 changed files with 23 additions and 42 deletions

View file

@ -911,7 +911,7 @@ function configuration_restore(callback) {
GUI.log(i18n.getMessage('eeprom_saved_ok')); GUI.log(i18n.getMessage('eeprom_saved_ok'));
GUI.tab_switch_cleanup(function() { GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection('setup', _callback)); MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(_callback));
}); });
} }
} }

View file

@ -74,19 +74,7 @@ const GuiControl = function () {
}; };
function GUI_checkOperatingSystem() { function GUI_checkOperatingSystem() {
if (navigator.appVersion.indexOf("Win") !== -1) { return navigator.userAgentData.platform;
return "Windows";
} else if (navigator.appVersion.indexOf("Mac") !== -1) {
return "MacOS";
} else if (navigator.appVersion.indexOf("Android") !== -1) {
return "Android";
} else if (navigator.appVersion.indexOf("Linux") !== -1) {
return "Linux";
} else if (navigator.appVersion.indexOf("X11") !== -1) {
return "UNIX";
} else {
return "Unknown";
}
} }
// Timer managing methods // Timer managing methods
@ -390,11 +378,9 @@ GuiControl.prototype.content_ready = function (callback) {
GuiControl.prototype.selectDefaultTabWhenConnected = function() { GuiControl.prototype.selectDefaultTabWhenConnected = function() {
const result = ConfigStorage.get(['rememberLastTab', 'lastTab']); const result = ConfigStorage.get(['rememberLastTab', 'lastTab']);
if (result.rememberLastTab && result.lastTab) { const tab = result.rememberLastTab && result.lastTab ? result.lastTab : 'tab_setup';
$(`#tabs ul.mode-connected .${result.lastTab} a`).click();
} else { $(`#tabs ul.mode-connected .${tab} a`).trigger('click');
$('#tabs ul.mode-connected .tab_setup a').click();
}
}; };
GuiControl.prototype.isNWJS = function () { GuiControl.prototype.isNWJS = function () {

View file

@ -588,7 +588,7 @@ function startProcess() {
$(expertModeCheckbox).trigger("change"); $(expertModeCheckbox).trigger("change");
result = ConfigStorage.get('cliAutoComplete'); result = ConfigStorage.get('cliAutoComplete');
CliAutoComplete.setEnabled(typeof result.cliAutoComplete === undefined || result.cliAutoComplete); // On by default CliAutoComplete.setEnabled(typeof result.cliAutoComplete === "undefined" || result.cliAutoComplete); // On by default
result = ConfigStorage.get('darkTheme'); result = ConfigStorage.get('darkTheme');
if (result.darkTheme === undefined || typeof result.darkTheme !== "number") { if (result.darkTheme === undefined || typeof result.darkTheme !== "number") {

View file

@ -351,7 +351,7 @@ const MSP = {
if (!requestExists) { if (!requestExists) {
obj.timer = setInterval(function () { obj.timer = setInterval(function () {
console.warn(`MSP: data request timed-out: ${code} ID: ${serial.connectionId} TAB: ${GUI.active_tab} TIMEOUT: ${MSP.timeout}`); console.warn(`MSP: data request timed-out: ${code} ID: ${serial.connectionId} TAB: ${GUI.active_tab} TIMEOUT: ${MSP.timeout} QUEUE: ${MSP.callbacks.length}`);
serial.send(bufferOut, function (_sendInfo) { serial.send(bufferOut, function (_sendInfo) {
obj.stop = performance.now(); obj.stop = performance.now();
const executionTime = Math.round(obj.stop - obj.start); const executionTime = Math.round(obj.stop - obj.start);

View file

@ -244,6 +244,7 @@ function onOpen(openInfo) {
FC.resetState(); FC.resetState();
mspHelper = new MspHelper(); mspHelper = new MspHelper();
MSP.listen(mspHelper.process_data.bind(mspHelper)); MSP.listen(mspHelper.process_data.bind(mspHelper));
MSP.timeout = 250;
console.log(`Requesting configuration data`); console.log(`Requesting configuration data`);
MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, function () { MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, function () {
@ -590,6 +591,8 @@ function onClosed(result) {
function read_serial(info) { function read_serial(info) {
if (CONFIGURATOR.cliActive) { if (CONFIGURATOR.cliActive) {
MSP.clearListeners();
MSP.disconnect_cleanup();
TABS.cli.read(info); TABS.cli.read(info);
} else if (CONFIGURATOR.cliEngineActive) { } else if (CONFIGURATOR.cliEngineActive) {
TABS.presets.read(info); TABS.presets.read(info);
@ -816,7 +819,7 @@ function update_dataflash_global() {
} }
} }
function reinitializeConnection(originatorTab, callback) { function reinitializeConnection(callback) {
// Close connection gracefully if it still exists. // Close connection gracefully if it still exists.
const previousTimeStamp = connectionTimestamp; const previousTimeStamp = connectionTimestamp;
@ -834,13 +837,12 @@ function reinitializeConnection(originatorTab, callback) {
let attempts = 0; let attempts = 0;
const reconnect = setInterval(waitforSerial, 100); const reconnect = setInterval(waitforSerial, 100);
async function waitforSerial() { function waitforSerial() {
if (connectionTimestamp !== previousTimeStamp && CONFIGURATOR.connectionValid) { if (connectionTimestamp !== previousTimeStamp && CONFIGURATOR.connectionValid) {
console.log(`Serial connection available after ${attempts / 10} seconds`); console.log(`Serial connection available after ${attempts / 10} seconds`);
clearInterval(reconnect); clearInterval(reconnect);
await getStatus(); getStatus();
GUI.log(i18n.getMessage('deviceReady')); GUI.log(i18n.getMessage('deviceReady'));
originatorTab.initialize(false, $('#content').scrollTop());
callback?.(); callback?.();
} else { } else {
attempts++; attempts++;

View file

@ -462,7 +462,7 @@ cli.read = function (readInfo) {
CONFIGURATOR.cliActive = false; CONFIGURATOR.cliActive = false;
CONFIGURATOR.cliValid = false; CONFIGURATOR.cliValid = false;
GUI.log(i18n.getMessage('cliReboot')); GUI.log(i18n.getMessage('cliReboot'));
reinitializeConnection(self); reinitializeConnection();
} }
} }

View file

@ -627,7 +627,7 @@ configuration.initialize = function (callback) {
GUI.log(i18n.getMessage('configurationEepromSaved')); GUI.log(i18n.getMessage('configurationEepromSaved'));
GUI.tab_switch_cleanup(function() { GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(self)); MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection);
}); });
} }

View file

@ -2,8 +2,7 @@ import { i18n } from "../localization";
const failsafe = {}; const failsafe = {};
failsafe.initialize = function (callback, scrollPosition) { failsafe.initialize = function (callback) {
const self = this;
if (GUI.active_tab != 'failsafe') { if (GUI.active_tab != 'failsafe') {
GUI.active_tab = 'failsafe'; GUI.active_tab = 'failsafe';
@ -219,11 +218,6 @@ failsafe.initialize = function (callback, scrollPosition) {
FC.RXFAIL_CONFIG[i].value = parseInt($(this).val()); FC.RXFAIL_CONFIG[i].value = parseInt($(this).val());
}); });
// for some odd reason chrome 38+ changes scroll according to the touched select element
// i am guessing this is a bug, since this wasn't happening on 37
// code below is a temporary fix, which we will be able to remove in the future (hopefully)
$('#content').scrollTop((scrollPosition) ? scrollPosition : 0);
// fill stage 1 Valid Pulse Range Settings // fill stage 1 Valid Pulse Range Settings
$('input[name="rx_min_usec"]').val(FC.RX_CONFIG.rx_min_usec); $('input[name="rx_min_usec"]').val(FC.RX_CONFIG.rx_min_usec);
$('input[name="rx_max_usec"]').val(FC.RX_CONFIG.rx_max_usec); $('input[name="rx_max_usec"]').val(FC.RX_CONFIG.rx_max_usec);
@ -413,7 +407,7 @@ failsafe.initialize = function (callback, scrollPosition) {
GUI.log(i18n.getMessage('configurationEepromSaved')); GUI.log(i18n.getMessage('configurationEepromSaved'));
GUI.tab_switch_cleanup(function() { GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(self)); MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection);
}); });
} }

View file

@ -1153,10 +1153,9 @@ motors.initialize = async function (callback) {
content_ready(); content_ready();
} }
async function reboot() { function reboot() {
GUI.log(i18n.getMessage('configurationEepromSaved')); GUI.log(i18n.getMessage('configurationEepromSaved'));
await MSP.promise(MSPCodes.MSP_SET_REBOOT); MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection);
reinitializeConnection(self);
} }
function showDialogMixerReset(message) { function showDialogMixerReset(message) {

View file

@ -49,7 +49,7 @@ onboard_logging.initialize = function (callback) {
GUI.log(i18n.getMessage('configurationEepromSaved')); GUI.log(i18n.getMessage('configurationEepromSaved'));
GUI.tab_switch_cleanup(function() { GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(self)); MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection);
}); });
} }

View file

@ -413,7 +413,7 @@ ports.initialize = function (callback) {
GUI.log(i18n.getMessage('configurationEepromSaved')); GUI.log(i18n.getMessage('configurationEepromSaved'));
GUI.tab_switch_cleanup(function() { GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(self)); MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection);
}); });
} }
} }

View file

@ -476,7 +476,7 @@ receiver.initialize = function (callback) {
GUI.log(i18n.getMessage('configurationEepromSaved')); GUI.log(i18n.getMessage('configurationEepromSaved'));
if (boot) { if (boot) {
GUI.tab_switch_cleanup(function() { GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(tab)); MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection);
}); });
} }
} }

View file

@ -302,7 +302,7 @@ transponder.initialize = function(callback) {
GUI.log(i18n.getMessage('transponderEepromSaved')); GUI.log(i18n.getMessage('transponderEepromSaved'));
if ( $(_this).hasClass('reboot') ) { if ( $(_this).hasClass('reboot') ) {
GUI.tab_switch_cleanup(function() { GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(self)); MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection);
}); });
} }
}); });