Skip to content

Commit 2c0015e

Browse files
committed
rfc filter sliders
1 parent 2dca1e7 commit 2c0015e

File tree

4 files changed

+91
-11
lines changed

4 files changed

+91
-11
lines changed

locales/en/messages.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3634,6 +3634,14 @@
36343634
"message": "<strong>Note:</strong> Sliders are disabled because values were changed manually. Clicking the '$t(pidTuningSliderEnableButton.message)' button will activate them again. This will reset the values and any unsaved changes will be lost.",
36353635
"description": "Tuning sliders disabled note when manual changes are detected"
36363636
},
3637+
"pidTuningGyroSliderDisabled": {
3638+
"message": "<strong>Note:</strong> Gyro Slider is disabled because values were changed manually. Clicking the '$t(pidTuningGyroSliderEnableButton.message)' button will activate them again. This will reset the values and any unsaved changes will be lost.",
3639+
"description": "Gyro Tuning sliders disabled note when manual changes are detected"
3640+
},
3641+
"pidTuningDTermSliderDisabled": {
3642+
"message": "<strong>Note:</strong> DTerm Slider is disabled because values were changed manually. Clicking the '$t(pidTuningDTermSliderEnableButton.message)' button will activate them again. This will reset the values and any unsaved changes will be lost.",
3643+
"description": "DTerm Tuning sliders disabled note when manual changes are detected"
3644+
},
36373645
"pidTuningPidSlidersDisabled": {
36383646
"message": "<strong>Note:</strong> Sliders are disabled. Clicking the '$t(pidTuningSliderEnableButton.message)' button will change the PID values to match your previously saved slider position.",
36393647
"description": "Tuning sliders disabled note"
@@ -3642,6 +3650,14 @@
36423650
"message": "Enable Sliders",
36433651
"description": "Button label for enabling sliders"
36443652
},
3653+
"pidTuningGyroSliderEnableButton": {
3654+
"message": "Enable Gyro Slider",
3655+
"description": "Button label for enabling Gyro filter sliders"
3656+
},
3657+
"pidTuningDTermSliderEnableButton": {
3658+
"message": "Enable Dterm Slider",
3659+
"description": "Button label for enabling DTerm filter sliders"
3660+
},
36453661
"pidTuningSlidersNonExpertMode": {
36463662
"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.",
36473663
"description": "Sliders restricted message"

src/js/TuningSliders.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,19 @@ TuningSliders.updateFilterSlidersDisplay = function() {
434434
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
435435
this.GyroSliderUnavailable = !FC.TUNING_SLIDERS.slider_gyro_filter;
436436
this.DTermSliderUnavailable = !FC.TUNING_SLIDERS.slider_dterm_filter;
437-
438-
if (parseInt($('.pid_filter input[name="gyroLowpassDynMinFrequency"]').val()) !==
439-
Math.floor(this.FILTER_DEFAULT.gyro_lowpass_dyn_min_hz * this.sliderGyroFilterMultiplier) ||
440-
parseInt($('.pid_filter input[name="gyroLowpassDynMaxFrequency"]').val()) !==
441-
Math.floor(this.FILTER_DEFAULT.gyro_lowpass_dyn_max_hz * this.sliderGyroFilterMultiplier) ||
442-
parseInt($('.pid_filter select[name="gyroLowpassDynType"]').val()) !== this.FILTER_DEFAULT.gyro_lowpass_type ||
443-
parseInt($('.pid_filter input[name="gyroLowpass2Frequency"]').val()) !==
444-
Math.floor(this.FILTER_DEFAULT.gyro_lowpass2_hz * this.sliderGyroFilterMultiplier) ||
445-
parseInt($('.pid_filter select[name="gyroLowpass2Type"]').val()) !== this.FILTER_DEFAULT.gyro_lowpass2_type) {
437+
const lp1Changed = parseInt($('.pid_filter input[name="gyroLowpassDynMinFrequency"]').val()) !== Math.floor(this.FILTER_DEFAULT.gyro_lowpass_dyn_min_hz * this.sliderGyroFilterMultiplier);
438+
const lp2Changed = parseInt($('.pid_filter input[name="gyroLowpass2Frequency"]').val()) !== Math.floor(this.FILTER_DEFAULT.gyro_lowpass2_hz * this.sliderGyroFilterMultiplier);
439+
const lp1Enabled = parseInt($('.pid_filter input[name="gyroLowpassDynMinFrequency"]').val()) > 1;
440+
const lp2Enabled = parseInt($('.pid_filter input[name="gyroLowpass2Frequency"]').val()) > 1;
441+
const lpxChanged = lp1Changed && lp2Changed;
442+
const lpxDisabled = !(lp1Enabled || lp2Enabled);
443+
const lpxOffAndChanged = lpxChanged && lpxDisabled;
444+
445+
const lpDynMaxChanged = parseInt($('.pid_filter input[name="gyroLowpassDynMaxFrequency"]').val()) !== Math.floor(this.FILTER_DEFAULT.gyro_lowpass_dyn_max_hz * this.sliderGyroFilterMultiplier);
446+
const lpfDynTypeChanged = parseInt($('.pid_filter select[name="gyroLowpassDynType"]').val()) !== this.FILTER_DEFAULT.gyro_lowpass_type;
447+
const lpf2TypeChanged = parseInt($('.pid_filter select[name="gyroLowpass2Type"]').val()) !== this.FILTER_DEFAULT.gyro_lowpass2_type;
448+
449+
if ((lp1Changed || lpDynMaxChanged || lpfDynTypeChanged || lp2Changed || lpf2TypeChanged) && lpxOffAndChanged) {
446450
this.GyroSliderUnavailable = true;
447451
this.sliderGyroFilter = 0;
448452
} else {
@@ -479,8 +483,13 @@ TuningSliders.updateFilterSlidersDisplay = function() {
479483
$('.tuningFilterSliders .sliderLabels tr:last-child').show();
480484
}
481485

482-
$('.tuningFilterSliders').toggle(!(this.GyroSliderUnavailable && this.DTermSliderUnavailable));
483-
$('.subtab-filter .slidersDisabled').toggle(this.GyroSliderUnavailable || this.DTermSliderUnavailable);
486+
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
487+
$('.subtab-filter .slidersDisabled').hide();
488+
$('.subtab-filter .sliderGyroDisabled').toggle(this.GyroSliderUnavailable);
489+
$('.subtab-filter .sliderDTermDisabled').toggle(this.DTermSliderUnavailable);
490+
} else {
491+
$('.tuningFilterSliders').toggle(!(this.GyroSliderUnavailable && this.DTermSliderUnavailable));
492+
}
484493
$('.subtab-filter .nonExpertModeSlidersNote').toggle((!this.GyroSliderUnavailable || !this.DTermSliderUnavailable) && !this.expertMode);
485494
this.updateFilterSlidersWarning(this.GyroSliderUnavailable, this.DTermSliderUnavailable);
486495
};

src/js/tabs/pid_tuning.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,10 @@ TABS.pid_tuning.initialize = function (callback) {
716716
self.updateFilterWarning();
717717
});
718718

719+
$('.pid_filter input[name="gyroLowpassDynMinFrequency"]').on('change', () => $('input[id="gyroLowpassDynEnabled"]').prop('checked', false).trigger('change'));
720+
$('.pid_filter input[name="gyroLowpassDynMaxFrequency"]').on('change', () => $('input[id="gyroLowpassDynEnabled"]').prop('checked', false).trigger('change'));
721+
$('.pid_filter input[name="gyroLowpass2Frequency"]').on('change', () => $('input[id="gyroLowpass2Enabled"]').prop('checked', false).trigger('change'));
722+
719723
$('input[id="gyroLowpassDynEnabled"]').change(function() {
720724
const checked = $(this).is(':checked');
721725
let cutoff_min = FILTER_DEFAULT.gyro_lowpass_dyn_min_hz;
@@ -2192,6 +2196,38 @@ TABS.pid_tuning.initialize = function (callback) {
21922196
}
21932197
});
21942198

2199+
// enable Gyro Filter sliders button
2200+
$('a.buttonFilterGyroTuningSlider').click(function() {
2201+
if (TuningSliders.GyroSliderUnavailable) {
2202+
//set Slider mode to ON when re-enabling Sliders
2203+
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
2204+
FC.TUNING_SLIDERS.slider_gyro_filter = 1;
2205+
}
2206+
// update switchery dynamically based on defaults
2207+
$('input[id="gyroLowpassDynEnabled"]').prop('checked', false).click();
2208+
$('input[id="gyroLowpassEnabled"]').prop('checked', true).click();
2209+
$('input[id="gyroLowpass2Enabled"]').prop('checked', false).click();
2210+
TuningSliders.resetGyroFilterSlider();
2211+
self.analyticsChanges['GyroFilterTuningSlider'] = "On";
2212+
}
2213+
});
2214+
2215+
// enable DTerm Filter sliders button
2216+
$('a.buttonFilterDTermTuningSlider').click(function() {
2217+
if (TuningSliders.DTermSliderUnavailable) {
2218+
//set Slider mode to ON when re-enabling Sliders
2219+
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
2220+
FC.TUNING_SLIDERS.slider_dterm_filter = 1;
2221+
}
2222+
// update switchery dynamically based on defaults
2223+
$('input[id="dtermLowpassDynEnabled"]').prop('checked', false).click();
2224+
$('input[id="dtermLowpassEnabled"]').prop('checked', true).click();
2225+
$('input[id="dtermLowpass2Enabled"]').prop('checked', false).click();
2226+
TuningSliders.resetDTermFilterSlider();
2227+
self.analyticsChanges['DTermFilterTuningSlider'] = "On";
2228+
}
2229+
});
2230+
21952231
// update on pid table inputs
21962232
$('#pid_main input').on('input', function() {
21972233
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) {

src/tabs/pid_tuning.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,25 @@
11371137
</th>
11381138
</tr>
11391139
</table>
1140+
1141+
<div class="gui_box sliderGyroDisabled">
1142+
<table class="note-button">
1143+
<td i18n="pidTuningGyroSliderDisabled"></td>
1144+
<td>
1145+
<a href="#" class="buttonFilterGyroTuningSlider regular-button" i18n="pidTuningGyroSliderEnableButton"></a>
1146+
</td>
1147+
</table>
1148+
</div>
1149+
1150+
<div class="gui_box sliderDTermDisabled">
1151+
<table class="note-button">
1152+
<td i18n="pidTuningDTermSliderDisabled"></td>
1153+
<td>
1154+
<a href="#" class="buttonFilterDTermTuningSlider regular-button" i18n="pidTuningDTermSliderEnableButton"></a>
1155+
</td>
1156+
</table>
1157+
</div>
1158+
11401159
<table class="sliderLabels">
11411160
<tr class="xs sliderHeaders">
11421161
<td colspan="5">

0 commit comments

Comments
 (0)