Преглед на файлове

Adjustable ADC debounce delay (#16264)

Dennis преди 4 години
родител
ревизия
2d7f94cae1
променени са 3 файла, в които са добавени 17 реда и са изтрити 3 реда
  1. 7
    0
      Marlin/Configuration_adv.h
  2. 4
    0
      Marlin/src/inc/SanityCheck.h
  3. 6
    3
      Marlin/src/module/temperature.cpp

+ 7
- 0
Marlin/Configuration_adv.h Целия файл

@@ -1379,6 +1379,13 @@
1379 1379
   //#define TFT_BTOKMENU_COLOR 0x145F // 00010 100010 11111 Cyan
1380 1380
 #endif
1381 1381
 
1382
+//
1383
+// ADC Button Debounce
1384
+//
1385
+#if HAS_ADC_BUTTONS
1386
+  #define ADC_BUTTON_DEBOUNCE_DELAY 16  // (ms) Increase if buttons bounce or repeat too fast
1387
+#endif
1388
+
1382 1389
 // @section safety
1383 1390
 
1384 1391
 /**

+ 4
- 0
Marlin/src/inc/SanityCheck.h Целия файл

@@ -2509,3 +2509,7 @@ static_assert(   _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
2509 2509
     #error "SHOW_REMAINING_TIME currently requires a Graphical LCD."
2510 2510
   #endif
2511 2511
 #endif
2512
+
2513
+#if HAS_ADC_BUTTONS && defined(ADC_BUTTON_DEBOUNCE_DELAY) && !WITHIN(ADC_BUTTON_DEBOUNCE_DELAY, 16, 255)
2514
+  #error "ADC_BUTTON_DEBOUNCE_DELAY must be an integer from 16 to 255."
2515
+#endif

+ 6
- 3
Marlin/src/module/temperature.cpp Целия файл

@@ -2712,11 +2712,14 @@ void Temperature::tick() {
2712 2712
     #endif
2713 2713
 
2714 2714
     #if HAS_ADC_BUTTONS
2715
+      #ifndef ADC_BUTTON_DEBOUNCE_DELAY
2716
+        #define ADC_BUTTON_DEBOUNCE_DELAY 16
2717
+      #endif
2715 2718
       case Prepare_ADC_KEY: HAL_START_ADC(ADC_KEYPAD_PIN); break;
2716 2719
       case Measure_ADC_KEY:
2717 2720
         if (!HAL_ADC_READY())
2718 2721
           next_sensor_state = adc_sensor_state; // redo this state
2719
-        else if (ADCKey_count < 16) {
2722
+        else if (ADCKey_count < ADC_BUTTON_DEBOUNCE_DELAY) {
2720 2723
           raw_ADCKey_value = HAL_READ_ADC();
2721 2724
           if (raw_ADCKey_value <= 900UL * HAL_ADC_RANGE / 1024UL) {
2722 2725
             NOMORE(current_ADCKey_raw, raw_ADCKey_value);
@@ -2730,9 +2733,9 @@ void Temperature::tick() {
2730 2733
             }
2731 2734
           }
2732 2735
         }
2733
-        if (ADCKey_count == 16) ADCKey_pressed = true;
2736
+        if (ADCKey_count == ADC_BUTTON_DEBOUNCE_DELAY) ADCKey_pressed = true;
2734 2737
         break;
2735
-    #endif // ADC_KEYPAD
2738
+    #endif // HAS_ADC_BUTTONS
2736 2739
 
2737 2740
     case StartupDelay: break;
2738 2741
 

Loading…
Отказ
Запис