示例#1
0
/**
 ****************************************************************************************
 * @brief Handles button press after cancel the jitter.
 *
 * @param[in] msgid     Id of the message received
 * @param[in] param     None
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_APP
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int app_button_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)
{
    switch(msgid)
    {
        case APP_SYS_BUTTON_1_TIMER:
            // make sure the button is pressed
            if(gpio_read_pin(BUTTON1_PIN) == GPIO_LOW)
            {
                if(APP_IDLE == ke_state_get(TASK_APP))
                {
                    struct app_proxr_env_tag *app_proxr_env = &app_env.proxr_ev;
                    if(!app_proxr_env->enabled)
                    {
                        // start adv
                        app_gap_adv_start_req(GAP_GEN_DISCOVERABLE|GAP_UND_CONNECTABLE,
                                app_env.adv_data, app_set_adv_data(GAP_GEN_DISCOVERABLE),
                                app_env.scanrsp_data, app_set_scan_rsp_data(app_get_local_service_flag()),
                                GAP_ADV_FAST_INTV1, GAP_ADV_FAST_INTV2);

#if (QN_DEEP_SLEEP_EN)
                        // prevent entering into deep sleep mode
                        sleep_set_pm(PM_SLEEP);
#endif
#if	(FB_OLED)
		ke_timer_set(APP_OLED_STATE_DISPlAY_TIMER,TASK_APP,20);
#endif
                    }
                }
                else if(APP_ADV == ke_state_get(TASK_APP))
                {
                    // stop adv
                    app_gap_adv_stop_req();

#if (QN_DEEP_SLEEP_EN)
                    // allow entering into deep sleep mode
                    sleep_set_pm(PM_DEEP_SLEEP);
#endif
#if	(FB_OLED)
		ke_timer_set(APP_OLED_STATE_DISPlAY_TIMER,TASK_APP,20);
#endif
                }
            }
            break;

        case APP_SYS_BUTTON_2_TIMER:
            if(gpio_read_pin(BUTTON2_PIN) == GPIO_LOW)
            {
                buzzer_off();
            }
            break;

        default:
            ASSERT_ERR(0);
            break;
    }

    return (KE_MSG_CONSUMED);
}
示例#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);
}
示例#3
0
/*
 ****************************************************************************************
 * @brief Handles the ind/ntf indication message from the HOGPD.    *//**
 *
 * @param[in] msgid     HOGPD_NTF_CFG_IND
 * @param[in] param     Pointer to the struct hogpd_ntf_cfg_ind
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_HOGPD
 *
 * @return If the message was consumed or not.
 * @description
 *
 ****************************************************************************************
 */
int app_hogpd_ntf_cfg_ind_handler(ke_msg_id_t const msgid,
                                  struct hogpd_ntf_cfg_ind *param,
                                  ke_task_id_t const dest_id,
                                  ke_task_id_t const src_id)
{
    switch (param->cfg_code)
    {
        case HOGPD_BOOT_KB_IN_REPORT_CFG:
            if (param->ntf_en == PRF_CLI_START_NTF)
            {
                //DEVELOPER NOTE: SET boot_kb_in_report and boot_kb_out_report to REAL VALUE OF USER APPLICATION HERE
                app_hogpd_env->features[param->hids_nb].svc_features |= HOGPD_BOOT_KB_IN_NTF_CFG_MASK;
                ke_timer_set(APP_HOGPD_BOOT_KB_IN_REPORT_TIMER, TASK_APP, APP_HOGPD_BOOT_KB_IN_REPORT_TO);
            }
            else
            {
                app_hogpd_env->features[param->hids_nb].svc_features &= ~HOGPD_BOOT_KB_IN_NTF_CFG_MASK;
                ke_timer_clear(APP_HOGPD_BOOT_KB_IN_REPORT_TIMER, TASK_APP);
            }
            break;
        case HOGPD_BOOT_MOUSE_IN_REPORT_CFG:
            if (param->ntf_en == PRF_CLI_START_NTF)
            {
                //DEVELOPER NOTE: SET boot_mouse_in_report to REAL VALUE OF USER APPLICATION HERE
                app_hogpd_env->features[param->hids_nb].svc_features |= HOGPD_BOOT_MOUSE_IN_NTF_CFG_MASK;
                ke_timer_set(APP_HOGPD_BOOT_MOUSE_IN_REPORT_TIMER, TASK_APP, APP_HOGPD_BOOT_MOUSE_IN_REPORT_TO);
            }
            else
            {
                app_hogpd_env->features[param->hids_nb].svc_features &= ~HOGPD_BOOT_MOUSE_IN_NTF_CFG_MASK;
                ke_timer_clear(APP_HOGPD_BOOT_MOUSE_IN_REPORT_TIMER, TASK_APP);
            }
            break;
        case HOGPD_REPORT_CFG:
            if (param->ntf_en == PRF_CLI_START_NTF)
            {
                // only input report support notify property
                if (app_hogpd_env->features[param->hids_nb].report_char_cfg[param->report_nb] & HOGPD_CFG_REPORT_IN)
                {
                    //DEVELOPER NOTE: SET report to REAL VALUE OF USER APPLICATION HERE
                    app_hogpd_env->features[param->hids_nb].report_char_cfg[param->report_nb] |= HOGPD_REPORT_NTF_CFG_MASK;
                    ke_timer_set(APP_HOGPD_REPORT_TIMER, TASK_APP, APP_HOGPD_BOOT_KB_IN_REPORT_TO);
                }
            }
            else
            {
                app_hogpd_env->features[param->hids_nb].report_char_cfg[param->report_nb] &= ~HOGPD_REPORT_NTF_CFG_MASK;
                ke_timer_clear(APP_HOGPD_REPORT_TIMER, TASK_APP);
            }
            break;
        default:
            break;
    }
    return (KE_MSG_CONSUMED);
}
示例#4
0
/**
 ****************************************************************************************
 * @brief   Led 1 flash process
 ****************************************************************************************
 */
