Sensitivity value now between 0 and 255

custom
ailurux 1 year ago
parent 0426d245c8
commit 26ae027d67
  1. 9
      lua/settings.lua
  2. 7
      src/drivers/include/relative_wheel.hpp
  3. 13
      src/drivers/relative_wheel.cpp
  4. 2
      src/ui/encoder_input.cpp
  5. 2
      src/ui/include/encoder_input.hpp

@ -260,14 +260,15 @@ function settings.input()
text = "Scroll Sensitivity", text = "Scroll Sensitivity",
}:add_style(theme.settings_title) }:add_style(theme.settings_title)
local slider_scale = 4; -- Power steering
local sensitivity = menu.content:Slider { local sensitivity = menu.content:Slider {
w = lvgl.PCT(100), w = lvgl.PCT(90),
h = 5, h = 5,
range = { min = 5, max = 45 }, range = { min = 0, max = 255/slider_scale },
value = controls.scroll_sensitivity:get(), value = controls.scroll_sensitivity:get()/slider_scale,
} }
sensitivity:onevent(lvgl.EVENT.VALUE_CHANGED, function() sensitivity:onevent(lvgl.EVENT.VALUE_CHANGED, function()
controls.scroll_sensitivity:set(sensitivity:value()) controls.scroll_sensitivity:set(sensitivity:value()*slider_scale)
end) end)
return menu return menu

@ -25,8 +25,8 @@ class RelativeWheel {
auto Update() -> void; auto Update() -> void;
auto SetEnabled(bool) -> void; auto SetEnabled(bool) -> void;
auto SetThreshold(int) -> void; auto SetSensitivity(uint8_t) -> void;
auto GetThreshold() -> int; auto GetSensitivity() -> uint8_t;
auto is_clicking() const -> bool; auto is_clicking() const -> bool;
auto ticks() const -> std::int_fast16_t; auto ticks() const -> std::int_fast16_t;
@ -39,7 +39,8 @@ class RelativeWheel {
TouchWheel& touch_; TouchWheel& touch_;
bool is_enabled_; bool is_enabled_;
int threshold_; uint8_t sensitivity_;
uint8_t threshold_;
bool is_clicking_; bool is_clicking_;
bool was_clicking_; bool was_clicking_;

@ -16,6 +16,7 @@ namespace drivers {
RelativeWheel::RelativeWheel(TouchWheel& touch) RelativeWheel::RelativeWheel(TouchWheel& touch)
: touch_(touch), : touch_(touch),
is_enabled_(true), is_enabled_(true),
sensitivity_(128),
threshold_(10), threshold_(10),
is_clicking_(false), is_clicking_(false),
was_clicking_(false), was_clicking_(false),
@ -48,7 +49,6 @@ auto RelativeWheel::Update() -> void {
int delta = 128 - last_angle_; int delta = 128 - last_angle_;
uint8_t rotated_angle = new_angle + delta; uint8_t rotated_angle = new_angle + delta;
if (rotated_angle < 128 - threshold_) { if (rotated_angle < 128 - threshold_) {
ticks_ = 1; ticks_ = 1;
last_angle_ = new_angle; last_angle_ = new_angle;
@ -64,12 +64,15 @@ auto RelativeWheel::SetEnabled(bool en) -> void {
is_enabled_ = en; is_enabled_ = en;
} }
auto RelativeWheel::SetThreshold(int val) -> void { auto RelativeWheel::SetSensitivity(uint8_t val) -> void {
threshold_ = val; sensitivity_ = val;
int tmax = 35;
int tmin = 5;
threshold_ = (((255. - sensitivity_)/255.)*(tmax - tmin) + tmin);
} }
auto RelativeWheel::GetThreshold() -> int { auto RelativeWheel::GetSensitivity() -> uint8_t {
return threshold_; return sensitivity_;
} }
auto RelativeWheel::is_clicking() const -> bool { auto RelativeWheel::is_clicking() const -> bool {

@ -275,7 +275,7 @@ auto EncoderInput::Read(lv_indev_data_t* data) -> void {
auto EncoderInput::scroll_sensitivity(uint8_t val) -> void { auto EncoderInput::scroll_sensitivity(uint8_t val) -> void {
scroll_sensitivity_ = val; scroll_sensitivity_ = val;
relative_wheel_->SetThreshold(scroll_sensitivity_); relative_wheel_->SetSensitivity(scroll_sensitivity_);
} }
auto EncoderInput::UpdateKeyState(Keys key, uint64_t ms, bool clicked) -> void { auto EncoderInput::UpdateKeyState(Keys key, uint64_t ms, bool clicked) -> void {

@ -38,7 +38,7 @@ class EncoderInput {
auto registration() -> lv_indev_t* { return registration_; } auto registration() -> lv_indev_t* { return registration_; }
auto mode(drivers::NvsStorage::InputModes mode) { mode_ = mode; } auto mode(drivers::NvsStorage::InputModes mode) { mode_ = mode; }
auto scroll_sensitivity(uint8_t val) -> void; auto scroll_sensitivity(uint8_t val) -> void; // Value between 0-255, used to scale the threshold
auto lock(bool l) -> void { is_locked_ = l; } auto lock(bool l) -> void { is_locked_ = l; }
private: private:

Loading…
Cancel
Save