summaryrefslogtreecommitdiff
path: root/src/drivers/include
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-02-06 12:38:11 +1100
committerjacqueline <me@jacqueline.id.au>2024-02-06 13:37:20 +1100
commit99c56641e9ee531a0553ff19422009dd667a3add (patch)
tree8cb4dcd954a563b42bee9e991e8ad9bb99a0f3c7 /src/drivers/include
parentab314b82e10aadb674fab223bffa4933a9a65750 (diff)
downloadtangara-fw-99c56641e9ee531a0553ff19422009dd667a3add.tar.gz
fix various of bluetooth issues
connecting and disconnecting is a bit more consistent now!
Diffstat (limited to 'src/drivers/include')
-rw-r--r--src/drivers/include/bluetooth.hpp15
-rw-r--r--src/drivers/include/bluetooth_types.hpp5
-rw-r--r--src/drivers/include/nvs.hpp4
3 files changed, 16 insertions, 8 deletions
diff --git a/src/drivers/include/bluetooth.hpp b/src/drivers/include/bluetooth.hpp
index 4aefbc42..291d049d 100644
--- a/src/drivers/include/bluetooth.hpp
+++ b/src/drivers/include/bluetooth.hpp
@@ -44,8 +44,8 @@ class Bluetooth {
auto KnownDevices() -> std::vector<bluetooth::Device>;
- auto SetPreferredDevice(const bluetooth::mac_addr_t& mac) -> void;
- auto PreferredDevice() -> std::optional<bluetooth::mac_addr_t>;
+ auto SetPreferredDevice(std::optional<bluetooth::MacAndName> dev) -> void;
+ auto PreferredDevice() -> std::optional<bluetooth::MacAndName>;
auto SetSource(StreamBufferHandle_t) -> void;
auto SetEventHandler(std::function<void(bluetooth::Event)> cb) -> void;
@@ -107,8 +107,8 @@ class BluetoothState : public tinyfsm::Fsm<BluetoothState> {
static auto devices() -> std::vector<Device>;
- static auto preferred_device() -> std::optional<mac_addr_t>;
- static auto preferred_device(std::optional<mac_addr_t>) -> void;
+ static auto preferred_device() -> std::optional<bluetooth::MacAndName>;
+ static auto preferred_device(std::optional<bluetooth::MacAndName>) -> void;
static auto scanning() -> bool;
static auto discovery() -> bool;
@@ -142,8 +142,8 @@ class BluetoothState : public tinyfsm::Fsm<BluetoothState> {
static std::mutex sDevicesMutex_;
static std::map<mac_addr_t, Device> sDevices_;
- static std::optional<mac_addr_t> sPreferredDevice_;
- static std::optional<Device> sCurrentDevice_;
+ static std::optional<bluetooth::MacAndName> sPreferredDevice_;
+ static std::optional<bluetooth::MacAndName> sConnectingDevice_;
static bool sIsDiscoveryAllowed_;
static std::atomic<StreamBufferHandle_t> sSource_;
@@ -205,6 +205,9 @@ class Connected : public BluetoothState {
void react(const events::internal::Avrc& ev) override;
using BluetoothState::react;
+
+ private:
+ mac_addr_t connected_to_;
};
} // namespace bluetooth
diff --git a/src/drivers/include/bluetooth_types.hpp b/src/drivers/include/bluetooth_types.hpp
index 518771e5..87da0ab5 100644
--- a/src/drivers/include/bluetooth_types.hpp
+++ b/src/drivers/include/bluetooth_types.hpp
@@ -11,6 +11,11 @@ namespace bluetooth {
typedef std::array<uint8_t, 6> mac_addr_t;
+struct MacAndName {
+ mac_addr_t mac;
+ std::string name;
+};
+
struct Device {
mac_addr_t address;
std::pmr::string name;
diff --git a/src/drivers/include/nvs.hpp b/src/drivers/include/nvs.hpp
index f592b1c3..1184b72c 100644
--- a/src/drivers/include/nvs.hpp
+++ b/src/drivers/include/nvs.hpp
@@ -25,8 +25,8 @@ class 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;
+ auto PreferredBluetoothDevice() -> std::optional<bluetooth::MacAndName>;
+ auto PreferredBluetoothDevice(std::optional<bluetooth::MacAndName>) -> bool;
enum class Output : uint8_t {
kHeadphones = 0,