From 746c164c593d2b9aa63a0f9a1c1ad032de9627a0 Mon Sep 17 00:00:00 2001 From: JF Date: Mon, 27 Apr 2020 20:13:27 +0200 Subject: [PATCH] BLE : Display the actual status of the connection on the screen. --- src/CMakeLists.txt | 1 - src/Components/Ble/NimbleController.cpp | 5 ++++ src/Components/Ble/NimbleController.h | 3 +- src/SystemTask/SystemTask.cpp | 3 +- src/main.cpp | 39 ------------------------- 5 files changed, 9 insertions(+), 42 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ad83caee..bd9f3b42 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -357,7 +357,6 @@ set(INCLUDE_FILES drivers/SpiMaster.h drivers/Watchdog.h drivers/DebugPins.h - BLE/BleManager.h Components/Battery/BatteryController.h Components/Ble/BleController.h Components/Ble/NotificationManager.h diff --git a/src/Components/Ble/NimbleController.cpp b/src/Components/Ble/NimbleController.cpp index 7894ff43..02f99180 100644 --- a/src/Components/Ble/NimbleController.cpp +++ b/src/Components/Ble/NimbleController.cpp @@ -22,9 +22,11 @@ using namespace Pinetime::Controllers; // Let's try to improve this code (and keep it working!) NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, + Pinetime::Controllers::Ble& bleController, DateTime& dateTimeController, Pinetime::Controllers::NotificationManager& notificationManager) : systemTask{systemTask}, + bleController{bleController}, dateTimeController{dateTimeController}, notificationManager{notificationManager}, currentTimeClient{dateTimeController}, @@ -149,7 +151,9 @@ int NimbleController::OnGAPEvent(ble_gap_event *event) { if (event->connect.status != 0) { /* Connection failed; resume advertising. */ StartAdvertising(); + bleController.Disconnect(); } else { + bleController.Connect(); connectionHandle = event->connect.conn_handle; ble_gattc_disc_all_svcs(connectionHandle, OnAllSvrDisco, this); } @@ -160,6 +164,7 @@ int NimbleController::OnGAPEvent(ble_gap_event *event) { NRF_LOG_INFO("disconnect; reason=%d ", event->disconnect.reason); /* Connection terminated; resume advertising. */ + bleController.Disconnect(); StartAdvertising(); break; case BLE_GAP_EVENT_CONN_UPDATE: diff --git a/src/Components/Ble/NimbleController.h b/src/Components/Ble/NimbleController.h index 7a7a94c9..99e0c811 100644 --- a/src/Components/Ble/NimbleController.h +++ b/src/Components/Ble/NimbleController.h @@ -12,7 +12,7 @@ namespace Pinetime { class NimbleController { public: - NimbleController(Pinetime::System::SystemTask& systemTask, DateTime& dateTimeController, Pinetime::Controllers::NotificationManager& notificationManager); + NimbleController(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController, DateTime& dateTimeController, Pinetime::Controllers::NotificationManager& notificationManager); void Init(); void StartAdvertising(); int OnGAPEvent(ble_gap_event *event); @@ -28,6 +28,7 @@ namespace Pinetime { private: static constexpr char* deviceName = "Pinetime-JF"; Pinetime::System::SystemTask& systemTask; + Pinetime::Controllers::Ble& bleController; DateTime& dateTimeController; Pinetime::Controllers::NotificationManager& notificationManager; diff --git a/src/SystemTask/SystemTask.cpp b/src/SystemTask/SystemTask.cpp index a003163c..6516f68b 100644 --- a/src/SystemTask/SystemTask.cpp +++ b/src/SystemTask/SystemTask.cpp @@ -21,7 +21,8 @@ SystemTask::SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd, Drivers::C Pinetime::Controllers::NotificationManager& notificationManager) : spi{spi}, lcd{lcd}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController}, bleController{bleController}, dateTimeController{dateTimeController}, - watchdog{}, watchdogView{watchdog}, notificationManager{notificationManager}, nimbleController(*this, dateTimeController, notificationManager) { + watchdog{}, watchdogView{watchdog}, notificationManager{notificationManager}, + nimbleController(*this, bleController,dateTimeController, notificationManager) { systemTaksMsgQueue = xQueueCreate(10, 1); } diff --git a/src/main.cpp b/src/main.cpp index 9748f533..7c5eaf7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,6 @@ #include #include #include -//#include #include #include "Components/Battery/BatteryController.h" #include "Components/Ble/BleController.h" @@ -90,34 +89,6 @@ void DebounceTimerCallback(TimerHandle_t xTimer) { systemTask->OnButtonPushed(); } -void OnBleConnection() { - bleController.Connect(); -} - -void OnBleDisconnection() { - bleController.Disconnect(); -} - -void OnNewNotification(const char* message, uint8_t size) { - notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, message, size); - systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); -} - -//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; -// auto day = currentTime->exact_time_256.day_date_time.date_time.day; -// auto hour = currentTime->exact_time_256.day_date_time.date_time.hours; -// auto minute = currentTime->exact_time_256.day_date_time.date_time.minutes; -// auto second = currentTime->exact_time_256.day_date_time.date_time.seconds; -// -// dateTimeController.SetTime(year, month, day, -// dayOfWeek, hour, minute, second, nrf_rtc_counter_get(portNRF_RTC_REG)); -// -// systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewTime); -//} - void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void) { if(((NRF_SPIM0->INTENSET & (1<<6)) != 0) && NRF_SPIM0->EVENTS_END == 1) { NRF_SPIM0->EVENTS_END = 0; @@ -218,8 +189,6 @@ void nimble_port_init(void) { ble_ll_init(); ble_hci_ram_init(); nimble_port_freertos_init(BleHost); - - } void nimble_port_ll_task_func(void *args) { @@ -238,16 +207,8 @@ int main(void) { systemTask.reset(new Pinetime::System::SystemTask(spi, lcd, touchPanel, lvgl, batteryController, bleController, dateTimeController, notificationManager)); systemTask->Start(); - nimble_port_init(); - -// ble_manager_init(); -// ble_manager_set_new_time_callback(OnNewTime); -// ble_manager_set_ble_connection_callback(OnBleConnection); -// ble_manager_set_ble_disconnection_callback(OnBleDisconnection); -// ble_manager_set_new_notification_callback(OnNewNotification); - vTaskStartScheduler(); for (;;) {