CC2540官方例程KeyFobDemo中,KEY的值是如何传递的,并且系统得到把EVT之后在哪里设置开始广播!
HI,管理员&各社员:
刚接触CC2540,被OSAL搞混乱了。
在官方例程KeyFobDemo中是如何通过按键来发生广播事件的,KEY的值是如何传递的,并且系统得到把EVT之后在哪里设置开始广播!?
对于获取Key值我的理解是:在Hal_ProcessEvent:
if (events & HAL_KEY_EVENT)
{
#if (defined HAL_KEY) && (HAL_KEY == TRUE)
/* Check for keys */
HalKeyPoll();
/* if interrupt disabled, do next polling */
if (!Hal_KeyIntEnable)
{
osal_start_timerEx( Hal_TaskID, HAL_KEY_EVENT, 100);
}
#endif return events ^ HAL_KEY_EVENT; }
这是获取key值的语句,而且在void HalKeyPoll (void) 里面,最后有这样一条语句:
/* Invoke Callback if new keys were depressed */
if (notify && (pHalKeyProcessFunction))
{
(pHalKeyProcessFunction) (keys, HAL_KEY_STATE_NORMAL);
}
请问这条就是发送key的事件函数吗?我该如何去理解这句话,这是一个回调函数,回调给谁?
而且在哪个具体的地方能了解key事件来触发BLE的广播的?
请各位帮我指点指点方向,不胜感激!
felix,
在下面:
if ( keys & HAL_KEY_SW_2 )
{
SK_Keys |= SK_KEY_RIGHT;
// if device is not in a connection, pressing the right key should toggle
// advertising on and off
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, ¤t_adv_enabled_status );
if( current_adv_enabled_status == FALSE )
{
new_adv_enabled_status = TRUE;
}
else
{
new_adv_enabled_status = FALSE;
}
//change the GAP advertisement status to opposite of current status
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status );
}
}
thanks Yan.
经过你的提醒,我找到了相关的函数。但是我现在又遇到了这样一个问题,我想把KeyFobDemo所有的LED灯给关了,包括广播时和连接上后的LED灯。我参考TI论坛上的一个帖子把相关的函数给注释掉了:
看 peripheralStateNotificationCB函数中的GAPROLE_ADVERTISING和GAPROLE_CONNECTED事件中有Led的处理。
case GAPROLE_ADVERTISING:
{ // Visual feedback that we are advertising.
HalLedSet( HAL_LED_2, HAL_LED_MODE_ON );
}
break;
//if the state changed to connected, initially assume that keyfob is in range
case GAPROLE_CONNECTED:
{
// set the proximity state to either path loss alert or in range depending
// on the value of keyfobProxIMAlertLevel (which was set by proximity monitor)
if( keyfobProxIMAlertLevel != PP_ALERT_LEVEL_NO )
{
keyfobProximityState = KEYFOB_PROXSTATE_PATH_LOSS;
// perform alert
keyfobapp_PerformAlert();
buzzer_beep_count = 0;
}
else
if keyfobProxIMAlertLevel == PP_ALERT_LEVEL_NO)
{
keyfobProximityState = KEYFOB_PROXSTATE_CONNECTED_IN_RANGE;
keyfobapp_StopAlert();
}
GAPRole_GetParameter( GAPROLE_CONNHANDLE, &connHandle );
#if defined ( PLUS_BROADCASTER )
osal_start_timerEx( keyfobapp_TaskID, KFD_ADV_IN_CONNECTION_EVT, ADV_IN_CONN_WAIT );
#endif
// Turn off LED that shows we're advertising
HalLedSet( HAL_LED_2, HAL_LED_MODE_OFF );
}
break;
按照上面的提示注释掉后,CC2540MINIDK-EM两个LED灯依然正常工作,按键后依然闪烁。
然后我全局查找HalLedSet()函数,把全部的HalLedSet()都给注释掉,现象依然跟没注释的一样。所以我的问题来了,是不是LED的控制被封装了,还是要不然都去掉了为何依然跟源程序一样。迷惑求解!