From 544b0013b104a6584660724ccd502adcccd7ca6c Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 15 Aug 2023 17:32:57 +1000 Subject: persist preferred bluetooth device in nvs --- src/drivers/include/bluetooth.hpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'src/drivers/include/bluetooth.hpp') diff --git a/src/drivers/include/bluetooth.hpp b/src/drivers/include/bluetooth.hpp index bdc45910..fc72d393 100644 --- a/src/drivers/include/bluetooth.hpp +++ b/src/drivers/include/bluetooth.hpp @@ -11,32 +11,22 @@ #include #include +#include "bluetooth_types.hpp" #include "esp_a2dp_api.h" #include "esp_avrc_api.h" #include "esp_gap_bt_api.h" +#include "nvs.hpp" #include "tinyfsm.hpp" #include "tinyfsm/include/tinyfsm.hpp" namespace drivers { -namespace bluetooth { - -typedef std::array mac_addr_t; - -struct Device { - mac_addr_t address; - std::string name; - uint32_t class_of_device; - int8_t signal_strength; -}; -} // namespace bluetooth - /* * A handle used to interact with the bluetooth state machine. */ class Bluetooth { public: - Bluetooth(); + Bluetooth(NvsStorage* storage); auto Enable() -> bool; auto Disable() -> void; @@ -74,6 +64,8 @@ struct Avrc : public tinyfsm::Event { class BluetoothState : public tinyfsm::Fsm { public: + static auto Init(NvsStorage* storage) -> void; + static auto devices() -> std::vector; static auto preferred_device() -> std::optional; static auto preferred_device(const mac_addr_t&) -> void; @@ -96,6 +88,8 @@ class BluetoothState : public tinyfsm::Fsm { virtual void react(const events::internal::Avrc& ev){}; protected: + static NvsStorage* sStorage_; + static std::mutex sDevicesMutex_; static std::map sDevices_; static std::optional sPreferredDevice_; -- cgit v1.2.3