⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 headset_buttonmanager.c

📁 BlueLab 3.5.2 单声道耳机源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************Copyright (C) Cambridge Silicon Radio Ltd. 2005-2006Part of BlueLab 3.6.2-releaseFILE NAME    main.c        DESCRIPTION    This is the button manager for BC4-Headset    This file provides a configurable wrapper for the button messages and    converts them into the standard system messages which are passed to the    main message handler - main.cNOTES */#include "headset_private.h"#include "headset_buttonmanager.h"#include "headset_statemanager.h"#include "headset_buttons.h"#include <stddef.h>#include <csrtypes.h>#include <panic.h>#include <stdlib.h>#include "headset_events.h"#ifdef DEBUG_BUT_MAN    #define BM_DEBUG(x) DEBUG(x)        const char * const gDebugTimeStrings[11] = {"Inv" ,     											"Short",                                                 "Long" ,                                                "VLong" ,                                                 "Double" ,                                                "Rpt" ,                                                 "LToH" ,                                                 "HToL" ,                                                 "ShSingle",                                                "Long Release",                                                "VLong Release"} ;                 #else    #define BM_DEBUG(x) #endif/* LOCAL FUNCTION PROTOTYPES */void BMMessageHandler ( Task pTask, MessageId pId, Message pMessage )   ;static void BMCheckForButtonMatch ( uint16 pButtonMask , ButtonsTime_t  pDuration  )  ;static void buttonManagerCreateEvents ( void ) ;static void buttonManagerCreateButtonPatterns ( void ) ;static ButtonEvents_t * BMGetButtonEvent ( void ) ;static bool BMIsButtonEventMatch ( ButtonEvents_t * pButtonEvent , headsetEvents_t pEvent ) ;static bool BMIsButtonEventEmpty ( ButtonEvents_t * pButtonEvent ) ;static void BMReleaseButtonEvent ( ButtonEvents_t * pButtonEvent ) ;/*only deals with short button presses*/static void BMCheckForButtonPatternMatch ( uint16 pButtonMask ) ;/****************************************************************************VARIABLES  */    /* Instance pointer to the task that we are registered with*/static BTaskData * gButtonsTask = NULL ;#define BM_EVENTS_PER_BLOCK (20)#define BM_NUM_BLOCKS (2)#define BM_NUM_CONFIGURABLE_EVENTS (BM_EVENTS_PER_BLOCK * BM_NUM_BLOCKS)/****************************************************************************  FUNCTIONS*//****************************************************************************NAME  	buttonManagerInit    DESCRIPTION 	Initialises the Button Module parametersRETURNS 	void*/  void buttonManagerInit ( BTaskData *pBTask, Task pClient ){           /*a pointer to the buttons task*/    gButtonsTask = pBTask ;                   gButtonsTask->client       = pClient;         /*the button events*/    gButtonsTask->gButtonEvents [0]  = NULL ;    gButtonsTask->gButtonEvents [1]  = NULL ;        buttonManagerCreateEvents ( ) ;        buttonManagerCreateButtonPatterns() ;      /*init the PIO button routines with the Button manager Task data */     ButtonsInit( gButtonsTask ) ; }static void buttonManagerCreateButtonPatterns ( void ){    uint16 lIndex = 0 ;    uint16 lButtonIndex = 0;        /*get the memory for the button Match Patterns*/    uint16 lSize = sizeof(ButtonMatchPattern_t) * BM_NUM_BUTTON_MATCH_PATTERNS  ;        gButtonsTask->gButtonPatterns[0] = mallocPanic ( lSize ) ;        gButtonsTask->gButtonPatterns[1] =  gButtonsTask->gButtonPatterns[0] + 1 ;        BM_DEBUG(("BM: Button MatchPats [%d] [%d] [%d]\n" , lSize, (int)gButtonsTask->gButtonPatterns[0] , (int)gButtonsTask->gButtonPatterns[1]));        for (lIndex = 0 ; lIndex < BM_NUM_BUTTON_MATCH_PATTERNS ; lIndex++ )    {        /*set the progress to the beginning*/        gButtonsTask->gButtonMatchProgress[lIndex] = 0 ;                    /*set the button match patterns to known vals*/        gButtonsTask->gButtonPatterns[lIndex]->NumberOfMatches = 0 ;        gButtonsTask->gButtonPatterns[lIndex]->EventToSend = 0 ;                        for (lButtonIndex = 0 ; lButtonIndex < BM_NUM_BUTTONS_PER_MATCH_PATTERN ; lButtonIndex++)        {            gButtonsTask->gButtonPatterns[lIndex]->ButtonToMatch[lButtonIndex] = B_INVALID ;        }       }   }/****************************************************************************NAME  buttonManagerCreateEventsDESCRIPTION    internal function to create the memory required for the button managerRETURNS*/static void buttonManagerCreateEvents ( void ) {    uint16 lIndex =0 ;            /*create the array of Button Events that we are going to poulate*/        gButtonsTask->gButtonEvents[0] = (ButtonEvents_t * ) ( mallocPanic( sizeof( ButtonEvents_t ) * BM_EVENTS_PER_BLOCK ) ) ;    gButtonsTask->gButtonEvents[1]= (ButtonEvents_t * ) ( mallocPanic( sizeof( ButtonEvents_t ) * BM_EVENTS_PER_BLOCK ) ) ;        for ( lIndex = 0 ; lIndex < BM_EVENTS_PER_BLOCK ; lIndex++ )    {        BMReleaseButtonEvent ( &gButtonsTask->gButtonEvents[ 0 ][ lIndex ]) ;        BMReleaseButtonEvent ( &gButtonsTask->gButtonEvents[ 1 ][ lIndex ]) ;    }      } /****************************************************************************NAME		buttonManagerAddMappingDESCRIPTION	Maps a button event to a system event            pButtonMask -     mask of the buttons that when pressed will generate an event    e.g.  0x0001 = button PIO 0              0x0003 = combination of PIO 0  and PIO 1    pSystemEvent        The Event to be signalled as define in headset_events.h    pStateMask        the states as defined in headset_states that the event will be generated in    pDuration        the Duration of the button press as defined in headset_buttons.h        B_SHORT , B_LONG , B_VLONG, B_DOUBLE          RETURNS bool to indicate success of button being added to map    */     bool buttonManagerAddMapping ( uint16        pButtonMask ,                                headsetEvents_t     pSystemEvent ,                                uint16        pStateMask ,                                ButtonsTime_t pDuration ) {    ButtonTriggerType_t lTrigger = ButtonLevelTrigger ;        ButtonEvents_t * lButtonEvent ;    bool lAddOk = FALSE;        BM_DEBUG(("BM : nB[%x]E[%x]S[%x] [%s]",pButtonMask, pSystemEvent, pStateMask , gDebugTimeStrings[pDuration])) ;            lButtonEvent =  BMGetButtonEvent() ;        /**if we were given a button event**/    if ( lButtonEvent )    {           lButtonEvent->ButtonMask = pButtonMask ;        lButtonEvent->Duration   = pDuration ;        lButtonEvent->Event      = pSystemEvent ;        lButtonEvent->StateMask  = pStateMask ;                /*inc the global index*/        gButtonsTask->gNumEventsConfigured++ ;                    /*register the buttons we are interested in with the buttons task*/                lTrigger   =ButtonLevelTrigger ;        if ( (pDuration == B_LOW_TO_HIGH ) || (pDuration == B_HIGH_TO_LOW) )        {            lTrigger = ButtonEdgeTrigger ;        }                ButtonsRegisterButtons (gButtonsTask , pButtonMask , lTrigger ) ;                lAddOk = TRUE ;    }    else    {        BM_DEBUG(("_![%x]\n", gButtonsTask->gNumEventsConfigured)) ;    }       return lAddOk ;}/****************************************************************************NAME		BMButtonDetectedDESCRIPTION	function call for when a button has been detected RETURNS	void    */void BMButtonDetected ( uint16 pButtonMask , ButtonsTime_t pTime  ){     BM_DEBUG(("BM : But [%x] [%s]\n" , pButtonMask , gDebugTimeStrings[pTime]  )) ;         /*perform the search over both blocks*/    BMCheckForButtonMatch ( pButtonMask  , pTime ) ;            /*only use regular button presses for the pattern matching to make life simpler*/    if ( ( pTime == B_SHORT ) || (pTime == B_LONG ) )    {        BMCheckForButtonPatternMatch ( pButtonMask ) ;    }   }/****************************************************************************NAME  BMCheckForButtonMatch    DESCRIPTION function to check a button for a match in the button events map - sends a message    to a connected task with the corresponding event    RETURNS    void*/   static void BMCheckForButtonMatch ( uint16 pButtonMask , ButtonsTime_t  pDuration ) {    uint16 lStateBit = ( 1 << stateManagerGetState () ) ;     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 ++)        {             ButtonEvents_t * lButtonEvent = &gButtonsTask->gButtonEvents [lBlockIndex] [ lEvIndex ] ;            /*if the event is valid*/            if ( lButtonEvent != NULL)            {                            if (lButtonEvent->ButtonMask == pButtonMask )                {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -