Skip to content

Commit e4bc56d

Browse files
committed
Enable mouse scroll wheel for sliders
1 parent cc32aaf commit e4bc56d

File tree

4 files changed

+75
-13
lines changed

4 files changed

+75
-13
lines changed

src/css/tabs/pid_tuning.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@
732732
}
733733
}
734734
.slidersWarning {
735+
text-align: center;
735736
background: #ffa3a3;
736737
border: 1px solid red;
737738
font-weight: 600;

src/js/tabs/motors.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -898,12 +898,13 @@ motors.initialize = async function (callback) {
898898
setSlidersDefault();
899899

900900
const ignoreKeys = [
901-
'PageUp',
902-
'PageDown',
903-
'End',
904-
'Home',
905-
'ArrowUp',
906-
'ArrowDown',
901+
33, // Page Up
902+
34, // Page Down
903+
35, // End
904+
36, // Home
905+
38, // Arrow Up
906+
40, // Arrow Down
907+
18, // Alt / Opt
907908
];
908909

909910
motorsEnableTestModeElement.on('change', function () {
@@ -921,7 +922,7 @@ motors.initialize = async function (callback) {
921922

922923
function disableMotorTest(e) {
923924
if (motorsEnableTestModeElement.is(':checked')) {
924-
if (!ignoreKeys.includes(e.code)) {
925+
if (!ignoreKeys.includes(e.which)) {
925926
motorsEnableTestModeElement.prop('checked', false).trigger('change');
926927
document.removeEventListener('keydown', evt => disableMotorTest(evt));
927928
}
@@ -978,6 +979,10 @@ motors.initialize = async function (callback) {
978979
}
979980
});
980981

982+
$('div.sliders input:not(.master)').on('input wheel', function (e) {
983+
self.scrollSlider($(this), e);
984+
});
985+
981986
$('div.sliders input.master').on('input', function () {
982987
const val = $(this).val();
983988

@@ -986,6 +991,10 @@ motors.initialize = async function (callback) {
986991
$('div.sliders input:not(:last):first').trigger('input');
987992
});
988993

994+
$('div.sliders input.master').on('input wheel', function (e) {
995+
self.scrollSlider($(this), e);
996+
});
997+
989998
// check if motors are already spinning
990999
let motorsRunning = false;
9911000

@@ -1316,6 +1325,25 @@ motors.cleanup = function (callback) {
13161325
if (callback) callback();
13171326
};
13181327

1328+
motors.scrollSlider = function(slider, e) {
1329+
if (slider.prop('disabled')) {
1330+
return;
1331+
}
1332+
1333+
if (!(e.originalEvent?.deltaY && e.originalEvent?.altKey)) {
1334+
return;
1335+
}
1336+
1337+
e.preventDefault();
1338+
1339+
const step = 25;
1340+
const delta = e.originalEvent.deltaY > 0 ? -step : step;
1341+
const val = parseInt(slider.val()) + delta;
1342+
const roundedVal = Math.round(val / step) * step;
1343+
slider.val(roundedVal);
1344+
slider.trigger('input');
1345+
};
1346+
13191347
TABS.motors = motors;
13201348
export {
13211349
motors,

src/js/tabs/pid_tuning.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,10 @@ pid_tuning.initialize = function (callback) {
20212021
self.analyticsChanges['PidTuningSliders'] = "On";
20222022
});
20232023

2024+
allPidTuningSliders.each(function (i) {
2025+
self.sliderOnScroll($(this));
2026+
});
2027+
20242028
// reset to middle with double click
20252029
allPidTuningSliders.dblclick(function() {
20262030
const slider = $(this);
@@ -2118,6 +2122,10 @@ pid_tuning.initialize = function (callback) {
21182122
}
21192123
});
21202124

2125+
allFilterTuningSliders.each(function() {
2126+
self.sliderOnScroll($(this));
2127+
});
2128+
21212129
// reset to middle with double click
21222130
allFilterTuningSliders.dblclick(function() {
21232131
const slider = $(this);
@@ -2970,6 +2978,29 @@ pid_tuning.expertModeChanged = function(expertModeEnabled) {
29702978
TuningSliders.setExpertMode(expertModeEnabled);
29712979
};
29722980

2981+
pid_tuning.sliderOnScroll = function(slider, e) {
2982+
slider.parent().on('input wheel', function(e) {
2983+
if (slider.prop('disabled')) {
2984+
return;
2985+
}
2986+
2987+
if (!(e.originalEvent?.deltaY && e.originalEvent?.altKey)) {
2988+
return;
2989+
}
2990+
2991+
e.preventDefault();
2992+
2993+
const step = parseFloat(slider.attr('step'));
2994+
const delta = e.originalEvent.deltaY > 0 ? -step : step;
2995+
const preScrollSliderValue = isInt(slider.val()) ? parseInt(slider.val()) : parseFloat(slider.val());
2996+
const sliderValue = (Math.floor(preScrollSliderValue * 100) + Math.floor(delta * 100)) / 100;
2997+
2998+
slider.val(sliderValue);
2999+
slider.trigger('input');
3000+
slider.trigger('change');
3001+
});
3002+
};
3003+
29733004
TABS.pid_tuning = pid_tuning;
29743005
export {
29753006
pid_tuning,

src/tabs/pid_tuning.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@
6666
<div class="note dMinDisabledNote">
6767
<p i18n="pidTuningDMinDisabledNote"></p>
6868
</div>
69-
<div class="note slidersWarning">
70-
<p i18n="pidTuningSliderWarning"></p>
71-
</div>
7269
<div class="profile_name">
7370
<div class="number">
7471
<label> <input type="text" name="pidProfileName" maxlength="8" style="width:100px;"/> <span
@@ -374,6 +371,10 @@
374371

375372
</table>
376373
</div>
374+
375+
<div class="gui_box topspacer slidersWarning">
376+
<p i18n="pidTuningSliderWarning"></p>
377+
</div>
377378

378379
<div class="gui_box topspacer nonExpertModeSlidersNote">
379380
<p i18n="pidTuningPidSlidersNonExpertMode"></p>
@@ -1183,9 +1184,6 @@
11831184
<div class="note dynamicNotchWarning">
11841185
<p i18n="pidTuningDynamicNotchFilterDisabledWarning"></p>
11851186
</div>
1186-
<div class="note slidersWarning">
1187-
<p i18n="pidTuningSliderWarning"></p>
1188-
</div>
11891187
<div class="gui_box slidersDisabled">
11901188
<table class="note-button">
11911189
<td i18n="pidTuningSlidersDisabled"></td>
@@ -1255,6 +1253,10 @@
12551253
</table>
12561254
</div>
12571255

1256+
<div class="gui_box topspacer slidersWarning">
1257+
<p i18n="pidTuningSliderWarning"></p>
1258+
</div>
1259+
12581260
<div class="gui_box topspacer nonExpertModeSlidersNote">
12591261
<p i18n="pidTuningFilterSlidersNonExpertMode"></p>
12601262
</div>

0 commit comments

Comments
 (0)