Arduino A2DP
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
BluetoothA2DPCommon Class Referenceabstract

Common Bluetooth A2DP functions. More...

#include <BluetoothA2DPCommon.h>

Inheritance diagram for BluetoothA2DPCommon:
BluetoothA2DPSink BluetoothA2DPSource BluetoothA2DPSinkQueued

Public Member Functions

 BluetoothA2DPCommon ()
 Default constructor.
 
virtual ~BluetoothA2DPCommon ()=default
 Destructor.
 
virtual void clean_last_connection ()
 clean last connection (delete)
 
virtual bool connect_to (esp_bd_addr_t peer)
 Connnects to the indicated address.
 
virtual void debounce (void(*cb)(void), int ms)
 
void delay_ms (uint32_t millis)
 calls vTaskDelay to pause for the indicated number of milliseconds
 
virtual void disconnect ()
 Closes the connection.
 
virtual void end (bool releaseMemory=false)
 Closes the connection and stops A2DP.
 
virtual esp_a2d_audio_state_t get_audio_state ()
 Determine the actual audio state.
 
virtual esp_a2d_connection_state_t get_connection_state ()
 Determine the connection state.
 
virtual esp_bd_addr_tget_last_peer_address ()
 Provides the address of the last device.
 
unsigned long get_millis ()
 Provides the time in milliseconds since the last system boot.
 
virtual const char * get_name ()
 Provides the actual SSID name.
 
virtual int get_volume ()
 Determines the actual volume.
 
virtual bool is_connected ()
 Checks if A2DP is connected.
 
void log_free_heap ()
 Logs the free heap.
 
virtual bool reconnect ()
 Reconnects to the last device.
 
void set_auto_reconnect (bool active)
 
virtual void set_avrc_rn_events (std::vector< esp_avrc_rn_event_ids_t > events)
 
void set_bluedroid_config_t (esp_bluedroid_config_t cfg)
 Defines the esp_bluedroid_config_t: Available from IDF 5.2.1.
 
virtual void set_connectable (bool connectable)
 Bluetooth connectable.
 
virtual void set_connected (bool active)
 Calls disconnect or reconnect.
 
virtual void set_default_bt_mode (esp_bt_mode_t mode)
 
virtual void set_discoverability (esp_bt_discovery_mode_t d)
 Bluetooth discoverability. More...
 
void set_event_queue_size (int size)
 Defines the queue size of the event task.
 
void set_event_stack_size (int size)
 Defines the stack size of the event task (in bytes)
 
virtual void set_on_audio_state_changed (void(*callBack)(esp_a2d_audio_state_t state, void *), void *obj=nullptr)
 Set the callback that is called when the audio state is changed. More...
 
virtual void set_on_audio_state_changed_post (void(*callBack)(esp_a2d_audio_state_t state, void *), void *obj=nullptr)
 
virtual void set_on_connection_state_changed (void(*callBack)(esp_a2d_connection_state_t state, void *), void *obj=nullptr)
 Set the callback that is called when the connection state is changed. More...
 
void set_task_core (BaseType_t core)
 
void set_task_priority (UBaseType_t priority)
 defines the task priority (the default value is configMAX_PRIORITIES - 10)
 
virtual void set_volume (uint8_t volume)
 Sets the volume (range 0 - 127)
 
virtual void set_volume_control (A2DPVolumeControl *ptr)
 you can define a custom VolumeControl implementation
 
const char * to_str (esp_a2d_audio_state_t state)
 converts a esp_a2d_audio_state_t to a string
 
const char * to_str (esp_a2d_connection_state_t state)
 converts esp_a2d_connection_state_t to a string
 
const char * to_str (esp_avrc_playback_stat_t state)
 converts esp_avrc_playback_stat_t to a string More...
 
const char * to_str (esp_bd_addr_t bda)
 converts a esp_bd_addr_t to a string - the string is 18 characters long!
 

Protected Member Functions

virtual void app_a2d_callback (esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)=0
 callback function for A2DP source
 
virtual void app_gap_callback (esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)=0
 
virtual void app_rc_ct_callback (esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param)=0
 callback function for AVRCP controller
 
virtual void app_rc_tg_callback (esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param)=0
 
virtual bool app_send_msg (bt_app_msg_t *msg)
 
virtual void app_task_handler (void *arg)
 
virtual void app_task_shut_down ()
 
