This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

advertising enable with long key press ?

Hi all,

I want to enable the advertising with 3 sec long key press. i tried below  steps. but it is not working. it seem to be keyfob task blocked after doing below setting:

I set a 3 sec timer with CHECK_LONG_KEY_PRESS_EVT event , which will start adv . if user hold the key .

uint16 KeyFobApp_ProcessEvent( uint8 task_id, uint16 events )
{
  	if(events & CHECK_LONG_KEY_PRESS_EVT){
          			events ^= CHECK_LONG_KEY_PRESS_EVT; 
			if(gapProfileState != GAPROLE_CONNECTED ){

                      			uint8 current_adv_enabled_status;
                     				 uint8 new_adv_enabled_status;
                      			//Find the current GAP advertisement status
                      			GAPRole_GetParameter(GAPROLE_ADVERT_ENABLED,&current_adv_enabled_status );
                     				 if( current_adv_enabled_status == FALSE ){
                          				new_adv_enabled_status = TRUE;
                         				 GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status );
                    				  }
    
                  			}	
			
          			return (events ^ CHECK_LONG_KEY_PRESS_EVT);
  	}

		
}

static void keyfobapp_HandleKeys( uint8 shift, uint8 keys ){

            uint8 SK_Keys = 0;

        if ( keys & HAL_KEY_SW_1 ){
        
  	------
	-------
	osal_start_timerEx( keyfobapp_TaskID,CHECK_LONG_KEY_PRESS_EVT) , 3000 );//3 sec
   

        }

is it a correct approach to do it ? or am i missing something? any pointer ?


thanks in advance.

robin

  • Hi Robin,

    With this setting, the timer will generate call back after 3 seconds. But I think it won't solve your purpose. You should check status of the switch at regular interval for 3 seconds., for example at every 100 ms. And even after 3 seconds, still the switch is pressed you should Turn ON the advertisement.

    The code for turning on the Advertisement seems fine to me.

    Thanks,

    Dahval

  • I was making mistake in EVENT code , tried this and working :

    if(events & CHECK_LONG_KEY_PRESS_EVT){
            
         if(HalKeyRead()!=0x00){
           
              if( gapProfileState != GAPROLE_CONNECTED ){
                    uint8 current_adv_enabled_status;
                    uint8 new_adv_enabled_status;
    
                    //Find the current GAP advertisement status
                    GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, &current_adv_enabled_status );
                    if( current_adv_enabled_status == FALSE ){
                        new_adv_enabled_status = TRUE;
                        GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status );
                    }
                }
           
         }