From 6abf12ffb7a26e8d42b1dcb41b1fa9bcccd3ac16 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 12 Jan 2020 16:39:03 +0100 Subject: Detect BLE disconnection (in addition to BLE connection) and update the display accordingly. --- src/main.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 7f8bef8c..ac6f3fcc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,8 @@ Pinetime::Controllers::Ble bleController; Pinetime::Controllers::DateTime dateTimeController; +void ble_manager_set_ble_connection_callback(void (*connection)()); +void ble_manager_set_ble_disconnection_callback(void (*disconnection)()); static constexpr uint8_t pinButton = 13; static constexpr uint8_t pinTouchIrq = 28; @@ -98,10 +100,17 @@ void SystemTask(void *) { vTaskSuspend(nullptr); } -void OnNewTime(current_time_char_t* currentTime) { +void OnBleConnection() { bleController.Connect(); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBleConnection); +} +void OnBleDisconnection() { + bleController.Disconnect(); + displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBleConnection); +} + +void OnNewTime(current_time_char_t* currentTime) { auto dayOfWeek = currentTime->exact_time_256.day_date_time.day_of_week; auto year = currentTime->exact_time_256.day_date_time.date_time.year; auto month = currentTime->exact_time_256.day_date_time.date_time.month; @@ -122,7 +131,9 @@ int main(void) { APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); ble_manager_init(); - ble_manager_set_callback(OnNewTime); + ble_manager_set_new_time_callback(OnNewTime); + ble_manager_set_ble_connection_callback(OnBleConnection); + ble_manager_set_ble_disconnection_callback(OnBleDisconnection); vTaskStartScheduler(); @@ -133,3 +144,4 @@ int main(void) { + -- cgit v1.2.3