示例#1
0
文件: main.c 项目: IOIOI/nRF51
/**@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;
    }
}
示例#2
0
/**@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;
    }
}