From 3cd19a8ec080dda75c6326886e90fc2f0972b499 Mon Sep 17 00:00:00 2001 From: Pavel4e5 <50713272+Pavel4e5@users.noreply.github.com> Date: Sun, 19 May 2019 06:52:55 +0500 Subject: [PATCH] Improve Zonestar keypad responsiveness (#14056) --- Marlin/src/lcd/ultralcd.cpp | 4 ++-- Marlin/src/module/temperature.cpp | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 4035bd34cd..a044886793 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -996,8 +996,8 @@ void MarlinUI::update() { uint8_t get_ADC_keyValue(void) { if (thermalManager.ADCKey_count >= 16) { - const uint16_t currentkpADCValue = thermalManager.current_ADCKey_raw >> 2; - thermalManager.current_ADCKey_raw = 0; + const uint16_t currentkpADCValue = thermalManager.current_ADCKey_raw << 2; + thermalManager.current_ADCKey_raw = 1024; thermalManager.ADCKey_count = 0; if (currentkpADCValue < 4000) for (uint8_t i = 0; i < ADC_KEY_NUM; i++) { diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index a4a94fc678..a6902af884 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -310,7 +310,7 @@ temp_range_t Temperature::temp_range[HOTENDS] = ARRAY_BY_HOTENDS(sensor_heater_0 // public: #if HAS_ADC_BUTTONS - uint32_t Temperature::current_ADCKey_raw = 0; + uint32_t Temperature::current_ADCKey_raw = 1024; uint8_t Temperature::ADCKey_count = 0; #endif @@ -2300,6 +2300,7 @@ void Temperature::isr() { #if HAS_ADC_BUTTONS static unsigned int raw_ADCKey_value = 0; + static bool ADCKey_pressed = false; #endif #if ENABLED(SLOW_PWM_HEATERS) @@ -2702,16 +2703,19 @@ void Temperature::isr() { next_sensor_state = adc_sensor_state; // redo this state else if (ADCKey_count < 16) { raw_ADCKey_value = HAL_READ_ADC(); - if (raw_ADCKey_value > 900) { - //ADC Key release - ADCKey_count = 0; - current_ADCKey_raw = 0; - } - else { - current_ADCKey_raw += raw_ADCKey_value; + if (raw_ADCKey_value <= 900) { + NOMORE(current_ADCKey_raw, raw_ADCKey_value); ADCKey_count++; } + else { //ADC Key release + if (ADCKey_count > 0) ADCKey_count++; else ADCKey_pressed = false; + if (ADCKey_pressed) { + ADCKey_count = 0; + current_ADCKey_raw = 1024; + } + } } + if (ADCKey_count == 16) ADCKey_pressed = true; break; #endif // ADC_KEYPAD