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/include/nvs.hpp | 3 +++ src/drivers/include/relative_wheel.hpp | 4 ++++ src/drivers/nvs.cpp | 12 ++++++++++++ src/drivers/relative_wheel.cpp | 14 +++++++++++--- 4 files changed, 30 insertions(+), 3 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/include/nvs.hpp b/src/drivers/include/nvs.hpp index 1184b72c..560cdefd 100644 --- a/src/drivers/include/nvs.hpp +++ b/src/drivers/include/nvs.hpp @@ -38,6 +38,9 @@ class NvsStorage { auto ScreenBrightness() -> uint_fast8_t; auto ScreenBrightness(uint_fast8_t) -> bool; + auto ScrollSensitivity() -> uint_fast8_t; + auto ScrollSensitivity(uint_fast8_t) -> bool; + auto AmpMaxVolume() -> uint16_t; auto AmpMaxVolume(uint16_t) -> bool; diff --git a/src/drivers/include/relative_wheel.hpp b/src/drivers/include/relative_wheel.hpp index 88077d08..a44e3598 100644 --- a/src/drivers/include/relative_wheel.hpp +++ b/src/drivers/include/relative_wheel.hpp @@ -25,6 +25,9 @@ class RelativeWheel { auto Update() -> void; auto SetEnabled(bool) -> void; + auto SetThreshold(int) -> void; + auto GetThreshold() -> int; + auto is_clicking() const -> bool; auto ticks() const -> std::int_fast16_t; @@ -36,6 +39,7 @@ class RelativeWheel { TouchWheel& touch_; bool is_enabled_; + int threshold_; bool is_clicking_; bool was_clicking_; diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp index ab623d01..7f764852 100644 --- a/src/drivers/nvs.cpp +++ b/src/drivers/nvs.cpp @@ -34,6 +34,7 @@ static constexpr char kKeyAmpCurrentVolume[] = "hp_vol"; static constexpr char kKeyAmpLeftBias[] = "hp_bias"; static constexpr char kKeyOnboarded[] = "intro"; static constexpr char kKeyPrimaryInput[] = "in_pri"; +static constexpr char kKeyScrollSensitivity[] = "scroll"; static constexpr char kKeyLockPolarity[] = "lockpol"; auto NvsStorage::OpenSync() -> NvsStorage* { @@ -164,6 +165,17 @@ auto NvsStorage::ScreenBrightness(uint_fast8_t val) -> bool { return nvs_commit(handle_) == ESP_OK; } +auto NvsStorage::ScrollSensitivity() -> uint_fast8_t { + uint8_t out = 10; + nvs_get_u8(handle_, kKeyScrollSensitivity, &out); + return out; +} + +auto NvsStorage::ScrollSensitivity(uint_fast8_t val) -> bool { + nvs_set_u8(handle_, kKeyScrollSensitivity, val); + return nvs_commit(handle_) == ESP_OK; +} + auto NvsStorage::AmpMaxVolume() -> uint16_t { uint16_t out = wm8523::kDefaultMaxVolume; nvs_get_u16(handle_, kKeyAmpMaxVolume, &out); 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/include/relative_wheel.hpp | 7 ++++--- src/drivers/relative_wheel.cpp | 13 ++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/include/relative_wheel.hpp b/src/drivers/include/relative_wheel.hpp index a44e3598..e1106143 100644 --- a/src/drivers/include/relative_wheel.hpp +++ b/src/drivers/include/relative_wheel.hpp @@ -25,8 +25,8 @@ class RelativeWheel { auto Update() -> void; auto SetEnabled(bool) -> void; - auto SetThreshold(int) -> void; - auto GetThreshold() -> int; + auto SetSensitivity(uint8_t) -> void; + auto GetSensitivity() -> uint8_t; auto is_clicking() const -> bool; auto ticks() const -> std::int_fast16_t; @@ -39,7 +39,8 @@ class RelativeWheel { TouchWheel& touch_; bool is_enabled_; - int threshold_; + uint8_t sensitivity_; + uint8_t threshold_; bool is_clicking_; bool was_clicking_; 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 From bbbe3a3d5543bd4ffe218e45534dab64235b7e60 Mon Sep 17 00:00:00 2001 From: ailurux Date: Tue, 13 Feb 2024 10:42:47 +1100 Subject: Updated sensitivity nvs store --- src/drivers/include/nvs.hpp | 3 ++- src/drivers/nvs.cpp | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/include/nvs.hpp b/src/drivers/include/nvs.hpp index f862b43e..5bd825e5 100644 --- a/src/drivers/include/nvs.hpp +++ b/src/drivers/include/nvs.hpp @@ -88,7 +88,7 @@ class NvsStorage { auto ScreenBrightness(uint_fast8_t) -> void; auto ScrollSensitivity() -> uint_fast8_t; - auto ScrollSensitivity(uint_fast8_t) -> bool; + auto ScrollSensitivity(uint_fast8_t) -> void; auto AmpMaxVolume() -> uint16_t; auto AmpMaxVolume(uint16_t) -> void; @@ -121,6 +121,7 @@ class NvsStorage { Setting lock_polarity_; Setting brightness_; + Setting sensitivity_; Setting amp_max_vol_; Setting amp_cur_vol_; Setting amp_left_bias_; diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp index bcfddd92..dd89a419 100644 --- a/src/drivers/nvs.cpp +++ b/src/drivers/nvs.cpp @@ -162,6 +162,7 @@ NvsStorage::NvsStorage(nvs_handle_t handle) : handle_(handle), lock_polarity_(kKeyLockPolarity), brightness_(kKeyBrightness), + sensitivity_(kKeyScrollSensitivity), amp_max_vol_(kKeyAmpMaxVolume), amp_cur_vol_(kKeyAmpCurrentVolume), amp_left_bias_(kKeyAmpLeftBias), @@ -180,6 +181,7 @@ auto NvsStorage::Read() -> void { std::lock_guard lock{mutex_}; lock_polarity_.read(handle_); brightness_.read(handle_); + sensitivity_.read(handle_); amp_max_vol_.read(handle_); amp_cur_vol_.read(handle_); amp_left_bias_.read(handle_); @@ -286,14 +288,13 @@ auto NvsStorage::ScreenBrightness(uint_fast8_t val) -> void { } auto NvsStorage::ScrollSensitivity() -> uint_fast8_t { - uint8_t out = 10; - nvs_get_u8(handle_, kKeyScrollSensitivity, &out); - return out; + std::lock_guard lock{mutex_}; + return std::clamp(sensitivity_.get().value_or(128), 0, 100); } -auto NvsStorage::ScrollSensitivity(uint_fast8_t val) -> bool { - nvs_set_u8(handle_, kKeyScrollSensitivity, val); - return nvs_commit(handle_) == ESP_OK; +auto NvsStorage::ScrollSensitivity(uint_fast8_t val) -> void { + std::lock_guard lock{mutex_}; + sensitivity_.set(val); } auto NvsStorage::AmpMaxVolume() -> uint16_t { -- cgit v1.2.3 From ffa0894e380874774fb13986b3ff1a48696d304e Mon Sep 17 00:00:00 2001 From: ailurux Date: Tue, 13 Feb 2024 11:35:18 +1100 Subject: Fixed clamp and write on scroll sensitivity --- src/drivers/nvs.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/drivers') diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp index dd89a419..875059be 100644 --- a/src/drivers/nvs.cpp +++ b/src/drivers/nvs.cpp @@ -195,6 +195,7 @@ auto NvsStorage::Write() -> bool { std::lock_guard lock{mutex_}; lock_polarity_.write(handle_); brightness_.write(handle_); + sensitivity_.write(handle_); amp_max_vol_.write(handle_); amp_cur_vol_.write(handle_); amp_left_bias_.write(handle_); @@ -289,7 +290,7 @@ auto NvsStorage::ScreenBrightness(uint_fast8_t val) -> void { auto NvsStorage::ScrollSensitivity() -> uint_fast8_t { std::lock_guard lock{mutex_}; - return std::clamp(sensitivity_.get().value_or(128), 0, 100); + return std::clamp(sensitivity_.get().value_or(128), 0, 255); } auto NvsStorage::ScrollSensitivity(uint_fast8_t val) -> void { -- cgit v1.2.3