espressif / esp-adf

Espressif Audio Development Framework
Other
1.52k stars 669 forks source link

bluetooth_service: Add function to get connected A2DP device (AUD-4747) #1038

Open ftab opened 1 year ago

ftab commented 1 year ago

This is helpful for storing the last known connected device for reconnecting to it on startup.

For example:

            if ((msg.cmd == PERIPH_BLUETOOTH_CONNECTED))
            {
                /* Save this as the last device that was connected */
                nvs_handle_t my_handle;
                esp_err_t err;

                err = nvs_open("storage", NVS_READWRITE, &my_handle);
                ESP_ERROR_CHECK_WITHOUT_ABORT(err);

                esp_bd_addr_t connected_bd_addr;
                periph_bt_get_connected_bd_addr(periph_set_handle, connected_bd_addr);

                err = nvs_set_blob(my_handle, "last_bd_addr", connected_bd_addr, 6);
                ESP_ERROR_CHECK_WITHOUT_ABORT(err);

                err = nvs_commit(my_handle);
                ESP_ERROR_CHECK_WITHOUT_ABORT(err);

                nvs_close(my_handle);
            }
CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

JosephTang commented 1 year ago

Hi @ftab , the commit message should inform the new function is to get the address of a2dp connected device

ftab commented 1 year ago

@JosephTang Thanks for the review, I have updated the commit message and implemented your suggestions.