Adjustable ADC debounce delay (#16264)

This commit is contained in:
Dennis 2020-01-15 19:06:03 -05:00 committed by Scott Lahteine
parent 7481563bd9
commit 2d7f94cae1
3 changed files with 17 additions and 3 deletions

View file

@ -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
/**

View file

@ -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

View file

@ -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);
@ -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;