static void usr_led1_process(void)
{
    if(led_get(1) == LED_ON)
    {
        led_set(1, LED_OFF);
        ke_timer_set(APP_SYS_LED_1_TIMER, TASK_APP, usr_env.led1_off_dur);
    }
    else
    {
        led_set(1, LED_ON);
        ke_timer_set(APP_SYS_LED_1_TIMER, TASK_APP, usr_env.led1_on_dur);
    }
}
示例#5
0
/**
 ****************************************************************************************
 * @brief Handles the temperature timer.
 *
 * @param[in] msgid     APP_HTPT_PERIOD_MEAS_TIMER
 * @param[in] param     None
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_APP
 *
 * @return If the message was consumed or not.
 * @description
 *  Handles the temperature timer.
 ****************************************************************************************
 */
int app_htpt_period_meas_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)
{
    bool start_meas = false;

    // Measurement Ready - send if Client Configuration is Configured,
    // and regardless of connected
    if(usr_env.is_temp_meas_config)
    {
        ++usr_env.meas_counter;

        ASSERT_ERR(app_htpt_env->meas_intv != 0);
        //if interval is zero, don't send indication
        if( usr_env.meas_counter % app_htpt_env->meas_intv == 0 )
        {
            start_meas = true;
            usr_env.is_should_indicate = true;
        }
    }

    if (usr_env.is_temp_imeas_config)
        start_meas = true;

    if(start_meas)
        start_measure_temperature();

    ke_timer_set(APP_HTPT_PERIOD_MEAS_TIMER, TASK_APP, HTPT_PERIOD_MEAS_TIME);

    return (KE_MSG_CONSUMED);
}
示例#6
0
void free_notic_info_timer(unsigned short const msgid)
{
	unsigned int start_time=0,end_time=0;
	unsigned int current_time=0;

	QPRINTF("==free notice count\r\n");
	if((++free_notic_info.count_time) >= free_notic_info.time)
	{
		/*1.clear count time */
		free_notic_info.count_time = 0;
		/*2.motor open */
		if(free_notic_info.free_enable)
		{
			s_tm ltime = {0};
			system_time_get(&ltime);
			current_time = 60*ltime.hour + ltime.minute;
			start_time = free_notic_info.start_time_hour*60 +
						 free_notic_info.start_time_minute;
			end_time   = free_notic_info.end_time_hour*60 + 
						 free_notic_info.end_time_minute;
			
			if((start_time <= current_time) && (current_time < end_time))
			{
				QPRINTF(" free notic : motor turn on \r\n");
			}
		}
	}
	ke_timer_set(USR_FREE_NOTICE_INFO_TIMER, 60*100);

}
示例#7
0
/*
****************************************************************************************
* @brief             ble_adv
* @param[in]         pcCommandString            ÃüÁîºÍ²ÎÊý´æ·ÅµØÖ·
* @param[in]         pcWriteBuffer              дÈë´ËÊý×éµÄÃüÁ±»·¢Ë͵½´®¿Ú
* @param[in]         commpare_length            ÃüÁîËùÕ¼³¤¶È
* @return            None
* @description       ¿ªÆô»òÕ߹رչ㲥£¬ÃüÁî¸ñʽ£ºAT+ADV=0  ¿ªÆô¹ã²¥    AT+ADV=1   ¹Ø±Õ¹ã²¥
*****************************************************************************************/
int ble_adv( const uint8_t * const pcCommandString,uint8_t* pcWriteBuffer,uint32_t commpare_length)
{
	const int8_t *pcom;
	int32_t arg1;
	uint32_t pxParameterStringLength;

	pcom = at_get_parameter((const int8_t*)pcCommandString + commpare_length + 1, 0, &pxParameterStringLength);
	arg1 = at_HEXstringToNum((const uint8_t *)pcom, pxParameterStringLength); 
	if(arg1 == 0)
	{
		usr_led1_set(LED_ON_DUR_IDLE,LED_OFF_DUR_IDLE);
		app_gap_adv_stop_req();
	}
	else if(arg1 == 1)
	{
				usr_led1_set(LED_ON_DUR_ADV_FAST,LED_ON_DUR_ADV_FAST);
				app_gap_adv_start_req(GAP_GEN_DISCOVERABLE|GAP_UND_CONNECTABLE,
						app_env.adv_data, app_set_adv_data(GAP_GEN_DISCOVERABLE),
						app_env.scanrsp_data, app_set_scan_rsp_data(app_get_local_service_flag()),
						GAP_ADV_FAST_INTV1, GAP_ADV_FAST_INTV2);
				ke_timer_set(APP_ADV_INTV_UPDATE_TIMER,TASK_APP,30);
	}
	else
	{
		return sprintf((char*)pcWriteBuffer,"ERR\r\n");
	}
	return sprintf((char*)pcWriteBuffer,"OK\r\n");
}
示例#8
0
/**
 ****************************************************************************************
 * @brief Handles the demo Glucose measurement timer.
 *
 * @param[in] msgid     Id of the message received
 * @param[in] param     None
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_APP
 *
 * @return If the message was consumed or not.
 * @description 
 *  Handles the demo Glucose measurement timer.
 ****************************************************************************************
 */