virtual void app_task_start_up ()
 
virtual void app_work_dispatched (bt_app_msg_t *msg)
 
virtual void av_hdl_avrc_tg_evt (uint16_t event, void *p_param)=0
 
virtual void av_hdl_stack_evt (uint16_t event, void *p_param)=0
 
virtual esp_err_t bluedroid_init ()
 
virtual bool bt_start ()
 Startup logic as implemented by Arduino. More...
 
virtual esp_err_t esp_a2d_connect (esp_bd_addr_t peer)=0
 
virtual esp_err_t esp_a2d_disconnect (esp_bd_addr_t remote_bda)=0
 
virtual void get_last_connection ()
 
virtual bool has_last_connection ()
 
virtual void init_nvs ()
 
virtual bool isSource ()=0
 
virtual const char * last_bda_nvs_name ()=0
 
virtual bool read_address (const char *name, esp_bd_addr_t &bda)
 
virtual void set_last_connection (esp_bd_addr_t bda)
 
virtual void set_scan_mode_connectable (bool connectable)
 Defines if the bluetooth is connectable.
 
virtual void set_scan_mode_connectable_default ()=0
 
virtual A2DPVolumeControlvolume_control ()
 provides access to the VolumeControl object
 
virtual bool write_address (const char *name, esp_bd_addr_t bda)
 

Protected Attributes

TaskHandle_t app_task_handle = nullptr
 
QueueHandle_t app_task_queue = nullptr
 
esp_a2d_audio_state_t audio_state = ESP_A2D_AUDIO_STATE_STOPPED
 
void(* audio_state_callback )(esp_a2d_audio_state_t state, void *obj) = nullptr
 
void(* audio_state_callback_post )(esp_a2d_audio_state_t state, void *obj) = nullptr
 
void * audio_state_obj = nullptr
 
void * audio_state_obj_post = nullptr
 
std::vector< esp_avrc_rn_event_ids_tavrc_rn_events
 
esp_bluedroid_config_t bluedroid_config {.ssp_en = true}
 
esp_bt_mode_t bt_mode = ESP_BT_MODE_CLASSIC_BT
 
const char * bt_name = {0}
 
esp_a2d_connection_state_t connection_state
 
void(* connection_state_callback )(esp_a2d_connection_state_t state, void *obj) = nullptr
 
void * connection_state_obj = nullptr
 
uint32_t debounce_ms = 0
 
unsigned int default_reconnect_timout = 10000
 
A2DPDefaultVolumeControl default_volume_control
 
esp_bt_discovery_mode_t discoverability = ESP_BT_GENERAL_DISCOVERABLE
 
int event_queue_size = 20
 
int event_stack_size = 3072
 
bool is_autoreconnect_allowed = false
 
bool is_start_disabled = false
 
bool is_target_status_active = true
 
bool is_volume_used = false
 
esp_bd_addr_t last_connection = {0, 0, 0, 0, 0, 0}
 
const char * m_a2d_audio_state_str [4] = {"Suspended", "Started", "Suspended", "Suspended"}
 
const char * m_a2d_conn_state_str [4]
 
const char * m_avrc_playback_state_str [5]
 
esp_bd_addr_t peer_bd_addr
 
ReconnectStatus reconnect_status = NoReconnect
 
unsigned long reconnect_timout = 0
 
BaseType_t task_core = 1
 
UBaseType_t task_priority = configMAX_PRIORITIES - 10
 
A2DPVolumeControlvolume_control_ptr = nullptr
 
uint8_t volume_value = 0
 

Friends

