Detect BLE disconnection (in addition to BLE connection) and update the display accordingly.
This commit is contained in:
parent
3c29a11c78
commit
6abf12ffb7
3 changed files with 35 additions and 9 deletions
|
@ -118,6 +118,22 @@ void ble_manager_init_stack() {
|
||||||
NRF_SDH_BLE_OBSERVER(m_ble_observer, BLE_MANAGER__OBSERVER_PRIO, ble_manager_event_handler, NULL);
|
NRF_SDH_BLE_OBSERVER(m_ble_observer, BLE_MANAGER__OBSERVER_PRIO, ble_manager_event_handler, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void (*OnNewTimeCallback)(current_time_char_t*);
|
||||||
|
void ble_manager_set_new_time_callback(void (*OnNewTime)(current_time_char_t*)) {
|
||||||
|
OnNewTimeCallback = OnNewTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void (*OnBleConnectionCallback)();
|
||||||
|
void ble_manager_set_ble_connection_callback(void (*OnBleConnection)()) {
|
||||||
|
OnBleConnectionCallback = OnBleConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
void (*OnBleDisconnectionCallback)();
|
||||||
|
void ble_manager_set_ble_disconnection_callback(void (*OnBleDisconnection)()) {
|
||||||
|
OnBleDisconnectionCallback = OnBleDisconnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ble_manager_event_handler(ble_evt_t const *p_ble_evt, void *p_context) {
|
void ble_manager_event_handler(ble_evt_t const *p_ble_evt, void *p_context) {
|
||||||
uint32_t err_code;
|
uint32_t err_code;
|
||||||
|
|
||||||
|
@ -126,6 +142,7 @@ void ble_manager_event_handler(ble_evt_t const *p_ble_evt, void *p_context) {
|
||||||
NRF_LOG_INFO("Connected");
|
NRF_LOG_INFO("Connected");
|
||||||
ble_manager_connection_handle = p_ble_evt->evt.gap_evt.conn_handle;
|
ble_manager_connection_handle = p_ble_evt->evt.gap_evt.conn_handle;
|
||||||
err_code = nrf_ble_qwr_conn_handle_assign(&ble_manager_queue_write, ble_manager_connection_handle);
|
err_code = nrf_ble_qwr_conn_handle_assign(&ble_manager_queue_write, ble_manager_connection_handle);
|
||||||
|
OnBleConnectionCallback();
|
||||||
APP_ERROR_CHECK(err_code);
|
APP_ERROR_CHECK(err_code);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -135,6 +152,7 @@ void ble_manager_event_handler(ble_evt_t const *p_ble_evt, void *p_context) {
|
||||||
if (p_ble_evt->evt.gap_evt.conn_handle == ble_manager_cts_client.conn_handle) {
|
if (p_ble_evt->evt.gap_evt.conn_handle == ble_manager_cts_client.conn_handle) {
|
||||||
ble_manager_cts_client.conn_handle = BLE_CONN_HANDLE_INVALID;
|
ble_manager_cts_client.conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||||
}
|
}
|
||||||
|
OnBleDisconnectionCallback();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BLE_GAP_EVT_PHY_UPDATE_REQUEST: {
|
case BLE_GAP_EVT_PHY_UPDATE_REQUEST: {
|
||||||
|
@ -320,11 +338,6 @@ void ble_manager_start_advertising(void *p_erase_bonds) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void (*OnNewTimeCallback)(current_time_char_t*);
|
|
||||||
void ble_manager_set_callback(void (*OnNewTime)(current_time_char_t*)) {
|
|
||||||
OnNewTimeCallback = OnNewTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ble_manager_init_services() {
|
void ble_manager_init_services() {
|
||||||
ret_code_t err_code;
|
ret_code_t err_code;
|
||||||
ble_hrs_init_t hrs_init;
|
ble_hrs_init_t hrs_init;
|
||||||
|
|
|
@ -35,8 +35,9 @@ void ble_manager_init();
|
||||||
void ble_manager_start_advertising(void *p_erase_bonds);
|
void ble_manager_start_advertising(void *p_erase_bonds);
|
||||||
|
|
||||||
// TODO use signals from RTOS to notify new time
|
// TODO use signals from RTOS to notify new time
|
||||||
void ble_manager_set_callback(void (*OnNewTime)(current_time_char_t* currentTime));
|
void ble_manager_set_new_time_callback(void (*OnNewTime)(current_time_char_t* currentTime));
|
||||||
|
void ble_manager_set_ble_disconnection_callback(void (*OnBleDisconnection)());
|
||||||
|
void ble_manager_set_ble_connection_callback(void (*OnBleConnection)());
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
16
src/main.cpp
16
src/main.cpp
|
@ -33,6 +33,8 @@ Pinetime::Controllers::Ble bleController;
|
||||||
Pinetime::Controllers::DateTime dateTimeController;
|
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 pinButton = 13;
|
||||||
static constexpr uint8_t pinTouchIrq = 28;
|
static constexpr uint8_t pinTouchIrq = 28;
|
||||||
|
|
||||||
|
@ -98,10 +100,17 @@ void SystemTask(void *) {
|
||||||
vTaskSuspend(nullptr);
|
vTaskSuspend(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnNewTime(current_time_char_t* currentTime) {
|
void OnBleConnection() {
|
||||||
bleController.Connect();
|
bleController.Connect();
|
||||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBleConnection);
|
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 dayOfWeek = currentTime->exact_time_256.day_date_time.day_of_week;
|
||||||
auto year = currentTime->exact_time_256.day_date_time.date_time.year;
|
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 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);
|
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
||||||
|
|
||||||
ble_manager_init();
|
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();
|
vTaskStartScheduler();
|
||||||
|
|
||||||
|
@ -133,3 +144,4 @@ int main(void) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue