Esempio n. 1
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;
    }
}
Esempio n. 2
0
/**@brief Function for handling write events to the si7021 characteristic.
 *
 * @param[in] p_si7021  Instance of si7021 Service to which the write applies.
 * @param[in] led_state Written/desired state of the LED.
 */
static void blesi7021_write_handler(ble_si7021_t * p_si7021, ble_si7021_evt_t *evt) {
    uint32_t err_code;

    if (evt->evt_type == BLE_si7021_EVT_NOTIFICATION_ENABLED) {
    	NRF_LOG_INFO("BLE_si7021_EVT_NOTIFICATION_ENABLED\r\n");
        err_code = app_timer_start(m_si7021_timer_id, APP_TIMER_TICKS(p_si7021->interval, APP_TIMER_PRESCALER), NULL);
        APP_ERROR_CHECK(err_code);
        p_si7021->running=1;
    } else if (evt->evt_type == BLE_si7021_EVT_INTERVAL_CHANGE) {
    	NRF_LOG_INFO("BLE_si7021_EVT_INTERVAL_CHANGE %d\r\n",p_si7021->interval);
    	if (p_si7021->running==1) {
            err_code = app_timer_stop(m_si7021_timer_id);
            APP_ERROR_CHECK(err_code);
            p_si7021->running=0;

            err_code = app_timer_start(m_si7021_timer_id, APP_TIMER_TICKS(p_si7021->interval, APP_TIMER_PRESCALER), NULL);
            APP_ERROR_CHECK(err_code);
            p_si7021->running=1;
    	}
    } else { // BLE_si7021_EVT_NOTIFICATION_DISABLED | BLE_si7021_EVT_DISCONNECTED
    	NRF_LOG_INFO("BLE_si7021_EVT_NOTIFICATION_DISABLED\r\n");
        err_code = app_timer_stop(m_si7021_timer_id);
        APP_ERROR_CHECK(err_code);
        p_si7021->running=0;
    }
}
/**@brief Function for stopping all advertising and all running timers */
void all_advertising_halt(void)
{
    sd_ble_gap_adv_stop();
    app_timer_stop(m_eddystone_adv_interval_timer);
    app_timer_stop(m_eddystone_adv_slot_timer);
    app_timer_stop(m_eddystone_etlm_cycle_timer);
}
Esempio n. 4
0
File: main.c Progetto: tkadom/TWBLE
/**@brief Function for Stopping application timers.
 */
static void application_timers_stop(void)
{
    uint32_t err_code;
    
    err_code = app_timer_stop(m_notif_timer_id);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_stop(m_conn_int_timer_id);
    APP_ERROR_CHECK(err_code);
}
static void sensor_timer_stop(void)
{
		uint32_t err_code;
		err_code = app_timer_stop(iss_struct_h.meas_timer);
		APP_ERROR_CHECK(err_code);
		iss_struct_h.timer_running = false;
}
Esempio n. 6
0
/**@brief Function for handling the GPIOTE event.
 *
 * @details Saves the current status of the button pins, and starts a timer. If the timer is already
 *          running, it will be restarted.
 *
 * @param[in]  event_pins_low_to_high   Mask telling which pin(s) had a low to high transition.
 * @param[in]  event_pins_high_to_low   Mask telling which pin(s) had a high to low transition.
 */
