From 3ebd1697a5e8a6340831f4b737ebbdf34c93f00d Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Mon, 11 Oct 2021 23:19:20 +0200 Subject: [PATCH] Extend save and restore for all settings Fix Enable PID sliders button Fix duplicate block? --- src/js/TuningSliders.js | 51 ------------------------- src/js/main.js | 4 +- src/js/tabs/pid_tuning.js | 78 ++++++++++++++++++++++++++++++--------- 3 files changed, 63 insertions(+), 70 deletions(-) diff --git a/src/js/TuningSliders.js b/src/js/TuningSliders.js index 4af9cd1b..a74e3990 100644 --- a/src/js/TuningSliders.js +++ b/src/js/TuningSliders.js @@ -32,7 +32,6 @@ const TuningSliders = { PID_DEFAULT: [], FILTER_DEFAULT: {}, SLIDER_DEFAULT: {}, - initialSettings: {}, cachedPidSliderValues: false, cachedGyroSliderValues: false, @@ -43,56 +42,6 @@ const TuningSliders = { const D_MIN_RATIO = 0.85; -TuningSliders.saveInitialSettings = function () { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - this.initialSettings.sliderPidsMode = FC.TUNING_SLIDERS.slider_pids_mode; - this.initialSettings.sliderDGain = FC.TUNING_SLIDERS.slider_d_gain / 100; - this.initialSettings.sliderPIGain = FC.TUNING_SLIDERS.slider_pi_gain / 100; - this.initialSettings.sliderFeedforwardGain = FC.TUNING_SLIDERS.slider_feedforward_gain / 100; - this.initialSettings.sliderDMaxGain = FC.TUNING_SLIDERS.slider_dmax_gain / 100; - this.initialSettings.sliderIGain = FC.TUNING_SLIDERS.slider_i_gain / 100; - this.initialSettings.sliderRollPitchRatio = FC.TUNING_SLIDERS.slider_roll_pitch_ratio / 100; - this.initialSettings.sliderPitchPIGain = FC.TUNING_SLIDERS.slider_pitch_pi_gain / 100; - this.initialSettings.sliderMasterMultiplier = FC.TUNING_SLIDERS.slider_master_multiplier / 100; - this.initialSettings.sliderGyroFilter = FC.TUNING_SLIDERS.slider_gyro_filter; - this.initialSettings.sliderGyroFilterMultiplier = FC.TUNING_SLIDERS.slider_gyro_filter_multiplier / 100; - this.initialSettings.sliderDTermFilter = FC.TUNING_SLIDERS.slider_dterm_filter; - this.initialSettings.sliderDTermFilterMultiplier = FC.TUNING_SLIDERS.slider_dterm_filter_multiplier / 100; - } -}; - -TuningSliders.restoreInitialSettings = function () { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - FC.TUNING_SLIDERS.slider_pids_mode = this.initialSettings.sliderPidsMode; - - FC.TUNING_SLIDERS.slider_d_gain = Math.round(this.initialSettings.sliderDGain * 20) * 5; - FC.TUNING_SLIDERS.slider_pi_gain = Math.round(this.initialSettings.sliderPIGain * 20) * 5; - FC.TUNING_SLIDERS.slider_feedforward_gain = Math.round(this.initialSettings.sliderFeedforwardGain * 20) * 5; - FC.TUNING_SLIDERS.slider_dmax_gain = Math.round(this.initialSettings.sliderDMaxGain * 20) * 5; - FC.TUNING_SLIDERS.slider_i_gain = Math.round(this.initialSettings.sliderIGain * 20) * 5; - FC.TUNING_SLIDERS.slider_roll_pitch_ratio = Math.round(this.initialSettings.sliderRollPitchRatio * 20) * 5; - FC.TUNING_SLIDERS.slider_pitch_pi_gain = Math.round(this.initialSettings.sliderPitchPIGain * 20) * 5; - FC.TUNING_SLIDERS.slider_master_multiplier = Math.round(this.initialSettings.sliderMasterMultiplier * 20) * 5; - - FC.TUNING_SLIDERS.slider_gyro_filter = this.initialSettings.sliderGyroFilter; - FC.TUNING_SLIDERS.slider_gyro_filter_multiplier = this.initialSettings.sliderGyroFilterMultiplier * 100; - FC.TUNING_SLIDERS.slider_dterm_filter = this.initialSettings.sliderDTermFilter; - FC.TUNING_SLIDERS.slider_dterm_filter_multiplier = this.initialSettings.sliderDTermFilterMultiplier * 100; - - MSP.promise(MSPCodes.MSP_SET_TUNING_SLIDERS, mspHelper.crunch(MSPCodes.MSP_SET_TUNING_SLIDERS)) - .then(() => MSP.promise(MSPCodes.MSP_PID)) - .then(() => MSP.promise(MSPCodes.MSP_PID_ADVANCED)) - .then(() => MSP.promise(MSPCodes.MSP_FILTER_CONFIG)) - .then(() => { - if (GUI.active_tab === 'pid_tuning') { - this.updateFormPids(); - TABS.pid_tuning.updatePIDColors(); - } - }); - TABS.pid_tuning.sliderRetainConfiguration = false; - } -}; - TuningSliders.setDMinFeatureEnabled = function(dMinFeatureEnabled) { this.dMinFeatureEnabled = dMinFeatureEnabled; if (this.dMinFeatureEnabled) { diff --git a/src/js/main.js b/src/js/main.js index c66fd098..d39dea61 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -252,8 +252,8 @@ function startProcess() { const tabName = $(self).text(); if (GUI.active_tab === 'pid_tuning') { - if (TABS.pid_tuning.sliderRetainConfiguration) { - TuningSliders.restoreInitialSettings(); + if (TABS.pid_tuning.retainConfiguration) { + TABS.pid_tuning.restoreInitialSettings(); } } diff --git a/src/js/tabs/pid_tuning.js b/src/js/tabs/pid_tuning.js index 08c5725e..89ae49eb 100644 --- a/src/js/tabs/pid_tuning.js +++ b/src/js/tabs/pid_tuning.js @@ -22,7 +22,14 @@ TABS.pid_tuning = { activeSubtab: 'pid', analyticsChanges: {}, - sliderRetainConfiguration: false, + retainConfiguration: false, + + CONFIGURATOR_PIDS: [], + CONFIGURATOR_ADVANCED_TUNING: {}, + CONFIGURATOR_FILTER_CONFIG: {}, + CONFIGURATOR_RC_TUNING: {}, + CONFIGURATOR_FEATURE_CONFIG: {}, + CONFIGURATOR_TUNING_SLIDERS: {}, }; TABS.pid_tuning.initialize = function (callback) { @@ -1360,7 +1367,7 @@ TABS.pid_tuning.initialize = function (callback) { $('#resetPidProfile').on('click', function(){ self.updating = true; - self.sliderRetainConfiguration = true; + self.retainConfiguration = true; MSP.promise(MSPCodes.MSP_SET_RESET_CURR_PID).then(function () { self.refresh(function () { @@ -1895,10 +1902,10 @@ TABS.pid_tuning.initialize = function (callback) { const sliderPidsModeSelect = $('#sliderPidsModeSelect'); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - if (self.sliderRetainConfiguration) { + if (self.retainConfiguration) { self.setDirty(true); } else { - TuningSliders.saveInitialSettings(); + self.saveInitialSettings(); } sliderPidsModeSelect.val(FC.TUNING_SLIDERS.slider_pids_mode); } else { @@ -1943,6 +1950,11 @@ TABS.pid_tuning.initialize = function (callback) { $('#pid_main .YAW .pid_data input').each(function() { $(this).prop('disabled', disableY); }); + + if (setMode !== self.CONFIGURATOR_TUNING_SLIDERS.slider_pids_mode) { + self.setDirty(true); + } + }).trigger('change'); } @@ -2070,11 +2082,11 @@ TABS.pid_tuning.initialize = function (callback) { $('a.buttonPidTuningSliders').click(function() { // set Slider PID mode to RP(Y) when re-enabling Sliders if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - const firmwareMode = TuningSliders.initialSettings.sliderPidsMode; + const firmwareMode = self.CONFIGURATOR_TUNING_SLIDERS.slider_pids_mode; const workingMode = firmwareMode === 1 ? 1 : 2; if (firmwareMode !== workingMode) { - self.sliderRetainConfiguration = true; + self.retainConfiguration = true; } sliderPidsModeSelect.val(workingMode).trigger('change'); } @@ -2154,8 +2166,6 @@ TABS.pid_tuning.initialize = function (callback) { }); // enable Filter sliders button $('a.buttonFilterTuningSliders').click(function() { - self.sliderRetainConfiguration = true; - if (TuningSliders.GyroSliderUnavailable) { //set Slider mode to ON when re-enabling Sliders if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { @@ -2184,18 +2194,13 @@ TABS.pid_tuning.initialize = function (callback) { // update on pid table inputs $('#pid_main input').on('input', function() { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - self.sliderRetainConfiguration = true; - } else { + if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) { TuningSliders.updatePidSlidersDisplay(); self.analyticsChanges['PidTuningSliders'] = "Off"; } }); // update on filter value or type changes $('.pid_filter tr:not(.newFilter) input, .pid_filter tr:not(.newFilter) select').on('input', function() { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - self.sliderRetainConfiguration = true; - } TuningSliders.updateFilterSlidersDisplay(); if (TuningSliders.GyroSliderUnavailable) { self.analyticsChanges['GyroFilterTuningSlider'] = "Off"; @@ -2268,7 +2273,7 @@ TABS.pid_tuning.initialize = function (callback) { return MSP.promise(MSPCodes.MSP_EEPROM_WRITE); }).then(function () { self.updating = false; - self.sliderRetainConfiguration = false; + self.retainConfiguration = false; self.setDirty(false); @@ -2379,8 +2384,8 @@ TABS.pid_tuning.cleanup = function (callback) { TABS.pid_tuning.refresh = function (callback) { const self = this; - if (self.sliderRetainConfiguration && !self.updating) { - TuningSliders.restoreInitialSettings(); + if (self.retainConfiguration && !self.updating) { + self.restoreInitialSettings(); } GUI.tab_switch_cleanup(function () { @@ -2394,6 +2399,41 @@ TABS.pid_tuning.refresh = function (callback) { }); }; +TABS.pid_tuning.saveInitialSettings = function () { + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + this.CONFIGURATOR_PIDS = [ ...FC.PIDS ]; + this.CONFIGURATOR_ADVANCED_TUNING = { ...FC.ADVANCED_TUNING }; + this.CONFIGURATOR_FILTER_CONFIG = { ...FC.FILTER_CONFIG }; + this.CONFIGURATOR_RC_TUNING = { ...FC.RC_TUNING }; + this.CONFIGURATOR_FEATURE_CONFIG = { ...FC.FEATURE_CONFIG }; + this.CONFIGURATOR_TUNING_SLIDERS = { ...FC.TUNING_SLIDERS}; + } +}; + +TABS.pid_tuning.restoreInitialSettings = function () { + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + FC.PIDS = [ ...this.CONFIGURATOR_PIDS ]; + FC.ADVANCED_TUNING = { ...this.CONFIGURATOR_ADVANCED_TUNING }; + FC.FILTER_CONFIG = { ...this.CONFIGURATOR_FILTER_CONFIG }; + FC.RC_TUNING = { ...this.CONFIGURATOR_RC_TUNING }; + FC.FEATURE_CONFIG = { ...this.CONFIGURATOR_FEATURE_CONFIG }; + FC.TUNING_SLIDERS = { ...this.CONFIGURATOR_TUNING_SLIDERS }; + + Promise.resolve(true) + .then(() => MSP.promise(MSPCodes.MSP_SET_PID, mspHelper.crunch(MSPCodes.MSP_SET_PID))) + .then(() => MSP.promise(MSPCodes.MSP_SET_PID_ADVANCED, mspHelper.crunch(MSPCodes.MSP_SET_PID_ADVANCED))) + .then(() => MSP.promise(MSPCodes.MSP_SET_FILTER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FILTER_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_RC_TUNING, mspHelper.crunch(MSPCodes.MSP_SET_RC_TUNING))) + .then(() => MSP.promise(MSPCodes.MSP_SET_FEATURE_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FEATURE_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_TUNING_SLIDERS, mspHelper.crunch(MSPCodes.MSP_SET_TUNING_SLIDERS))) + .then(() => { + TABS.pid_tuning.retainConfiguration = false; + + console.log('Configuration restored to initial values'); + }); + } +}; + TABS.pid_tuning.setProfile = function () { const self = this; @@ -2416,6 +2456,10 @@ TABS.pid_tuning.setDirty = function (isDirty) { if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { $('.tab-pid_tuning select[name="rate_profile"]').prop('disabled', isDirty); } + + if (isDirty) { + self.retainConfiguration = true; + } }; TABS.pid_tuning.checkUpdateProfile = function (updateRateProfile) {