summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorcooljqln <cooljqln@noreply.codeberg.org>2024-02-13 00:47:53 +0000
committercooljqln <cooljqln@noreply.codeberg.org>2024-02-13 00:47:53 +0000
commite466522c25758670da335195d60a5d599ed56177 (patch)
tree8a7d29a07c3045b3e6a666468bcad63a7c0ba697 /src/drivers
parentcb379f4bc3c51eacf80b786566ab3c2675191164 (diff)
parentffa0894e380874774fb13986b3ff1a48696d304e (diff)
downloadtangara-fw-e466522c25758670da335195d60a5d599ed56177.tar.gz
Merge pull request 'scroll-sensitivity' (#36) from scroll-sensitivity into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/36 Reviewed-by: cooljqln <cooljqln@noreply.codeberg.org>
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/include/nvs.hpp4
-rw-r--r--src/drivers/include/relative_wheel.hpp5
-rw-r--r--src/drivers/nvs.cpp14
-rw-r--r--src/drivers/relative_wheel.cpp19
4 files changed, 38 insertions, 4 deletions
diff --git a/src/drivers/include/nvs.hpp b/src/drivers/include/nvs.hpp
index 197591d5..5bd825e5 100644
--- a/src/drivers/include/nvs.hpp
+++ b/src/drivers/include/nvs.hpp
@@ -87,6 +87,9 @@ class NvsStorage {
auto ScreenBrightness() -> uint_fast8_t;
auto ScreenBrightness(uint_fast8_t) -> void;
+ auto ScrollSensitivity() -> uint_fast8_t;
+ auto ScrollSensitivity(uint_fast8_t) -> void;
+
auto AmpMaxVolume() -> uint16_t;
auto AmpMaxVolume(uint16_t) -> void;
@@ -118,6 +121,7 @@ class NvsStorage {
Setting<uint8_t> lock_polarity_;
Setting<uint8_t> brightness_;
+ Setting<uint8_t> sensitivity_;
Setting<uint16_t> amp_max_vol_;
Setting<uint16_t> amp_cur_vol_;
Setting<int8_t> amp_left_bias_;
diff --git a/src/drivers/include/relative_wheel.hpp b/src/drivers/include/relative_wheel.hpp
index 88077d08..e1106143 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 SetSensitivity(uint8_t) -> void;
+ auto GetSensitivity() -> uint8_t;
+
auto is_clicking() const -> bool;
auto ticks() const -> std::int_fast16_t;
@@ -36,6 +39,8 @@ class RelativeWheel {
TouchWheel& touch_;
bool is_enabled_;
+ uint8_t sensitivity_;
+ uint8_t threshold_;
bool is_clicking_;
bool was_clicking_;
diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp
index a304c149..875059be 100644
--- a/src/drivers/nvs.cpp
+++ b/src/drivers/nvs.cpp
@@ -35,6 +35,7 @@ static constexpr char kKeyAmpMaxVolume[] = "hp_vol_max";
static constexpr char kKeyAmpCurrentVolume[] = "hp_vol";
static constexpr char kKeyAmpLeftBias[] = "hp_bias";
static constexpr char kKeyPrimaryInput[] = "in_pri";
+static constexpr char kKeyScrollSensitivity[] = "scroll";
static constexpr char kKeyLockPolarity[] = "lockpol";
static auto nvs_get_string(nvs_handle_t nvs, const char* key)
@@ -161,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),
@@ -179,6 +181,7 @@ auto NvsStorage::Read() -> void {
std::lock_guard<std::mutex> 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_);
@@ -192,6 +195,7 @@ auto NvsStorage::Write() -> bool {
std::lock_guard<std::mutex> 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_);
@@ -284,6 +288,16 @@ auto NvsStorage::ScreenBrightness(uint_fast8_t val) -> void {
brightness_.set(val);
}
+auto NvsStorage::ScrollSensitivity() -> uint_fast8_t {
+ std::lock_guard<std::mutex> lock{mutex_};
+ return std::clamp<uint8_t>(sensitivity_.get().value_or(128), 0, 255);
+}
+
+auto NvsStorage::ScrollSensitivity(uint_fast8_t val) -> void {
+ std::lock_guard<std::mutex> lock{mutex_};
+ sensitivity_.set(val);
+}
+
auto NvsStorage::AmpMaxVolume() -> uint16_t {
std::lock_guard<std::mutex> lock{mutex_};
return amp_max_vol_.get().value_or(wm8523::kDefaultMaxVolume);
diff --git a/src/drivers/relative_wheel.cpp b/src/drivers/relative_wheel.cpp
index 2b8c9b20..e90143ae 100644
--- a/src/drivers/relative_wheel.cpp
+++ b/src/drivers/relative_wheel.cpp
@@ -16,6 +16,8 @@ namespace drivers {
RelativeWheel::RelativeWheel(TouchWheel& touch)
: touch_(touch),
is_enabled_(true),
+ sensitivity_(128),
+ threshold_(10),
is_clicking_(false),
was_clicking_(false),
is_first_read_(true),
@@ -47,12 +49,10 @@ 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,17 @@ auto RelativeWheel::SetEnabled(bool en) -> void {
is_enabled_ = en;
}
+auto RelativeWheel::SetSensitivity(uint8_t val) -> void {
+ sensitivity_ = val;
+ int tmax = 35;
+ int tmin = 5;
+ threshold_ = (((255. - sensitivity_)/255.)*(tmax - tmin) + tmin);
+}
+
+auto RelativeWheel::GetSensitivity() -> uint8_t {
+ return sensitivity_;
+}
+
auto RelativeWheel::is_clicking() const -> bool {
if (!is_enabled_) {
return false;