📄 headset_buttonmanager.c
字号:
/*we have a button match*/
if ( lButtonEvent->Duration == pDuration )
{
/* BM_DEBUG(("2")) ;*/
if ( (lButtonEvent->StateMask) & (lStateBit) )
{
BM_DEBUG(("BM : Match [%x][%x]\n" , pButtonMask , lButtonEvent->Event)) ;
/*we have fully matched an event....so tell the main task about it*/
MessageSend( gButtonsTask->client, lButtonEvent->Event , 0 ) ;
}
}
}
}
}
}
}
/****************************************************************************
NAME
ButtonManagerConfigDurations
DESCRIPTION
Wrapper method for the button Duration Setup
RETURNS
void
*/
void buttonManagerConfigDurations ( uint16 pLong , uint16 pVeryLong , uint16 pDouble , uint16 pRepeat )
{
BM_DEBUG(("BM : Dur [%d][%d][%d][%d]\n" , pLong , pVeryLong , pDouble , pRepeat)) ;
ButtonsConfigDurations ( gButtonsTask , pLong , pVeryLong , pDouble , pRepeat) ;
}
/****************************************************************************
NAME
ButtonManagerUnregisterButtons
DESCRIPTION
Wrapper method for the button unregister function
RETURNS
void
*/
void buttonManagerUnregisterButtons ( uint16 pButtonMask )
{
ButtonsUnRegisterButtons (gButtonsTask , pButtonMask ) ;
}
/****************************************************************************
NAME
buttonManagerCleanDestroy
DESCRIPTION
function to delete all allocated memory malloced by the button task
- used on power down.
RETURNS
*/
void buttonManagerClean ( void )
{
ButtonsUnRegisterButtons (gButtonsTask, 0xFFFF ) ;
if ( gButtonsTask->gButtonEvents )
{
free ( &gButtonsTask->gButtonEvents[0] ) ;
}
}
/****************************************************************************
NAME
buttonManagerRemoveMapping
DESCRIPTION
External Method to remove all button events previously defined whith a given event index
This is used by the Config Manager if changes to the default config are required
RETURNS
uint16 - Number of Events Deleted
*/
uint16 buttonManagerRemoveMapping ( headsetEvents_t pEvent )
{
uint16 lNumEventsDeleted = 0 ;
/*check the allocated events for a match*/
uint16 lBlockIndex = 0 ;
uint16 lEvIndex = 0 ;
BM_DEBUG(("BM: Remove Button [%x]\n", pEvent)) ;
/*each block*/
for (lBlockIndex = 0 ; lBlockIndex < BM_NUM_BLOCKS ; lBlockIndex++)
{ /*Each Entry*/
for (lEvIndex = 0 ; lEvIndex < BM_EVENTS_PER_BLOCK ; lEvIndex ++)
{
ButtonEvents_t * lButtonEvent = &gButtonsTask->gButtonEvents[lBlockIndex][lEvIndex] ;
/*if this ButtonEvent is the event we are looking for*/
if ( BMIsButtonEventMatch( lButtonEvent , pEvent ) )
{
/*unregister the button associated level or edge*/
buttonManagerUnregisterButtons ( lButtonEvent->ButtonMask) ;
/*remove it*/
BMReleaseButtonEvent ( lButtonEvent ) ;
/*store the fact that weve found one*/
lNumEventsDeleted++ ;
}
}
}
BM_DEBUG(("BM: Rem [%d]Events\n" , lNumEventsDeleted)) ;
gButtonsTask->gNumEventsConfigured -= lNumEventsDeleted ;
return lNumEventsDeleted ;
}
/****************************************************************************
NAME
BMGetButtonEvent
DESCRIPTION
Method to get a ButtonEvent if there are any free ones available
RETURNS
ButtonEvents_t * if there is one available - NULL otherwise
*/
static ButtonEvents_t * BMGetButtonEvent ( void )
{
ButtonEvents_t * lButtonEvent = NULL ;
/*iterate through the button Eventts looking for an empty block*/
uint16 lBlockIndex = 0 ;
uint16 lEvIndex = 0 ;
/*each block*/
for (lBlockIndex = 0 ; lBlockIndex < BM_NUM_BLOCKS ; lBlockIndex++)
{ /*Each Entry*/
for (lEvIndex = 0 ; lEvIndex < BM_EVENTS_PER_BLOCK ; lEvIndex ++)
{
lButtonEvent = &gButtonsTask->gButtonEvents[lBlockIndex][lEvIndex];
/*if this event is empty*/
if ( BMIsButtonEventEmpty( lButtonEvent ) )
{
BM_DEBUG(("BM: BuF[%d][%d]\n" , lBlockIndex , lEvIndex )) ;
/*if we find an empty one then do not continue looking*/
return lButtonEvent ;
}
}
}
/*if there were no events available return NULL*/
return lButtonEvent ;
}
/****************************************************************************
NAME
BMReleaseButtonEvent
DESCRIPTION
Method to release a ButtonEvent -sets to invalid so it can be used again
RETURNS
void
*/
static void BMReleaseButtonEvent ( ButtonEvents_t * pButtonEvent )
{
if ( pButtonEvent )
{
/*invalidate the buttonEvent*/
pButtonEvent->ButtonMask = 0x0000 ;
pButtonEvent->Duration = B_INVALID ;
pButtonEvent->Event = EventInvalid ;
pButtonEvent->StateMask = 0x0000 ;
}
}
/****************************************************************************
NAME
BMIsButtonEventEmpty
DESCRIPTION
helper Method to determine if a given button event is empty or not
RETURNS
bool - IsEmpty
*/
static bool BMIsButtonEventEmpty ( ButtonEvents_t * pButtonEvent )
{
/*an empty event is defined as containing an invalid EventIndex*/
return ( BMIsButtonEventMatch ( pButtonEvent , EventInvalid) ) ;
}
/****************************************************************************
NAME
BMIsButtonEventMatch
DESCRIPTION
helper Method to determine if a given button event matches a given event
RETURNS
bool - IsMatch
*/
static bool BMIsButtonEventMatch ( ButtonEvents_t * pButtonEvent , headsetEvents_t pEvent )
{
bool lIsMatch = FALSE ;
if ( pButtonEvent->Event == pEvent )
{
lIsMatch = TRUE ;
}
return lIsMatch ;
}
bool BMAddPatternMapping ( uint16 pSystemEvent , uint16 * pButtonsToMatch )
{
uint16 lMapIndex = 0 ;
uint16 lButtonIndex = 0 ;
/*adds a button pattern map*/
for (lMapIndex = 0 ; lMapIndex < BM_NUM_BUTTON_MATCH_PATTERNS ; lMapIndex++)
{
if (gButtonsTask->gButtonPatterns[lMapIndex]->EventToSend == B_INVALID )
{
gButtonsTask->gButtonPatterns[lMapIndex]->EventToSend = pSystemEvent ;
for (lButtonIndex = 0 ; lButtonIndex < BM_NUM_BUTTONS_PER_MATCH_PATTERN ; lButtonIndex++)
{
gButtonsTask->gButtonPatterns[lMapIndex]->ButtonToMatch[lButtonIndex] = pButtonsToMatch[lButtonIndex] ;
if (gButtonsTask->gButtonPatterns[lMapIndex]->ButtonToMatch[lButtonIndex] != 0)
{
gButtonsTask->gButtonPatterns[lMapIndex]->NumberOfMatches = lButtonIndex + 1;
}
}
BM_DEBUG(("BM: But Pat Added[%d] [%x] ,[%d][%d][%d][%d][%d][%d] [%d]\n" , lMapIndex , gButtonsTask->gButtonPatterns[lMapIndex]->EventToSend
, gButtonsTask->gButtonPatterns[lMapIndex]->ButtonToMatch[0]
, gButtonsTask->gButtonPatterns[lMapIndex]->ButtonToMatch[1]
, gButtonsTask->gButtonPatterns[lMapIndex]->ButtonToMatch[2]
, gButtonsTask->gButtonPatterns[lMapIndex]->ButtonToMatch[3]
, gButtonsTask->gButtonPatterns[lMapIndex]->ButtonToMatch[4]
, gButtonsTask->gButtonPatterns[lMapIndex]->ButtonToMatch[5]
, gButtonsTask->gButtonPatterns[lMapIndex]->NumberOfMatches
)) ;
return TRUE ;
}
}
return FALSE ;
}
static void BMCheckForButtonPatternMatch ( uint16 pButtonMask )
{
uint16 lIndex = 0 ;
BM_DEBUG(("BM: Pat[%x]\n", pButtonMask )) ;
for (lIndex = 0; lIndex < BM_NUM_BUTTON_MATCH_PATTERNS ; lIndex++ )
{
if ( gButtonsTask->gButtonPatterns[lIndex]->ButtonToMatch[gButtonsTask->gButtonMatchProgress[lIndex]] == pButtonMask )
{
/*we have matched a button*/
gButtonsTask->gButtonMatchProgress[lIndex]++ ;
BM_DEBUG(("BM: Pat Prog[%d][%x]\n", lIndex , gButtonsTask->gButtonMatchProgress[lIndex] )) ;
if (gButtonsTask->gButtonMatchProgress[lIndex] >= gButtonsTask->gButtonPatterns[lIndex]->NumberOfMatches)
{
/*we have matched a pattern*/
BM_DEBUG(("BM: Pat Match[%d] Ev[%x]\n", lIndex ,gButtonsTask->gButtonPatterns[lIndex]->EventToSend)) ;
gButtonsTask->gButtonMatchProgress[lIndex] = 0 ;
MessageSend( gButtonsTask->client, gButtonsTask->gButtonPatterns[lIndex]->EventToSend , 0 ) ;
}
}
else
{
gButtonsTask->gButtonMatchProgress[lIndex] = 0 ;
/*special case = if the last button pressed was the same as the first button*/
if ( gButtonsTask->gButtonPatterns [ lIndex ]->ButtonToMatch[0]== pButtonMask)
{
gButtonsTask->gButtonMatchProgress[lIndex] = 1 ;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -