Skip to content

Commit

Permalink
✨ Encoder button noise filter (#23925)
Browse files Browse the repository at this point in the history
  • Loading branch information
Na1w authored and thinkyhead committed May 7, 2022
1 parent 7e88ee8 commit 05dea4e
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,31 @@ class MarlinUI {
#endif

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

#if HAS_ENCODER_NOISE
#ifndef ENCODER_SAMPLES
#define ENCODER_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 hw_button_pressed() {
LOOP_L_N(s, ENCODER_SAMPLES) {
if (!BUTTON_CLICK()) return false;
safe_delay(1);
}
return true;
}
#else
static bool hw_button_pressed() { return BUTTON_CLICK(); }
#endif

static bool button_pressed() { return hw_button_pressed() || TERN0(TOUCH_SCREEN, touch_pressed()); }

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

0 comments on commit 05dea4e

Please sign in to comment.