Skip to content

Commit

Permalink
Add function to get connected device
Browse files Browse the repository at this point in the history
  • Loading branch information
ftab committed Jul 19, 2023
1 parent 49e63cd commit c8354f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions components/bluetooth_service/a2dp_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions components/bluetooth_service/include/a2dp_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c8354f1

Please sign in to comment.