Esempio n. 1
0
/*
 * LOCAL FUNCTION DEFINITIONS
 ****************************************************************************************
 */
static void app_display_hdl_adv(enum display_input input)
{
    switch(input)
    {
        case DISPLAY_INPUT_SELECT:
        {
            display_screen_update(app_display_env.screen_id_adv, 0, "o ADVERTISING");
        }
        break;
        case DISPLAY_INPUT_DESELECT:
        {
            display_screen_update(app_display_env.screen_id_adv, 0, "< ADVERTISING");
        }
        break;
        case DISPLAY_INPUT_LEFT:
        case DISPLAY_INPUT_RIGHT:
        {
            if (!app_display_env.advertising)
            {
                app_adv_start();
                app_display_env.advertising = true;
                display_screen_update(app_display_env.screen_id_adv, 1, "s ON");
            }
            else
            {
                app_adv_stop();
                app_display_env.advertising = false;
                display_screen_update(app_display_env.screen_id_adv, 1, "s OFF");
            }
        }
        break;
        default:
        break;
    }
}
Esempio n. 2
0
int app_accel_adv_timer_handler(ke_msg_id_t const msgid,
                                   void const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{
    // Shedule interval is: adv starts with APP_ADV_INT_MIN, then after 500ms goes to 200ms, 
    // then after 3 mins goes to 1sec, then after 3 mins goes to 2 sec
    
    // Check if we need to change Advertising interval
    if( accel_adv_count == 0 )
    {
        // First schedule for advertising interval has been reached. Move to the next schedule
        accel_adv_interval = 0x140; // 200ms  (200ms/0.625)
        // Increment counter in retension memory
        accel_adv_count += 1; 
//        ke_timer_set(APP_ACCEL_ADV_TIMER, TASK_APP, 18000);
        ke_timer_set(APP_ACCEL_ADV_TIMER, TASK_APP, 3000);
		//stop Accelerometer
		acc_stop();
    }    
    else if( accel_adv_count == 1 )
    {
        accel_adv_interval = 0x640; // 1sec  (1000ms/0.625)
        // Increment counter in retension memory
        accel_adv_count += 1; 
//        ke_timer_set(APP_ACCEL_ADV_TIMER, TASK_APP, 18000);
        ke_timer_set(APP_ACCEL_ADV_TIMER, TASK_APP, 3000);
    }
    else if( accel_adv_count == 2 )
    {
        accel_adv_interval = 0xc80; // 2sec  (2000ms/0.625)
        // Increment counter in retension memory
        accel_adv_count += 1; 
//        ke_timer_set(APP_ACCEL_ADV_TIMER, TASK_APP, 18000);
        ke_timer_set(APP_ACCEL_ADV_TIMER, TASK_APP, 3000);
    }
    
	if( accel_adv_count == 3 )
    {
        accel_adv_count = 0; 
		accel_adv_interval = APP_ADV_INT_MIN;
        // Max schedule for advertising interval has been reached. Stop timer
        ke_timer_clear(APP_ACCEL_ADV_TIMER, TASK_APP);
		// Stop Advertising
		app_adv_stop();
		// Update APP State
		ke_state_set(TASK_APP, APP_IDLE);
		// Activate Accelerometer
		set_accel_freefall();
		acc_enable_wakeup_irq();
    }
	else
		app_adv_start();
    
    return (KE_MSG_CONSUMED);
}
Esempio n. 3
0
/**
 ****************************************************************************************
 * @brief Handles accelerometer start advertising request from the Wakeup ISR.
 *
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance (TASK_GAP).
 * @param[in] src_id    ID of the sending task instance.
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int accel_msg_handler(ke_msg_id_t const msgid,
									struct accel_create_db_cfm const *param,
									ke_task_id_t const dest_id,
									ke_task_id_t const src_id)
{
	// If state is not idle, ignore the message
	if (ke_state_get(dest_id) == APP_CONNECTABLE)
		app_adv_start();

	return (KE_MSG_CONSUMED);
}
Esempio n. 4
0
/**
 ****************************************************************************************
 * @brief Handles connection complete event from the GAP. Will enable profile.
 *
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance (TASK_GAP).
 * @param[in] src_id    ID of the sending task instance.
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int gapc_connection_req_ind_handler(ke_msg_id_t const msgid,
                                           struct gapc_connection_req_ind const *param,
                                           ke_task_id_t const dest_id,
                                           ke_task_id_t const src_id)
{
		// Connection Index
		if (ke_state_get(dest_id) == APP_CONNECTABLE)
		{
				app_env.conidx = KE_IDX_GET(src_id);
				
				if (app_env.conidx != GAP_INVALID_CONIDX)
				{
						//Disable timer of the establishment of the connection
						ke_timer_clear(APP_CONN_TIMER, TASK_APP);
						
						ke_state_set(dest_id, APP_CONNECTED);
						
						app_connection_func(param);
						
						// Retrieve the connection info from the parameters
						app_env.conhdl = param->conhdl;
						
						app_env.peer_addr_type = param->peer_addr_type;
						memcpy(app_env.peer_addr.addr, param->peer_addr.addr, BD_ADDR_LEN);
             
						// send connection confirmation    // 发送连接确认aiwesky 20151004
						app_connect_confirm(GAP_AUTH_REQ_NO_MITM_NO_BOND);            
						
						// Start param update
						app_param_update_start();         // 此时,就可以进行profile读取了  aiwesky 20151004
				}
				else
				{
						// No connection has been establish, restart advertising
						app_adv_start();    // 如果没有连接,则继续进行广播 aiwesky 20151005
				}        
				
		}
		else
		{
				// APP_CONNECTABLE state is used to wait the GAP_LE_CREATE_CONN_REQ_CMP_EVT message
				ASSERT_ERR(0);
    }

    return (KE_MSG_CONSUMED);
}