1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-24 00:35:26 +03:00

Handle expert settings

reduce code

Add props

Allow changing mode without save inbetween

Fix affecting touching slider
This commit is contained in:
Mark Haslinghuis 2021-10-06 01:11:44 +02:00
parent 3feefcb184
commit 348198d9be
5 changed files with 121 additions and 47 deletions

View file

@ -2006,7 +2006,7 @@
"description": "Pidtuning slider mode can be OFF, RP or RPY"
},
"pidTuningSliderModeHelp": {
"message": "<strong>Pid Tuning Slider Mode</strong><br><br>Pidtuning slider mode can be:<br><br>&bull; OFF - no sliders, enter values manually<br>&bull; RP - sliders control Roll and Pitch only, enter Yaw values manually<br>&bull; RPY - sliders control all PID values<br><br><strong class=\"message-negative\">Important:</strong><br><br>Please save after changing slider mode before changing other settings."
"message": "<strong>Pid Tuning Slider Mode</strong><br><br>Pidtuning slider mode can be:<br><br>&bull; OFF - no sliders, enter values manually<br>&bull; RP - sliders control Roll and Pitch only, enter Yaw values manually<br>&bull; RPY - sliders control all PID values<br><br><span class=\"message-negative\"><b>Warning:</b></span>Going from RP to RPY mode will overwrite Yaw settings with firmware settings."
},
"receiverThrottleMid": {
@ -3654,6 +3654,10 @@
"message": "<strong>Note:</strong> Sliders range is restricted because you are not in expert mode. This range should be suitable for most builds and beginners.",
"description": "Firmware filter sliders restricted message"
},
"pidTuningSlidersExpertSettingsDetectedNote": {
"message": "<span class=\"message-negative\">CAUTION</span>: expert settings detected while in non-expert mode. Please enable Expert Mode to be able to make affected sliders accessible again.",
"desciption": "Slider expert settings detected while in non-expert mode"
},
"pidTuningSliderLow": {
"message": "Low",
"description": "Tuning Slider Low header"

View file

@ -251,6 +251,11 @@
text-align: right;
border: 1px solid var(--subtleAccent);
border-radius: 3px;
background-color: #f9f9f9;
}
.tab-pid_tuning .subtab-pid table input:disabled {
background-color: #dddddd;
}
.tab-pid_tuning .subtab-filter table input,
@ -838,7 +843,8 @@
font-size: 12px;
}
.tab-pid_tuning .nonExpertModeSlidersNote {
.tab-pid_tuning .nonExpertModeSlidersNote,
.tab-pid_tuning .expertSettingsDetectedNote {
text-align: center;
padding-top: 2px;
padding-bottom: 2px;

View file

@ -45,7 +45,7 @@ const D_MIN_RATIO = 0.85;
TuningSliders.saveInitialSettings = function () {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
this.initialSettings.sliderPidsModeSelect = FC.TUNING_SLIDERS.slider_pids_mode;
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;
@ -63,7 +63,7 @@ TuningSliders.saveInitialSettings = function () {
TuningSliders.restoreInitialSettings = function () {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
FC.TUNING_SLIDERS.slider_pids_mode = this.initialSettings.sliderPidsModeSelect;
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;
@ -126,17 +126,68 @@ TuningSliders.initialize = function() {
this.updateFilterSlidersDisplay();
};
TuningSliders.updateExpertModeSlidersDisplay = function() {
const NON_EXPERT_SLIDER_MIN = 70;
const NON_EXPERT_SLIDER_MAX = 140;
const NON_EXPERT_SLIDER_MIN_GYRO = 50;
const NON_EXPERT_SLIDER_MAX_GYRO = 150;
const NON_EXPERT_SLIDER_MIN_DTERM = 80;
const NON_EXPERT_SLIDER_MAX_DTERM = 120;
const dGain = FC.TUNING_SLIDERS.slider_d_gain < NON_EXPERT_SLIDER_MIN || FC.TUNING_SLIDERS.slider_d_gain > NON_EXPERT_SLIDER_MAX;
const piGain = FC.TUNING_SLIDERS.slider_pi_gain < NON_EXPERT_SLIDER_MIN || FC.TUNING_SLIDERS.slider_pi_gain > NON_EXPERT_SLIDER_MAX;
const ffGain = FC.TUNING_SLIDERS.slider_feedforward_gain < NON_EXPERT_SLIDER_MIN || FC.TUNING_SLIDERS.slider_feedforward_gain > NON_EXPERT_SLIDER_MAX;
const dMaxGain = FC.TUNING_SLIDERS.slider_dmax_gain !== FC.DEFAULT_TUNING_SLIDERS.slider_dmax_gain;
const iGain = FC.TUNING_SLIDERS.slider_i_gain !== FC.DEFAULT_TUNING_SLIDERS.slider_i_gain;
const rpRatio = FC.TUNING_SLIDERS.slider_roll_pitch_ratio !== FC.DEFAULT_TUNING_SLIDERS.slider_roll_pitch_ratio;
const rpIGain = FC .TUNING_SLIDERS.slider_pitch_pi_gain !== FC.DEFAULT_TUNING_SLIDERS.slider_pitch_pi_gain;
const master = FC.TUNING_SLIDERS.slider_master_multiplier !== FC.DEFAULT_TUNING_SLIDERS.slider_master_multiplier;
const gyro = FC.TUNING_SLIDERS.slider_gyro_filter_multiplier < NON_EXPERT_SLIDER_MIN_GYRO || FC.TUNING_SLIDERS.slider_gyro_filter_multiplier > NON_EXPERT_SLIDER_MAX_GYRO;
const dterm = FC.TUNING_SLIDERS.slider_dterm_filter_multiplier < NON_EXPERT_SLIDER_MIN_DTERM || FC.TUNING_SLIDERS.slider_dterm_filter_multiplier > NON_EXPERT_SLIDER_MAX_DTERM;
const basic = dGain || piGain || ffGain;
const advanced = dMaxGain || iGain || rpRatio || rpIGain || master;
$('#sliderDGain').prop('disabled', dGain && !this.expertMode);
$('#sliderPIGain').prop('disabled', piGain && !this.expertMode);
$('#sliderFeedforwardGain').prop('disabled', ffGain && !this.expertMode);
$('#sliderDMaxGain').prop('disabled', !this.expertMode);
$('#sliderIGain').prop('disabled', !this.expertMode);
$('#sliderRollPitchRatio').prop('disabled', !this.expertMode);
$('#sliderPitchPIGain').prop('disabled', !this.expertMode);
$('#sliderMasterMultiplier').prop('disabled', !this.expertMode);
$('#sliderGyroFilterMultiplier').prop('disabled', gyro && !this.expertMode);
$('#sliderDTermFilterMultiplier').prop('disabled', dterm && !this.expertMode);
$('.baseSliderDGain').toggleClass('disabledSliders', dGain && !this.expertMode);
$('.baseSliderPIGain').toggleClass('disabledSliders', piGain && !this.expertMode);
$('.baseSliderFeedforwardGain').toggleClass('disabledSliders', ffGain && !this.expertMode);
$('.advancedSlider').toggleClass('disabledSliders', !this.expertMode);
$('.sliderGyroFilter').toggleClass('disabledSliders', gyro && !this.expertMode);
$('.sliderDtermFilter').toggleClass('disabledSliders', dterm && !this.expertMode);
$('.advancedSliderDmaxGain').toggle(dMaxGain || this.expertMode);
$('.advancedSliderIGain').toggle(iGain || this.expertMode);
$('.advancedSliderRollPitchRatio').toggle(rpRatio || this.expertMode);
$('.advancedSliderPitchPIGain').toggle(rpIGain || this.expertMode);
$('.advancedSliderMaster').toggle(master || this.expertMode);
$('.expertSettingsDetectedNote').toggle((basic || advanced) && !this.expertMode);
};
TuningSliders.setExpertMode = function(expertModeEnabled) {
this.expertMode = expertModeEnabled;
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
document.getElementById('sliderDMaxGain').disabled = !this.expertMode;
document.getElementById('sliderIGain').disabled = !this.expertMode;
document.getElementById('sliderRollPitchRatio').disabled = !this.expertMode;
document.getElementById('sliderPitchPIGain').disabled = !this.expertMode;
document.getElementById('sliderMasterMultiplier').disabled = !this.expertMode;
$('.advancedSlider').toggleClass('disabledSliders', !this.expertMode);
this.updateExpertModeSlidersDisplay();
$('.tab-pid_tuning .legacySlider').hide();
$('.legacyNonExpertModeSlidersNote').hide();
$('.subtab-pid .nonExpertModeSlidersNote').toggle(!this.pidSlidersUnavailable && !this.expertMode);
@ -146,6 +197,7 @@ TuningSliders.setExpertMode = function(expertModeEnabled) {
$('.tab-pid_tuning .baseSlider').hide();
$('.tab-pid_tuning .advancedSlider').hide();
$('.nonExpertModeSlidersNote').hide();
$('.expertSettingsDetectedNote').hide();
$('.subtab-pid .legacyNonExpertModeSlidersNote').toggle(!this.pidSlidersUnavailable && !this.expertMode);
$('.subtab-filter .legacyNonExpertModeSlidersNote').toggle((!this.GyroSliderUnavailable || !this.DTermSliderUnavailable) && !this.expertMode);
}
@ -396,7 +448,7 @@ TuningSliders.updatePidSlidersDisplay = function() {
let rows = 3;
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
rows = FC.TUNING_SLIDERS.slider_pids_mode === 1 ? 2 : 3;
rows = this.sliderPidsMode === 1 ? 2 : 3;
} else {
this.calculateNewPids(true);
}
@ -494,10 +546,14 @@ TuningSliders.updateFilterSlidersDisplay = function() {
TuningSliders.updateFormPids = function(updateSlidersOnly = false) {
if (!updateSlidersOnly) {
let rows = 3;
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
rows = this.sliderPidsMode === 1 ? 2 : 3;
}
FC.PID_NAMES.forEach(function (elementPid, indexPid) {
const pidElements = $(`.pid_tuning .${elementPid} input`);
pidElements.each(function (indexInput) {
if (indexPid < 3 && indexInput < 3) {
if (indexPid < rows && indexInput < rows) {
$(this).val(FC.PIDS[indexPid][indexInput]);
}
});
@ -591,7 +647,7 @@ TuningSliders.calculateNewPids = function(updateSlidersOnly = false) {
// values get set both into forms and their respective variables
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
FC.TUNING_SLIDERS.slider_pids_mode = parseInt($('#sliderPidsModeSelect').val());
FC.TUNING_SLIDERS.slider_pids_mode = this.sliderPidsMode;
//rounds slider values to nearies multiple of 5 and passes to the FW. Avoid dividing calc by (* x 100)/5 = 20
FC.TUNING_SLIDERS.slider_d_gain = Math.round(this.sliderDGain * 20) * 5;
FC.TUNING_SLIDERS.slider_pi_gain = Math.round(this.sliderPIGain * 20) * 5;

View file

@ -630,7 +630,6 @@ TABS.pid_tuning.initialize = function (callback) {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
$('.dMinGroupCheckbox').addClass('switchery-disabled');
$('.dMinDisabledNote').hide();
self.updateGuiElements();
} else {
dMinSwitch.prop('checked', FC.ADVANCED_TUNING.dMinRoll > 0 || FC.ADVANCED_TUNING.dMinPitch > 0 || FC.ADVANCED_TUNING.dMinYaw > 0);
@ -668,9 +667,9 @@ TABS.pid_tuning.initialize = function (callback) {
$('.pid_tuning input[name="dMinYaw"]').val(0);
}
});
}
dMinSwitch.trigger('change');
}
}
$('input[id="gyroNotch1Enabled"]').change(function() {
const checked = $(this).is(':checked');
@ -861,7 +860,7 @@ TABS.pid_tuning.initialize = function (callback) {
// Assign each value
searchRow.each(function (indexInput) {
if ($(this).val()) {
FC.PIDS[indexPid][indexInput] = parseFloat($(this).val());
FC.PIDS[indexPid][indexInput] = parseInt($(this).val());
}
});
});
@ -1806,7 +1805,6 @@ TABS.pid_tuning.initialize = function (callback) {
&& $(item).attr('class') !== "nonProfile") {
$(item).change(function () {
self.setDirty(true);
self.sliderRetainConfiguration = true;
});
}
});
@ -1907,7 +1905,6 @@ TABS.pid_tuning.initialize = function (callback) {
} else {
TuningSliders.saveInitialSettings();
}
sliderPidsModeSelect.val(FC.TUNING_SLIDERS.slider_pids_mode);
} else {
$('#dMinSwitch').change(function() {
@ -1934,25 +1931,22 @@ TABS.pid_tuning.initialize = function (callback) {
// trigger Slider Display update when PID mode is changed
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
$('select[id="sliderPidsModeSelect"]').on('change', function () {
const originalMode = TuningSliders.initialSettings.sliderPidsModeSelect;
const setMode = parseInt($(this).val());
TuningSliders.sliderPidsMode = setMode;
TuningSliders.calculateNewPids();
TuningSliders.updateFormPids();
TuningSliders.updatePidSlidersDisplay();
const allowRP = originalMode === 0 && setMode === 0;
const allowRPY = originalMode < 2 && originalMode === setMode;
const allowRP = !!setMode;
const allowY = setMode !== 1;
$('#pid_main .ROLL .pid_data input').each(function() {
$(this).prop('disabled', !allowRP);
});
$('#pid_main .PITCH .pid_data input').each(function() {
$(this).prop('disabled', !allowRP);
$('#pid_main .ROLL .pid_data input, #pid_main .PITCH .pid_data input').each(function() {
$(this).prop('disabled', allowRP);
});
$('#pid_main .YAW .pid_data input').each(function() {
$(this).prop('disabled', !allowRPY);
$(this).prop('disabled', allowY);
});
}).trigger('change');
}
@ -2029,9 +2023,6 @@ TABS.pid_tuning.initialize = function (callback) {
$('.pid_tuning .PITCH input[name="d"]').change();
$('.pid_tuning .YAW input[name="d"]').change();
});
} else {
TuningSliders.updatePidSlidersDisplay();
TuningSliders.updateSlidersWarning();
}
// reset to middle with double click
allPidTuningSliders.dblclick(function() {
@ -2079,14 +2070,13 @@ TABS.pid_tuning.initialize = function (callback) {
slider.val(value);
TuningSliders.calculateNewPids();
TuningSliders.updatePidSlidersDisplay();
});
// enable PID sliders button
$('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.sliderPidsModeSelect;
const firmwareMode = TuningSliders.initialSettings.sliderPidsMode;
const workingMode = firmwareMode === 1 ? 1 : 2;
if (firmwareMode !== workingMode) {
@ -2200,11 +2190,18 @@ 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 {
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";
@ -2729,6 +2726,10 @@ TABS.pid_tuning.updateFilterWarning = function() {
};
TABS.pid_tuning.updatePIDColors = function(clear = false) {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
return;
}
const setTuningElementColor = function(element, mspValue, currentValue) {
if (clear) {
element.css({ "background-color": "transparent" });

View file

@ -172,7 +172,7 @@
<div id="slidersPidsBox" class="gui_box grey topspacer tuningPIDSliders">
<table class="pid_titlebar">
<tr>
<th scope="col" class="sm-min">
<th scope="col" class="sm-min">Mode
<select id="sliderPidsModeSelect" class="sliderMode">
<option value="0">OFF</option>
<option value="1">RP</option>
@ -247,7 +247,7 @@
</td>
</tr>
<tr class="baseSlider">
<tr class="baseSlider baseSliderDGain">
<td>
<span i18n="pidTuningDGainSlider"></span>
</td>
@ -261,7 +261,7 @@
<div class="helpicon cf_tip" i18n_title="pidTuningDGainSliderHelp"></div>
</td>
</tr>
<tr class="baseSlider">
<tr class="baseSlider baseSliderPIGain">
<td>
<span i18n="pidTuningPIGainSlider"></span>
</td>
@ -275,7 +275,7 @@
<div class="helpicon cf_tip" i18n_title="pidTuningPIGainSliderHelp"></div>
</td>
</tr>
<tr class="baseSlider">
<tr class="baseSlider baseSliderFeedforwardGain">
<td>
<span i18n="pidTuningResponseSlider"></span>
</td>
@ -292,7 +292,7 @@
<tr class="advancedSlider">
<td colspan="6" class="sliderDivider"><hr /></td>
</tr>
<tr class="advancedSlider">
<tr class="advancedSlider advancedSliderDmaxGain">
<td>
<span i18n="pidTuningDMaxGainSlider"></span>
</td>
@ -306,7 +306,7 @@
<div class="helpicon cf_tip" i18n_title="pidTuningDMaxGainSliderHelp"></div>
</td>
</tr>
<tr class="advancedSlider">
<tr class="advancedSlider advancedSliderIGain">
<td>
<span i18n="pidTuningIGainSlider"></span>
</td>
@ -320,7 +320,7 @@
<div class="helpicon cf_tip" i18n_title="pidTuningIGainSliderHelp"></div>
</td>
</tr>
<tr class="advancedSlider">
<tr class="advancedSlider advancedSliderRollPitchRatio">
<td>
<span i18n="pidTuningRollPitchRatioSlider"></span>
</td>
@ -334,7 +334,7 @@
<div class="helpicon cf_tip" i18n_title="pidTuningRollPitchRatioSliderHelp"></div>
</td>
</tr>
<tr class="advancedSlider">
<tr class="advancedSlider advancedSliderPitchPIGain">
<td>
<span i18n="pidTuningPitchPIGainSlider"></span>
</td>
@ -348,7 +348,7 @@
<div class="helpicon cf_tip" i18n_title="pidTuningPitchPIGainSliderHelp"></div>
</td>
</tr>
<tr class="advancedSlider">
<tr class="advancedSlider advancedSliderMaster">
<td>
<span i18n="pidTuningMasterSlider"></span>
</td>
@ -369,6 +369,9 @@
<div class="gui_box topspacer nonExpertModeSlidersNote">
<p i18n="pidTuningPidSlidersNonExpertMode"></p>
</div>
<div class="gui_box topspacer expertSettingsDetectedNote">
<p i18n="pidTuningSlidersExpertSettingsDetectedNote"></p>
</div>
<!-- BARO, MAG, GPS -->
<div id="pid_baro_mag_gps" class="pid_optional needed_by_ALT needed_by_VEL needed_by_MAG needed_by_Pos needed_by_PosR needed_by_NavR gui_box grey topspacer pid_tuning">
@ -1139,7 +1142,7 @@
<span i18n="pidTuningGyroFilterSlider"></span>
</td>
</tr>
<tr>
<tr class="sliderGyroFilter">
<td class="sm-min">
<span i18n="pidTuningGyroFilterSlider"></span>
</td>
@ -1158,7 +1161,7 @@
<span i18n="pidTuningDTermFilterSlider"></span>
</td>
</tr>
<tr>
<tr class="sliderDtermFilter">
<td class="sm-min">
<span i18n="pidTuningDTermFilterSlider"></span>
</td>
@ -1179,6 +1182,10 @@
<p i18n="pidTuningFilterSlidersNonExpertMode"></p>
</div>
<div class="gui_box topspacer expertSettingsDetectedNote">
<p i18n="pidTuningSlidersExpertSettingsDetectedNote"></p>
</div>
<div class="cf_column two_columns">
<div class="gui_box grey topspacer pid_filter two_columns_first">
<table class="pid_titlebar new_rates">