diff options
| author | James A. Jerkins <evergreen@jamesjerkinscomputer.com> | 2021-09-05 20:53:20 (GMT) |
|---|---|---|
| committer | James A. Jerkins <evergreen@jamesjerkinscomputer.com> | 2021-09-05 20:53:20 (GMT) |
| commit | 22571d4b384e40d647cd994202956f08ed32d925 (patch) | |
| tree | 5ecf4349a0d0cc8b29cdf35f779e5565dbb6cae4 /src/components/ble/NimbleController.cpp | |
| parent | 4820b2ffe8be0b8d1abefd307a4c0fe6d4d41a73 (diff) | |
Advertise fast for at least 30 secs then slow down
On power up, advertise aggressively for at least 30 seconds then switch
to a longer interval to conserve battery life. This fast/slow pattern
is designed to balance connection response time and battery life.
When a disconnect event is received restart the fast/slow pattern.
When a failed connect event is received, restart the fast/slow pattern.
When the screen is activated and ble is not connected, restart the fast/slow pattern.
This pattern is consistent with Apple's BLE developer standards (QA 1931).
Diffstat (limited to 'src/components/ble/NimbleController.cpp')
| -rw-r--r-- | src/components/ble/NimbleController.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp index 8e0fe75..226f669 100644 --- a/src/components/ble/NimbleController.cpp +++ b/src/components/ble/NimbleController.cpp @@ -122,6 +122,15 @@ void NimbleController::StartAdvertising() { adv_params.conn_mode = BLE_GAP_CONN_MODE_UND; adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN; + /* fast advertise for 30 sec */ + if (fastAdvCount < 15) { + adv_params.itvl_min = 32; + adv_params.itvl_max = 47; + fastAdvCount++; + } else { + adv_params.itvl_min = 1636; + adv_params.itvl_max = 1651; + } fields.flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP; fields.uuids128 = &dfuServiceUuid; @@ -139,7 +148,7 @@ void NimbleController::StartAdvertising() { rc = ble_gap_adv_rsp_set_fields(&rsp_fields); ASSERT(rc == 0); - rc = ble_gap_adv_start(addrType, NULL, 5000, &adv_params, GAPEventCallback, this); + rc = ble_gap_adv_start(addrType, NULL, 2000, &adv_params, GAPEventCallback, this); ASSERT(rc == 0); } @@ -163,6 +172,7 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) { alertNotificationClient.Reset(); connectionHandle = BLE_HS_CONN_HANDLE_NONE; bleController.Disconnect(); + fastAdvCount = 0; StartAdvertising(); } else { connectionHandle = event->connect.conn_handle; @@ -181,6 +191,7 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) { alertNotificationClient.Reset(); connectionHandle = BLE_HS_CONN_HANDLE_NONE; bleController.Disconnect(); + fastAdvCount = 0; StartAdvertising(); break; |
