From 77260bc68a75a706eabcfe793ab1ddd35eb1e8c3 Mon Sep 17 00:00:00 2001 From: bernd-herzog Date: Wed, 3 May 2023 10:47:43 +0200 Subject: [PATCH 1/2] fixed touch handling issue causing multiple inputs --- firmware/application/touch.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/firmware/application/touch.cpp b/firmware/application/touch.cpp index 681c2518..cb6028d7 100644 --- a/firmware/application/touch.cpp +++ b/firmware/application/touch.cpp @@ -81,16 +81,18 @@ void Manager::feed(const Frame& frame) { const auto touch_raw = frame.touch; //const auto touch_stable = touch_debounce.state(); const auto touch_stable = frame.touch; - bool touch_pressure = false; + bool touch_down_pressure = false; + bool touch_up_pressure = false; // Only feed coordinate averaging if there's a touch. // TODO: Separate threshold to gate coordinates for filtering? if( touch_raw ) { const auto metrics = calculate_metrics(frame); - // TODO: Add touch pressure hysteresis? - touch_pressure = (metrics.r < r_touch_threshold); - if( touch_pressure ) { + touch_down_pressure = (metrics.r < r_touch_threshold); + touch_up_pressure = (metrics.r < r_touch_threshold*2); + + if( touch_down_pressure ) { filter_x.feed(metrics.x * 1024); filter_y.feed(metrics.y * 1024); } @@ -101,7 +103,7 @@ void Manager::feed(const Frame& frame) { switch(state) { case State::NoTouch: - if( touch_stable && touch_pressure && !persistent_memory::disable_touchscreen()) { + if( touch_stable && touch_down_pressure && !persistent_memory::disable_touchscreen()) { if( point_stable() ) { state = State::TouchDetected; touch_started(); @@ -110,7 +112,7 @@ void Manager::feed(const Frame& frame) { break; case State::TouchDetected: - if( touch_stable && touch_pressure ) { + if( touch_stable && touch_up_pressure ) { touch_moved(); } else { state = State::NoTouch; From 078da8ca16f4bc991ca2d9036dae1080c0e9aee4 Mon Sep 17 00:00:00 2001 From: bernd-herzog Date: Wed, 3 May 2023 11:18:37 +0200 Subject: [PATCH 2/2] Improved sensitivity for non pointy touches --- firmware/application/touch.cpp | 7 +++++-- firmware/application/touch.hpp | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/firmware/application/touch.cpp b/firmware/application/touch.cpp index cb6028d7..a0c77a25 100644 --- a/firmware/application/touch.cpp +++ b/firmware/application/touch.cpp @@ -89,8 +89,11 @@ void Manager::feed(const Frame& frame) { if( touch_raw ) { const auto metrics = calculate_metrics(frame); - touch_down_pressure = (metrics.r < r_touch_threshold); - touch_up_pressure = (metrics.r < r_touch_threshold*2); + constexpr float r_touch_down_threshold = 3200.0f; + constexpr float r_touch_up_threshold = r_touch_down_threshold * 2.0f; + + touch_down_pressure = (metrics.r < r_touch_down_threshold); + touch_up_pressure = (metrics.r < r_touch_up_threshold); if( touch_down_pressure ) { filter_x.feed(metrics.x * 1024); diff --git a/firmware/application/touch.hpp b/firmware/application/touch.hpp index 7fa1c029..4aa18297 100644 --- a/firmware/application/touch.hpp +++ b/firmware/application/touch.hpp @@ -219,7 +219,6 @@ private: TouchDetected, }; - static constexpr float r_touch_threshold = 640; static constexpr size_t touch_count_threshold { 3 }; static constexpr uint32_t touch_stable_bound { 8 };