static void gpiote_event_handler(uint32_t event_pins_low_to_high, uint32_t event_pins_high_to_low)
{
    uint32_t err_code;
 
    // Start detection timer. If timer is already running, the detection period is restarted.
    // NOTE: Using the p_context parameter of app_timer_start() to transfer the pin states to the
    //       timeout handler (by casting event_pins_mask into the equally sized void * p_context
    //       parameter).
    STATIC_ASSERT(sizeof(void *) == sizeof(uint32_t));

    err_code = app_timer_stop(m_detection_delay_timer_id);
    if (err_code != NRF_SUCCESS)
    {
        // The impact in app_button of the app_timer queue running full is losing a button press.
        // The current implementation ensures that the system will continue working as normal. 
        return;
    }

    m_pin_transition.low_to_high = event_pins_low_to_high;
    m_pin_transition.high_to_low = event_pins_high_to_low;
    
    err_code = app_timer_start(m_detection_delay_timer_id,
                               m_detection_delay,
                               (void *)(event_pins_low_to_high | event_pins_high_to_low));
    if (err_code != NRF_SUCCESS)
    {
        // The impact in app_button of the app_timer queue running full is losing a button press.
        // The current implementation ensures that the system will continue working as normal. 
    }
}
Esempio n. 7
0
/*---------------------------------------------------------------------------*/
void buzzer_stop(void)
{
    app_timer_stop(m_buzzer_timer_id);

    BUZZ_TIMER->TASKS_STOP = 1;
    buzzer_gpiote_unconfig();
}
static void lock_control_handler(ble_doorlock_t * p_doorlock, uint8_t state) 
{ 
    uint32_t             err_code;
    if (state) 
    { 
        // Open door
        LEDS_ON((BSP_LED_3_MASK));
        // Start timer
        if (m_lock_timer_id != 0xFFFFFFFF) {
            err_code = app_timer_stop(m_lock_timer_id);
            APP_ERROR_CHECK(err_code);
        } else {
            err_code = app_timer_create(&m_lock_timer_id, 
                                        APP_TIMER_MODE_SINGLE_SHOT, 
                                        lock_timeout_handler); 
            APP_ERROR_CHECK(err_code); 
        }
        err_code = app_timer_start(m_lock_timer_id, APP_TIMER_TICKS(APP_CFG_CHAR_LOCK_TIMEOUT, APP_TIMER_PRESCALER), NULL);
        APP_ERROR_CHECK(err_code);
    } 
    else 
    { 
        // Lock door
        LEDS_OFF((BSP_LED_3_MASK));
    } 
} 
Esempio n. 9
0
static void on_write(ble_evt_t * p_ble_evt)
{
    ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;

    // Check if this the correct CCCD
    if (
        (p_evt_write->handle == m_conn_params_config.start_on_notify_cccd_handle)
        &&
        (p_evt_write->len == 2)
       )
    {
        // Check if this is a 'start notification'
        if (ble_srv_is_notification_enabled(p_evt_write->data))
        {
            // Do connection parameter negotiation if necessary
            conn_params_negotiation();
        }
        else
        {
#ifdef USE_APP_TIMER
            uint32_t err_code;

            // Stop timer if running
            err_code = app_timer_stop(m_conn_params_timer_id);
            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
            {
                m_conn_params_config.error_handler(err_code);
            }
#else /* #if !USE_APP_TIMER */
            m_conn_params_timer.detach();
#endif /* #if !USE_APP_TIMER */
        }
    }
}
Esempio n. 10
0
/** @brief Function for executing method for entering calibration not active state. 
 *
 * Execute method for entering calibration not active state, meaning notifying the application of 
 * the state entry event. Additionally, if the timeout handler is running, it will be stopped.
 */
