Skip to content

Commit

Permalink
Adjustable ADC debounce delay (#16264)
Browse files Browse the repository at this point in the history
  • Loading branch information
soligen2010 authored and thinkyhead committed Jan 16, 2020
1 parent 7481563 commit 2d7f94c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,13 @@
//#define TFT_BTOKMENU_COLOR 0x145F // 00010 100010 11111 Cyan
#endif

//
// ADC Button Debounce
//
#if HAS_ADC_BUTTONS
#define ADC_BUTTON_DEBOUNCE_DELAY 16 // (ms) Increase if buttons bounce or repeat too fast
#endif

// @section safety

/**
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -2509,3 +2509,7 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
#error "SHOW_REMAINING_TIME currently requires a Graphical LCD."
#endif
#endif

#if HAS_ADC_BUTTONS && defined(ADC_BUTTON_DEBOUNCE_DELAY) && !WITHIN(ADC_BUTTON_DEBOUNCE_DELAY, 16, 255)
#error "ADC_BUTTON_DEBOUNCE_DELAY must be an integer from 16 to 255."
#endif
9 changes: 6 additions & 3 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2712,11 +2712,14 @@ void Temperature::tick() {
#endif

#if HAS_ADC_BUTTONS
#ifndef ADC_BUTTON_DEBOUNCE_DELAY
#define ADC_BUTTON_DEBOUNCE_DELAY 16
#endif
case Prepare_ADC_KEY: HAL_START_ADC(ADC_KEYPAD_PIN); break;
case Measure_ADC_KEY:
if (!HAL_ADC_READY())
next_sensor_state = adc_sensor_state; // redo this state
else if (ADCKey_count < 16) {
else if (ADCKey_count < ADC_BUTTON_DEBOUNCE_DELAY) {
raw_ADCKey_value = HAL_READ_ADC();
if (raw_ADCKey_value <= 900UL * HAL_ADC_RANGE / 1024UL) {
NOMORE(current_ADCKey_raw, raw_ADCKey_value);
Expand All @@ -2730,9 +2733,9 @@ void Temperature::tick() {
}
}
}
if (ADCKey_count == 16) ADCKey_pressed = true;
if (ADCKey_count == ADC_BUTTON_DEBOUNCE_DELAY) ADCKey_pressed = true;
break;
#endif // ADC_KEYPAD
#endif // HAS_ADC_BUTTONS

case StartupDelay: break;

Expand Down

0 comments on commit 2d7f94c

Please sign in to comment.