📄 headset_buttons.c
字号:
ButtonsButtonDetected ( lBTask, lBTask->gBOldState , lBTask->gBTime );
}
break ;
case B_REPEAT_TIMER:
{
/*if we have reached here, the repeat time has been reached so send a new message*/
B_DEBUG(("B : Repeat [%lx][%x]\n", lBTask->gBOldState , B_REPEAT )) ;
/*send another repeat message*/
MessageSendLater ( &lBTask->task , B_REPEAT_TIMER , 0 , lBTask->gBRepeatDuration_ms ) ;
ButtonsButtonDetected ( lBTask, lBTask->gBOldState , B_REPEAT );
}
break;
default :
B_DEBUG(("B : ?[%x]\n",pId)) ;
break ;
}
}
/****************************************************************************
NAME
ButtonsWasButtonPressed
DESCRIPTION
Helper method - returns true if a button was pressed.
*/
static bool ButtonsWasButtonPressed ( uint32 pOldState , uint32 pNewState)
{
bool lWasButtonPressed = FALSE ;
uint32 lButton = ButtonsWhichButtonChanged ( pOldState , pNewState ) ;
if ( ( lButton & pNewState ) != 0 )
{
lWasButtonPressed = TRUE ;
}
return lWasButtonPressed ;
}
/****************************************************************************
NAME
ButtonsWhichButtonChanged
DESCRIPTION
Helper method - returns mask ofwhich button changed.
*/
static uint32 ButtonsWhichButtonChanged ( uint32 pOldState , uint32 pNewState )
{
uint32 lWhichButton = 0 ;
lWhichButton = (pNewState ^ pOldState ) ;
return lWhichButton ;
}
/****************************************************************************
NAME
ButtonsButtonDetected
DESCRIPTION
Function to handle a button press - informs button manager of a change
currently makes direct call - may want to use message handling (tasks).
*/
static void ButtonsButtonDetected ( BTaskData * pBTask, uint32 pButtonMask , ButtonsTime_t pTime )
{
if( pButtonMask == 0 )
{
MessageCancelAll ( &pBTask->task , B_REPEAT_TIMER ) ;
}
else
{
BMButtonDetected ( pButtonMask , pTime ) ;
}
}
/****************************************************************************
NAME
ButtonsLevelDetect
DESCRIPTION
Function to detect level changes of buttons / multiple buttons.
*/
static void ButtonsLevelDetect ( const uint32 pState , BTaskData * pBTask )
{
uint32 lNewState = 0x0000;
/*we have an indication from the PIO subsytem that a PIO has changed value*/
lNewState = (uint32) (pState & (pBTask->gButtonLevelMask) ) ;
B_DEBUG(("B| : [%lx][%lx]\n", pState , (pBTask->gButtonLevelMask) )) ;
B_DEBUG(("B| : [%lx][%lx]\n", pBTask->gBOldState , lNewState )) ;
if ( ButtonsWasButtonPressed( pBTask->gBOldState , lNewState ) )
{
/*cancel all previously timed messages*/
MessageCancelAll ( &pBTask->task , B_INTERNAL_TIMER ) ;
MessageCancelAll ( &pBTask->task , B_REPEAT_TIMER ) ;
MessageCancelAll ( &pBTask->task , B_DOUBLE_TIMER ) ;
/* send new timed messages*/
MessageSendLater ( &pBTask->task , B_INTERNAL_TIMER , 0 , pBTask->gBLongDuration_ms ) ;
MessageSendLater ( &pBTask->task , B_INTERNAL_TIMER , 0 , pBTask->gBVeryLongDuration_ms ) ;
MessageSendLater ( &pBTask->task , B_INTERNAL_TIMER , 0 , pBTask->gBVeryVeryLongDuration_ms ) ;
MessageSendLater ( &pBTask->task , B_REPEAT_TIMER , 0 , pBTask->gBRepeatDuration_ms ) ;
/*having restrted the timers, reset the time*/
pBTask->gBTime = B_SHORT ;
}
else /*button was released or was masked out*/
{ /*it was only a released if there was a button actually pressed last time around -
buttons we have masked out still end up here but no state changes are made */
if ( pBTask->gBOldState != 0 )
{
/*if we have had a double press in the required time
and the button pressed was the same as this one*/
if ( (pBTask->gBDoubleTap ) && (pBTask->gBOldState == pBTask->gBDoubleState ) )
{
pBTask->gBTime = B_DOUBLE ;
/*reset the double state*/
pBTask->gBDoubleState = 0x0000 ;
pBTask->gBDoubleTap = FALSE ;
ButtonsButtonDetected ( pBTask , pBTask->gBOldState , B_DOUBLE );
}
/*only send a message if it was a short one - long / v long /double handled elsewhere*/
if ( (pBTask->gBTime == B_SHORT ) )
{
ButtonsButtonDetected ( pBTask , pBTask->gBOldState , B_SHORT );
/*store the double state*/
pBTask->gBDoubleState = pBTask->gBOldState ;
pBTask->gBDoubleTap = TRUE ;
/*start the double timer - only applicable to a short press*/
MessageSendLater ( &pBTask->task , B_DOUBLE_TIMER , 0 ,pBTask->gBDoubleDuration_ms ) ;
}
else if ( (pBTask->gBTime == B_LONG) )
{
ButtonsButtonDetected ( pBTask , pBTask->gBOldState , B_LONG_RELEASE );
}
else if ( (pBTask->gBTime == B_VERY_LONG) )
{
ButtonsButtonDetected ( pBTask , pBTask->gBOldState , B_VERY_LONG_RELEASE );
}
else if ( (pBTask->gBTime == B_VERY_VERY_LONG) )
{
ButtonsButtonDetected ( pBTask , pBTask->gBOldState , B_VERY_VERY_LONG_RELEASE );
}
if (pBTask->gBTime != B_INVALID)
{
MessageCancelAll ( &pBTask->task , B_INTERNAL_TIMER) ;
MessageCancelAll ( &pBTask->task , B_REPEAT_TIMER ) ;
}
/*removing this allows all releases to generate combination presses is this right?*/
if ( !lNewState )
{
pBTask->gBTime = B_INVALID ;
}
}
}
pBTask->gBOldState = lNewState ;
}
/****************************************************************************
NAME
ButtonsEdgeDetect
DESCRIPTION
Function to detect edge changes of buttons / multiple buttons.
*/
static void ButtonsEdgeDetect ( const uint32 pState , BTaskData * pBTask )
{
uint32 lNewState = 0x0000 ;
uint32 lButton = 0x0000 ;
/*what has changed */
lNewState = (uint32) ( pState & (pBTask->gButtonEdgeMask) ) ;
lButton = ButtonsWhichButtonChanged( pBTask->gBOldEdgeState , lNewState ) ;
B_DEBUG(("BA: [%lx][%lx][%lx]\n", pBTask->gBOldEdgeState , lNewState , pBTask->gButtonEdgeMask )) ;
B_DEBUG(("BB: [%lx][%lx][%lx]\n", lNewState , lButton , (lNewState & lButton) )) ;
/*if a button has changed*/
if ( lButton )
{
/*determine which edge has been received and process accordingly*/
if ( lNewState & lButton )
{
ButtonsButtonDetected ( pBTask , lButton , B_LOW_TO_HIGH ) ;
}
else
{
ButtonsButtonDetected ( pBTask , lButton , B_HIGH_TO_LOW ) ;
}
}
/*remember the last state*/
pBTask->gBOldEdgeState = lNewState;
}
/****************************************************************************
NAME
ButtonsIsChargerConnected
DESCRIPTION
Returns if the charger is connected or not.
*/
static bool ButtonsIsChargerConnected ( void )
{
bool connected = FALSE;
switch (ChargerStatus())
{
case TRICKLE_CHARGE:
case FAST_CHARGE:
case CHARGING:
case STANDBY:
case DISABLED_ERROR:
connected = TRUE;
break;
case NO_POWER:
case NOT_CHARGING:
break;
default:
break;
}
B_DEBUG(("B : Is charger connected : %d %d\n",ChargerStatus(),connected));
return connected;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -