🚸 Adjust encoder multiplier

This commit is contained in:
Scott Lahteine 2024-02-07 18:25:13 -06:00
parent 371fb5a256
commit 4aa48beb37
6 changed files with 40 additions and 53 deletions

View file

@ -127,7 +127,7 @@ EncoderState encoderReceiveAnalyze() {
#if ENABLED(ENCODER_RATE_MULTIPLIER) #if ENABLED(ENCODER_RATE_MULTIPLIER)
millis_t ms = millis(); millis_t ms = millis();
int32_t encoderMultiplier = 1; int32_t encoder_multiplier = 1;
// if must encoder rati multiplier // if must encoder rati multiplier
if (encoderRate.enabled) { if (encoderRate.enabled) {
@ -137,10 +137,10 @@ EncoderState encoderReceiveAnalyze() {
// Note that the rate is always calculated between two passes through the // Note that the rate is always calculated between two passes through the
// loop and that the abs of the temp_diff value is tracked. // loop and that the abs of the temp_diff value is tracked.
const float encoderStepRate = encoderMovementSteps / float(ms - encoderRate.lastEncoderTime) * 1000; const float encoderStepRate = encoderMovementSteps / float(ms - encoderRate.lastEncoderTime) * 1000;
if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100; if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoder_multiplier = 100;
else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10; else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoder_multiplier = 10;
#if ENCODER_5X_STEPS_PER_SEC #if ENCODER_5X_STEPS_PER_SEC
else if (encoderStepRate >= ENCODER_5X_STEPS_PER_SEC) encoderMultiplier = 5; else if (encoderStepRate >= ENCODER_5X_STEPS_PER_SEC) encoder_multiplier = 5;
#endif #endif
} }
encoderRate.lastEncoderTime = ms; encoderRate.lastEncoderTime = ms;
@ -148,12 +148,12 @@ EncoderState encoderReceiveAnalyze() {
#else #else
constexpr int32_t encoderMultiplier = 1; constexpr int32_t encoder_multiplier = 1;
#endif #endif
// encoderRate.encoderMoveValue += (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP); // encoderRate.encoderMoveValue += (temp_diff * encoder_multiplier) / (ENCODER_PULSES_PER_STEP);
encoderRate.encoderMoveValue = (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP); encoderRate.encoderMoveValue = (temp_diff * encoder_multiplier) / (ENCODER_PULSES_PER_STEP);
if (encoderRate.encoderMoveValue < 0) encoderRate.encoderMoveValue = -encoderRate.encoderMoveValue; if (encoderRate.encoderMoveValue < 0) encoderRate.encoderMoveValue = -encoderRate.encoderMoveValue;
temp_diff = 0; temp_diff = 0;

View file

@ -398,12 +398,7 @@ void MarlinUI::init() {
bool MarlinUI::screen_changed; bool MarlinUI::screen_changed;
#if ENABLED(ENCODER_RATE_MULTIPLIER) #if ENABLED(ENCODER_RATE_MULTIPLIER)
bool MarlinUI::encoderRateMultiplierEnabled; bool MarlinUI::encoder_multiplier_enabled;
millis_t MarlinUI::lastEncoderMovementMillis = 0;
void MarlinUI::enable_encoder_multiplier(const bool onoff) {
encoderRateMultiplierEnabled = onoff;
lastEncoderMovementMillis = 0;
}
#endif #endif
#if ANY(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION) #if ANY(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
@ -614,8 +609,6 @@ void MarlinUI::init() {
void MarlinUI::status_screen() { void MarlinUI::status_screen() {
TERN_(HAS_MARLINUI_MENU, ENCODER_RATE_MULTIPLY(false));
#if BASIC_PROGRESS_BAR #if BASIC_PROGRESS_BAR
// //
@ -1053,41 +1046,37 @@ void MarlinUI::init() {
#if ALL(HAS_MARLINUI_MENU, ENCODER_RATE_MULTIPLIER) #if ALL(HAS_MARLINUI_MENU, ENCODER_RATE_MULTIPLIER)
int32_t encoderMultiplier = 1; int32_t encoder_multiplier = 1;
if (encoderRateMultiplierEnabled) { if (encoder_multiplier_enabled) {
const float encoderMovementSteps = float(abs_diff) / epps; // Note that the rate is always calculated between two passes through the
// loop and that the abs of the encoderDiff value is tracked.
static millis_t encoder_mult_prev_ms = 0;
const float encoderStepRate = ((float(abs_diff) / float(epps)) * 1000.0f) / float(ms - encoder_mult_prev_ms);
encoder_mult_prev_ms = ms;
if (lastEncoderMovementMillis) { if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoder_multiplier = 100;
// Note that the rate is always calculated between two passes through the else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoder_multiplier = 10;
// loop and that the abs of the encoderDiff value is tracked.
const float encoderStepRate = encoderMovementSteps / float(ms - lastEncoderMovementMillis) * 1000;
if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100; // Enable to output the encoder steps per second value
else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10; //#define ENCODER_RATE_MULTIPLIER_DEBUG
#if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
// Enable to output the encoder steps per second value SERIAL_ECHO_START();
//#define ENCODER_RATE_MULTIPLIER_DEBUG SERIAL_ECHOPGM("Enc Step Rate: ", encoderStepRate);
#if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG) SERIAL_ECHOPGM(" Multiplier: ", encoder_multiplier);
SERIAL_ECHO_START(); SERIAL_ECHOPGM(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
SERIAL_ECHOPGM("Enc Step Rate: ", encoderStepRate); SERIAL_ECHOPGM(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
SERIAL_ECHOPGM(" Multiplier: ", encoderMultiplier); SERIAL_EOL();
SERIAL_ECHOPGM(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC); #endif
SERIAL_ECHOPGM(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC); }
SERIAL_EOL();
#endif
}
lastEncoderMovementMillis = ms;
} // encoderRateMultiplierEnabled
#else #else
constexpr int32_t encoderMultiplier = 1; constexpr int32_t encoder_multiplier = 1;
#endif // ENCODER_RATE_MULTIPLIER #endif // ENCODER_RATE_MULTIPLIER
if (can_encode()) encoderPosition += (encoderDiff * encoderMultiplier) / epps; if (can_encode()) encoderPosition += (encoderDiff * encoder_multiplier) / epps;
encoderDiff = 0; encoderDiff = 0;
} }

View file

@ -658,6 +658,13 @@ public:
TERN(HAS_SCREEN_TIMEOUT, return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS, UNUSED(ms)); TERN(HAS_SCREEN_TIMEOUT, return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS, UNUSED(ms));
} }
#if ALL(HAS_MARLINUI_MENU, ENCODER_RATE_MULTIPLIER)
static bool encoder_multiplier_enabled;
static void enable_encoder_multiplier(const bool onoff) { encoder_multiplier_enabled = onoff; }
#else
static void enable_encoder_multiplier(const bool) {}
#endif
#if HAS_MARLINUI_MENU #if HAS_MARLINUI_MENU
#if HAS_TOUCH_BUTTONS #if HAS_TOUCH_BUTTONS
@ -667,15 +674,6 @@ public:
static constexpr uint8_t touch_buttons = 0; static constexpr uint8_t touch_buttons = 0;
#endif #endif
#if ENABLED(ENCODER_RATE_MULTIPLIER)
static bool encoderRateMultiplierEnabled;
static millis_t lastEncoderMovementMillis;
static void enable_encoder_multiplier(const bool onoff);
#define ENCODER_RATE_MULTIPLY(F) (ui.encoderRateMultiplierEnabled = F)
#else
#define ENCODER_RATE_MULTIPLY(F) NOOP
#endif
// Manual Movement // Manual Movement
static ManualMove manual_move; static ManualMove manual_move;
static bool can_show_slider() { return !external_control && currentScreen != manual_move.screen_ptr; } static bool can_show_slider() { return !external_control && currentScreen != manual_move.screen_ptr; }

View file

@ -222,6 +222,7 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co
TERN_(HAS_MARLINUI_U8GLIB, drawing_screen = false); TERN_(HAS_MARLINUI_U8GLIB, drawing_screen = false);
TERN_(HAS_MARLINUI_MENU, encoder_direction_normal()); TERN_(HAS_MARLINUI_MENU, encoder_direction_normal());
enable_encoder_multiplier(false);
set_selection(false); set_selection(false);
} }
@ -255,7 +256,6 @@ void MarlinUI::synchronize(FSTR_P const fmsg/*=nullptr*/) {
*/ */
void scroll_screen(const uint8_t limit, const bool is_menu) { void scroll_screen(const uint8_t limit, const bool is_menu) {
ui.encoder_direction_menus(); ui.encoder_direction_menus();
ENCODER_RATE_MULTIPLY(false);
if (int32_t(ui.encoderPosition) < 0) ui.encoderPosition = 0; if (int32_t(ui.encoderPosition) < 0) ui.encoderPosition = 0;
if (ui.first_page) { if (ui.first_page) {
encoderLine = ui.encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM); encoderLine = ui.encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM);

View file

@ -287,8 +287,8 @@ class MenuItem_bool : public MenuEditItemBase {
#define _MENU_INNER_F(TYPE, USE_MULTIPLIER, FLABEL, V...) do { \ #define _MENU_INNER_F(TYPE, USE_MULTIPLIER, FLABEL, V...) do { \
FSTR_P const flabel = FLABEL; \ FSTR_P const flabel = FLABEL; \
if (CLICKED()) { \ if (CLICKED()) { \
_MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
MenuItem_##TYPE::action(flabel, ##V); \ MenuItem_##TYPE::action(flabel, ##V); \
_MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
if (ui.screen_changed) return; \ if (ui.screen_changed) return; \
} \ } \
if (ui.should_draw()) \ if (ui.should_draw()) \

View file

@ -43,7 +43,7 @@
void _lcd_mixer_gradient_z_edit(const bool isend) { void _lcd_mixer_gradient_z_edit(const bool isend) {
ui.defer_status_screen(); ui.defer_status_screen();
ENCODER_RATE_MULTIPLY(true); ui.enable_encoder_multiplier(true);
float &zvar = isend ? mixer.gradient.end_z : mixer.gradient.start_z; float &zvar = isend ? mixer.gradient.end_z : mixer.gradient.start_z;