static __INLINE void calibration_not_active_execute(void)
{
    const uint32_t err_code = app_timer_stop(m_timer_id);
    APP_ERROR_CHECK(err_code);
    
    APP_ERROR_CHECK_BOOL(m_calibration_process_callback != NULL);    
    m_calibration_process_callback(CALIBRATION_NOT_ACTIVE_STATE_ENTER);
}
Esempio n. 11
0
uint32_t ble_conn_params_stop(void)
{
#ifdef USE_APP_TIMER
    return app_timer_stop(m_conn_params_timer_id);
#else /* #if !USE_APP_TIMER */
    m_conn_params_timer.detach();
    return NRF_SUCCESS;
#endif /* #if !USE_APP_TIMER */
}
Esempio n. 12
0
static void ip_app_handler(iot_interface_t * p_interface, ipv6_event_t * p_event)
{
    uint32_t    err_code;
    ipv6_addr_t src_addr;

    APPL_LOG("[APPL]: Got IP Application Handler Event on interface 0x%p\r\n", p_interface);

    switch (p_event->event_id)
    {
        case IPV6_EVT_INTERFACE_ADD:
#ifdef COMMISSIONING_ENABLED
            commissioning_joining_mode_timer_ctrl(JOINING_MODE_TIMER_STOP_RESET);
#endif // COMMISSIONING_ENABLED
            APPL_LOG("[APPL]: New interface added!\r\n");
            mp_interface = p_interface;

            m_display_state = LEDS_IPV6_IF_UP;

            APPL_LOG("[APPL]: Sending Router Solicitation to all routers!\r\n");

            // Create Link Local addresses
            IPV6_CREATE_LINK_LOCAL_FROM_EUI64(&src_addr, p_interface->local_addr.identifier);

            // Delay first solicitation due to possible restriction on other side.
            nrf_delay_ms(APP_RTR_SOLICITATION_DELAY);

            // Send Router Solicitation to all routers.
            err_code = icmp6_rs_send(p_interface,
                                     &src_addr,
                                     &m_local_routers_multicast_addr);
            APP_ERROR_CHECK(err_code);
        break;

        case IPV6_EVT_INTERFACE_DELETE:
#ifdef COMMISSIONING_ENABLED
            commissioning_joining_mode_timer_ctrl(JOINING_MODE_TIMER_START);
#endif // COMMISSIONING_ENABLED
            APPL_LOG("[APPL]: Interface removed!\r\n");
            mp_interface = NULL;

            m_display_state = LEDS_IPV6_IF_DOWN;

            // Stop application state machine timer.
            m_app_state = APP_STATE_IDLE;
            err_code = app_timer_stop(m_app_timer);
            APP_ERROR_CHECK(err_code);
            break;

        case IPV6_EVT_INTERFACE_RX_DATA:
            APPL_LOG("[APPL]: Got unsupported protocol data!\r\n");
            break;

        default:
            // Unknown event. Should not happen.
            break;
    }
}
Esempio n. 13
0
/**@brief Function for handling button events.
 *
 * @param[in]   pin_no         The pin number of the button pressed.
 * @param[in]   button_action  The action performed on button.
 */
static void button_event_handler(uint8_t pin_no, uint8_t button_action)
{
    uint32_t err_code;
#ifdef COMMISSIONING_ENABLED
    if ((button_action == APP_BUTTON_PUSH) && (pin_no == ERASE_BUTTON_PIN_NO))
    {
        APPL_LOG("[APPL]: Erasing all commissioning settings from persistent storage... \r\n");
        commissioning_settings_clear();
        return;
    }
#endif // COMMISSIONING_ENABLED

    // Check if interface is UP.
    if(mp_interface == NULL)
    {
        return;
    }

    if (button_action == APP_BUTTON_PUSH)
    {
        switch (pin_no)
        {
            case START_BUTTON_PIN_NO:
            {
                APPL_LOG("[APPL]: Start button has been pushed.\r\n");

                // Change application state in case being in IDLE state.
                if(m_app_state == APP_STATE_IDLE)
                {
                    m_app_state = APP_STATE_QUERYING;

                    // Start application state machine timer.
                    err_code = app_timer_start(m_app_timer, APP_STATE_INTERVAL, NULL);
                    APP_ERROR_CHECK(err_code);
                }

                break;
            }
            case STOP_BUTTON_PIN_NO:
            {
                APPL_LOG("[APPL]: Stop button has been pushed.\r\n");
                LEDS_OFF((LED_THREE | LED_FOUR));

                // Back to IDLE state.
                m_app_state = APP_STATE_IDLE;

                // Stop application state machine timer.
                err_code = app_timer_stop(m_app_timer);
                APP_ERROR_CHECK(err_code);
                break;
            }

            default:
              break;
        }
    }
}
static void update_measurement_samp_freq(){
	 if(iss_struct.timer_running){
		  uint32_t err_code;
			err_code = app_timer_stop(iss_struct.meas_timer);
			APP_ERROR_CHECK(err_code);
			err_code = app_timer_start(iss_struct.meas_timer, APP_TIMER_TICKS(iss_struct.samp_freq_in_m_sec, APP_TIMER_PRESCALER), &iss_struct);
			APP_ERROR_CHECK(err_code);
			advertising_init();
	 }   
}
/**@brief Function to stop the blinking of the Alert LED.
 */
