diff options
| author | ailurux <ailuruxx@gmail.com> | 2024-12-19 04:29:23 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2024-12-19 04:29:23 +0000 |
| commit | 5cdc1141ee5f5c7b19809940457b4c4c21db9ae6 (patch) | |
| tree | 3d4484992bb819a4809ae828ee6cd7f571b00ad7 /src/drivers/nvs.cpp | |
| parent | ceb66b46eac7811a9e1ad4d8141b09947f7ee4b2 (diff) | |
| download | tangara-fw-5cdc1141ee5f5c7b19809940457b4c4c21db9ae6.tar.gz | |
Queue repeat modes (#126)
This replaces the previous system of a separate track and queue repeat, with a RepeatMode type with the following options and behaviours:
- OFF: No repeat, queue or track. When the current queue finishes, shuffled or otherwise, playback will stop.
- REPEAT_TRACK: The current track will loop indefinitely, unless next is explicitly called through some user action (ie using the next button in the now playing screen)
- REPEAT_QUEUE: The entire queue will repeat indefinitely. When shuffled is enabled this will repeat the queue with new combinations each cycle.
The repeat mode is persisted in non-volatile storage, so the behaviour will be consistent throughout restarts and queue replacements, and so the "queue repeat by default" use case can be met in this way.
In addition, I've made it work a little nicer when the queue runs out in the now playing screen, keeping the previously played track shown and playback can be continued by using the play button or by going to a previous song in the queue.
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/126
Co-authored-by: ailurux <ailuruxx@gmail.com>
Co-committed-by: ailurux <ailuruxx@gmail.com>
Diffstat (limited to 'src/drivers/nvs.cpp')
| -rw-r--r-- | src/drivers/nvs.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp index d004201b..6c916e60 100644 --- a/src/drivers/nvs.cpp +++ b/src/drivers/nvs.cpp @@ -41,6 +41,7 @@ static constexpr char kKeyDisplayRows[] = "disprows"; static constexpr char kKeyHapticMotorType[] = "hapticmtype"; static constexpr char kKeyLraCalibration[] = "lra_cali"; static constexpr char kKeyDbAutoIndex[] = "dbautoindex"; +static constexpr char kKeyQueueRepeatMode[] = "queue_rpt"; static constexpr char kKeyFastCharge[] = "fastchg"; static auto nvs_get_string(nvs_handle_t nvs, const char* key) @@ -278,6 +279,7 @@ NvsStorage::NvsStorage(nvs_handle_t handle) bt_preferred_(kKeyBluetoothPreferred), bt_names_(kKeyBluetoothNames), db_auto_index_(kKeyDbAutoIndex), + queue_repeat_mode_(kKeyQueueRepeatMode), bt_volumes_(), bt_volumes_dirty_(false) {} @@ -304,6 +306,7 @@ auto NvsStorage::Read() -> void { bt_preferred_.read(handle_); bt_names_.read(handle_); db_auto_index_.read(handle_); + queue_repeat_mode_.read(handle_); readBtVolumes(); } @@ -325,6 +328,7 @@ auto NvsStorage::Write() -> bool { bt_preferred_.write(handle_); bt_names_.write(handle_); db_auto_index_.write(handle_); + queue_repeat_mode_.write(handle_); writeBtVolumes(); return nvs_commit(handle_) == ESP_OK; } @@ -566,6 +570,16 @@ auto NvsStorage::PrimaryInput(InputModes mode) -> void { 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); +} + +auto NvsStorage::QueueRepeatMode(uint8_t mode) -> void { + std::lock_guard<std::mutex> lock{mutex_}; + queue_repeat_mode_.set(mode); +} + auto NvsStorage::DbAutoIndex() -> bool { std::lock_guard<std::mutex> lock{mutex_}; return db_auto_index_.get().value_or(true); |
