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
custom
jacqueline 1 year ago
parent 0731a3fbcc
commit 7fbb2162ee
  1. 3
      src/drivers/include/nvs.hpp
  2. 14
      src/drivers/nvs.cpp
  3. 2
      src/system_fsm/booting.cpp

@ -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;

@ -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};

@ -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);

Loading…
Cancel
Save