static void alert_led_blink_stop(void)
{
    uint32_t err_code;

    err_code = app_timer_stop(m_alert_led_blink_timer_id);
    APP_ERROR_CHECK(err_code);

    m_is_alert_led_blinking = false;

    nrf_gpio_pin_clear(ALERT_PIN_NO);
}
Esempio n. 16
0
uint32_t app_timer_stop_all(void)
{
    for (int i = 0; i < app_timer_control.max_timers; i++)
    {
        if (app_timer_control.app_timers[i].id)
        {
            (void)app_timer_stop((app_timer_id_t)app_timer_control.app_timers[i].id);
        }
    }
    return 0;
}
static void lock_timeout_handler(void * p_context) 
{ 
    uint32_t err_code; 
    UNUSED_PARAMETER(p_context); 

    // Lock door
    LEDS_OFF((BSP_LED_3_MASK));
    
    err_code = app_timer_stop(m_lock_timer_id);  
    APP_ERROR_CHECK(err_code);
} 
Esempio n. 18
0
uint32_t dfu_image_activate (void)
{
    uint32_t            err_code = NRF_SUCCESS;
    dfu_update_status_t update_status;

    switch (m_dfu_state)
    {
        case DFU_STATE_WAIT_4_ACTIVATE:

            // Stop the DFU Timer because the peer activity need not be monitored any longer.
            err_code = app_timer_stop(m_dfu_timer_id);
            APP_ERROR_CHECK(err_code);

            if (IS_UPDATING_SD()) //lint !e655 suppress Lint Warning 655: Bit-wise operations
            {
                update_status.sd_image_size = m_start_packet.sd_image_size;
            }
            else
            {
                update_status.sd_image_size = NEW_IMAGE_SIZE_EMPTY;
            }

            if (IS_UPDATING_BL()) //lint !e655 suppress Lint Warning 655: Bit-wise operations
            {
                update_status.bl_image_size = m_start_packet.bl_image_size;
            }
            else
            {
                update_status.bl_image_size = NEW_IMAGE_SIZE_EMPTY;
            }

            if (IS_UPDATING_APP()) //lint !e655 suppress Lint Warning 655: Bit-wise operations
            {
                update_status.ap_image_size = m_start_packet.app_image_size;
            }
            else
            {
                update_status.ap_image_size = NEW_IMAGE_SIZE_EMPTY;
            }

            update_status.status_code = DFU_UPDATE_NEW_IMAGES;
            update_status.bank_used = m_active_bank;
            update_status.src_image_address = dfu_storage_start_address_get();
            bootloader_dfu_update_process(update_status);

            break;

        default:
            err_code = NRF_ERROR_INVALID_STATE;
            break;
    }

    return err_code;
}
Esempio n. 19
0
void ble_hrs_app_stop(void)
{
    uint32_t err_code;
    
    // Stop any impending connection parameters update.
    err_code = ble_conn_params_stop();
    APP_ERROR_CHECK(err_code);
    
    // Stop application timers.
    err_code = app_timer_stop(m_battery_timer_id);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_stop(m_heart_rate_timer_id);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_stop(m_rr_interval_timer_id);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_stop(m_sensor_contact_timer_id);
    APP_ERROR_CHECK(err_code);
}
Esempio n. 20
0
/**@brief Function to handle interface down event. */
void nrf51_driver_interface_down(void)
{
    uint32_t err_code;

    APPL_LOG ("[APPL]: IPv6 interface down.\r\n");

    err_code = app_timer_stop(m_sys_timer_id);
    APP_ERROR_CHECK(err_code);

    LEDS_ON(ADVERTISING_LED);
    LEDS_OFF(CONNECTED_LED);
}
Esempio n. 21
0
File: main.c Progetto: mcanos/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 = NRF_SUCCESS;

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            printf("@Connected\n\r");
            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);

            err_code = app_timer_start(m_sec_ping, PING_DELAY, &m_notification_latest);
            APP_ERROR_CHECK(err_code);
				
				    // BSP_LED_0_MASK  BSP_LED_1_MASK BSP_LED_2_MASK
            LEDS_ON(BSP_LED_1_MASK);

            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            printf("@Disconnected\n\r");
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
				
				    // BSP_LED_0_MASK  BSP_LED_1_MASK BSP_LED_2_MASK
            LEDS_OFF(BSP_LED_1_MASK);
        
            err_code = app_timer_stop(m_sec_ping);
            APP_ERROR_CHECK(err_code);
        
            while (1) {
              nrf_delay_ms(200);
              LEDS_INVERT(BSP_LED_1_MASK);
            }

            break;

        case BLE_GATTC_EVT_TIMEOUT:
        case BLE_GATTS_EVT_TIMEOUT:
            LOG("Timeout.\n\r");
            // Disconnect on GATT Server and Client time-out events.
            err_code = sd_ble_gap_disconnect(m_conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
            break;

        default:
            // No implementation needed.
            break;
    }
    APP_ERROR_CHECK(err_code);
}
Esempio n. 22
0
/**@brief IP stack event handler.
 *
 * @details Callback registered with the ICMP6 to receive asynchronous events from the module.
 */
