summaryrefslogtreecommitdiff
path: root/src/drivers/include/bluetooth.hpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-08-15 17:32:57 +1000
committerjacqueline <me@jacqueline.id.au>2023-08-15 17:32:57 +1000
commit544b0013b104a6584660724ccd502adcccd7ca6c (patch)
tree46b140ca9d51cdc14f0004ce64c7b89d021d5fce /src/drivers/include/bluetooth.hpp
parentd6b83fcf4a1a3039c06e0b1d1a1f7e2af2351efb (diff)
downloadtangara-fw-544b0013b104a6584660724ccd502adcccd7ca6c.tar.gz
persist preferred bluetooth device in nvs
Diffstat (limited to 'src/drivers/include/bluetooth.hpp')
-rw-r--r--src/drivers/include/bluetooth.hpp20
1 files changed, 7 insertions, 13 deletions
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 <freertos/FreeRTOS.h>
#include <freertos/stream_buffer.h>
+#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<uint8_t, 6> 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<BluetoothState> {
public:
+ static auto Init(NvsStorage* storage) -> void;
+
static auto devices() -> std::vector<Device>;
static auto preferred_device() -> std::optional<mac_addr_t>;
static auto preferred_device(const mac_addr_t&) -> void;
@@ -96,6 +88,8 @@ class BluetoothState : public tinyfsm::Fsm<BluetoothState> {
virtual void react(const events::internal::Avrc& ev){};
protected:
+ static NvsStorage* sStorage_;
+
static std::mutex sDevicesMutex_;
static std::map<mac_addr_t, Device> sDevices_;
static std::optional<mac_addr_t> sPreferredDevice_;