extmod/modbluetooth: Add _IRQ_CONNECTION_UPDATE event.
This allows the application to be notified of changes to the connection interval, connection latency and supervision timeout. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
committed by
Damien George
parent
f2a9a0ac41
commit
c70665fb0b
@@ -295,20 +295,34 @@ STATIC void btstack_packet_handler(uint8_t packet_type, uint8_t *packet, uint8_t
|
||||
|
||||
if (event_type == HCI_EVENT_LE_META) {
|
||||
DEBUG_printf(" --> hci le meta\n");
|
||||
if (hci_event_le_meta_get_subevent_code(packet) == HCI_SUBEVENT_LE_CONNECTION_COMPLETE) {
|
||||
uint16_t conn_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
||||
uint8_t addr_type = hci_subevent_le_connection_complete_get_peer_address_type(packet);
|
||||
bd_addr_t addr;
|
||||
hci_subevent_le_connection_complete_get_peer_address(packet, addr);
|
||||
uint16_t irq_event;
|
||||
if (hci_subevent_le_connection_complete_get_role(packet) == 0) {
|
||||
// Master role.
|
||||
irq_event = MP_BLUETOOTH_IRQ_PERIPHERAL_CONNECT;
|
||||
} else {
|
||||
// Slave role.
|
||||
irq_event = MP_BLUETOOTH_IRQ_CENTRAL_CONNECT;
|
||||
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE: {
|
||||
uint16_t conn_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
||||
uint8_t addr_type = hci_subevent_le_connection_complete_get_peer_address_type(packet);
|
||||
bd_addr_t addr;
|
||||
hci_subevent_le_connection_complete_get_peer_address(packet, addr);
|
||||
uint16_t irq_event;
|
||||
if (hci_subevent_le_connection_complete_get_role(packet) == 0) {
|
||||
// Master role.
|
||||
irq_event = MP_BLUETOOTH_IRQ_PERIPHERAL_CONNECT;
|
||||
} else {
|
||||
// Slave role.
|
||||
irq_event = MP_BLUETOOTH_IRQ_CENTRAL_CONNECT;
|
||||
}
|
||||
mp_bluetooth_gap_on_connected_disconnected(irq_event, conn_handle, addr_type, addr);
|
||||
break;
|
||||
}
|
||||
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE: {
|
||||
uint8_t status = hci_subevent_le_connection_update_complete_get_status(packet);
|
||||
uint16_t conn_handle = hci_subevent_le_connection_update_complete_get_connection_handle(packet);
|
||||
uint16_t conn_interval = hci_subevent_le_connection_update_complete_get_conn_interval(packet);
|
||||
uint16_t conn_latency = hci_subevent_le_connection_update_complete_get_conn_latency(packet);
|
||||
uint16_t supervision_timeout = hci_subevent_le_connection_update_complete_get_supervision_timeout(packet);
|
||||
DEBUG_printf("- LE Connection %04x: connection update - connection interval %u.%02u ms, latency %u, timeout %u\n",
|
||||
conn_handle, conn_interval * 125 / 100, 25 * (conn_interval & 3), conn_latency, supervision_timeout);
|
||||
mp_bluetooth_gap_on_connection_update(conn_handle, conn_interval, conn_latency, supervision_timeout, status);
|
||||
break;
|
||||
}
|
||||
mp_bluetooth_gap_on_connected_disconnected(irq_event, conn_handle, addr_type, addr);
|
||||
}
|
||||
} else if (event_type == BTSTACK_EVENT_STATE) {
|
||||
uint8_t state = btstack_event_state_get_state(packet);
|
||||
|
||||
Reference in New Issue
Block a user