From 26ae027d6721510e4b4a8107e95acc57efaaf2c6 Mon Sep 17 00:00:00 2001 From: ailurux Date: Tue, 13 Feb 2024 10:31:48 +1100 Subject: Sensitivity value now between 0 and 255 --- src/drivers/relative_wheel.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/drivers/relative_wheel.cpp') diff --git a/src/drivers/relative_wheel.cpp b/src/drivers/relative_wheel.cpp index 056c80c9..e90143ae 100644 --- a/src/drivers/relative_wheel.cpp +++ b/src/drivers/relative_wheel.cpp @@ -16,6 +16,7 @@ namespace drivers { RelativeWheel::RelativeWheel(TouchWheel& touch) : touch_(touch), is_enabled_(true), + sensitivity_(128), threshold_(10), is_clicking_(false), was_clicking_(false), @@ -48,7 +49,6 @@ auto RelativeWheel::Update() -> void { int delta = 128 - last_angle_; uint8_t rotated_angle = new_angle + delta; - if (rotated_angle < 128 - threshold_) { ticks_ = 1; last_angle_ = new_angle; @@ -64,12 +64,15 @@ auto RelativeWheel::SetEnabled(bool en) -> void { is_enabled_ = en; } -auto RelativeWheel::SetThreshold(int val) -> void { - threshold_ = val; +auto RelativeWheel::SetSensitivity(uint8_t val) -> void { + sensitivity_ = val; + int tmax = 35; + int tmin = 5; + threshold_ = (((255. - sensitivity_)/255.)*(tmax - tmin) + tmin); } -auto RelativeWheel::GetThreshold() -> int { - return threshold_; +auto RelativeWheel::GetSensitivity() -> uint8_t { + return sensitivity_; } auto RelativeWheel::is_clicking() const -> bool { -- cgit v1.2.3