int app_glps_meas_send_timer_handler(ke_msg_id_t const msgid,
                                     void *param,
                                     ke_task_id_t const dest_id,
                                     ke_task_id_t const src_id)
{
    //DEVELOPER NOTE: SET REAL VALUE OF USER APPLICATION IN THIS FUNCTION
    if ((app_glps_env->evt_cfg & GLPS_MEAS_NTF_CFG) || (app_glps_env->evt_cfg & GLPS_MEAS_CTX_NTF_CFG))
    {
        app_glps_meas_send((app_glps_env->evt_cfg & GLPS_MEAS_NTF_CFG) ? false : true);

        if (app_glps_env->racp_req.filter.operator == GLP_OP_FIRST_REC)
        {
            app_glps_racp_rsp_req_send(app_glps_env->conhdl, 0, app_glps_env->racp_req.op_code, GLP_RSP_SUCCESS);
        }
        else if (app_glps_env->racp_req.filter.operator == GLP_OP_LAST_REC)
        {
            app_glps_racp_rsp_req_send(app_glps_env->conhdl, 0, app_glps_env->racp_req.op_code, GLP_RSP_SUCCESS);
        }
        else if (app_glps_env->racp_req.filter.operator == GLP_OP_ALL_RECS)
        {
            if (app_glps_env->records_idx >= APP_GLPS_STROED_RECORDS_NUM)
            {
                app_glps_racp_rsp_req_send(app_glps_env->conhdl, 0, app_glps_env->racp_req.op_code, GLP_RSP_SUCCESS);
                app_glps_env->records_idx = 0;
            }
            else
                ke_timer_set(APP_GLPS_MEAS_SEND_TIMER, TASK_APP, APP_GLPS_MEAS_SEND_TO);
        }
    }
    return (KE_MSG_CONSUMED);
}
示例#9
0
/**
 ****************************************************************************************
 * @brief Handles the battery level timer.
 *
 * @param[in] msgid     Id of the message received
 * @param[in] param     None
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_APP
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int app_bass_batt_level_timer_handler(ke_msg_id_t const msgid,
                                      void *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
    // Battery monitor enable
    battery_monitor_enable(MASK_ENABLE);


    // ADC initialize
    adc_init(ADC_SINGLE_WITH_BUF_DRV, ADC_CLK_1000000, ADC_INT_REF, ADC_12BIT);

    // Enable ADC decimation
    adc_decimation_enable(DECI_RATE_64, MASK_ENABLE);

    // Read voltage. use interrupt
    adc_read_configuration read_cfg;
    read_cfg.trig_src = ADC_TRIG_SOFT;
    read_cfg.mode = CONTINUE_MOD;
    read_cfg.start_ch = BATT;
    read_cfg.end_ch = BATT;
    adc_read(&read_cfg, usr_env.bas_reg_buf, BASS_SAMPLE_NUMBER, adc_sample_complete_callback);


    // Restart update timer
    ke_timer_set(APP_BASS_BATT_LEVEL_TIMER, TASK_APP, APP_BASS_BATT_LEVEL_TO);

    return (KE_MSG_CONSUMED);
}
示例#10
0
/**
 ****************************************************************************************
 * @brief  Wakeup 32k XTAL
 * @description
 *  This function will be called after waking up from deep sleep mode.
 *****************************************************************************************
 */
