Scroll sensitivity configurable, but inverted

custom
ailurux 1 year ago
parent 527374c72e
commit 0426d245c8
  1. 14
      lua/settings.lua
  2. 3
      src/drivers/include/nvs.hpp
  3. 4
      src/drivers/include/relative_wheel.hpp
  4. 12
      src/drivers/nvs.cpp
  5. 14
      src/drivers/relative_wheel.cpp
  6. 6
      src/ui/encoder_input.cpp
  7. 2
      src/ui/include/encoder_input.hpp
  8. 2
      src/ui/include/ui_fsm.hpp
  9. 24
      src/ui/ui_fsm.cpp

@ -256,6 +256,20 @@ function settings.input()
controls.scheme:set(scheme)
end)
menu.content:Label {
text = "Scroll Sensitivity",
}:add_style(theme.settings_title)
local sensitivity = menu.content:Slider {
w = lvgl.PCT(100),
h = 5,
range = { min = 5, max = 45 },
value = controls.scroll_sensitivity:get(),
}
sensitivity:onevent(lvgl.EVENT.VALUE_CHANGED, function()
controls.scroll_sensitivity:set(sensitivity:value())
end)
return menu
end

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

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

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

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

@ -50,6 +50,7 @@ EncoderInput::EncoderInput(drivers::IGpios& gpios, drivers::TouchWheel& wheel)
scroller_(std::make_unique<Scroller>()),
mode_(drivers::NvsStorage::InputModes::kRotatingWheel),
is_locked_(false),
scroll_sensitivity_(10),
is_scrolling_wheel_(false) {
lv_indev_drv_init(&driver_);
driver_.type = LV_INDEV_TYPE_ENCODER;
@ -272,6 +273,11 @@ 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_);
}
auto EncoderInput::UpdateKeyState(Keys key, uint64_t ms, bool clicked) -> void {
if (clicked) {
if (!touch_time_ms_.contains(key)) {

@ -38,6 +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 lock(bool l) -> void { is_locked_ = l; }
private:
@ -51,6 +52,7 @@ class EncoderInput {
drivers::NvsStorage::InputModes mode_;
bool is_locked_;
uint8_t scroll_sensitivity_;
// Every kind of distinct input that we could map to an action.
enum class Keys {

@ -128,7 +128,7 @@ class UiState : public tinyfsm::Fsm<UiState> {
static lua::Property sDisplayBrightness;
static lua::Property sControlsScheme;
static lua::Property sControlSensitivity;
static lua::Property sScrollSensitivity;
static lua::Property sDatabaseUpdating;
};

@ -242,6 +242,25 @@ lua::Property UiState::sControlsScheme{
return true;
}};
lua::Property UiState::sScrollSensitivity{
0, [](const lua::LuaValue& val) {
std::optional<int> sensitivity = 0;
std::visit(
[&](auto&& v) {
using T = std::decay_t<decltype(v)>;
if constexpr (std::is_same_v<T, int>) {
sensitivity = v;
}
},
val);
if (!sensitivity) {
return false;
}
sInput->scroll_sensitivity(*sensitivity);
sServices->nvs().ScrollSensitivity(*sensitivity);
return true;
}};
lua::Property UiState::sDatabaseUpdating{false};
auto UiState::InitBootSplash(drivers::IGpios& gpios) -> bool {
@ -397,6 +416,10 @@ void Splash::react(const system_fsm::BootComplete& ev) {
sInput->mode(mode);
sControlsScheme.Update(static_cast<int>(mode));
auto sensitivity = sServices->nvs().ScrollSensitivity();
sInput->scroll_sensitivity(sensitivity);
sScrollSensitivity.Update(static_cast<int>(sensitivity));
sTask->input(sInput);
} else {
ESP_LOGE(kTag, "no input devices initialised!");
@ -460,6 +483,7 @@ void Lua::entry() {
sLua->bridge().AddPropertyModule("controls",
{
{"scheme", &sControlsScheme},
{"scroll_sensitivity", &sScrollSensitivity},
});
sLua->bridge().AddPropertyModule(

Loading…
Cancel
Save