void ip_app_handler(iot_interface_t * p_interface, ipv6_event_t * p_event)
{
    uint32_t err_code;

    APPL_LOG("[APPL]: Got IP Application Handler Event on interface 0x%p\r\n", p_interface);

    switch(p_event->event_id)
    {
        case IPV6_EVT_INTERFACE_ADD:
            APPL_LOG("[APPL]: New interface added!\r\n");

            err_code = udp6_socket_allocate(&m_udp_socket);
            APP_ERROR_CHECK(err_code);

            err_code = udp6_socket_bind(&m_udp_socket, IPV6_ADDR_ANY, HTONS(UDP_PORT));
            APP_ERROR_CHECK(err_code);

            err_code = udp6_socket_recv(&m_udp_socket, rx_udp_port_app_handler);
            APP_ERROR_CHECK(err_code);

            memset(&m_packet_buffer[0][0], 0x00, sizeof(m_packet_buffer));
            m_node_state    = APP_STATE_IPV6_IF_UP;
            m_display_state = LEDS_TX_ECHO_REQUEST;

            // IPv6 interface is up, start sending Echo Requests to peer.
            err_code = app_timer_start(m_tx_node_timer, APP_PING_INTERVAL, NULL);
            APP_ERROR_CHECK(err_code);

            break;
        case IPV6_EVT_INTERFACE_DELETE:
            err_code = app_timer_stop(m_tx_node_timer);
            APP_ERROR_CHECK(err_code);

            APPL_LOG("[APPL]: Interface removed!\r\n");

            err_code = udp6_socket_free(&m_udp_socket);
            APP_ERROR_CHECK(err_code);

            memset(&m_packet_buffer[0][0], 0x00, sizeof(m_packet_buffer));
            m_node_state    = APP_STATE_IPV6_IF_DOWN;
            m_display_state = LEDS_IPV6_IF_DOWN;

            break;
        case IPV6_EVT_INTERFACE_RX_DATA:
            APPL_LOG("[APPL]: Got unsupported protocol data!\r\n");
            break;

        default:
            //Unknown event. Should not happen.
            break;
    }
}
Esempio n. 23
0
uint32_t app_button_disable(void)
{
    ASSERT(mp_buttons);

    uint32_t i;
    for (i = 0; i < m_button_count; i++)
    {
       nrf_drv_gpiote_in_event_disable(mp_buttons[i].pin_no);
    }

    // Make sure polling timer is not running.
    return app_timer_stop(m_detection_delay_timer_id);
}
Esempio n. 24
0
void message_deinit() {
    uint32_t err_code;

    if (!initialized) {
	return;
    }

    if (messageTimerID != TIMER_NULL) {
	err_code = app_timer_stop(messageTimerID);
	APP_ERROR_CHECK(err_code);
    }

    initialized = false;
}
Esempio n. 25
0
File: main.c Progetto: tkadom/TWBLE
/**@brief Function for handling the Notification timeout.
 *
 * @details This function will be called when the notification timer expires. This will stop the
 *          timer for connection interval and disconnect from the peer.
 *
 * @param[in]   p_context   Pointer used for passing some arbitrary information (context) from the
 *                          app_start_timer() call to the timeout handler.
 */
