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",
}:add_style(theme.settings_title)
local slider_scale = 4; -- Power steering
local sensitivity = menu.content:Slider {
w = lvgl.PCT(100),
w = lvgl.PCT(90),
h = 5,
range = { min = 5, max = 45 },
value = controls.scroll_sensitivity:get(),
range = { min = 0, max = 255/slider_scale },
value = controls.scroll_sensitivity:get()/slider_scale,
}
sensitivity:onevent(lvgl.EVENT.VALUE_CHANGED, function()
controls.scroll_sensitivity:set(sensitivity:value())
controls.scroll_sensitivity:set(sensitivity:value()*slider_scale)
end)
return menu

@ -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_;

@ -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 {

@ -275,7 +275,7 @@ auto EncoderInput::Read(lv_indev_data_t* data) -> void {
auto EncoderInput::scroll_sensitivity(uint8_t val) -> void {
scroll_sensitivity_ = val;
relative_wheel_->SetThreshold(scroll_sensitivity_);
relative_wheel_->SetSensitivity(scroll_sensitivity_);
}
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 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; }
private:

Loading…
Cancel
Save