void wakeup_32k_xtal_start_timer(void)
{
    if(sleep_env.deep_sleep)
    {
        // start 32k XTAL wakeup timer
        ke_timer_set(APP_SYS_32K_XTAL_WAKEUP_TIMER, TASK_APP, 50);
    }
}
示例#11
0
/**
 ****************************************************************************************
 * @brief Handles button press before key debounce.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
void app_event_button1_press_handler(void)
{
#if ((QN_DEEP_SLEEP_EN) && (!QN_32K_RCO))
    if (sleep_env.deep_sleep)
    {
        sleep_env.deep_sleep = false;
        // start 32k xtal wakeup timer
        wakeup_32k_xtal_start_timer();
    }
#endif
    // delay 20ms to debounce
#if (FB_JOYSTICKS)
    ke_timer_set(APP_KEY_SCAN_TIMER,TASK_APP,2);
#else
    ke_timer_set(APP_SYS_BUTTON_1_TIMER, TASK_APP, 2);
#endif
    ke_evt_clear(1UL << EVENT_BUTTON1_PRESS_ID);
}
示例#12
0
void usr_clock_time_unit_handler(unsigned short const msgid)
{
//	unsigned char time = 0;

	//time = clock_alarm_check();
  clock_alarm_check();
	//ke_timer_set(USR_TIME_CHECK_TIMER, time*100);
  ke_timer_set(USR_TIME_CHECK_TIMER, 30);
}
示例#13
0
/*
 * Name         : app_param_update_func - Request update of connection params 
 *
 * Scope        : PUBLIC
 *
 * Arguments    : task_id - id of the kernel task calling this function
 *                param - parameters passed from the stack
 *
 * Description  : After connection and, optionally, pairing is completed, this function 
 *                is called to (optionally) modify the connection parameters.
 *
 * Returns      : void
 *
 */
void app_param_update_func(void)
{
    //Set a timer to update connection params after i.e. 10sec
    ke_timer_set(APP_HID_TIMER, TASK_APP, 100);
    arch_printf("** Set param update timer to 1 sec\r\n");
    
#ifndef MITM_REQUIRED
    // Call test code here    
#endif    
}
示例#14
0
/**
 ****************************************************************************************
 * @brief Handles measurement interval start indication from the Health Thermometer
 *        profile.
 *        Start or stop a timer following the value of the param intv.
 *
 * @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.
 ****************************************************************************************
 */
static int htpt_meas_intv_chg_ind_handler(ke_msg_id_t const msgid,
                                          struct htpt_meas_intv_chg_ind const *param,
                                          ke_task_id_t const dest_id,
                                          ke_task_id_t const src_id)
{
    if (ke_state_get(dest_id) == APP_HT_CONNECTED)
    {
        // Store the received Measurement Interval value
        app_ht_env.htpt_meas_intv = param->intv;

        // Check the new Measurement Interval Value
        if (app_ht_env.htpt_meas_intv != 0)
        {
            // Check if a Timer already exists
            if (!app_ht_env.timer_enable)
            {
                // Set a Timer
                ke_timer_set(APP_HT_TIMER, TASK_APP_HT, app_ht_env.htpt_meas_intv*100);
                app_ht_env.timer_enable = true;
            }
            else
            {
                // Clear the previous timer
                ke_timer_clear(APP_HT_TIMER, TASK_APP_HT);
                // Create a new timer with the received measurement interval
                ke_timer_set(APP_HT_TIMER, TASK_APP_HT, app_ht_env.htpt_meas_intv*100);
            }
        }
        else
        {
            // Check if a Timer exists
            if (app_ht_env.timer_enable)
            {
                // Measurement Interval is 0, clear the timer
                ke_timer_clear(APP_HT_TIMER, TASK_APP_HT);
                app_ht_env.timer_enable = false;
            }
        }
    }

    return (KE_MSG_CONSUMED);
}
示例#15
0
static int app_rco_cal_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)
{
    clock_32k_correction_enable(clock_32k_correction_cb);

    dev_prevent_sleep(PM_MASK_TIMER1_ACTIVE_BIT);

    ke_timer_set(APP_SYS_RCO_CAL_TIMER, TASK_APP, 100);

    return (KE_MSG_CONSUMED);
}
示例#16
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GATT_WRITE_CHAR_RESP message.
 * @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.
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int gatt_write_char_rsp_handler(ke_msg_id_t const msgid,
                                       struct gatt_write_char_resp const *param,
                                       ke_task_id_t const dest_id,
                                       ke_task_id_t const src_id)
{
    // Get the address of the environment
    struct cscpc_env_tag *cscpc_env = PRF_CLIENT_GET_ENV(dest_id, cscpc);

    if (cscpc_env != NULL)
    {
        ASSERT_ERR(cscpc_env->operation != NULL);

        // Retrieve the operation currently performed
        uint8_t operation = ((struct cscpc_cmd *)cscpc_env->operation)->operation;

        switch (operation)
        {
            case (CSCPC_CFG_NTF_IND_OP_CODE):
            {
                // Send the complete event status
                cscpc_send_cmp_evt(cscpc_env, operation, param->status);
            } break;

            case (CSCPC_CTNL_PT_CFG_WR_OP_CODE):
            {
                if (param->status == PRF_ERR_OK)
                {
                    // Start Timeout Procedure
                    ke_timer_set(CSCPC_TIMEOUT_TIMER_IND, dest_id, CSCPC_PROC_TIMEOUT_TIMER_VAL);

                    // Wait for the response indication
                    ((struct cscpc_cmd *)cscpc_env->operation)->operation = CSCPC_CTNL_PT_CFG_IND_OP_CODE;
                }
                else
                {
                    // Send the complete event status
                    cscpc_send_cmp_evt(cscpc_env, operation, param->status);
                }

            } break;

            default:
            {
                ASSERT_ERR(0);
            } break;
        }
    }
    // else ignore the message

    return (KE_MSG_CONSUMED);
}
示例#17
0
/**
 ****************************************************************************************
 * @brief Handles the send scan refresh timer.
 *
 * @param[in] msgid     Id of the message received.
 * @param[in] param     None
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_APP
 *
 * @return If the message was consumed or not.
 * @description
 *  Handles the send scan refresh timer.
 ****************************************************************************************
 */
