summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-02-13 12:06:14 +1100
committerjacqueline <me@jacqueline.id.au>2024-02-13 12:06:14 +1100
commit3bb002b6b81851e98fa906a02e3aa25381b9d6b9 (patch)
tree9f1a76290bc8efee4e18f258b06cb3b88e295498 /src/drivers
parent786546653a062c8270e608524de1c0a7e1fc1e6e (diff)
parente466522c25758670da335195d60a5d599ed56177 (diff)
downloadtangara-fw-3bb002b6b81851e98fa906a02e3aa25381b9d6b9.tar.gz
Merge branch 'main' of codeberg.org:cool-tech-zone/tangara-fw
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;