void ccall_app_a2d_callback (esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
 
void ccall_app_gap_callback (esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
 
void ccall_app_rc_ct_callback (esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param)
 
void ccall_app_rc_tg_callback (esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param)
 handle esp_avrc_tg_cb_event_t
 
void ccall_av_hdl_avrc_tg_evt (uint16_t event, void *p_param)
 
void ccall_av_hdl_stack_evt (uint16_t event, void *p_param)
 
void ccall_bt_app_task_handler (void *arg)
 task handler
 

Detailed Description

Common Bluetooth A2DP functions.

Author
Phil Schatzmann

Member Function Documentation

◆ bt_start()

bool BluetoothA2DPCommon::bt_start ( )
protectedvirtual

Startup logic as implemented by Arduino.

Returns
true
false

◆ debounce()

void BluetoothA2DPCommon::debounce ( void(*)(void)  cb,
int  ms 
)
virtual

Prevents that the same method is executed multiple times within the indicated time limit

◆ set_auto_reconnect()

void BluetoothA2DPCommon::set_auto_reconnect ( bool  active)

activate / deactivate the automatic reconnection to the last address (per default this is on)

◆ set_avrc_rn_events()

virtual void BluetoothA2DPCommon::set_avrc_rn_events ( std::vector< esp_avrc_rn_event_ids_t events)
inlinevirtual

Define the vector of esp_avrc_rn_event_ids_t with e.g. ESP_AVRC_RN_PLAY_STATUS_CHANGE | ESP_AVRC_RN_TRACK_CHANGE | ESP_AVRC_RN_TRACK_REACHED_END | ESP_AVRC_RN_TRACK_REACHED_START | ESP_AVRC_RN_PLAY_POS_CHANGED | ESP_AVRC_RN_BATTERY_STATUS_CHANGE | ESP_AVRC_RN_SYSTEM_STATUS_CHANGE | ESP_AVRC_RN_APP_SETTING_CHANGE | ESP_AVRC_RN_NOW_PLAYING_CHANGE | ESP_AVRC_RN_AVAILABLE_PLAYERS_CHANGE | ESP_AVRC_RN_ADDRESSED_PLAYER_CHANGE | ESP_AVRC_RN_UIDS_CHANGE|ESP_AVRC_RN_VOLUME_CHANGE

◆ set_default_bt_mode()

virtual void BluetoothA2DPCommon::set_default_bt_mode ( esp_bt_mode_t  mode)
inlinevirtual

Defines the default bt mode. The default is ESP_BT_MODE_CLASSIC_BT: use this e.g. to set to ESP_BT_MODE_BTDM

◆ set_discoverability()

void BluetoothA2DPCommon::set_discoverability ( esp_bt_discovery_mode_t  d)
virtual

Bluetooth discoverability.

Defines if the bluetooth is discoverable.

◆ set_on_audio_state_changed()

void BluetoothA2DPCommon::set_on_audio_state_changed ( void(*)(esp_a2d_audio_state_t state, void *)  callBack,
void *  obj = nullptr 
)
virtual

Set the callback that is called when the audio state is changed.

Set the callback that is called when the audio state is changed This callback is called before the I2S bus is changed.

◆ set_on_audio_state_changed_post()

void BluetoothA2DPCommon::set_on_audio_state_changed_post ( void(*)(esp_a2d_audio_state_t state, void *)  callBack,
void *  obj = nullptr 
)
virtual

Set the callback that is called after the audio state has changed. This callback is called after the I2S bus has changed.

◆ set_on_connection_state_changed()

void BluetoothA2DPCommon::set_on_connection_state_changed ( void(*)(esp_a2d_connection_state_t state, void *)  callBack,
void *  obj = nullptr 
)
virtual

Set the callback that is called when the connection state is changed.

Set the callback that is called when the connection state is changed This callback is called before the I2S bus is changed.

◆ set_task_core()

void BluetoothA2DPCommon::set_task_core ( BaseType_t  core)
inline

Defines the core which is used to start the tasks (to process the events and audio queue)

◆ to_str()

const char * BluetoothA2DPCommon::to_str ( esp_avrc_playback_stat_t  state)

converts esp_avrc_playback_stat_t to a string

converts a esp_a2d_audio_state_t to a string

Member Data Documentation

◆ avrc_rn_events

std::vector<esp_avrc_rn_event_ids_t> BluetoothA2DPCommon::avrc_rn_events
protected
Initial value:
= {
ESP_AVRC_RN_VOLUME_CHANGE}

◆ connection_state

esp_a2d_connection_state_t BluetoothA2DPCommon::connection_state
protected
Initial value:
=
@ ESP_A2D_CONNECTION_STATE_DISCONNECTED
Definition: external_lists.h:17

◆ m_a2d_conn_state_str

const char* BluetoothA2DPCommon::m_a2d_conn_state_str[4]
protected
Initial value:
= {"Disconnected", "Connecting",
"Connected", "Disconnecting"}

◆ m_avrc_playback_state_str

const char* BluetoothA2DPCommon::m_avrc_playback_state_str[5]
protected
Initial value:
= {"stopped", "playing", "paused",
"forward seek", "reverse seek"}

The documentation for this class was generated from the following files: