From 0426d245c8d863f18babdfbaf21c8673b0746feb Mon Sep 17 00:00:00 2001 From: ailurux Date: Mon, 12 Feb 2024 17:44:55 +1100 Subject: Scroll sensitivity configurable, but inverted --- src/drivers/relative_wheel.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/drivers/relative_wheel.cpp') diff --git a/src/drivers/relative_wheel.cpp b/src/drivers/relative_wheel.cpp index 2b8c9b20..056c80c9 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), + threshold_(10), is_clicking_(false), was_clicking_(false), is_first_read_(true), @@ -47,12 +48,11 @@ auto RelativeWheel::Update() -> void { int delta = 128 - last_angle_; uint8_t rotated_angle = new_angle + delta; - int threshold = 10; - if (rotated_angle < 128 - threshold) { + if (rotated_angle < 128 - threshold_) { ticks_ = 1; last_angle_ = new_angle; - } else if (rotated_angle > 128 + threshold) { + } else if (rotated_angle > 128 + threshold_) { ticks_ = -1; last_angle_ = new_angle; } else { @@ -64,6 +64,14 @@ auto RelativeWheel::SetEnabled(bool en) -> void { is_enabled_ = en; } +auto RelativeWheel::SetThreshold(int val) -> void { + threshold_ = val; +} + +auto RelativeWheel::GetThreshold() -> int { + return threshold_; +} + auto RelativeWheel::is_clicking() const -> bool { if (!is_enabled_) { return false; -- cgit v1.2.3 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