Extend save and restore for all settings

Fix Enable PID sliders button

Fix duplicate block?
10.8-maintenance
Mark Haslinghuis 2021-10-11 23:19:20 +02:00
parent faa3982890
commit 3ebd1697a5
No known key found for this signature in database
GPG Key ID: 198B0F616296A584
3 changed files with 63 additions and 70 deletions

View File

@ -32,7 +32,6 @@ const TuningSliders = {
PID_DEFAULT: [], PID_DEFAULT: [],
FILTER_DEFAULT: {}, FILTER_DEFAULT: {},
SLIDER_DEFAULT: {}, SLIDER_DEFAULT: {},
initialSettings: {},
cachedPidSliderValues: false, cachedPidSliderValues: false,
cachedGyroSliderValues: false, cachedGyroSliderValues: false,
@ -43,56 +42,6 @@ const TuningSliders = {
const D_MIN_RATIO = 0.85; 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) { TuningSliders.setDMinFeatureEnabled = function(dMinFeatureEnabled) {
this.dMinFeatureEnabled = dMinFeatureEnabled; this.dMinFeatureEnabled = dMinFeatureEnabled;
if (this.dMinFeatureEnabled) { if (this.dMinFeatureEnabled) {

View File

@ -252,8 +252,8 @@ function startProcess() {
const tabName = $(self).text(); const tabName = $(self).text();
if (GUI.active_tab === 'pid_tuning') { if (GUI.active_tab === 'pid_tuning') {
if (TABS.pid_tuning.sliderRetainConfiguration) { if (TABS.pid_tuning.retainConfiguration) {
TuningSliders.restoreInitialSettings(); TABS.pid_tuning.restoreInitialSettings();
} }
} }

View File

@ -22,7 +22,14 @@ TABS.pid_tuning = {
activeSubtab: 'pid', activeSubtab: 'pid',
analyticsChanges: {}, 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) { TABS.pid_tuning.initialize = function (callback) {
@ -1360,7 +1367,7 @@ TABS.pid_tuning.initialize = function (callback) {
$('#resetPidProfile').on('click', function(){ $('#resetPidProfile').on('click', function(){
self.updating = true; self.updating = true;
self.sliderRetainConfiguration = true; self.retainConfiguration = true;
MSP.promise(MSPCodes.MSP_SET_RESET_CURR_PID).then(function () { MSP.promise(MSPCodes.MSP_SET_RESET_CURR_PID).then(function () {
self.refresh(function () { self.refresh(function () {
@ -1895,10 +1902,10 @@ TABS.pid_tuning.initialize = function (callback) {
const sliderPidsModeSelect = $('#sliderPidsModeSelect'); const sliderPidsModeSelect = $('#sliderPidsModeSelect');
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
if (self.sliderRetainConfiguration) { if (self.retainConfiguration) {
self.setDirty(true); self.setDirty(true);
} else { } else {
TuningSliders.saveInitialSettings(); self.saveInitialSettings();
} }
sliderPidsModeSelect.val(FC.TUNING_SLIDERS.slider_pids_mode); sliderPidsModeSelect.val(FC.TUNING_SLIDERS.slider_pids_mode);
} else { } else {
@ -1943,6 +1950,11 @@ TABS.pid_tuning.initialize = function (callback) {
$('#pid_main .YAW .pid_data input').each(function() { $('#pid_main .YAW .pid_data input').each(function() {
$(this).prop('disabled', disableY); $(this).prop('disabled', disableY);
}); });
if (setMode !== self.CONFIGURATOR_TUNING_SLIDERS.slider_pids_mode) {
self.setDirty(true);
}
}).trigger('change'); }).trigger('change');
} }
@ -2070,11 +2082,11 @@ TABS.pid_tuning.initialize = function (callback) {
$('a.buttonPidTuningSliders').click(function() { $('a.buttonPidTuningSliders').click(function() {
// set Slider PID mode to RP(Y) when re-enabling Sliders // set Slider PID mode to RP(Y) when re-enabling Sliders
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { 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; const workingMode = firmwareMode === 1 ? 1 : 2;
if (firmwareMode !== workingMode) { if (firmwareMode !== workingMode) {
self.sliderRetainConfiguration = true; self.retainConfiguration = true;
} }
sliderPidsModeSelect.val(workingMode).trigger('change'); sliderPidsModeSelect.val(workingMode).trigger('change');
} }
@ -2154,8 +2166,6 @@ TABS.pid_tuning.initialize = function (callback) {
}); });
// enable Filter sliders button // enable Filter sliders button
$('a.buttonFilterTuningSliders').click(function() { $('a.buttonFilterTuningSliders').click(function() {
self.sliderRetainConfiguration = true;
if (TuningSliders.GyroSliderUnavailable) { if (TuningSliders.GyroSliderUnavailable) {
//set Slider mode to ON when re-enabling Sliders //set Slider mode to ON when re-enabling Sliders
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { 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 // update on pid table inputs
$('#pid_main input').on('input', function() { $('#pid_main input').on('input', function() {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
self.sliderRetainConfiguration = true;
} else {
TuningSliders.updatePidSlidersDisplay(); TuningSliders.updatePidSlidersDisplay();
self.analyticsChanges['PidTuningSliders'] = "Off"; self.analyticsChanges['PidTuningSliders'] = "Off";
} }
}); });
// update on filter value or type changes // update on filter value or type changes
$('.pid_filter tr:not(.newFilter) input, .pid_filter tr:not(.newFilter) select').on('input', function() { $('.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(); TuningSliders.updateFilterSlidersDisplay();
if (TuningSliders.GyroSliderUnavailable) { if (TuningSliders.GyroSliderUnavailable) {
self.analyticsChanges['GyroFilterTuningSlider'] = "Off"; self.analyticsChanges['GyroFilterTuningSlider'] = "Off";
@ -2268,7 +2273,7 @@ TABS.pid_tuning.initialize = function (callback) {
return MSP.promise(MSPCodes.MSP_EEPROM_WRITE); return MSP.promise(MSPCodes.MSP_EEPROM_WRITE);
}).then(function () { }).then(function () {
self.updating = false; self.updating = false;
self.sliderRetainConfiguration = false; self.retainConfiguration = false;
self.setDirty(false); self.setDirty(false);
@ -2379,8 +2384,8 @@ TABS.pid_tuning.cleanup = function (callback) {
TABS.pid_tuning.refresh = function (callback) { TABS.pid_tuning.refresh = function (callback) {
const self = this; const self = this;
if (self.sliderRetainConfiguration && !self.updating) { if (self.retainConfiguration && !self.updating) {
TuningSliders.restoreInitialSettings(); self.restoreInitialSettings();
} }
GUI.tab_switch_cleanup(function () { 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 () { TABS.pid_tuning.setProfile = function () {
const self = this; const self = this;
@ -2416,6 +2456,10 @@ TABS.pid_tuning.setDirty = function (isDirty) {
if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) {
$('.tab-pid_tuning select[name="rate_profile"]').prop('disabled', isDirty); $('.tab-pid_tuning select[name="rate_profile"]').prop('disabled', isDirty);
} }
if (isDirty) {
self.retainConfiguration = true;
}
}; };
TABS.pid_tuning.checkUpdateProfile = function (updateRateProfile) { TABS.pid_tuning.checkUpdateProfile = function (updateRateProfile) {