int app_scpps_scan_refresh_timer_handler(ke_msg_id_t const msgid,
        void *param,
        ke_task_id_t const dest_id,
        ke_task_id_t const src_id)
{
    if (app_scpps_env->scan_refresh_ntf_cfg == PRF_CLI_START_NTF)
    {
        if (app_scpps_env->ntf_sending == false) {
            app_scpps_env->ntf_sending = true;
            app_scpps_scan_refresh_req(app_scpps_env->conhdl, 0);
        }
        ke_timer_set(APP_SCPPS_SCAN_REFRESH_TIMER, TASK_APP, APP_SCPPS_SCAN_REFRESH_TO);
    }
    return (KE_MSG_CONSUMED);
}
示例#18
0
/**
 ****************************************************************************************
 * @brief   Show proxr alert. User can add their own code here to show alert.
 ****************************************************************************************
 */
static void usr_proxr_alert(struct proxr_alert_ind *param)
{
    // If it is PROXR_LLS_CHAR writting indication, don't alert,
    // otherwise (PROXR_IAS_CHAR, disconnect) to alert
    if (param->char_code == PROXR_IAS_CHAR || app_proxr_env->enabled == false)
    {
        if(param->alert_lvl == 2)
        {
            buzzer_on(BUZZ_VOL_HIGH);
            ke_timer_set(APP_PROXR_ALERT_STOP_TIMER, TASK_APP, 500);    // 5 seconds
        }
        else if(param->alert_lvl == 1)
        {
            buzzer_on(BUZZ_VOL_LOW);
            ke_timer_set(APP_PROXR_ALERT_STOP_TIMER, TASK_APP, 500);    // 5 seconds
        }
        else
        {
            buzzer_off();
            ke_timer_clear(APP_PROXR_ALERT_STOP_TIMER, TASK_APP);
        }
    }

}
示例#19
0
文件: glpc_task.c 项目: imGit/DA14580
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GLPC_RACP_REQ message.
 * When receiving this request, Glucose collector send a RACP command to Glucose sensor.
 *
 * @param[in] msgid Id of the message received (probably unused).
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance (probably unused).
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int glpc_racp_req_handler(ke_msg_id_t const msgid,
                                     struct glpc_racp_req const *param,
                                     ke_task_id_t const dest_id,
                                     ke_task_id_t const src_id)
{
    // Get the address of the environment
    struct glpc_env_tag *glpc_env = PRF_CLIENT_GET_ENV(dest_id, glpc);

    uint8_t status = glpc_validate_request(glpc_env,
                                           param->conhdl,
                                           GLPC_CHAR_RACP);

    if(status == PRF_ERR_OK)
    {
        // send command request
        uint8_t value[GLP_REC_ACCESS_CTRL_MAX_LEN];
        uint16_t length;

        // pack Record Access Control Point request
        length = glpc_pack_racp_req((uint8_t*)&(value[0]), &(param->racp_req));

        // write Record Access Control Point request
        prf_gatt_write(&(glpc_env->con_info),
                         glpc_env->gls.chars[GLPC_CHAR_RACP].val_hdl,
                         &(value[0]),length, GATTC_WRITE);
        glpc_env->last_uuid_req = ATT_CHAR_REC_ACCESS_CTRL_PT;

        // start the timer; will destroy the link if it expires
        ke_timer_set(GLPC_RACP_REQ_TIMEOUT, dest_id, GLPC_RACP_TIMEOUT);
    }
    // inform application that request cannot be performed
    else
    {
        struct glpc_racp_rsp * rsp = KE_MSG_ALLOC(GLPC_RACP_RSP,
                                                  glpc_env->con_info.appid, dest_id,
                                                  glpc_racp_rsp);
        // set error status
        rsp->conhdl = param->conhdl;
        rsp->status = status;

        ke_msg_send(rsp);
    }


    return (KE_MSG_CONSUMED);
}
示例#20
0
int accel_start_ind_handler(ke_msg_id_t const msgid,
                                   struct accel_start_ind const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{
    // Start the accelerometer with the correct parameters
//vm	
    acc_start((uint16_t*)&param->accel_en[0], param->range);

    if(update_conn_params)
        update_conn_params = 2;
    
    // Start the accelerometer timer
    ke_timer_set(APP_ACCEL_TIMER, dest_id, 5);


    return (KE_MSG_CONSUMED);
}
示例#21
0
/**
 ****************************************************************************************
 * @brief Handles the demo Running Speed and Cadence Sensor measurement timer.
 *
 * @param[in] msgid     Id of the message received
 * @param[in] param     None
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_APP
 *
 * @return If the message was consumed or not.
 * @description 
 *  Handles the demo Glucose measurement timer.
 ****************************************************************************************
 */
int app_rscps_meas_send_timer_handler(ke_msg_id_t const msgid,
                                      void *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
    //DEVELOPER NOTE: SET REAL VALUE OF USER APPLICATION IN THIS FUNCTION
    if (app_rscps_env->enabled == true &&
        (app_rscps_env->app_cfg & RSCP_PRF_CFG_FLAG_RSC_MEAS_NTF))
    {
        if (app_rscps_env->ntf_sending == false)
        {
            app_rscps_env->ntf_sending = true;
            app_rscps_ntf_rsc_meas_req(app_rscps_env->conhdl, RSCP_MEAS_INST_STRIDE_LEN_PRESENT | RSCP_MEAS_TOTAL_DST_MEAS_PRESENT,  
                                   50, 60, 50, 2000);
        }
        ke_timer_set(APP_RSCPS_MEAS_SEND_TIMER, TASK_APP, APP_RSCPS_MEAS_SEND_TO);
    }
    return (KE_MSG_CONSUMED);
}
示例#22
0
/*
 ****************************************************************************************
 * @brief *//**
 *
 * @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_HOGPD).
 * @param[in] src_id    ID of the sending task instance.
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int app_hogpd_boot_mouse_in_report_timer_handler(ke_msg_id_t const msgid,
                                                 void *param,
                                                 ke_task_id_t const dest_id,
                                                 ke_task_id_t const src_id)
{
    if (!(app_hogpd_env->ntf_sending & HOGPD_CFG_BOOT_MOUSE_WR)) {
        app_hogpd_env->ntf_sending |= HOGPD_CFG_BOOT_MOUSE_WR;
        for (uint8_t i = 0; i < app_hogpd_env->hids_nb; i++)
        {
            if (app_hogpd_env->features[i].svc_features & HOGPD_BOOT_MOUSE_IN_NTF_CFG_MASK)
            {
                app_hogpd_boot_report_upd_req(app_hogpd_env->conhdl, i, HOGPD_BOOT_MOUSE_IN_REPORT_CHAR, 
                                              sizeof(boot_mouse_in_report), boot_mouse_in_report);
            }
        }
    }
    ke_timer_set(APP_HOGPD_BOOT_MOUSE_IN_REPORT_TIMER, TASK_APP, APP_HOGPD_BOOT_MOUSE_IN_REPORT_TO);
    return (KE_MSG_CONSUMED);
}
示例#23
0
/*
 ****************************************************************************************
 * @brief *//**
 *
 * @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_HOGPD).
 * @param[in] src_id    ID of the sending task instance.
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int app_hogpd_report_timer_handler(ke_msg_id_t const msgid,
                                   void *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{
    if (!(app_hogpd_env->ntf_sending & HOGPD_CFG_REPORT_IN)) {
        app_hogpd_env->ntf_sending |= HOGPD_CFG_REPORT_IN;
        for (uint8_t i = 0; i < app_hogpd_env->hids_nb; i++)
        {
            for (uint8_t j = 0; j < app_hogpd_env->features[i].report_nb; j++) {
                if (app_hogpd_env->features[i].report_char_cfg[j] & HOGPD_REPORT_NTF_CFG_MASK) {
                    app_hogpd_report_upd_req(app_hogpd_env->conhdl, i, j, sizeof(in_report), in_report);
                }
            }
        }
    }
    ke_timer_set(APP_HOGPD_REPORT_TIMER, TASK_APP, APP_HOGPD_REPORT_TO);
    return (KE_MSG_CONSUMED);
}
示例#24
0
/**
 ****************************************************************************************
 * @brief trigger time check
 ****************************************************************************************
 */
void time_check_trigger(void)
{
    const uint32_t cur_tick_count_10ms = ke_time();
    uint32_t diff = 0;

    if(cur_tick_count_10ms > s_pre_tick_count_10ms)
    {
        diff = cur_tick_count_10ms - s_pre_tick_count_10ms;
    }
    else // over flow
    {
        diff = MAX_TICK_COUNT_10MS - s_pre_tick_count_10ms + cur_tick_count_10ms;
    }

    s_pre_tick_count_sec += BASE_TIME_CNT_TO_S(diff);
    s_pre_tick_count_10ms = cur_tick_count_10ms;

    ke_timer_set(APP_SYS_TIME_CHECK_TIMER, TASK_APP, SYS_TIME_CHECK_PERIOD);
}
示例#25
0
void free_notic_onoff(unsigned char on)
{
	static unsigned char on_flag = 0;

	if(on == 0)
	{
	//	QPRINTF("close free notice\r\n");
		on_flag = 0;
		ke_timer_clear(USR_FREE_NOTICE_INFO_TIMER);
	}
	else{
		if(on_flag == 0)
		{
		//	QPRINTF("open free notice\r\n");
			on_flag = 1;
			free_notic_info.count_time = 0; //clear count when open it!
			ke_timer_set(USR_FREE_NOTICE_INFO_TIMER, 60*100);
		}
	}
}
示例#26
0
int app_proxr_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)
{
		 
		if (alert_state.blink_toggle)
		{
            GPIO_SetInactive( alert_state.port, alert_state.pin);
			alert_state.blink_toggle = 0;
		}
		else
		{
            GPIO_SetActive( alert_state.port, alert_state.pin);
			alert_state.blink_toggle = 1;
		}
		
		ke_timer_set(APP_PXP_TIMER, dest_id, alert_state.blink_timeout);
		
    return (KE_MSG_CONSUMED);
}
示例#27
0
/*
****************************************************************************************
* @brief             set_baudrate
* @param[in]         pcCommandString            ÃüÁîºÍ²ÎÊý´æ·ÅµØÖ·
* @param[in]         pcWriteBuffer              дÈë´ËÊý×éµÄÃüÁ±»·¢Ë͵½´®¿Ú
* @param[in]         commpare_length            ÃüÁîËùÕ¼³¤¶È
* @return            None
* @description       ÉèÖÃÄ£¿é²¨ÌØÂÊ£¬¸ñʽ£ºAT+BAUDx,xȡֵΪ0~16¡AAT+BAUD£ ºÍAT+BAUD±íʾ²éѯµ±Ç°²¨ÌØÂÊ
*										UART_1200     = 0,     //!< Set baud rate to 1200 when UART clock is 8MHz //
*    								UART_2400     = 1,     //!< Set baud rate to 2400 when UART clock is 8MHz //
*    								UART_4800     = 2,     //!< Set baud rate to 4800 when UART clock is 8MHz //
*    								UART_9600     = 3,     //!< Set baud rate to 9600 when UART clock is 8MHz //
*    								UART_14400    = 4,     //!< Set baud rate to 14400 when UART clock is 8MHz //
*    								UART_19200    = 5,     //!< Set baud rate to 19200 when UART clock is 8MHz //
*    								UART_28800    = 6,     //!< Set baud rate to 28800 when UART clock is 8MHz //
*    								UART_38400    = 7,     //!< Set baud rate to 38400 when UART clock is 8MHz //
*    								UART_57600    = 8,     //!< Set baud rate to 57600 when UART clock is 8MHz //
*    								UART_64000    = 9,     //!< Set baud rate to 64000 when UART clock is 8MHz //
*    								UART_76800    = 10,    //!< Set baud rate to 76800 when UART clock is 8MHz //
*    								UART_115200   = 11,    //!< Set baud rate to 115200 when UART clock is 8MHz //
*    								UART_128000   = 12,    //!< Set baud rate to 128000 when UART clock is 8MHz //
*    								UART_230400   = 13,    //!< Set baud rate to 230400 when UART clock is 8MHz //
*    								UART_345600   = 14,    //!< Set baud rate to 345600 when UART clock is 8MHz //
*    								UART_460800   = 15,    //!< Set baud rate to 460800 when UART clock is 8MHz //
*    								UART_500000   = 16,    //!< Set baud rate to 500000 when UART clock is 8MHz //
*****************************************************************************************/
int set_baudrate( const uint8_t * const pcCommandString,uint8_t* pcWriteBuffer,uint32_t commpare_length)
{
	const int8_t *pcom;
	uint32_t pxParameterStringLength;
	int len;
	
	//the baudrate inquire with the follow byte is "?" or "\0"
	if(pcCommandString[commpare_length+1] == '?' || pcCommandString[commpare_length+1] == '\0')
	{
		len = commpare_length+1;
		memcpy(pcWriteBuffer, pcCommandString, len);
		len += sprintf((char *)pcWriteBuffer + len,":%d\r\nOK\r\n",baudrate);	
	}
	//set baudrate  with the follow byte is "="
	else if(pcCommandString[commpare_length+1] == '=')
	{
		// get parameter and fill into *pcom
		pcom = at_get_parameter((const int8_t*)pcCommandString + commpare_length + 2, 0, &pxParameterStringLength);
		if(pxParameterStringLength != 0)
		{
			baudrate = at_HEXstringToNum((const uint8_t *)pcom, pxParameterStringLength); 
			if(baudrate > 16)
			{
				baudrate = 3;
			}		
			ke_timer_set(APP_COM_AT_BAUDRATE_CHANGE, TASK_APP, 1);	
			len = sprintf((char *)pcWriteBuffer,"OK\r\n");	
		}
		else
		{
			len = sprintf((char *)pcWriteBuffer,"ERR\r\n");
		}
	}
	else
	{
		len = sprintf((char *)pcWriteBuffer,"ERR\r\n");		
	}
	return len;
}
示例#28
0
/**
 ****************************************************************************************
 * @brief   Led1 for BLE status
 ****************************************************************************************
 */
