diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-02-06 09:01:12 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-02-06 13:37:20 +1100 |
| commit | 7fbb2162ee448b8d8a1744f9a3e31db86149da21 (patch) | |
| tree | f07618f320c844f04b1171821ca2b63cc71d6f8c | |
| parent | 0731a3fbcc5f68b8f36cb5e946f34fff78f0339e (diff) | |
| download | tangara-fw-7fbb2162ee448b8d8a1744f9a3e31db86149da21.tar.gz | |
Start keeping lock switch polarity in nvs
i will use this to do a sneaky trick; in-place upgrading brendan,
hailey, and erin's devices
| -rw-r--r-- | src/drivers/include/nvs.hpp | 3 | ||||
| -rw-r--r-- | src/drivers/nvs.cpp | 14 | ||||
| -rw-r--r-- | src/system_fsm/booting.cpp | 2 |
3 files changed, 19 insertions, 0 deletions
diff --git a/src/drivers/include/nvs.hpp b/src/drivers/include/nvs.hpp index bf0bebab..f592b1c3 100644 --- a/src/drivers/include/nvs.hpp +++ b/src/drivers/include/nvs.hpp @@ -22,6 +22,9 @@ class NvsStorage { public: static auto OpenSync() -> NvsStorage*; + auto LockPolarity() -> bool; + auto LockPolarity(bool) -> bool; + auto PreferredBluetoothDevice() -> std::optional<bluetooth::mac_addr_t>; auto PreferredBluetoothDevice(std::optional<bluetooth::mac_addr_t>) -> bool; diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp index c8d4d636..8c9aa361 100644 --- a/src/drivers/nvs.cpp +++ b/src/drivers/nvs.cpp @@ -33,6 +33,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 kKeyLockPolarity[] = "lockpol"; auto NvsStorage::OpenSync() -> NvsStorage* { esp_err_t err = nvs_flash_init(); @@ -85,6 +86,19 @@ auto NvsStorage::SchemaVersionSync() -> uint8_t { return ret; } +auto NvsStorage::LockPolarity() -> bool { + uint8_t res; + if (nvs_get_u8(handle_, kKeyLockPolarity, &res) != ESP_OK) { + return false; + } + return res > 0; +} + +auto NvsStorage::LockPolarity(bool p) -> bool { + nvs_set_u8(handle_, kKeyLockPolarity, p); + return nvs_commit(handle_) == ESP_OK; +} + auto NvsStorage::PreferredBluetoothDevice() -> std::optional<bluetooth::mac_addr_t> { bluetooth::mac_addr_t out{0}; diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp index e6267879..888ce5d3 100644 --- a/src/system_fsm/booting.cpp +++ b/src/system_fsm/booting.cpp @@ -98,6 +98,8 @@ auto Booting::entry() -> void { sServices->bluetooth().Enable(); } + sServices->nvs().LockPolarity(true); + BootComplete ev{.services = sServices}; events::Audio().Dispatch(ev); events::Ui().Dispatch(ev); |
