Ejemplo n.º 1
0
/**@brief Function for handling the Device Manager events.
 *
 * @param[in] p_evt  Data associated to the device manager event.
 */
static uint32_t device_manager_evt_handler(dm_handle_t const * p_handle,
                                           dm_event_t const  * p_event,
                                           ret_code_t        event_result)
{
    uint32_t err_code;
    bool     is_indication_enabled;

    switch(p_event->event_id)
    {
        case DM_EVT_LINK_SECURED:
            // Send a single temperature measurement if indication is enabled.
            // NOTE: For this to work, make sure ble_hts_on_ble_evt() is called before
            //       dm_ble_evt_handler() in ble_evt_dispatch().
            err_code = ble_hts_is_indication_enabled(&m_hts, &is_indication_enabled);
            APP_ERROR_CHECK(err_code);

            if (is_indication_enabled)
            {
                temperature_measurement_send();
            }
            break;

        default:
            break;
    }

    return NRF_SUCCESS;
}
Ejemplo n.º 2
0
 */
static void button_event_handler(uint8_t pin_no, uint8_t button_action)
{
    if (button_action == APP_BUTTON_PUSH)
    {
        switch (pin_no)
        {
            case SEND_MEAS_BUTTON_PIN_NO:
                temperature_measurement_send();
                break;

            default:
                APP_ERROR_HANDLER(pin_no);
        }
    }
Ejemplo n.º 3
0
/**@brief Function for handling the Running Speed and Cadence measurement timer timeout.
 *
 * @details This function will be called each time the running speed and cadence
 *          measurement timer expires.
 *
 * @param[in]   p_context   Pointer used for passing some arbitrary information (context) from the
 *                          app_start_timer() call to the timeout handler.
 */
static void rsc_meas_timeout_handler(void * p_context)
{
	static uint8_t	i;
    uint32_t        err_code;
    ble_rscs_meas_t rscs_measurement;
	ak8963_cmps *cmps;
	

    UNUSED_PARAMETER(p_context);
	
	if(get_work_mode() == SYSTEM_PEDOMETER_MODE)	pedometer_startup();

	if(++i >= 100)				//100 * 10ms = 1s
	{
		i = 0;
		
		if(get_work_mode() == SYSTEM_PEDOMETER_MODE)
		{
			rsc_sim_measurement(&rscs_measurement);

			err_code = ble_rscs_measurement_send(&m_rscs, &rscs_measurement);
		}
		else if(get_work_mode() == SYSTEM_TEMP_MODE)
		{
			temperature_measurement_send();
		}
		else if(get_work_mode() == SYSTEM_COMPASS_MODE)
		{
			cmps = ak8963_get_value();
			oled_update_cmps(cmps);
		}
		if (
			(err_code != NRF_SUCCESS)
			&&
			(err_code != NRF_ERROR_INVALID_STATE)
			&&
			(err_code != BLE_ERROR_NO_TX_BUFFERS)
			&&
			(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
		)
		{
// 			APP_ERROR_HANDLER(err_code);
		}
	}
}
Ejemplo n.º 4
0
 */
static void on_hts_evt(ble_hts_t * p_hts, ble_hts_evt_t *p_evt)
{
    switch (p_evt->evt_type)
    {
        case BLE_HTS_EVT_INDICATION_ENABLED:
            // Indication has been enabled, send a single temperature measurement
            temperature_measurement_send();
            break;

        case BLE_HTS_EVT_INDICATION_CONFIRMED:
            m_hts_meas_ind_conf_pending = false;
            break;

        default:
            // No implementation needed.
            break;
    }
Ejemplo n.º 5
0
 */
static void bond_evt_handler(ble_bondmngr_evt_t * p_evt)
{
    uint32_t err_code;
    bool     is_indication_enabled;

    switch (p_evt->evt_type)
    {
        case BLE_BONDMNGR_EVT_ENCRYPTED:
            // Send a single temperature measurement if indication is enabled.
            // NOTE: For this to work, make sure ble_hts_on_ble_evt() is called before
            //       ble_bondmngr_on_ble_evt() in ble_evt_dispatch().
            err_code = ble_hts_is_indication_enabled(&m_hts, &is_indication_enabled);
            APP_ERROR_CHECK(err_code);

            if (is_indication_enabled)
            {
                temperature_measurement_send();
            }
            break;

        default:
            break;
    }
Ejemplo n.º 6
0
/**@brief Function for handling events from the BSP module.
 *
 * @param[in]   event   Event generated by button press.
 */
static void bsp_event_handler(bsp_event_t event)
{
    uint32_t err_code;
    switch (event)
    {
        case BSP_EVENT_SLEEP:
            sleep_mode_enter();
            break;

        case BSP_EVENT_DISCONNECT:
            err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            if (err_code != NRF_ERROR_INVALID_STATE)
            {
                APP_ERROR_CHECK(err_code);
            }
            break;

        case BSP_EVENT_WHITELIST_OFF:
            err_code = ble_advertising_restart_without_whitelist();
            if (err_code != NRF_ERROR_INVALID_STATE)
            {
                APP_ERROR_CHECK(err_code);
            }
            break;

        case BSP_EVENT_KEY_0:
            if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
            {
                temperature_measurement_send();
            }
            break;

        default:
            break;
    }
}