Detect BLE disconnection (in addition to BLE connection) and update the display accordingly.
This commit is contained in:
parent
3c29a11c78
commit
6abf12ffb7
|
@ -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);
|
||||
}
|
||||
|
||||
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) {
|
||||
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");
|
||||
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);
|
||||
OnBleConnectionCallback();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
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) {
|
||||
ble_manager_cts_client.conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||
}
|
||||
OnBleDisconnectionCallback();
|
||||
break;
|
||||
|
||||
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() {
|
||||
ret_code_t err_code;
|
||||
ble_hrs_init_t hrs_init;
|
||||
|
|
|
@ -35,8 +35,9 @@ void ble_manager_init();
|
|||
void ble_manager_start_advertising(void *p_erase_bonds);
|
||||
|
||||
// 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
|
||||
|
|
16
src/main.cpp
16
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) {
|
|||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user