From d5d6e3993cd67238ff245446e69e2f200c3fd0e5 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 4 Sep 2023 16:17:55 +1000 Subject: Support changing max volume, persisted to nvs --- src/drivers/nvs.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/drivers/nvs.cpp') diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp index c2832bf4..7bd1afe2 100644 --- a/src/drivers/nvs.cpp +++ b/src/drivers/nvs.cpp @@ -17,6 +17,7 @@ #include "nvs.h" #include "nvs_flash.h" #include "tasks.hpp" +#include "wm8523.hpp" namespace drivers { @@ -27,6 +28,8 @@ static constexpr char kKeyVersion[] = "ver"; static constexpr char kKeyBluetooth[] = "bt"; static constexpr char kKeyOutput[] = "out"; static constexpr char kKeyBrightness[] = "bright"; +static constexpr char kKeyAmpMaxVolume[] = "hp_vol_max"; +static constexpr char kKeyAmpCurrentVolume[] = "hp_vol"; auto NvsStorage::OpenSync() -> NvsStorage* { esp_err_t err = nvs_flash_init(); @@ -154,4 +157,34 @@ auto NvsStorage::ScreenBrightness(uint_fast8_t val) -> std::future { }); } +auto NvsStorage::AmpMaxVolume() -> std::future { + return writer_->Dispatch([&]() -> uint16_t { + uint16_t out = wm8523::kDefaultMaxVolume; + nvs_get_u16(handle_, kKeyAmpMaxVolume, &out); + return out; + }); +} + +auto NvsStorage::AmpMaxVolume(uint16_t val) -> std::future { + return writer_->Dispatch([&]() { + nvs_set_u16(handle_, kKeyAmpMaxVolume, val); + return nvs_commit(handle_) == ESP_OK; + }); +} + +auto NvsStorage::AmpCurrentVolume() -> std::future { + return writer_->Dispatch([&]() -> uint16_t { + uint16_t out = wm8523::kDefaultVolume; + nvs_get_u16(handle_, kKeyAmpCurrentVolume, &out); + return out; + }); +} + +auto NvsStorage::AmpCurrentVolume(uint16_t val) -> std::future { + return writer_->Dispatch([&]() { + nvs_set_u16(handle_, kKeyAmpCurrentVolume, val); + return nvs_commit(handle_) == ESP_OK; + }); +} + } // namespace drivers -- cgit v1.2.3