Skip to content

Commit 76b5688

Browse files
committed
🚸 Optional encoder multipliers
1 parent 1e8fbb7 commit 76b5688

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

Marlin/src/inc/Conditionals_adv.h

+18
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,24 @@
869869
#define HAS_ENCODER_ACTION 1
870870
#endif
871871

872+
#if ENABLED(ENCODER_RATE_MULTIPLIER)
873+
#ifndef ENCODER_5X_STEPS_PER_SEC
874+
#define ENCODER_5X_STEPS_PER_SEC 0
875+
#endif
876+
#ifndef ENCODER_10X_STEPS_PER_SEC
877+
#define ENCODER_10X_STEPS_PER_SEC 0
878+
#endif
879+
#ifndef ENCODER_100X_STEPS_PER_SEC
880+
#define ENCODER_100X_STEPS_PER_SEC 0
881+
#endif
882+
#if !((HAS_MARLINUI_MENU || HAS_DWIN_E3V2) && (ENCODER_5X_STEPS_PER_SEC || ENCODER_10X_STEPS_PER_SEC || ENCODER_100X_STEPS_PER_SEC))
883+
#undef ENCODER_RATE_MULTIPLIER
884+
#undef ENCODER_5X_STEPS_PER_SEC
885+
#undef ENCODER_10X_STEPS_PER_SEC
886+
#undef ENCODER_100X_STEPS_PER_SEC
887+
#endif
888+
#endif
889+
872890
#if STATUS_MESSAGE_TIMEOUT_SEC > 0
873891
#define HAS_STATUS_MESSAGE_TIMEOUT 1
874892
#endif

Marlin/src/lcd/e3v2/common/encoder.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@ EncoderState encoderReceiveAnalyze() {
137137
// Note that the rate is always calculated between two passes through the
138138
// loop and that the abs of the temp_diff value is tracked.
139139
const float encoderStepRate = encoderMovementSteps / float(ms - encoderRate.lastEncoderTime) * 1000;
140-
if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoder_multiplier = 100;
141-
else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoder_multiplier = 10;
142-
#if ENCODER_5X_STEPS_PER_SEC
143-
else if (encoderStepRate >= ENCODER_5X_STEPS_PER_SEC) encoder_multiplier = 5;
144-
#endif
140+
if (ENCODER_100X_STEPS_PER_SEC > 0 && encoderStepRate >= ENCODER_100X_STEPS_PER_SEC)
141+
encoder_multiplier = 100;
142+
else if (ENCODER_10X_STEPS_PER_SEC > 0 && encoderStepRate >= ENCODER_10X_STEPS_PER_SEC)
143+
encoder_multiplier = 10;
144+
else if (ENCODER_5X_STEPS_PER_SEC > 0 && encoderStepRate >= ENCODER_5X_STEPS_PER_SEC)
145+
encoder_multiplier = 5;
145146
}
146147
encoderRate.lastEncoderTime = ms;
147148
}

Marlin/src/lcd/marlinui.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -1055,18 +1055,23 @@ void MarlinUI::init() {
10551055
const float encoderStepRate = ((float(abs_diff) / float(epps)) * 1000.0f) / float(ms - encoder_mult_prev_ms);
10561056
encoder_mult_prev_ms = ms;
10571057

1058-
if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoder_multiplier = 100;
1059-
else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoder_multiplier = 10;
1058+
if (ENCODER_100X_STEPS_PER_SEC > 0 && encoderStepRate >= ENCODER_100X_STEPS_PER_SEC)
1059+
encoder_multiplier = 100;
1060+
else if (ENCODER_10X_STEPS_PER_SEC > 0 && encoderStepRate >= ENCODER_10X_STEPS_PER_SEC)
1061+
encoder_multiplier = 10;
1062+
else if (ENCODER_5X_STEPS_PER_SEC > 0 && encoderStepRate >= ENCODER_5X_STEPS_PER_SEC)
1063+
encoder_multiplier = 5;
10601064

10611065
// Enable to output the encoder steps per second value
10621066
//#define ENCODER_RATE_MULTIPLIER_DEBUG
10631067
#if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
1064-
SERIAL_ECHO_START();
1065-
SERIAL_ECHOPGM("Enc Step Rate: ", encoderStepRate);
1066-
SERIAL_ECHOPGM(" Multiplier: ", encoder_multiplier);
1067-
SERIAL_ECHOPGM(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
1068-
SERIAL_ECHOPGM(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
1069-
SERIAL_EOL();
1068+
SERIAL_ECHO_MSG(
1069+
"Enc Step Rate: ", encoderStepRate,
1070+
" Mult: ", encoder_multiplier,
1071+
" 5X Steps: ", ENCODER_5X_STEPS_PER_SEC,
1072+
" 10X Steps: ", ENCODER_10X_STEPS_PER_SEC,
1073+
" 100X Steps: ", ENCODER_100X_STEPS_PER_SEC
1074+
);
10701075
#endif
10711076
}
10721077

0 commit comments

Comments
 (0)