diff options
| author | ailurux <ailurux@noreply.codeberg.org> | 2025-03-19 04:25:20 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2025-03-19 04:25:20 +0000 |
| commit | c9ce88a457c9ed7124709a667d202a666f72bffa (patch) | |
| tree | 681cba582d4e18c743029cb72ea542eee23e9907 /src/drivers | |
| parent | 95dd0ddec52a25a57e367e5568ac97f8e3f0d312 (diff) | |
| download | tangara-fw-c9ce88a457c9ed7124709a667d202a666f72bffa.tar.gz | |
ailurux/button-media-controls (#264)
Splits the control scheme into separate schemes for the side buttons and touchwheel, allowing them to be configured independently of each other. At least one input must be used for navigation, and there are guards to prevent locking oneself out of any input. If the input scheme is invalid, a pop up will show alerting the user.
Different behaviours can be bound to the side buttons for when the device is locked or unlocked. This PR also adds a mode for these buttons that controls media playback (prev/next on up/down, pressing both buttons toggles play/pause).
There are some changes to the way inputs handle locking. Rather than the input devices tracking the current locked mode, different input devices are created on lock depending on the mode that is configured.
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/264
Co-authored-by: ailurux <ailurux@noreply.codeberg.org>
Co-committed-by: ailurux <ailurux@noreply.codeberg.org>
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/include/drivers/nvs.hpp | 27 | ||||
| -rw-r--r-- | src/drivers/nvs.cpp | 77 |
2 files changed, 68 insertions, 36 deletions
diff --git a/src/drivers/include/drivers/nvs.hpp b/src/drivers/include/drivers/nvs.hpp index 7ef1fbf7..b490ac3d 100644 --- a/src/drivers/include/drivers/nvs.hpp +++ b/src/drivers/include/drivers/nvs.hpp @@ -143,23 +143,27 @@ class NvsStorage { auto AmpLeftBias() -> int_fast8_t; auto AmpLeftBias(int_fast8_t) -> void; - enum class InputModes : uint8_t { - kButtonsOnly = 0, - kButtonsWithWheel = 1, - kDirectionalWheel = 2, - kRotatingWheel = 3, + enum class WheelInputModes : uint8_t { + kDisabled = 0, + kDirectionalWheel = 1, + kRotatingWheel = 2, }; - auto PrimaryInput() -> InputModes; - auto PrimaryInput(InputModes) -> void; + auto WheelInput() -> WheelInputModes; + auto WheelInput(WheelInputModes) -> void; - enum class LockedInputModes : uint8_t { + enum class ButtonInputModes : uint8_t { kDisabled = 0, kVolumeOnly = 1, + kMediaControls = 2, + kNavigation = 3, }; - auto LockedInput() -> LockedInputModes; - auto LockedInput(LockedInputModes) -> void; + auto ButtonInput() -> ButtonInputModes; + auto ButtonInput(ButtonInputModes) -> void; + + auto LockedInput() -> ButtonInputModes; + auto LockedInput(ButtonInputModes) -> void; auto QueueRepeatMode() -> uint8_t; auto QueueRepeatMode(uint8_t) -> void; @@ -191,7 +195,8 @@ class NvsStorage { Setting<uint16_t> amp_max_vol_; Setting<uint16_t> amp_cur_vol_; Setting<int8_t> amp_left_bias_; - Setting<uint8_t> input_mode_; + Setting<uint8_t> wheel_input_mode_; + Setting<uint8_t> button_input_mode_; Setting<uint8_t> locked_input_mode_; Setting<uint8_t> output_mode_; Setting<uint8_t> haptics_mode_; diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp index 374c71d6..64ed9c1a 100644 --- a/src/drivers/nvs.cpp +++ b/src/drivers/nvs.cpp @@ -34,7 +34,8 @@ static constexpr char kKeyInterfaceTheme[] = "ui_theme"; 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 kKeyWheelInput[] = "in_wheel"; +static constexpr char kKeyButtonInput[] = "in_btn"; static constexpr char kKeyLockedInput[] = "in_locked"; static constexpr char kKeyHaptics[] = "haptic_mode"; static constexpr char kKeyScrollSensitivity[] = "scroll"; @@ -277,7 +278,8 @@ NvsStorage::NvsStorage(nvs_handle_t handle) amp_max_vol_(kKeyAmpMaxVolume), amp_cur_vol_(kKeyAmpCurrentVolume), amp_left_bias_(kKeyAmpLeftBias), - input_mode_(kKeyPrimaryInput), + wheel_input_mode_(kKeyWheelInput), + button_input_mode_(kKeyButtonInput), locked_input_mode_(kKeyLockedInput), output_mode_(kKeyOutput), haptics_mode_(kKeyHaptics), @@ -309,7 +311,8 @@ auto NvsStorage::Read() -> void { amp_max_vol_.read(handle_); amp_cur_vol_.read(handle_); amp_left_bias_.read(handle_); - input_mode_.read(handle_); + wheel_input_mode_.read(handle_); + button_input_mode_.read(handle_); locked_input_mode_.read(handle_); output_mode_.read(handle_); haptics_mode_.read(handle_); @@ -336,7 +339,8 @@ auto NvsStorage::Write() -> bool { amp_max_vol_.write(handle_); amp_cur_vol_.write(handle_); amp_left_bias_.write(handle_); - input_mode_.write(handle_); + wheel_input_mode_.write(handle_); + button_input_mode_.write(handle_); locked_input_mode_.write(handle_); output_mode_.write(handle_); haptics_mode_.write(handle_); @@ -615,40 +619,63 @@ auto NvsStorage::AmpLeftBias(int_fast8_t val) -> void { amp_left_bias_.set(val); } -auto NvsStorage::PrimaryInput() -> InputModes { +auto NvsStorage::WheelInput() -> WheelInputModes { std::lock_guard<std::mutex> lock{mutex_}; - switch (input_mode_.get().value_or(3)) { - case static_cast<uint8_t>(InputModes::kButtonsOnly): - return InputModes::kButtonsOnly; - case static_cast<uint8_t>(InputModes::kButtonsWithWheel): - return InputModes::kButtonsWithWheel; - case static_cast<uint8_t>(InputModes::kDirectionalWheel): - return InputModes::kDirectionalWheel; - case static_cast<uint8_t>(InputModes::kRotatingWheel): - return InputModes::kRotatingWheel; + switch (wheel_input_mode_.get().value_or(3)) { + case static_cast<uint8_t>(WheelInputModes::kDisabled): + return WheelInputModes::kDisabled; + case static_cast<uint8_t>(WheelInputModes::kDirectionalWheel): + return WheelInputModes::kDirectionalWheel; + case static_cast<uint8_t>(WheelInputModes::kRotatingWheel): + return WheelInputModes::kRotatingWheel; default: - return InputModes::kRotatingWheel; + return WheelInputModes::kRotatingWheel; } } -auto NvsStorage::PrimaryInput(InputModes mode) -> void { +auto NvsStorage::WheelInput(WheelInputModes mode) -> void { std::lock_guard<std::mutex> lock{mutex_}; - input_mode_.set(static_cast<uint8_t>(mode)); + wheel_input_mode_.set(static_cast<uint8_t>(mode)); } -auto NvsStorage::LockedInput() -> LockedInputModes { +auto NvsStorage::ButtonInput() -> ButtonInputModes { std::lock_guard<std::mutex> lock{mutex_}; - switch (locked_input_mode_.get().value_or(static_cast<uint8_t>(LockedInputModes::kDisabled))) { - case static_cast<uint8_t>(LockedInputModes::kDisabled): - return LockedInputModes::kDisabled; - case static_cast<uint8_t>(LockedInputModes::kVolumeOnly): - return LockedInputModes::kVolumeOnly; + switch (button_input_mode_.get().value_or(static_cast<uint8_t>(ButtonInputModes::kVolumeOnly))) { + case static_cast<uint8_t>(ButtonInputModes::kDisabled): + return ButtonInputModes::kDisabled; + case static_cast<uint8_t>(ButtonInputModes::kVolumeOnly): + return ButtonInputModes::kVolumeOnly; + case static_cast<uint8_t>(ButtonInputModes::kMediaControls): + return ButtonInputModes::kMediaControls; + case static_cast<uint8_t>(ButtonInputModes::kNavigation): + return ButtonInputModes::kNavigation; default: - return LockedInputModes::kDisabled; + return ButtonInputModes::kVolumeOnly; } } -auto NvsStorage::LockedInput(LockedInputModes mode) -> void { +auto NvsStorage::ButtonInput(ButtonInputModes mode) -> void { + std::lock_guard<std::mutex> lock{mutex_}; + button_input_mode_.set(static_cast<uint8_t>(mode)); +} + +auto NvsStorage::LockedInput() -> ButtonInputModes { + std::lock_guard<std::mutex> lock{mutex_}; + switch (locked_input_mode_.get().value_or(static_cast<uint8_t>(ButtonInputModes::kDisabled))) { + case static_cast<uint8_t>(ButtonInputModes::kDisabled): + return ButtonInputModes::kDisabled; + case static_cast<uint8_t>(ButtonInputModes::kVolumeOnly): + return ButtonInputModes::kVolumeOnly; + case static_cast<uint8_t>(ButtonInputModes::kMediaControls): + return ButtonInputModes::kMediaControls; + case static_cast<uint8_t>(ButtonInputModes::kNavigation): + return ButtonInputModes::kNavigation; + default: + return ButtonInputModes::kDisabled; + } +} + +auto NvsStorage::LockedInput(ButtonInputModes mode) -> void { std::lock_guard<std::mutex> lock{mutex_}; locked_input_mode_.set(static_cast<uint8_t>(mode)); } |
