From bbaccd342eaf5e4cdca6b988c367fa79faacab82 Mon Sep 17 00:00:00 2001
From: Keith Bennett <13375512+thisiskeithb@users.noreply.github.com>
Date: Sat, 30 Jul 2022 17:51:25 -0700
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Encoder=20Noise=20Filter=20(#24538)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Marlin/Configuration.h    | 10 ++++++++++
 Marlin/src/lcd/marlinui.h |  6 +-----
 buildroot/tests/mega2560  |  2 +-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index 2f34ebb7e8d..5e452f3c495 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -2467,6 +2467,16 @@
 //
 //#define REVERSE_SELECT_DIRECTION
 
+//
+// Encoder EMI Noise Filter
+//
+// This option increases encoder samples to filter out phantom encoder clicks caused by EMI noise.
+//
+//#define ENCODER_NOISE_FILTER
+#if ENABLED(ENCODER_NOISE_FILTER)
+  #define ENCODER_SAMPLES 10
+#endif
+
 //
 // Individual Axis Homing
 //
diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h
index 6bd9ec87378..b2a9bb5de95 100644
--- a/Marlin/src/lcd/marlinui.h
+++ b/Marlin/src/lcd/marlinui.h
@@ -694,11 +694,7 @@ public:
 
     static void update_buttons();
 
-    #if HAS_ENCODER_NOISE
-      #ifndef ENCODER_SAMPLES
-        #define ENCODER_SAMPLES 10
-      #endif
-
+    #if ENABLED(ENCODER_NOISE_FILTER)
       /**
        * Some printers may have issues with EMI noise especially using a motherboard with 3.3V logic levels
        * it may cause the logical LOW to float into the undefined region and register as a logical HIGH
diff --git a/buildroot/tests/mega2560 b/buildroot/tests/mega2560
index 89f9e046ce9..536f723b73b 100755
--- a/buildroot/tests/mega2560
+++ b/buildroot/tests/mega2560
@@ -32,7 +32,7 @@ opt_enable AUTO_BED_LEVELING_UBL RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATU
            EEPROM_SETTINGS EEPROM_CHITCHAT GCODE_MACROS CUSTOM_MENU_MAIN FREEZE_FEATURE CANCEL_OBJECTS SOUND_MENU_ITEM \
            MULTI_NOZZLE_DUPLICATION CLASSIC_JERK LIN_ADVANCE EXTRA_LIN_ADVANCE_K QUICK_HOME \
            LCD_SET_PROGRESS_MANUALLY PRINT_PROGRESS_SHOW_DECIMALS SHOW_REMAINING_TIME \
-           BABYSTEPPING BABYSTEP_XY NANODLP_Z_SYNC I2C_POSITION_ENCODERS M114_DETAIL
+           ENCODER_NOISE_FILTER BABYSTEPPING BABYSTEP_XY NANODLP_Z_SYNC I2C_POSITION_ENCODERS M114_DETAIL
 exec_test $1 $2 "Azteeg X3 Pro | EXTRUDERS 5 | RRDFGSC | UBL | LIN_ADVANCE ..." "$3"
 
 #