Deliver AVRC events on a background thread

We don't currently do anything with them, so need to wait for the lock
on the bt thread
custom
jacqueline 1 year ago
parent a67cd1dec6
commit c0be3f863f
  1. 8
      src/drivers/bluetooth.cpp
  2. 2
      src/drivers/include/bluetooth.hpp

@ -47,9 +47,12 @@ auto gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t* param) -> void {
auto avrcp_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t* param) auto avrcp_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t* param)
-> void { -> void {
esp_avrc_ct_cb_param_t copy = *param;
sBgWorker->Dispatch<void>([=]() {
auto lock = bluetooth::BluetoothState::lock(); auto lock = bluetooth::BluetoothState::lock();
tinyfsm::FsmList<bluetooth::BluetoothState>::dispatch( tinyfsm::FsmList<bluetooth::BluetoothState>::dispatch(
bluetooth::events::internal::Avrc{.type = event, .param = param}); bluetooth::events::internal::Avrc{.type = event, .param = copy});
});
} }
auto a2dp_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t* param) -> void { auto a2dp_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t* param) -> void {
@ -658,7 +661,6 @@ void Connected::react(const events::SourceChanged& ev) {
} }
void Connected::react(const events::ChangeVolume& ev) { void Connected::react(const events::ChangeVolume& ev) {
ESP_LOGI(kTag, "send vol %u", ev.volume);
esp_err_t err = esp_avrc_ct_send_set_absolute_volume_cmd( esp_err_t err = esp_avrc_ct_send_set_absolute_volume_cmd(
transaction_num_++, std::clamp<uint8_t>(ev.volume, 0, 0x7f)); transaction_num_++, std::clamp<uint8_t>(ev.volume, 0, 0x7f));
if (err != ESP_OK) { if (err != ESP_OK) {
@ -709,7 +711,7 @@ void Connected::react(const events::internal::A2dp& ev) {
void Connected::react(const events::internal::Avrc& ev) { void Connected::react(const events::internal::Avrc& ev) {
switch (ev.type) { switch (ev.type) {
case ESP_AVRC_CT_CONNECTION_STATE_EVT: case ESP_AVRC_CT_CONNECTION_STATE_EVT:
if (ev.param->conn_stat.connected) { if (ev.param.conn_stat.connected) {
// TODO: tell the target about our capabilities // TODO: tell the target about our capabilities
} }
// Don't worry about disconnect events; if there's a serious problem // Don't worry about disconnect events; if there's a serious problem

@ -75,7 +75,7 @@ struct A2dp : public tinyfsm::Event {
}; };
struct Avrc : public tinyfsm::Event { struct Avrc : public tinyfsm::Event {
esp_avrc_ct_cb_event_t type; esp_avrc_ct_cb_event_t type;
esp_avrc_ct_cb_param_t* param; esp_avrc_ct_cb_param_t param;
}; };
} // namespace internal } // namespace internal
} // namespace events } // namespace events

Loading…
Cancel
Save