From c8354f18ca309966880c58c7dcee51dab69896b6 Mon Sep 17 00:00:00 2001 From: Dennis Field Date: Fri, 13 Jan 2023 16:03:04 -0500 Subject: [PATCH] Add function to get connected device --- components/bluetooth_service/a2dp_stream.c | 11 +++++++++++ components/bluetooth_service/include/a2dp_stream.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/components/bluetooth_service/a2dp_stream.c b/components/bluetooth_service/a2dp_stream.c index ae6481f74..aa2ec33ff 100644 --- a/components/bluetooth_service/a2dp_stream.c +++ b/components/bluetooth_service/a2dp_stream.c @@ -47,6 +47,7 @@ typedef struct { bool avrcp_conn_state; audio_stream_type_t stream_type; uint8_t trans_label; + esp_bd_addr_t connected_bd_addr; #if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)) audio_hal_handle_t audio_hal; @@ -121,6 +122,7 @@ static void bt_a2d_sink_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param) bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); if (param->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) { ESP_LOGI(TAG, "A2DP connection state = DISCONNECTED"); + memset(s_aadp_handler.connected_bd_addr, 0x00, ESP_BD_ADDR_LEN); if (s_aadp_handler.sink_stream) { audio_element_report_status(s_aadp_handler.sink_stream, AEL_STATUS_INPUT_DONE); } @@ -129,6 +131,7 @@ static void bt_a2d_sink_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param) } } else if (param->conn_stat.state == ESP_A2D_CONNECTION_STATE_CONNECTED) { ESP_LOGI(TAG, "A2DP connection state = CONNECTED"); + memcpy(s_aadp_handler.connected_bd_addr, bda, ESP_BD_ADDR_LEN); if (s_aadp_handler.bt_avrc_periph) { esp_periph_send_event(s_aadp_handler.bt_avrc_periph, PERIPH_BLUETOOTH_CONNECTED, NULL, 0); } @@ -614,4 +617,12 @@ esp_err_t periph_bt_volume_down(esp_periph_handle_t periph) } #endif +esp_err_t periph_bt_get_connected_bd_addr(esp_periph_handle_t periph, uint8_t *dest) +{ + if (!dest) + return ESP_ERR_INVALID_ARG; + memcpy(dest, s_aadp_handler.connected_bd_addr, ESP_BD_ADDR_LEN); + return ESP_OK; +} + #endif diff --git a/components/bluetooth_service/include/a2dp_stream.h b/components/bluetooth_service/include/a2dp_stream.h index 05a61f2ba..199653e1e 100755 --- a/components/bluetooth_service/include/a2dp_stream.h +++ b/components/bluetooth_service/include/a2dp_stream.h @@ -208,6 +208,8 @@ esp_err_t periph_bt_volume_up(esp_periph_handle_t periph); esp_err_t periph_bt_volume_down(esp_periph_handle_t periph); #endif +esp_err_t periph_bt_get_connected_bd_addr(esp_periph_handle_t periph, uint8_t *dest); + #endif #ifdef __cplusplus