diff options
| author | Jean-François Milants <jf@codingfield.com> | 2021-11-11 09:08:20 (GMT) |
|---|---|---|
| committer | Jean-François Milants <jf@codingfield.com> | 2021-11-11 09:08:20 (GMT) |
| commit | f6d0ec49e6f2669c64729b081eb3342f02151f4a (patch) | |
| tree | 7e21c83726bd3e0d18ec4ebe871274b1dbe2eb38 /src/components/ble/NimbleController.cpp | |
| parent | f41aaad6836ae348d1b5b084b4533b636f516b93 (diff) | |
| parent | a57fda6ba4a29866083a1254ffdf92939d00e182 (diff) | |
Merge branch 'develop'
# Conflicts:
# doc/buildAndProgram.md
Diffstat (limited to 'src/components/ble/NimbleController.cpp')
| -rw-r--r-- | src/components/ble/NimbleController.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp index 879421e..1bcae1b 100644 --- a/src/components/ble/NimbleController.cpp +++ b/src/components/ble/NimbleController.cpp @@ -23,7 +23,8 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::NotificationManager& notificationManager, Controllers::Battery& batteryController, Pinetime::Drivers::SpiNorFlash& spiNorFlash, - Controllers::HeartRateController& heartRateController) + Controllers::HeartRateController& heartRateController, + Controllers::MotionController& motionController) : systemTask {systemTask}, bleController {bleController}, dateTimeController {dateTimeController}, @@ -39,6 +40,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, batteryInformationService {batteryController}, immediateAlertService {systemTask, notificationManager}, heartRateService {systemTask, heartRateController}, + motionService{systemTask, motionController}, serviceDiscovery({¤tTimeClient, &alertNotificationClient}) { } @@ -81,6 +83,7 @@ void NimbleController::Init() { batteryInformationService.Init(); immediateAlertService.Init(); heartRateService.Init(); + motionService.Init(); int rc; rc = ble_hs_util_ensure_addr(0); @@ -215,6 +218,19 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) { event->subscribe.prev_notify, event->subscribe.cur_notify, event->subscribe.prev_indicate); + + if(event->subscribe.reason == BLE_GAP_SUBSCRIBE_REASON_TERM) { + heartRateService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); + motionService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); + } + else if(event->subscribe.prev_notify == 0 && event->subscribe.cur_notify == 1) { + heartRateService.SubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); + motionService.SubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); + } + else if(event->subscribe.prev_notify == 1 && event->subscribe.cur_notify == 0) { + heartRateService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); + motionService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); + } break; case BLE_GAP_EVENT_MTU: |
