From 02ea9636eeb7f8ae3b2fc5c55f7556b7b490e406 Mon Sep 17 00:00:00 2001 From: Feksaaargh <158505890+Feksaaargh@users.noreply.github.com> Date: Sun, 4 Oct 2026 01:31:47 -0500 Subject: [PATCH] Add basic double click recognition --- sim/drivers/Cst816s.cpp | 12 +++++++++++- sim/drivers/Cst816s.h | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sim/drivers/Cst816s.cpp b/sim/drivers/Cst816s.cpp index eb800ff..c66c625 100644 --- a/sim/drivers/Cst816s.cpp +++ b/sim/drivers/Cst816s.cpp @@ -62,10 +62,12 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() { if (is_stationary && press_duration.count() > 1.0) { // longer than 1 second pressed, then it is long-press is_long_press = true; + tapped_recently = false; info.gesture = Gestures::LongPress; } else if (!is_stationary) { // moved mouse fast enough to not be a long-press is_swipe = true; + tapped_recently = false; double x_diff = static_cast(info.x) - x_start; double y_diff = static_cast(info.y) - y_start; if (fabs(x_diff) > fabs(y_diff)) { @@ -95,7 +97,15 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() { if (norm < 20) { if (is_stationary && !is_long_press && !is_swipe) { // no swipe with less than 5 pixel mouse movement - info.gesture = Gestures::SingleTap; + std::chrono::duration since_last_tap = std::chrono::steady_clock::now() - last_tapped; + if (tapped_recently && since_last_tap.count() < 0.4) { + info.gesture = Gestures::DoubleTap; + tapped_recently = false; + } else { + info.gesture = Gestures::SingleTap; + last_tapped = std::chrono::steady_clock::now(); + tapped_recently = true; + } } } } diff --git a/sim/drivers/Cst816s.h b/sim/drivers/Cst816s.h index e6b9a03..a6d2eca 100644 --- a/sim/drivers/Cst816s.h +++ b/sim/drivers/Cst816s.h @@ -77,8 +77,10 @@ namespace Pinetime { const uint8_t vendorId = 0; const uint8_t fwVersion = 1; - // simulation members for swipe detection from mouse + // simulation members for swipe/double click detection from mouse std::chrono::time_point pressed_since; + std::chrono::time_point last_tapped; + bool tapped_recently = false; bool is_pressed = false; bool is_long_press = false; bool is_stationary = true;