From a4c3490d3876907c299c6d3e12ee6100aaea7f5c Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Sun, 5 May 2024 21:04:55 +0200 Subject: [PATCH 1/2] Resolve some settings issues on Tuning tab and make settings saving a chain of MSP fames instead of flooding the MSP queue --- js/msp/MSPHelper.js | 1 - js/settings.js | 39 ++++++++++++++++++++++++++++++--------- tabs/pid_tuning.html | 12 ++++++------ tabs/pid_tuning.js | 6 +++--- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index c727dac55..4e45369b2 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -3075,7 +3075,6 @@ var mspHelper = (function () { }; self._getSetting = function (name) { - console.log("Getting setting " + name); if (FC.SETTINGS[name]) { return Promise.resolve(FC.SETTINGS[name]); } diff --git a/js/settings.js b/js/settings.js index 72bf5142a..086a2658f 100644 --- a/js/settings.js +++ b/js/settings.js @@ -53,6 +53,16 @@ var Settings = (function () { var settingName = input.data('setting'); var inputUnit = input.data('unit'); + let elementId = input.attr('id'); + if (elementId === undefined) { + + // If the element ID is not defined, we need to create one + // based on the setting name. If this ID exists, we will not create it + if ($('#' + settingName).length === 0) { + input.attr('id', settingName); + } + } + if (globalSettings.showProfileParameters) { if (FC.isBatteryProfileParameter(settingName)) { input.css("background-color","#fef2d5"); @@ -149,7 +159,8 @@ var Settings = (function () { input.data('setting-info', s.setting); if (input.data('live')) { input.on('change', function () { - self.saveInput(input); + const settingPair = self.processInput(input); + return mspHelper.setSetting(settingPair.setting, settingPair.value); }); } }); @@ -528,7 +539,7 @@ var Settings = (function () { }; } - self.saveInput = function(input) { + self.processInput = function(input) { var settingName = input.data('setting'); var setting = input.data('setting-info'); var value; @@ -536,7 +547,6 @@ var Settings = (function () { if (typeof setting == 'undefined') { return null; } - if (setting.table) { if (input.attr('type') == 'checkbox') { value = input.prop('checked') ? 1 : 0; @@ -585,8 +595,7 @@ var Settings = (function () { } } } - - return mspHelper.setSetting(settingName, value); + return {setting: settingName, value: value}; }; self.countDecimals = function(value) { @@ -604,14 +613,26 @@ var Settings = (function () { return 0; }; - self.saveInputs = function() { + self.pickAndSaveSingleInput = function(inputs, finalCallback) { + if (inputs.length > 0) { + var input = inputs.shift(); + var settingPair = self.processInput(input); + return mspHelper.setSetting(settingPair.setting, settingPair.value, function() { + return self.pickAndSaveSingleInput(inputs); + }); + } else { + if (finalCallback) { + finalCallback(); + } + } + }; + + self.saveInputs = function(finalCallback) { var inputs = []; $('[data-setting!=""][data-setting]').each(function() { inputs.push($(this)); }); - return mapSeries(inputs, function (input, ii) { - return self.saveInput(input); - }); + self.pickAndSaveSingleInput(inputs, finalCallback); }; self.processHtml = function(callback) { diff --git a/tabs/pid_tuning.html b/tabs/pid_tuning.html index 30c52b693..f982e2f8e 100644 --- a/tabs/pid_tuning.html +++ b/tabs/pid_tuning.html @@ -444,19 +444,19 @@

-
+
-
+
-
+
@@ -495,19 +495,19 @@

-
+
-
+
-
+
diff --git a/tabs/pid_tuning.js b/tabs/pid_tuning.js index 786bcc90c..bae27211b 100644 --- a/tabs/pid_tuning.js +++ b/tabs/pid_tuning.js @@ -103,8 +103,8 @@ TABS.pid_tuning.initialize = function (callback) { FC.RC_tuning.pitch_rate = parseFloat($('#rate-pitch').val()); FC.RC_tuning.yaw_rate = parseFloat($('#rate-yaw').val()); - FC.RC_tuning.dynamic_THR_PID = parseInt($('#tpa').val()); - FC.RC_tuning.dynamic_THR_breakpoint = parseInt($('#tpa-breakpoint').val()); + FC.RC_tuning.dynamic_THR_PID = parseInt($('#tpaRate').val()); + FC.RC_tuning.dynamic_THR_breakpoint = parseInt($('#tpaBreakpoint').val()); FC.RC_tuning.manual_roll_rate = $('#rate-manual-roll').val(); FC.RC_tuning.manual_pitch_rate = $('#rate-manual-pitch').val(); @@ -350,7 +350,7 @@ TABS.pid_tuning.initialize = function (callback) { } function saveSettings() { - Settings.saveInputs().then(save_to_eeprom); + Settings.saveInputs(save_to_eeprom); } function save_to_eeprom() { From 07600e1fa6c2be9aa3682e51a729c4765e04d855 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Sun, 5 May 2024 21:40:10 +0200 Subject: [PATCH 2/2] Fix additional tabs --- js/settings.js | 2 +- locale/en/messages.json | 4 +++- tabs/advanced_tuning.html | 2 +- tabs/advanced_tuning.js | 39 +++++++++++++++------------------------ tabs/configuration.js | 2 +- tabs/failsafe.js | 33 +++++++++++++-------------------- tabs/gps.js | 2 +- tabs/mixer.js | 2 +- tabs/osd.js | 25 +++++++++++++++---------- tabs/outputs.js | 2 +- tabs/receiver.js | 2 +- 11 files changed, 53 insertions(+), 62 deletions(-) diff --git a/js/settings.js b/js/settings.js index 086a2658f..bcee76277 100644 --- a/js/settings.js +++ b/js/settings.js @@ -618,7 +618,7 @@ var Settings = (function () { var input = inputs.shift(); var settingPair = self.processInput(input); return mspHelper.setSetting(settingPair.setting, settingPair.value, function() { - return self.pickAndSaveSingleInput(inputs); + return self.pickAndSaveSingleInput(inputs, finalCallback); }); } else { if (finalCallback) { diff --git a/locale/en/messages.json b/locale/en/messages.json index 7a2408531..565057bab 100644 --- a/locale/en/messages.json +++ b/locale/en/messages.json @@ -1714,7 +1714,9 @@ "auxiliaryEepromSaved": { "message": "EEPROM saved" }, - + "eepromSaved": { + "message": "EEPROM saved" + }, "adjustmentsHelp": { "message": "Configure adjustment switches. See the 'in-flight adjustments' section of the manual for details. The changes that adjustment functions make are not saved automatically. There are 4 slots. Each switch used to concurrently make adjustments requires exclusive use of a slot." }, diff --git a/tabs/advanced_tuning.html b/tabs/advanced_tuning.html index 708d17067..5282ef428 100644 --- a/tabs/advanced_tuning.html +++ b/tabs/advanced_tuning.html @@ -216,7 +216,7 @@
- +
diff --git a/tabs/advanced_tuning.js b/tabs/advanced_tuning.js index 17885eb69..06c195b74 100644 --- a/tabs/advanced_tuning.js +++ b/tabs/advanced_tuning.js @@ -19,6 +19,20 @@ TABS.advanced_tuning.initialize = function (callback) { loadHtml(); + function save_to_eeprom() { + console.log('save_to_eeprom'); + MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () { + GUI.log(i18n.getMessage('eepromSaved')); + + GUI.tab_switch_cleanup(function () { + MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, function () { + GUI.log(i18n.getMessage('deviceRebooting')); + GUI.handleReconnect($('.tab_advanced_tuning a')); + }); + }); + }); + } + function loadHtml() { GUI.load(path.join(__dirname, "advanced_tuning.html"), Settings.processHtml(function () { @@ -68,35 +82,12 @@ TABS.advanced_tuning.initialize = function (callback) { TABS.advanced_tuning.checkRequirements_LinearDescent(); $('a.save').on('click', function () { - Settings.saveInputs().then(function () { - var self = this; - MSP.promise(MSPCodes.MSP_EEPROM_WRITE); - var oldText = $(this).text(); - $(this).html("Saved"); - setTimeout(function () { - $(self).html(oldText); - }, 2000); - reboot(); - }); + Settings.saveInputs(save_to_eeprom); }); GUI.content_ready(callback); })); } - - function reboot() { - //noinspection JSUnresolvedVariable - GUI.log(i18n.getMessage('configurationEepromSaved')); - GUI.tab_switch_cleanup(function () { - MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitialize); - }); - } - - function reinitialize() { - //noinspection JSUnresolvedVariable - GUI.log(i18n.getMessage('deviceRebooting')); - GUI.handleReconnect($('.tab_advanced_tuning a')); - } }; diff --git a/tabs/configuration.js b/tabs/configuration.js index 04f0bca64..713b8b76e 100644 --- a/tabs/configuration.js +++ b/tabs/configuration.js @@ -52,7 +52,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) { ]; function saveSettings(onComplete) { - Settings.saveInputs().then(onComplete); + Settings.saveInputs(onComplete); } saveChainer.setChain(saveChain); diff --git a/tabs/failsafe.js b/tabs/failsafe.js index 8f6f9d19c..05c02b0f9 100644 --- a/tabs/failsafe.js +++ b/tabs/failsafe.js @@ -127,29 +127,22 @@ TABS.failsafe.initialize = function (callback, scrollPosition) { load_failssafe_config(); - function savePhaseTwo() { - Settings.saveInputs().then(function () { - var self = this; - MSP.promise(MSPCodes.MSP_EEPROM_WRITE); - setTimeout(function () { - $(self).html(''); - }, 2000); - reboot(); - }); - } - - function reboot() { - //noinspection JSUnresolvedVariable - GUI.log(i18n.getMessage('configurationEepromSaved')); - GUI.tab_switch_cleanup(function () { - MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitialize); + function save_to_eeprom() { + console.log('save_to_eeprom'); + MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () { + GUI.log(i18n.getMessage('eepromSaved')); + + GUI.tab_switch_cleanup(function () { + MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, function () { + GUI.log(i18n.getMessage('deviceRebooting')); + GUI.handleReconnect($('.tab_failsafe a')); + }); + }); }); } - function reinitialize() { - //noinspection JSUnresolvedVariable - GUI.log(i18n.getMessage('deviceRebooting')); - GUI.handleReconnect($('.tab_failsafe a')); + function savePhaseTwo() { + Settings.saveInputs(save_to_eeprom); } }; diff --git a/tabs/gps.js b/tabs/gps.js index 3362f3b9b..5a72d1f2e 100644 --- a/tabs/gps.js +++ b/tabs/gps.js @@ -73,7 +73,7 @@ TABS.gps.initialize = function (callback) { ]; function saveSettings(onComplete) { - Settings.saveInputs().then(onComplete); + Settings.saveInputs(onComplete); } saveChainer.setChain(saveChain); diff --git a/tabs/mixer.js b/tabs/mixer.js index a5ac2a83d..7e5e9d550 100644 --- a/tabs/mixer.js +++ b/tabs/mixer.js @@ -58,7 +58,7 @@ TABS.mixer.initialize = function (callback, scrollPosition) { saveChainer.setExitPoint(reboot); function saveSettings(onComplete) { - Settings.saveInputs().then(onComplete); + Settings.saveInputs(onComplete); } function reboot() { diff --git a/tabs/osd.js b/tabs/osd.js index 93a71a918..c0ce01f56 100644 --- a/tabs/osd.js +++ b/tabs/osd.js @@ -3256,6 +3256,20 @@ TABS.osd.initialize = function (callback) { GUI.active_tab = 'osd'; } + function save_to_eeprom() { + console.log('save_to_eeprom'); + MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () { + GUI.log(i18n.getMessage('eepromSaved')); + + GUI.tab_switch_cleanup(function () { + MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, function () { + GUI.log(i18n.getMessage('deviceRebooting')); + GUI.handleReconnect($('.tab_osd a')); + }); + }); + }); + } + GUI.load(path.join(__dirname, "osd.html"), Settings.processHtml(function () { // translate to user-selected language i18n.localize(); @@ -3274,16 +3288,7 @@ TABS.osd.initialize = function (callback) { }); $('a.save').on('click', function () { - Settings.saveInputs().then(function () { - var self = this; - MSP.promise(MSPCodes.MSP_EEPROM_WRITE); - GUI.log(i18n.getMessage('osdSettingsSaved')); - var oldText = $(this).text(); - $(this).html("Saved"); - setTimeout(function () { - $(self).html(oldText); - }, 2000); - }); + Settings.saveInputs(save_to_eeprom); }); // Initialise guides checkbox diff --git a/tabs/outputs.js b/tabs/outputs.js index c45d6bfa4..5a8ff5beb 100644 --- a/tabs/outputs.js +++ b/tabs/outputs.js @@ -79,7 +79,7 @@ TABS.outputs.initialize = function (callback) { } function saveSettings(onComplete) { - Settings.saveInputs().then(onComplete); + Settings.saveInputs(onComplete); } function onLoad() { diff --git a/tabs/receiver.js b/tabs/receiver.js index f1eb46168..9b20874f0 100644 --- a/tabs/receiver.js +++ b/tabs/receiver.js @@ -44,7 +44,7 @@ TABS.receiver.initialize = function (callback) { } function saveSettings(onComplete) { - Settings.saveInputs().then(onComplete); + Settings.saveInputs(onComplete); } function drawRollPitchExpo() {