🚸 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)
millis_t ms = millis();
int32_t encoderMultiplier = 1;
int32_t encoder_multiplier = 1;
// if must encoder rati multiplier
if (encoderRate.enabled) {
@ -137,10 +137,10 @@ 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) encoderMultiplier = 100;
else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
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) encoderMultiplier = 5;
else if (encoderStepRate >= ENCODER_5X_STEPS_PER_SEC) encoder_multiplier = 5;
#endif
}
encoderRate.lastEncoderTime = ms;
@ -148,12 +148,12 @@ EncoderState encoderReceiveAnalyze() {
#else
constexpr int32_t encoderMultiplier = 1;
constexpr int32_t encoder_multiplier = 1;
#endif
// encoderRate.encoderMoveValue += (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
encoderRate.encoderMoveValue = (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
// encoderRate.encoderMoveValue += (temp_diff * encoder_multiplier) / (ENCODER_PULSES_PER_STEP);
encoderRate.encoderMoveValue = (temp_diff * encoder_multiplier) / (ENCODER_PULSES_PER_STEP);
if (encoderRate.encoderMoveValue < 0) encoderRate.encoderMoveValue = -encoderRate.encoderMoveValue;
temp_diff = 0;

View file

@ -398,12 +398,7 @@ void MarlinUI::init() {
bool MarlinUI::screen_changed;
#if ENABLED(ENCODER_RATE_MULTIPLIER)
bool MarlinUI::encoderRateMultiplierEnabled;
millis_t MarlinUI::lastEncoderMovementMillis = 0;
void MarlinUI::enable_encoder_multiplier(const bool onoff) {
encoderRateMultiplierEnabled = onoff;
lastEncoderMovementMillis = 0;
}
bool MarlinUI::encoder_multiplier_enabled;
#endif
#if ANY(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
@ -614,8 +609,6 @@ void MarlinUI::init() {
void MarlinUI::status_screen() {
TERN_(HAS_MARLINUI_MENU, ENCODER_RATE_MULTIPLY(false));
#if BASIC_PROGRESS_BAR
//
@ -1053,41 +1046,37 @@ void MarlinUI::init() {
#if ALL(HAS_MARLINUI_MENU, ENCODER_RATE_MULTIPLIER)
int32_t encoderMultiplier = 1;
int32_t encoder_multiplier = 1;
if (encoderRateMultiplierEnabled) {
const float encoderMovementSteps = float(abs_diff) / epps;
if (encoder_multiplier_enabled) {
// 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) {
// Note that the rate is always calculated between two passes through the
// 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) encoder_multiplier = 100;
else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoder_multiplier = 10;
if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
// 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: ", encoderMultiplier);
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();
#endif
}
lastEncoderMovementMillis = ms;
} // encoderRateMultiplierEnabled
// 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();
#endif
}
#else
constexpr int32_t encoderMultiplier = 1;
constexpr int32_t encoder_multiplier = 1;
#endif // ENCODER_RATE_MULTIPLIER
if (can_encode()) encoderPosition += (encoderDiff * encoderMultiplier) / epps;
if (can_encode()) encoderPosition += (encoderDiff * encoder_multiplier) / epps;
encoderDiff = 0;
}

View file

@ -658,6 +658,13 @@ public:
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_TOUCH_BUTTONS
@ -667,15 +674,6 @@ public:
static constexpr uint8_t touch_buttons = 0;
#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
static ManualMove manual_move;
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_MENU, encoder_direction_normal());
enable_encoder_multiplier(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) {
ui.encoder_direction_menus();
ENCODER_RATE_MULTIPLY(false);
if (int32_t(ui.encoderPosition) < 0) ui.encoderPosition = 0;
if (ui.first_page) {
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 { \
FSTR_P const flabel = FLABEL; \
if (CLICKED()) { \
_MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
MenuItem_##TYPE::action(flabel, ##V); \
_MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
if (ui.screen_changed) return; \
} \
if (ui.should_draw()) \

View file

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