static void notif_timeout_handler(void * p_context)
{
    uint32_t err_code;
    
    UNUSED_PARAMETER(p_context);

    // Stop all notifications (by stopping the timer for connection interval that triggers 
    // notifications and disconnecting from peer).
    err_code = app_timer_stop(m_conn_int_timer_id); 
    APP_ERROR_CHECK(err_code);

    err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
    APP_ERROR_CHECK(err_code);
}
Esempio n. 26
0
static void timer_0_stop(uint8_t timer)
{
    uint32_t err_code;
    app_timer_id_t timer_id;

    if (timer == 0) {
        timer_id = led_0_timer_id;
    } else if (timer == 1) {
        timer_id = led_1_timer_id;
    } 

    err_code = app_timer_stop(timer_id);
    APP_ERROR_CHECK(err_code);
}
/**@brief Timeout handler for the etlm_cycle_timer*/
static void etlm_cycle_timeout(void * p_context)
{
    sd_ble_gap_adv_stop();

    if (m_etlm_adv_counter.eid_slot_counter >= eddystone_adv_slot_num_of_current_eids(NULL, NULL))
    {
        m_etlm_adv_counter.eid_slot_counter = 0;
        app_timer_stop(m_eddystone_etlm_cycle_timer);
    }
    else
    {
        etlm_adv(m_temporary_slot_no);
        //this will incremement eid_slot_counter
    }
}
Esempio n. 28
0
void stopwatch_fn_stop(void) {
		if (!ms_counter_active) {
				return;
		}
		
    uint32_t err_code = app_timer_stop(stopwatch_timer_id);
    APP_ERROR_CHECK(err_code);
		
		uint32_t current_ticks;
		uint32_t diff;
		ms_counter_active = false;
		app_timer_cnt_get(&current_ticks);
		app_timer_cnt_diff_compute(current_ticks, ms_counter_last_ticks, &diff);
		ms_counter += 1000*diff/APP_TIMER_CLOCK_FREQ;
}
Esempio n. 29
0
static void on_disconnect(ble_evt_t * p_ble_evt)
{
    uint32_t err_code;

    m_conn_handle = BLE_CONN_HANDLE_INVALID;

    // Stop timer if running
    m_update_count = 0; // Connection parameters updates should happen during every connection
    
    err_code = app_timer_stop(m_conn_params_timer_id);
    if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
    {
        m_conn_params_config.error_handler(err_code);
    }
}
/**@brief       Function for the Application's S110 SoftDevice event handler.
 *
 * @param[in]   p_ble_evt   S110 SoftDevice 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:
            nrf_gpio_pin_set(CONNECTED_LED_PIN_NO);
            nrf_gpio_pin_clear(ADVERTISING_LED_PIN_NO);
            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;

            break;
            
        case BLE_GAP_EVT_DISCONNECTED:
            nrf_gpio_pin_clear(CONNECTED_LED_PIN_NO);
            m_conn_handle = BLE_CONN_HANDLE_INVALID;

            advertising_start();

            break;
                    
        case BLE_GAP_EVT_PASSKEY_DISPLAY:
            // Don't send delayed Security Request if security procedure is already in progress.
            err_code = app_timer_stop(m_sec_req_timer_id);
            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)
            { 
                nrf_gpio_pin_clear(ADVERTISING_LED_PIN_NO);

                // Configure buttons with sense level low as wakeup source.
                nrf_gpio_cfg_sense_input(WAKEUP_BUTTON_PIN,
                                         BUTTON_PULL,
                                         NRF_GPIO_PIN_SENSE_LOW);
                
                // Go to system-off mode (this function will not return; wakeup will cause a reset)
                err_code = sd_power_system_off();    
                APP_ERROR_CHECK(err_code);
            }
            break;

        default:
            // No implementation needed.
            break;
    }
}