diff options
| author | cooljqln <cooljqln@noreply.codeberg.org> | 2025-02-03 23:45:28 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2025-02-03 23:45:28 +0000 |
| commit | 38cb3d8219da0d26077d238c3e633f75a11055a3 (patch) | |
| tree | 7279ecbf1be6e7384e3a90c15153863ae1cf994f /src/drivers | |
| parent | 28846b989b75ca6fe513462c209ce95bce2a46b7 (diff) | |
| parent | 546daf71c1b04284848c4b5edfbaa3c5b4a284f4 (diff) | |
| download | tangara-fw-38cb3d8219da0d26077d238c3e633f75a11055a3.tar.gz | |
Merge pull request 'Add optional support for adjusting volume while locked' (#230) from teisenbe/tangara-fw:locked_input into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/230
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/include/drivers/nvs.hpp | 9 | ||||
| -rw-r--r-- | src/drivers/nvs.cpp | 21 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/drivers/include/drivers/nvs.hpp b/src/drivers/include/drivers/nvs.hpp index 9725bb0f..18bc5de6 100644 --- a/src/drivers/include/drivers/nvs.hpp +++ b/src/drivers/include/drivers/nvs.hpp @@ -138,6 +138,14 @@ class NvsStorage { auto PrimaryInput() -> InputModes; auto PrimaryInput(InputModes) -> void; + enum class LockedInputModes : uint8_t { + kDisabled = 0, + kVolumeOnly = 1, + }; + + auto LockedInput() -> LockedInputModes; + auto LockedInput(LockedInputModes) -> void; + auto QueueRepeatMode() -> uint8_t; auto QueueRepeatMode(uint8_t) -> void; @@ -167,6 +175,7 @@ class NvsStorage { Setting<uint16_t> amp_cur_vol_; Setting<int8_t> amp_left_bias_; Setting<uint8_t> input_mode_; + Setting<uint8_t> locked_input_mode_; Setting<uint8_t> output_mode_; Setting<std::string> theme_; diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp index 6f0d874e..02a0058b 100644 --- a/src/drivers/nvs.cpp +++ b/src/drivers/nvs.cpp @@ -34,6 +34,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 kKeyLockedInput[] = "in_locked"; static constexpr char kKeyScrollSensitivity[] = "scroll"; static constexpr char kKeyLockPolarity[] = "lockpol"; static constexpr char kKeyDisplayCols[] = "dispcols"; @@ -272,6 +273,7 @@ NvsStorage::NvsStorage(nvs_handle_t handle) amp_cur_vol_(kKeyAmpCurrentVolume), amp_left_bias_(kKeyAmpLeftBias), input_mode_(kKeyPrimaryInput), + locked_input_mode_(kKeyLockedInput), output_mode_(kKeyOutput), theme_{kKeyInterfaceTheme}, bt_preferred_(kKeyBluetoothPreferred), @@ -300,6 +302,7 @@ auto NvsStorage::Read() -> void { amp_cur_vol_.read(handle_); amp_left_bias_.read(handle_); input_mode_.read(handle_); + locked_input_mode_.read(handle_); output_mode_.read(handle_); theme_.read(handle_); bt_preferred_.read(handle_); @@ -323,6 +326,7 @@ auto NvsStorage::Write() -> bool { amp_cur_vol_.write(handle_); amp_left_bias_.write(handle_); input_mode_.write(handle_); + locked_input_mode_.write(handle_); output_mode_.write(handle_); theme_.write(handle_); bt_preferred_.write(handle_); @@ -570,6 +574,23 @@ auto NvsStorage::PrimaryInput(InputModes mode) -> void { input_mode_.set(static_cast<uint8_t>(mode)); } +auto NvsStorage::LockedInput() -> LockedInputModes { + 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; + default: + return LockedInputModes::kDisabled; + } +} + +auto NvsStorage::LockedInput(LockedInputModes mode) -> void { + std::lock_guard<std::mutex> lock{mutex_}; + locked_input_mode_.set(static_cast<uint8_t>(mode)); +} + auto NvsStorage::QueueRepeatMode() -> uint8_t { std::lock_guard<std::mutex> lock{mutex_}; return queue_repeat_mode_.get().value_or(0); |
