mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-23 00:05:22 +03:00
Merge pull request #2616 from haslinghuis/fix_reset_profiles
This commit is contained in:
commit
2b98947fb4
3 changed files with 45 additions and 72 deletions
|
@ -45,7 +45,7 @@ const D_MIN_RATIO = 0.85;
|
||||||
|
|
||||||
TuningSliders.saveInitialSettings = function () {
|
TuningSliders.saveInitialSettings = function () {
|
||||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||||
this.initialSettings.sliderPidsMode = FC.TUNING_SLIDERS.slider_pids_mode;
|
this.initialSettings.sliderPidsModeSelect = FC.TUNING_SLIDERS.slider_pids_mode;
|
||||||
this.initialSettings.sliderDGain = FC.TUNING_SLIDERS.slider_d_gain / 100;
|
this.initialSettings.sliderDGain = FC.TUNING_SLIDERS.slider_d_gain / 100;
|
||||||
this.initialSettings.sliderPIGain = FC.TUNING_SLIDERS.slider_pi_gain / 100;
|
this.initialSettings.sliderPIGain = FC.TUNING_SLIDERS.slider_pi_gain / 100;
|
||||||
this.initialSettings.sliderFeedforwardGain = FC.TUNING_SLIDERS.slider_feedforward_gain / 100;
|
this.initialSettings.sliderFeedforwardGain = FC.TUNING_SLIDERS.slider_feedforward_gain / 100;
|
||||||
|
@ -63,11 +63,7 @@ TuningSliders.saveInitialSettings = function () {
|
||||||
|
|
||||||
TuningSliders.restoreInitialSettings = function () {
|
TuningSliders.restoreInitialSettings = function () {
|
||||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||||
if (this.sliderModeHasChanged && this.initialSetting.sliderPidsMode !== this.sliderPidsmode) {
|
FC.TUNING_SLIDERS.slider_pids_mode = this.initialSettings.sliderPidsModeSelect;
|
||||||
$('#sliderPidsModeSelect').val(this.initialSettings.sliderPidsMode).trigger('change');
|
|
||||||
}
|
|
||||||
|
|
||||||
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_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_pi_gain = Math.round(this.initialSettings.sliderPIGain * 20) * 5;
|
||||||
|
@ -88,12 +84,12 @@ TuningSliders.restoreInitialSettings = function () {
|
||||||
.then(() => MSP.promise(MSPCodes.MSP_PID_ADVANCED))
|
.then(() => MSP.promise(MSPCodes.MSP_PID_ADVANCED))
|
||||||
.then(() => MSP.promise(MSPCodes.MSP_FILTER_CONFIG))
|
.then(() => MSP.promise(MSPCodes.MSP_FILTER_CONFIG))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
TABS.pid_tuning.configChanges = {};
|
|
||||||
if (GUI.active_tab === 'pid_tuning') {
|
if (GUI.active_tab === 'pid_tuning') {
|
||||||
this.updateFormPids();
|
this.updateFormPids();
|
||||||
TABS.pid_tuning.updatePIDColors();
|
TABS.pid_tuning.updatePIDColors();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
TABS.pid_tuning.sliderRetainConfiguration = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -252,7 +252,7 @@ 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.sliderRetainPosition || TABS.pid_tuning.sliderRetainMode || TABS.pid_tuning.sliderRetainConfiguration) {
|
if (TABS.pid_tuning.sliderRetainConfiguration) {
|
||||||
TuningSliders.restoreInitialSettings();
|
TuningSliders.restoreInitialSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,6 @@ TABS.pid_tuning = {
|
||||||
activeSubtab: 'pid',
|
activeSubtab: 'pid',
|
||||||
analyticsChanges: {},
|
analyticsChanges: {},
|
||||||
|
|
||||||
sliderChanges: {},
|
|
||||||
sliderRetainMode: false,
|
|
||||||
sliderRetainPosition: false,
|
|
||||||
sliderRetainConfiguration: false,
|
sliderRetainConfiguration: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1809,6 +1806,7 @@ TABS.pid_tuning.initialize = function (callback) {
|
||||||
&& $(item).attr('class') !== "nonProfile") {
|
&& $(item).attr('class') !== "nonProfile") {
|
||||||
$(item).change(function () {
|
$(item).change(function () {
|
||||||
self.setDirty(true);
|
self.setDirty(true);
|
||||||
|
self.sliderRetainConfiguration = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1901,59 +1899,16 @@ TABS.pid_tuning.initialize = function (callback) {
|
||||||
const SLIDER_STEP_LOWER = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44) ? 0.05 : 0.1;
|
const SLIDER_STEP_LOWER = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44) ? 0.05 : 0.1;
|
||||||
const SLIDER_STEP_UPPER = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44) ? 0.05 : 0.1;
|
const SLIDER_STEP_UPPER = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44) ? 0.05 : 0.1;
|
||||||
|
|
||||||
|
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.sliderRetainConfiguration) {
|
||||||
|
self.setDirty(true);
|
||||||
|
} else {
|
||||||
TuningSliders.saveInitialSettings();
|
TuningSliders.saveInitialSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialConfiguration = TuningSliders.initialSettings;
|
sliderPidsModeSelect.val(FC.TUNING_SLIDERS.slider_pids_mode);
|
||||||
|
|
||||||
// we only target the range target type.
|
|
||||||
function sliderHandler(e) {
|
|
||||||
if (e.target !== e.currentTarget) {
|
|
||||||
const item = e.target.id === '' ? e.target.name : e.target.id;
|
|
||||||
const value = isInt(e.target.value) ? parseInt(e.target.value) : parseFloat(e.target.value);
|
|
||||||
self.sliderChanges[item] = value;
|
|
||||||
|
|
||||||
if (item in initialConfiguration) {
|
|
||||||
if (value !== initialConfiguration[item]) {
|
|
||||||
self.sliderRetainPosition = true;
|
|
||||||
} else {
|
|
||||||
delete self.sliderChanges[item];
|
|
||||||
if (Object.keys(self.sliderChanges).length === 0) {
|
|
||||||
self.sliderRetainPosition = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
e.stopPropagation();
|
|
||||||
}
|
|
||||||
|
|
||||||
function disableSliderOnManualChange(e, angle) {
|
|
||||||
const sliderPidsModeSelectElement = $('#sliderPidsModeSelect');
|
|
||||||
const mode = parseInt(sliderPidsModeSelectElement.val());
|
|
||||||
if (mode > 0) {
|
|
||||||
if (mode === 1 && angle === 'YAW') {
|
|
||||||
e.preventDefault();
|
|
||||||
} else {
|
|
||||||
sliderPidsModeSelectElement.val(0).trigger('change');
|
|
||||||
self.sliderRetainMode = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self.updateGuiElements();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function HandleEventParams(param) {
|
|
||||||
return (e) => disableSliderOnManualChange(e, param);
|
|
||||||
}
|
|
||||||
|
|
||||||
document.querySelectorAll('.sliderLabels').forEach(elem => elem.addEventListener('change', sliderHandler));
|
|
||||||
document.querySelectorAll('.sliderMode').forEach(elem => elem.addEventListener('change', sliderHandler));
|
|
||||||
document.querySelectorAll('.ROLL').forEach(elem => elem.addEventListener('change', HandleEventParams('ROLL')));
|
|
||||||
document.querySelectorAll('.PITCH').forEach(elem => elem.addEventListener('change', HandleEventParams('PITCH')));
|
|
||||||
document.querySelectorAll('.YAW').forEach(elem => elem.addEventListener('change', HandleEventParams('YAW')));
|
|
||||||
$('#sliderPidsModeSelect').val(FC.TUNING_SLIDERS.slider_pids_mode);
|
|
||||||
} else {
|
} else {
|
||||||
$('#dMinSwitch').change(function() {
|
$('#dMinSwitch').change(function() {
|
||||||
TuningSliders.setDMinFeatureEnabled($(this).is(':checked'));
|
TuningSliders.setDMinFeatureEnabled($(this).is(':checked'));
|
||||||
|
@ -1978,10 +1933,28 @@ TABS.pid_tuning.initialize = function (callback) {
|
||||||
|
|
||||||
// trigger Slider Display update when PID mode is changed
|
// trigger Slider Display update when PID mode is changed
|
||||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||||
$('select[id="sliderPidsModeSelect"]').change(function () {
|
$('select[id="sliderPidsModeSelect"]').on('change', function () {
|
||||||
TuningSliders.sliderPidsMode = parseInt($(this).val());
|
const originalMode = TuningSliders.initialSettings.sliderPidsModeSelect;
|
||||||
|
const setMode = parseInt($(this).val());
|
||||||
|
|
||||||
|
TuningSliders.sliderPidsMode = setMode;
|
||||||
TuningSliders.updatePidSlidersDisplay();
|
TuningSliders.updatePidSlidersDisplay();
|
||||||
}).change();
|
|
||||||
|
const allowRP = originalMode === 0 && setMode === 0;
|
||||||
|
const allowRPY = originalMode < 2 && originalMode === setMode;
|
||||||
|
|
||||||
|
$('.ROLL .pid_data input').each(function() {
|
||||||
|
$(this).prop('disabled', !allowRP);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.PITCH .pid_data input').each(function() {
|
||||||
|
$(this).prop('disabled', !allowRP);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.YAW .pid_data input').each(function() {
|
||||||
|
$(this).prop('disabled', !allowRPY);
|
||||||
|
});
|
||||||
|
}).trigger('change');
|
||||||
}
|
}
|
||||||
|
|
||||||
let allPidTuningSliders;
|
let allPidTuningSliders;
|
||||||
|
@ -2046,6 +2019,7 @@ TABS.pid_tuning.initialize = function (callback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TuningSliders.calculateNewPids();
|
TuningSliders.calculateNewPids();
|
||||||
|
self.updateGuiElements();
|
||||||
self.analyticsChanges['PidTuningSliders'] = "On";
|
self.analyticsChanges['PidTuningSliders'] = "On";
|
||||||
});
|
});
|
||||||
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||||
|
@ -2107,12 +2081,18 @@ TABS.pid_tuning.initialize = function (callback) {
|
||||||
TuningSliders.calculateNewPids();
|
TuningSliders.calculateNewPids();
|
||||||
TuningSliders.updatePidSlidersDisplay();
|
TuningSliders.updatePidSlidersDisplay();
|
||||||
});
|
});
|
||||||
|
|
||||||
// enable PID sliders button
|
// enable PID sliders button
|
||||||
$('a.buttonPidTuningSliders').click(function() {
|
$('a.buttonPidTuningSliders').click(function() {
|
||||||
//set Slider PID mode to RPY 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)) {
|
||||||
$('#sliderPidsModeSelect').val(2).trigger('change');
|
const firmwareMode = TuningSliders.initialSettings.sliderPidsModeSelect;
|
||||||
self.sliderRetainMode = true;
|
const workingMode = firmwareMode === 1 ? 1 : 2;
|
||||||
|
|
||||||
|
if (firmwareMode !== workingMode) {
|
||||||
|
self.sliderRetainConfiguration = true;
|
||||||
|
}
|
||||||
|
sliderPidsModeSelect.val(workingMode).trigger('change');
|
||||||
}
|
}
|
||||||
// if values were previously changed manually and then sliders are reactivated, reset pids to previous valid values if available, else default
|
// if values were previously changed manually and then sliders are reactivated, reset pids to previous valid values if available, else default
|
||||||
TuningSliders.resetPidSliders();
|
TuningSliders.resetPidSliders();
|
||||||
|
@ -2190,7 +2170,8 @@ TABS.pid_tuning.initialize = function (callback) {
|
||||||
});
|
});
|
||||||
// enable Filter sliders button
|
// enable Filter sliders button
|
||||||
$('a.buttonFilterTuningSliders').click(function() {
|
$('a.buttonFilterTuningSliders').click(function() {
|
||||||
self.sliderRetainMode = true;
|
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)) {
|
||||||
|
@ -2296,10 +2277,6 @@ 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.sliderRetainPosition = false;
|
|
||||||
self.sliderRetainMode = false;
|
|
||||||
self.sliderChanges = {};
|
|
||||||
self.sliderRetainConfiguration = false;
|
self.sliderRetainConfiguration = false;
|
||||||
|
|
||||||
self.setDirty(false);
|
self.setDirty(false);
|
||||||
|
@ -2411,7 +2388,7 @@ 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.sliderRetainPosition || self.sliderRetainMode) && !self.updating) {
|
if (self.sliderRetainConfiguration && !self.updating) {
|
||||||
TuningSliders.restoreInitialSettings();
|
TuningSliders.restoreInitialSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue