From e8023f33a964e27d0d4dfed236d8d0a4d56efabf Mon Sep 17 00:00:00 2001 From: root Date: Thu, 16 Jun 2022 14:56:18 -0500 Subject: [PATCH] Test for a BLE disconnect while reading --- ports/nrf/common-hal/_bleio/__init__.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ports/nrf/common-hal/_bleio/__init__.c b/ports/nrf/common-hal/_bleio/__init__.c index 1d59983896..718b28c7fe 100644 --- a/ports/nrf/common-hal/_bleio/__init__.c +++ b/ports/nrf/common-hal/_bleio/__init__.c @@ -185,7 +185,12 @@ STATIC bool _on_gattc_read_rsp_evt(ble_evt_t *ble_evt, void *param) { } break; } - + case BLE_GAP_EVT_DISCONNECTED: { + read->conn_handle = BLE_CONN_HANDLE_INVALID; + read->done = true; + return false; + break; + } default: // For debugging. // mp_printf(&mp_plat_print, "Unhandled characteristic event: 0x%04x\n", ble_evt->header.evt_id); @@ -219,6 +224,8 @@ size_t common_hal_bleio_gattc_read(uint16_t handle, uint16_t conn_handle, uint8_ while (!read_info.done) { RUN_BACKGROUND_TASKS; } + // Test if we were disconnected while reading + common_hal_bleio_check_connected(read_info.conn_handle); ble_drv_remove_event_handler(_on_gattc_read_rsp_evt, &read_info); check_gatt_status(read_info.status);