BLE : Display the actual status of the connection on the screen.

This commit is contained in:
JF 2020-04-27 20:13:27 +02:00
parent 557e8fa19f
commit 746c164c59
5 changed files with 9 additions and 42 deletions

View file

@ -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

View file

@ -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:

View file

@ -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;

View file

@ -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);
}

View file

@ -7,7 +7,6 @@
#include <softdevice/common/nrf_sdh.h>
#include <hal/nrf_rtc.h>
#include <timers.h>
//#include <ble/ble_services/ble_cts_c/ble_cts_c.h>
#include <Components/DateTime/DateTimeController.h>
#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 (;;) {