Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for EMI noise filter for button state #23925

Merged
merged 5 commits into from
Mar 21, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for EMI noise filter for button state
  • Loading branch information
Na1w committed Mar 19, 2022
commit 09e420921703b021707d96aa2a4167ef01617b7e
23 changes: 22 additions & 1 deletion Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
@@ -680,7 +680,28 @@ class MarlinUI {
#endif

static void update_buttons();
static bool button_pressed() { return BUTTON_CLICK() || TERN(TOUCH_SCREEN, touch_pressed(), false); }

#ifdef HAS_ENCODER_EMI_NOISE_PROBLEM
#ifndef EMI_NOISE_FILTER_SAMPLES
#define EMI_NOISE_FILTER_SAMPLES (10)
#endif
/*
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
causing it to errorenously register as if someone clicked the button and in worst case make the printer
unusable in practice.
*/
static bool button_pressed() {
for(auto sample=0;sample<EMI_NOISE_FILTER_SAMPLES;sample++) {
if(!BUTTON_CLICK()) { return false;}
safe_delay(1);
}
return true || TERN(TOUCH_SCREEN, touch_pressed(), false);
}
#else
static bool button_pressed() { return BUTTON_CLICK() || TERN(TOUCH_SCREEN, touch_pressed(), false); }
#endif

#if EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
static void wait_for_release();
#endif