/**@brief Function for handling the Application's BLE Stack events. * * @param[in] p_ble_evt Bluetooth stack event. */ static void on_ble_evt(ble_evt_t * p_ble_evt) { uint32_t err_code = NRF_SUCCESS; static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: led_stop(); m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; // Initialize the current heart rate to the average of max and min values. So that // everytime a new connection is made, the heart rate starts from the same value. m_cur_heart_rate = (MAX_HEART_RATE + MIN_HEART_RATE) / 2; // Start timers used to generate battery and HR measurements. application_timers_start(); // Start handling button presses err_code = app_button_enable(); break; case BLE_GAP_EVT_DISCONNECTED: // Since we are not in a connection and have not started advertising, store bonds err_code = ble_bondmngr_bonded_masters_store(); APP_ERROR_CHECK(err_code); // Go to system-off mode, should not return from this function, wakeup will trigger // a reset. system_off_mode_enter(); break; case BLE_GAP_EVT_SEC_PARAMS_REQUEST: err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_SUCCESS, &m_sec_params); break; case BLE_GAP_EVT_TIMEOUT: if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT) { led_stop(); GPIO_WAKEUP_BUTTON_CONFIG(HR_INC_BUTTON_PIN_NO); GPIO_WAKEUP_BUTTON_CONFIG(HR_DEC_BUTTON_PIN_NO); system_off_mode_enter(); } break; default: break; } APP_ERROR_CHECK(err_code); }
/**@brief Function for handling the Application's BLE Stack events. * * @param[in] p_ble_evt Bluetooth stack event. */ static void on_ble_evt(ble_evt_t * p_ble_evt) { uint32_t err_code; switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: led_stop(); // Initialize the current heart rate to the average of max and min values. So that // everytime a new connection is made, the heart rate starts from the same value. m_cur_heart_rate = (MAX_HEART_RATE + MIN_HEART_RATE) / 2; // Start timers used to generate battery and HR measurements. application_timers_start(); // Start handling button presses err_code = app_button_enable(); APP_ERROR_CHECK(err_code); break; case BLE_GAP_EVT_DISCONNECTED: // @note Flash access may not be complete on return of this API. System attributes are now // stored to flash when they are updated to ensure flash access on disconnect does not // result in system powering off before data was successfully written. // Go to system-off mode, should not return from this function, wakeup will trigger // a reset. system_off_mode_enter(); break; case BLE_GAP_EVT_TIMEOUT: if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT) { led_stop(); nrf_gpio_cfg_sense_input(HR_INC_BUTTON_PIN_NO, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW); nrf_gpio_cfg_sense_input(HR_DEC_BUTTON_PIN_NO, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW); system_off_mode_enter(); } break; default: // No implementation needed. break; } }
/**@brief Function for handling the Application's system events. * * @param[in] sys_evt system event. */ static void on_sys_evt(uint32_t sys_evt) { switch(sys_evt) { case NRF_EVT_FLASH_OPERATION_SUCCESS: case NRF_EVT_FLASH_OPERATION_ERROR: if (m_memory_access_in_progress) { m_memory_access_in_progress = false; system_off_mode_enter(); } break; default: // No implementation needed. break; } }
/**@brief Function for handling the Application's BLE Stack events. * * @param[in] p_ble_evt Bluetooth stack event. */ static void on_ble_evt(ble_evt_t * p_ble_evt) { uint32_t err_code; static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: led_stop(); nrf_gpio_pin_set(CONNECTED_LED_PIN_NO); //GreenLED m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; // Initialize the current heart rate to the average of max and min values. So that // everytime a new connection is made, the heart rate starts from the same value. m_cur_heart_rate = (MAX_HEART_RATE + MIN_HEART_RATE) / 2; // Start timers used to generate battery and HR measurements. application_timers_start(); // Start handling button presses err_code = app_button_enable(); APP_ERROR_CHECK(err_code); break; case BLE_GAP_EVT_DISCONNECTED: // Since we are not in a connection and have not started advertising, store bonds err_code = ble_bondmngr_bonded_centrals_store(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_clear(CONNECTED_LED_PIN_NO); //GreenLED m_storage_in_progress = true; // @note Flash access may not be complete on return of this API. System attributes are now // stored to flash when they are updated to ensure flash access on disconnect does not // result in system powering off before data was successfully written. // Go to system-off mode, should not return from this function, wakeup will trigger // a reset. system_off_mode_enter(); break; case BLE_GAP_EVT_SEC_PARAMS_REQUEST: err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_SUCCESS, &m_sec_params); APP_ERROR_CHECK(err_code); break; case BLE_GAP_EVT_TIMEOUT: if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT) { led_stop(); nrf_gpio_cfg_sense_input(HR_INC_BUTTON_PIN_NO, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW); nrf_gpio_cfg_sense_input(HR_DEC_BUTTON_PIN_NO, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW); system_off_mode_enter(); } break; default: // No implementation needed. break; } }