Skip to content

Commit

Permalink
🚸 Optional encoder multipliers
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Feb 10, 2024
1 parent 1e8fbb7 commit 76b5688
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
18 changes: 18 additions & 0 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,24 @@
#define HAS_ENCODER_ACTION 1
#endif

#if ENABLED(ENCODER_RATE_MULTIPLIER)
#ifndef ENCODER_5X_STEPS_PER_SEC
#define ENCODER_5X_STEPS_PER_SEC 0
#endif
#ifndef ENCODER_10X_STEPS_PER_SEC
#define ENCODER_10X_STEPS_PER_SEC 0
#endif
#ifndef ENCODER_100X_STEPS_PER_SEC
#define ENCODER_100X_STEPS_PER_SEC 0
#endif
#if !((HAS_MARLINUI_MENU || HAS_DWIN_E3V2) && (ENCODER_5X_STEPS_PER_SEC || ENCODER_10X_STEPS_PER_SEC || ENCODER_100X_STEPS_PER_SEC))
#undef ENCODER_RATE_MULTIPLIER
#undef ENCODER_5X_STEPS_PER_SEC
#undef ENCODER_10X_STEPS_PER_SEC
#undef ENCODER_100X_STEPS_PER_SEC
#endif
#endif

#if STATUS_MESSAGE_TIMEOUT_SEC > 0
#define HAS_STATUS_MESSAGE_TIMEOUT 1
#endif
Expand Down
11 changes: 6 additions & 5 deletions Marlin/src/lcd/e3v2/common/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ EncoderState encoderReceiveAnalyze() {
// Note that the rate is always calculated between two passes through the
// loop and that the abs of the temp_diff value is tracked.
const float encoderStepRate = encoderMovementSteps / float(ms - encoderRate.lastEncoderTime) * 1000;
if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoder_multiplier = 100;
else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoder_multiplier = 10;
#if ENCODER_5X_STEPS_PER_SEC
else if (encoderStepRate >= ENCODER_5X_STEPS_PER_SEC) encoder_multiplier = 5;
#endif
if (ENCODER_100X_STEPS_PER_SEC > 0 && encoderStepRate >= ENCODER_100X_STEPS_PER_SEC)
encoder_multiplier = 100;
else if (ENCODER_10X_STEPS_PER_SEC > 0 && encoderStepRate >= ENCODER_10X_STEPS_PER_SEC)
encoder_multiplier = 10;
else if (ENCODER_5X_STEPS_PER_SEC > 0 && encoderStepRate >= ENCODER_5X_STEPS_PER_SEC)
encoder_multiplier = 5;
}
encoderRate.lastEncoderTime = ms;
}
Expand Down
21 changes: 13 additions & 8 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,18 +1055,23 @@ void MarlinUI::init() {
const float encoderStepRate = ((float(abs_diff) / float(epps)) * 1000.0f) / float(ms - encoder_mult_prev_ms);
encoder_mult_prev_ms = ms;

if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoder_multiplier = 100;
else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoder_multiplier = 10;
if (ENCODER_100X_STEPS_PER_SEC > 0 && encoderStepRate >= ENCODER_100X_STEPS_PER_SEC)
encoder_multiplier = 100;
else if (ENCODER_10X_STEPS_PER_SEC > 0 && encoderStepRate >= ENCODER_10X_STEPS_PER_SEC)
encoder_multiplier = 10;
else if (ENCODER_5X_STEPS_PER_SEC > 0 && encoderStepRate >= ENCODER_5X_STEPS_PER_SEC)
encoder_multiplier = 5;

// Enable to output the encoder steps per second value
//#define ENCODER_RATE_MULTIPLIER_DEBUG
#if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
SERIAL_ECHO_START();
SERIAL_ECHOPGM("Enc Step Rate: ", encoderStepRate);
SERIAL_ECHOPGM(" Multiplier: ", encoder_multiplier);
SERIAL_ECHOPGM(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
SERIAL_ECHOPGM(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
SERIAL_EOL();
SERIAL_ECHO_MSG(
"Enc Step Rate: ", encoderStepRate,
" Mult: ", encoder_multiplier,
" 5X Steps: ", ENCODER_5X_STEPS_PER_SEC,
" 10X Steps: ", ENCODER_10X_STEPS_PER_SEC,
" 100X Steps: ", ENCODER_100X_STEPS_PER_SEC
);
#endif
}

Expand Down

0 comments on commit 76b5688

Please sign in to comment.