@@ -398,12 +398,7 @@ void MarlinUI::init() {
398
398
bool MarlinUI::screen_changed;
399
399
400
400
#if ENABLED(ENCODER_RATE_MULTIPLIER)
401
- bool MarlinUI::encoderRateMultiplierEnabled;
402
- millis_t MarlinUI::lastEncoderMovementMillis = 0 ;
403
- void MarlinUI::enable_encoder_multiplier (const bool onoff) {
404
- encoderRateMultiplierEnabled = onoff;
405
- lastEncoderMovementMillis = 0 ;
406
- }
401
+ bool MarlinUI::encoder_multiplier_enabled;
407
402
#endif
408
403
409
404
#if ANY(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
@@ -614,8 +609,6 @@ void MarlinUI::init() {
614
609
615
610
void MarlinUI::status_screen () {
616
611
617
- TERN_ (HAS_MARLINUI_MENU, ENCODER_RATE_MULTIPLY (false ));
618
-
619
612
#if BASIC_PROGRESS_BAR
620
613
621
614
//
@@ -1053,41 +1046,37 @@ void MarlinUI::init() {
1053
1046
1054
1047
#if ALL(HAS_MARLINUI_MENU, ENCODER_RATE_MULTIPLIER)
1055
1048
1056
- int32_t encoderMultiplier = 1 ;
1057
-
1058
- if (encoderRateMultiplierEnabled) {
1059
- const float encoderMovementSteps = float (abs_diff) / epps;
1060
-
1061
- if (lastEncoderMovementMillis) {
1062
- // Note that the rate is always calculated between two passes through the
1063
- // loop and that the abs of the encoderDiff value is tracked.
1064
- const float encoderStepRate = encoderMovementSteps / float (ms - lastEncoderMovementMillis) * 1000 ;
1065
-
1066
- if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100 ;
1067
- else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10 ;
1068
-
1069
- // Enable to output the encoder steps per second value
1070
- // #define ENCODER_RATE_MULTIPLIER_DEBUG
1071
- #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
1072
- SERIAL_ECHO_START ();
1073
- SERIAL_ECHOPGM (" Enc Step Rate: " , encoderStepRate);
1074
- SERIAL_ECHOPGM (" Multiplier: " , encoderMultiplier);
1075
- SERIAL_ECHOPGM (" ENCODER_10X_STEPS_PER_SEC: " , ENCODER_10X_STEPS_PER_SEC);
1076
- SERIAL_ECHOPGM (" ENCODER_100X_STEPS_PER_SEC: " , ENCODER_100X_STEPS_PER_SEC);
1077
- SERIAL_EOL ();
1078
- #endif
1079
- }
1080
-
1081
- lastEncoderMovementMillis = ms;
1082
- } // encoderRateMultiplierEnabled
1049
+ int32_t encoder_multiplier = 1 ;
1050
+
1051
+ if (encoder_multiplier_enabled) {
1052
+ // Note that the rate is always calculated between two passes through the
1053
+ // loop and that the abs of the encoderDiff value is tracked.
1054
+ static millis_t encoder_mult_prev_ms = 0 ;
1055
+ const float encoderStepRate = ((float (abs_diff) / float (epps)) * 1000 .0f ) / float (ms - encoder_mult_prev_ms);
1056
+ encoder_mult_prev_ms = ms;
1057
+
1058
+ if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoder_multiplier = 100 ;
1059
+ else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoder_multiplier = 10 ;
1060
+
1061
+ // Enable to output the encoder steps per second value
1062
+ // #define ENCODER_RATE_MULTIPLIER_DEBUG
1063
+ #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 ();
1070
+ #endif
1071
+ }
1083
1072
1084
1073
#else
1085
1074
1086
- constexpr int32_t encoderMultiplier = 1 ;
1075
+ constexpr int32_t encoder_multiplier = 1 ;
1087
1076
1088
1077
#endif // ENCODER_RATE_MULTIPLIER
1089
1078
1090
- if (can_encode ()) encoderPosition += (encoderDiff * encoderMultiplier ) / epps;
1079
+ if (can_encode ()) encoderPosition += (encoderDiff * encoder_multiplier ) / epps;
1091
1080
1092
1081
encoderDiff = 0 ;
1093
1082
}
0 commit comments