static void usr_led1_set(uint16_t timer_on, uint16_t timer_off)
{
    usr_env.led1_on_dur = timer_on;
    usr_env.led1_off_dur = timer_off;

    if (timer_on == 0 || timer_off == 0)
    {
        if (timer_on == 0)
        {
            led_set(1, LED_OFF);
        }
        if (timer_off == 0)
        {
            led_set(1, LED_ON);
        }
        ke_timer_clear(APP_SYS_LED_1_TIMER, TASK_APP);
    }
    else
    {
        led_set(1, LED_OFF);
        ke_timer_set(APP_SYS_LED_1_TIMER, TASK_APP, timer_off);
    }
}
示例#29
0
/**
 ****************************************************************************************
 * @brief Handles health thermometer timer
 *
 * @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.
 ****************************************************************************************
 */
static int app_ht_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)
{
    if (ke_state_get(dest_id) == APP_HT_CONNECTED)
    {
        // Random generation of a temperature value
        uint32_t rand_temp_step;
        // Sign used to know if the tempererature will be increased or decreased
        int8_t sign;

        // Generate temperature step
        rand_temp_step = (uint32_t)(rand()%20);
        // Increase or decrease the temperature value
        sign = (int8_t)(rand_temp_step & 0x00000001);

        if (!sign)
        {
            sign = -1;
        }

        app_ht_env.temp_value += sign*rand_temp_step;

        // Send the new temperature
        app_htpt_temp_send();

        #if (DISPLAY_SUPPORT)
        app_display_update_temp_val_screen(app_ht_env.temp_value);
        #endif //DISPLAY_SUPPORT

        // Reset the Timer (Measurement Interval is not 0 if we are here)
        ke_timer_set(APP_HT_TIMER, TASK_APP_HT, app_ht_env.htpt_meas_intv*100);
    }

    return (KE_MSG_CONSUMED);
}
示例#30
0
/**
 ****************************************************************************************
 * @brief Handles the demo heart rate measurement timer.
 *
 * @param[in] msgid     Id of the message received
 * @param[in] param     None
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_APP
 *
 * @return If the message was consumed or not.
 * @description
 *  Handles the demo heart rate measurement timer.
 ****************************************************************************************
 */
