diff options
Diffstat (limited to 'src/drivers/nvs.cpp')
| -rw-r--r-- | src/drivers/nvs.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp index a2de9518..8c7e54a8 100644 --- a/src/drivers/nvs.cpp +++ b/src/drivers/nvs.cpp @@ -10,6 +10,7 @@ #include <cstdint> #include <memory> +#include "bluetooth.hpp" #include "esp_log.h" #include "nvs.h" #include "nvs_flash.h" @@ -20,6 +21,7 @@ static constexpr char kTag[] = "nvm"; static constexpr uint8_t kSchemaVersion = 1; static constexpr char kKeyVersion[] = "ver"; +static constexpr char kKeyBluetooth[] = "bt"; auto NvsStorage::Open() -> NvsStorage* { esp_err_t err = nvs_flash_init(); @@ -70,4 +72,24 @@ auto NvsStorage::SchemaVersion() -> uint8_t { return ret; } +auto NvsStorage::PreferredBluetoothDevice() + -> std::optional<bluetooth::mac_addr_t> { + bluetooth::mac_addr_t out{0}; + size_t size = out.size(); + if (nvs_get_blob(handle_, kKeyBluetooth, out.data(), &size) != ESP_OK) { + return {}; + } + return out; +} +auto NvsStorage::PreferredBluetoothDevice( + std::optional<bluetooth::mac_addr_t> addr) -> void { + if (!addr) { + nvs_erase_key(handle_, kKeyBluetooth); + } else { + nvs_set_blob(handle_, kKeyBluetooth, addr.value().data(), + addr.value().size()); + } + nvs_commit(handle_); +} + } // namespace drivers |
