diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-02-07 11:17:20 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-02-07 11:17:20 +1100 |
| commit | c0be3f863fbcd3f539120f40fd42ae2f49be6f63 (patch) | |
| tree | 3c3a7c3f14b67d92ff38eed969ebe3619ec6db35 /src/drivers | |
| parent | a67cd1dec69242f144e6ce8646de3091921b65e8 (diff) | |
| download | tangara-fw-c0be3f863fbcd3f539120f40fd42ae2f49be6f63.tar.gz | |
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
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/bluetooth.cpp | 12 | ||||
| -rw-r--r-- | src/drivers/include/bluetooth.hpp | 2 |
2 files changed, 8 insertions, 6 deletions
diff --git a/src/drivers/bluetooth.cpp b/src/drivers/bluetooth.cpp index 0b30c7c1..f266b51c 100644 --- a/src/drivers/bluetooth.cpp +++ b/src/drivers/bluetooth.cpp @@ -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) -> void { - auto lock = bluetooth::BluetoothState::lock(); - tinyfsm::FsmList<bluetooth::BluetoothState>::dispatch( - bluetooth::events::internal::Avrc{.type = event, .param = param}); + esp_avrc_ct_cb_param_t copy = *param; + sBgWorker->Dispatch<void>([=]() { + auto lock = bluetooth::BluetoothState::lock(); + tinyfsm::FsmList<bluetooth::BluetoothState>::dispatch( + bluetooth::events::internal::Avrc{.type = event, .param = copy}); + }); } 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) { - ESP_LOGI(kTag, "send vol %u", ev.volume); esp_err_t err = esp_avrc_ct_send_set_absolute_volume_cmd( transaction_num_++, std::clamp<uint8_t>(ev.volume, 0, 0x7f)); if (err != ESP_OK) { @@ -709,7 +711,7 @@ void Connected::react(const events::internal::A2dp& ev) { void Connected::react(const events::internal::Avrc& ev) { switch (ev.type) { 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 } // Don't worry about disconnect events; if there's a serious problem diff --git a/src/drivers/include/bluetooth.hpp b/src/drivers/include/bluetooth.hpp index 2936fb8e..5fdd527c 100644 --- a/src/drivers/include/bluetooth.hpp +++ b/src/drivers/include/bluetooth.hpp @@ -75,7 +75,7 @@ struct A2dp : public tinyfsm::Event { }; struct Avrc : public tinyfsm::Event { esp_avrc_ct_cb_event_t type; - esp_avrc_ct_cb_param_t* param; + esp_avrc_ct_cb_param_t param; }; } // namespace internal } // namespace events |