int app_hrps_timer_handler(ke_msg_id_t const msgid,
                           void *param,
                           ke_task_id_t const dest_id,
                           ke_task_id_t const src_id)
{
    if (app_hrps_env->ntf_sending == false && app_hrps_env->features & HRPS_HR_MEAS_NTF_CFG)
    {
        struct hrs_hr_meas meas_val;

        meas_val.flags = HRS_FLAG_HR_8BITS_VALUE | HRS_FLAG_SENSOR_CCT_FET_NOT_SUPPORTED | HRS_FLAG_ENERGY_EXPENDED_PRESENT | HRS_FLAG_RR_INTERVAL_PRESENT;
        //DEVELOPER NOTE: SET nb_rr_interval TO REAL VALUE OF USER APPLICATION HERE
        meas_val.nb_rr_interval = 4;
        //DEVELOPER NOTE: SET rr_intervals TO REAL VALUE OF USER APPLICATION HERE
        meas_val.rr_intervals[0] = 0x12;
        meas_val.rr_intervals[1] = 0x34;
        meas_val.rr_intervals[2] = 0x56;
        meas_val.rr_intervals[3] = 0x78;
        //DEVELOPER NOTE: SET heart_rate TO REAL VALUE OF USER APPLICATION HERE
        meas_val.heart_rate = 70;
        meas_val.energy_expended = app_hrps_env->energy_expended;
        if ((0xffff - app_hrps_env->energy_expended) >= APP_HRPS_ENERGY_EXPENDED_STEP)
        {
            app_hrps_env->energy_expended += APP_HRPS_ENERGY_EXPENDED_STEP;
        }
        else
        {
            app_hrps_env->energy_expended = 0xFFFF;
        }

        app_hrps_measurement_send(app_hrps_env->conhdl, &meas_val);
        app_hrps_env->ntf_sending =true;
    }
    ke_timer_set(APP_HRPS_TIMER, TASK_APP, APP_HEART_RATE_MEASUREMENT_TO);

    return (KE_MSG_CONSUMED);
}