diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index a443d4b302..95c35f52f8 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2831,6 +2831,7 @@ // Set this option if CLOCKWISE causes values to DECREASE // //#define REVERSE_ENCODER_DIRECTION +//#define REVERSIBLE_ENCODER // Enable menu option to toggle direction // // This option reverses the encoder direction for navigating LCD menus. diff --git a/Marlin/src/lcd/dwin/proui/dwin.cpp b/Marlin/src/lcd/dwin/proui/dwin.cpp index ae94ee0025..8bfb907b60 100644 --- a/Marlin/src/lcd/dwin/proui/dwin.cpp +++ b/Marlin/src/lcd/dwin/proui/dwin.cpp @@ -1904,6 +1904,7 @@ void dwinSetDataDefaults() { applyLEDColor(); #endif TERN_(HAS_GCODE_PREVIEW, hmiData.enablePreview = true); + TERN_(REVERSIBLE_ENCODER, ui.reverse_encoder = false); } void dwinCopySettingsTo(char * const buff) { @@ -2741,6 +2742,10 @@ void applyMaxAccel() { planner.set_max_acceleration(hmiValue.axis, menuData.valu void setAddRecover() { setPFloatOnClick(-5, 5, UNITFDIGITS); } #endif +#if ENABLED(REVERSIBLE_ENCODER) + void toggleReverseEncoder() { toggleCheckboxLine(ui.reverse_encoder); } +#endif + // Special Menuitem Drawing functions ================================================= void onDrawBack(MenuItem* menuitem, int8_t line) { @@ -3265,7 +3270,7 @@ void drawAdvancedSettingsMenu() { constexpr uint8_t items = (1 + COUNT_ENABLED(EEPROM_SETTINGS, HAS_MESH, HAS_BED_PROBE, HAS_HOME_OFFSET, HAS_TRINAMIC_CONFIG, HAS_ESDIAG, \ HAS_LOCKSCREEN, EDITABLE_DISPLAY_TIMEOUT, SOUND_MENU_ITEM, POWER_LOSS_RECOVERY, HAS_GCODE_PREVIEW, \ - PROUI_MEDIASORT, BAUD_RATE_GCODE, HAS_CUSTOM_COLORS) + PROUI_MEDIASORT, BAUD_RATE_GCODE, HAS_CUSTOM_COLORS, REVERSIBLE_ENCODER) + 1 + (ENABLED(PIDTEMP) && ANY(PID_AUTOTUNE_MENU, PID_EDIT_MENU)) + ANY(MPC_EDIT_MENU, MPC_AUTOTUNE_MENU) @@ -3338,6 +3343,9 @@ void drawAdvancedSettingsMenu() { #if HAS_CUSTOM_COLORS MENU_ITEM(ICON_Scolor, MSG_COLORS_SELECT, onDrawSubMenu, drawSelectColorsMenu); #endif + #if ENABLED(REVERSIBLE_ENCODER) + EDIT_ITEM(ICON_Motion, MSG_REVERSE_ENCODER, onDrawChkbMenu, toggleReverseEncoder, &ui.reverse_encoder); + #endif } ui.reset_status(true); updateMenu(advancedSettingsMenu); diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index d1d4bfd0a6..3198548e17 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -71,6 +71,10 @@ MarlinUI ui; constexpr uint8_t epps = ENCODER_PULSES_PER_STEP; +#if ENABLED(REVERSIBLE_ENCODER) + bool MarlinUI::reverse_encoder; // = false +#endif + #if HAS_STATUS_MESSAGE #if ENABLED(STATUS_MESSAGE_SCROLLING) uint8_t MarlinUI::status_scroll_offset; // = 0 diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index 8ec25ab5c6..5686b9d20d 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -210,6 +210,10 @@ public: TERN_(HAS_MARLINUI_MENU, currentScreen = status_screen); } + #if ENABLED(REVERSIBLE_ENCODER) + static bool reverse_encoder; // Flag to reverse the encoder direction + #endif + static void init(); static void reinit_lcd() { TERN_(REINIT_NOISY_LCD, init_lcd()); } @@ -860,20 +864,26 @@ public: #define ENCODERBASE (TERN(REVERSE_ENCODER_DIRECTION, -1, +1)) - #if ANY(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION) + #if ANY(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION, REVERSIBLE_ENCODER) static int8_t encoderDirection; #else static constexpr int8_t encoderDirection = ENCODERBASE; #endif FORCE_INLINE static void encoder_direction_normal() { - #if ANY(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION) + #if ANY(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION, REVERSIBLE_ENCODER) encoderDirection = ENCODERBASE; #endif } FORCE_INLINE static void encoder_direction_menus() { - TERN_(REVERSE_MENU_DIRECTION, encoderDirection = -(ENCODERBASE)); + constexpr int8_t dir = TERN(REVERSE_MENU_DIRECTION, -(ENCODERBASE), ENCODERBASE); + #if ENABLED(REVERSIBLE_ENCODER) + encoderDirection = reverse_encoder ? -dir : dir; + #elif ENABLED(REVERSE_MENU_DIRECTION) + encoderDirection = dir; + #endif + UNUSED(dir); } FORCE_INLINE static void encoder_direction_select() { diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index e48b215b77..4bce5e46de 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -622,6 +622,13 @@ typedef struct SettingsDataStruct { bool sound_on; #endif + // + // Encoder Reverse + // + #if ENABLED(REVERSIBLE_ENCODER) + bool reverse_encoder; + #endif + // // Fan tachometer check // @@ -1741,6 +1748,13 @@ void MarlinSettings::postprocess() { EEPROM_WRITE(ui.sound_on); #endif + // + // Encoder Reverse + // + #if ENABLED(REVERSIBLE_ENCODER) + EEPROM_WRITE(ui.reverse_encoder); + #endif + // // Fan tachometer check // @@ -2864,6 +2878,14 @@ void MarlinSettings::postprocess() { EEPROM_READ(ui.sound_on); #endif + // + // Encoder Reverse + // + #if ENABLED(REVERSIBLE_ENCODER) + _FIELD_TEST(reverse_encoder); + EEPROM_READ(ui.reverse_encoder); + #endif + // // Fan tachometer check // @@ -3453,6 +3475,13 @@ void MarlinSettings::reset() { ui.sound_on = ENABLED(SOUND_ON_DEFAULT); #endif + // + // Encoder Reverse + // + #if ENABLED(REVERSIBLE_ENCODER) + ui.reverse_encoder = false; + #endif + // // Magnetic Parking Extruder //