/**@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: err_code = bsp_indication_set(BSP_INDICATE_CONNECTED); APP_ERROR_CHECK(err_code); m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; app_beacon_start(); break; case BLE_GAP_EVT_DISCONNECTED: err_code = bsp_indication_set(BSP_INDICATE_IDLE); APP_ERROR_CHECK(err_code); app_beacon_stop(); // when not using the timeslot implementation, it is necessary to initialize the advertizing data again. advertising_init(); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); 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; switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: debug_printf("Connected :)\r\n"); m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; app_beacon_stop(); app_timer_start(m_temperature_timer_id, TEMPERATURE_MEAS_INTERVAL, NULL); app_timer_start(m_door_timer_id, DOOR_MEAS_INTERVAL, NULL); break; case BLE_GAP_EVT_DISCONNECTED: app_beacon_start(); // when not using the timeslot implementation, it is necessary to initialize the advertizing data again. advertising_init(); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); app_timer_stop(m_temperature_timer_id); app_timer_stop(m_door_timer_id); debug_printf("Disconnected, Advertising peripheral again \r\n"); break; default: // No implementation needed. break; } }
/**@brief Function for stopping advertising. */ static void advertising_stop(void) { uint32_t err_code; //stop eddystone as well app_beacon_stop(); err_code = sd_ble_gap_adv_stop(); APP_ERROR_CHECK(err_code); }
/**@brief Function for preparing for system reset. * * @details This function implements @ref dfu_app_reset_prepare_t. It will be called by * @ref dfu_app_handler.c before entering the bootloader/DFU. * This allows the current running application to shut down gracefully. */ static void reset_prepare(void) { uint32_t err_code; if (m_conn_handle != BLE_CONN_HANDLE_INVALID) { // Disconnect from peer. err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); APP_ERROR_CHECK(err_code); //stop eddystone app_beacon_stop(); } else { // If not connected, the device will be advertising. Hence stop the advertising. advertising_stop(); app_beacon_stop(); } err_code = ble_conn_params_stop(); APP_ERROR_CHECK(err_code); nrf_delay_ms(500); }