Skip to content

Commit a8cf290

Browse files
authored
✨ Encoder button noise filter (MarlinFirmware#23925)
1 parent 032e5c9 commit a8cf290

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Marlin/src/lcd/marlinui.h

+25-1
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,31 @@ class MarlinUI {
680680
#endif
681681

682682
static void update_buttons();
683-
static bool button_pressed() { return BUTTON_CLICK() || TERN(TOUCH_SCREEN, touch_pressed(), false); }
683+
684+
#if HAS_ENCODER_NOISE
685+
#ifndef ENCODER_SAMPLES
686+
#define ENCODER_SAMPLES 10
687+
#endif
688+
689+
/**
690+
* Some printers may have issues with EMI noise especially using a motherboard with 3.3V logic levels
691+
* it may cause the logical LOW to float into the undefined region and register as a logical HIGH
692+
* causing it to errorenously register as if someone clicked the button and in worst case make the printer
693+
* unusable in practice.
694+
*/
695+
static bool hw_button_pressed() {
696+
LOOP_L_N(s, ENCODER_SAMPLES) {
697+
if (!BUTTON_CLICK()) return false;
698+
safe_delay(1);
699+
}
700+
return true;
701+
}
702+
#else
703+
static bool hw_button_pressed() { return BUTTON_CLICK(); }
704+
#endif
705+
706+
static bool button_pressed() { return hw_button_pressed() || TERN0(TOUCH_SCREEN, touch_pressed()); }
707+
684708
#if EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
685709
static void wait_for_release();
686710
#endif

0 commit comments

Comments
 (0)