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

📄 headset_event_handler.c

📁 bc5_stereo:bluetooth stereo Headset CODE 支持A2DP HSP 和 HSP 。可作为车载免提。BlueLab 2007环境下编译
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2007

FILE NAME
    headset_event_handler.c
    
DESCRIPTION
    Handle events arriving at the app.
    
*/

#include "headset_a2dp_connection.h"
#include "headset_avrcp_event_handler.h"
#include "headset_configmanager.h"
#include "headset_debug.h"
#include "headset_event_handler.h"
#include "headset_events.h"
#include "headset_hfp_call.h"
#include "headset_hfp_slc.h"
#include "headset_LEDmanager.h"
#include "headset_tones.h"
#include "headset_statemanager.h"
#include "headset_volume.h"


#ifdef DEBUG_EVENTS
#define EVENTS_DEBUG(x) DEBUG(x)
#else
#define EVENTS_DEBUG(x) 
#endif


/****************************************************************************
  FUNCTIONS
*/

/****************************************************************************/
void handleUEMessage( Task task, MessageId id, Message message )
{
    hsTaskData * lApp = (hsTaskData *) getAppTask() ;
    
    headsetHfpState lState = stateManagerGetHfpState() ;
    headsetA2dpState lA2dpState = stateManagerGetA2dpState() ;
    
    /* If we do not want the event received to be indicated then set this to FALSE. */
    bool lIndicateEvent = TRUE ;
    
    
    /* Deal with user generated Event specific actions*/
    switch ( id )
    {   
            /*these are the events that are not user generated and can occur at any time*/
        case EventOkBattery:
        case EventChargerDisconnected:
        case EventLEDEventComplete:
        case EventTrickleCharge:
        case EventLowBattery:
        case EventPowerOff:
        case EventLinkLoss:
        case EventSLCConnected:
		case EventA2dpConnected:
        case EventError:
        case EventChargeError:
        case EventCancelLedIndication:
        case EventAutoSwitchOff:
		case EventHfpReconnectFailed:
		case EventA2dpReconnectFailed:
            /*do nothing for these events*/
        break ;
        default:
                    /* If we have had an event then reset the timer - if it was the event then we will switch off anyway*/
            if (lApp->Timeouts.AutoSwitchOffTime_s !=0)
            {
                /*EVENTS_DEBUG(("HS: AUTOSent Ev[%x] Time[%d]\n",id , lApp->Timeouts.AutoSwitchOffTime_s )) ;*/
                MessageCancelAll( &lApp->task , EventAutoSwitchOff ) ;
                MessageSendLater( &lApp->task , EventAutoSwitchOff , 0 , D_SEC(lApp->Timeouts.AutoSwitchOffTime_s) ) ;                
            }
                /*handles the LED event timeouts - restarts state indications if we have had a user generated event only*/
            if (lApp->theLEDTask.gLEDSStateTimeout)
            {   
                EVENTS_DEBUG(("HS: Restart St Inds[%d]\n", lState )) ;                    
                LEDManagerIndicateState (&lApp->theLEDTask , lState , lA2dpState) ;     
                lApp->theLEDTask.gLEDSStateTimeout = FALSE ;
            }
            else
            {
                    /*reset the current number of repeats complete - i.e restart the timer so that the leds will disable after
                    the correct time*/
                LEDManagerResetStateIndNumRepeatsComplete  ( &lApp->theLEDTask ) ;
            }
   
        break;
    }
    
    
    switch (id)
    {
    case EventPowerOn:
        EVENTS_DEBUG(("EventPowerOn\n"));
        stateManagerPowerOn ( lApp );
        break;
    case EventPowerOff:
        EVENTS_DEBUG(("EventPowerOff\n"));
        stateManagerEnterPoweringOffState ( lApp );
        if (lApp->audioData.gMuted)
            VolumeMuteOff ( lApp ) ;
        hfpCallClearQueuedEvent ( lApp ) ;
        MessageCancelAll ( &lApp->task , EventPairingFail) ;
        break;
	case EventPowerOnConnect:
        EVENTS_DEBUG(("EventPowerOnConnect\n"));
		lApp->slcConnectFromPowerOn = TRUE;
        MessageSend ( &lApp->task , EventEstablishSLC , 0 ) ;
        break;	
    case EventLimboTimeout:
        EVENTS_DEBUG(("EventLimboTimeout\n"));
        stateManagerUpdateLimboState ( lApp );
        break;
    case EventChargerConnected:
        EVENTS_DEBUG(("EventChargerConnected\n"));
        powerManagerChargerConnected ( lApp->power );
        break;    
    case EventChargerDisconnected:
        EVENTS_DEBUG(("EventChargerDisconnected\n"));
        powerManagerChargerDisconnected( lApp->power );
        if (lState == headsetPoweringOn )
        {
            stateManagerUpdateLimboState ( lApp ) ;
        }
        break;
    case EventTrickleCharge:  
        /*EVENTS_DEBUG(("EventTrickleCharge\n"));*/
        break;
    case EventFastCharge:
        /*EVENTS_DEBUG(("EventFastCharge\n"));*/
        break;
    case EventCancelLedIndication:
        EVENTS_DEBUG(("EventCancelLedIndication\n"));
        LedManagerResetLEDIndications ( &lApp->theLEDTask ) ;            
		break ;  
    case EventOkBattery:
        /*EVENTS_DEBUG(("EventOkBattery\n"));*/
        break;
    case EventLowBattery:
        EVENTS_DEBUG(("EventLowBattery\n"));
        break;
    case EventEnterPairing:
        EVENTS_DEBUG(("EventEnterPairing\n"));
        if (lState != headsetPoweringOn)
        {
            stateManagerEnterConnDiscoverableState ( lApp ) ;
        }    
        break ;
    case EventPairingFail:  
        EVENTS_DEBUG(("EventPairingFail\n"));
        if (lState != headsetTestMode)
        {
            stateManagerEnterHfpConnectableState( lApp, TRUE) ;          
        }
        break ;    
    case EventPairingSuccessful:
        EVENTS_DEBUG(("EventPairingSuccessful\n"));
        if (lState == headsetConnDiscoverable)
        {
            stateManagerEnterHfpConnectableState( lApp , FALSE) ;
        }
        break ;
    case EventSLCConnected:
        EVENTS_DEBUG(("EventSLCConnected\n"));
        hfpCallRecallQueuedEvent ( lApp ) ;
        break;
    case EventLinkLoss:
        EVENTS_DEBUG(("EventLinkLoss\n"));        
        break;
    case EventSLCDisconnected:
        EVENTS_DEBUG(("EventSLCDisconnected\n"));
        lApp->voice_recognition_enabled = FALSE;
        break;
    case EventLongTimer:
        EVENTS_DEBUG(("EventLongTimer\n"));
        if (lState == headsetPoweringOn)
            lIndicateEvent = FALSE ;
        break;
    case EventVLongTimer:
        EVENTS_DEBUG(("EventVLongTimer\n"));
        if (lState == headsetPoweringOn)
            lIndicateEvent = FALSE ;
        break;
    case EventLEDEventComplete:
        EVENTS_DEBUG(("EventLEDEventComplete\n"));
        if ( (( LMEndMessage_t *)message)->Event  == EventResetPairedDeviceList )
        {
            /* The reset has been completed */
            MessageSend(&lApp->task , EventResetComplete , 0 ) ;
        }
        
        if (lApp->theLEDTask.Queue.Event1)
        {
             EVENTS_DEBUG(("HS : Play Q'd Ev [%x]\n", (EVENTS_EVENT_BASE + lApp->theLEDTask.Queue.Event1)  ));
             EVENTS_DEBUG(("HS : Queue [%x][%x][%x][%x]\n", lApp->theLEDTask.Queue.Event1,
                                                              lApp->theLEDTask.Queue.Event2,
                                                              lApp->theLEDTask.Queue.Event3,
                                                              lApp->theLEDTask.Queue.Event4
                                                                    
                                                                ));
                
             LEDManagerIndicateEvent (&lApp->theLEDTask , (EVENTS_EVENT_BASE + lApp->theLEDTask.Queue.Event1) ) ;
    
             /*shuffle the queue*/
             lApp->theLEDTask.Queue.Event1 = lApp->theLEDTask.Queue.Event2 ;
             lApp->theLEDTask.Queue.Event2 = lApp->theLEDTask.Queue.Event3 ;
             lApp->theLEDTask.Queue.Event3 = lApp->theLEDTask.Queue.Event4 ;
             lApp->theLEDTask.Queue.Event4 = 0x00 ;
        }
        break;
    case EventEstablishSLC:   
		
		/* Don't indicate event if it's from power on */
		if (lApp->slcConnectFromPowerOn)
			lIndicateEvent = FALSE ;
		
		/* Only send a connect request if the headset isn't currently connecting HFP and the headset
		   is on and not in pairing mode.
		*/
        if (! hfpSlcIsConnecting (lApp)  && (stateManagerGetHfpState() >= headsetHfpConnectable) )
        {
            EVENTS_DEBUG(("EventEstablishSLC\n")) ;
            hfpSlcConnectRequest( lApp , hfp_handsfree_profile ) ;
        }   
        else
        {
            EVENTS_DEBUG(("EventEstablishSLC - Ignored\n")) ;
            /*do not perform the action*/
            lIndicateEvent = FALSE ;
        } 
        break;
    case EventHfpReconnectFailed:
        EVENTS_DEBUG(("EventHfpReconnectFailed\n"));
        break;
	case EventA2dpReconnectFailed:
        EVENTS_DEBUG(("EventA2dpReconnectFailed\n"));
        break;
    case EventInitateVoiceDial:
        EVENTS_DEBUG(("EventInitateVoiceDial [%d]\n", lApp->voice_recognition_enabled )) ;            
        /* Toggle the voice dial behaviour depending on whether we are currently active */
        if (lApp->voice_recognition_enabled)
        {
            hfpCallCancelVoiceDial ( lApp ) ;
            lIndicateEvent = FALSE ;
        }
        else
        {                
            hfpCallInitiateVoiceDial ( lApp ) ;
        }            
        break ;
    case EventLastNumberRedial:
        EVENTS_DEBUG(("EventLastNumberRedial\n" )) ;         		
        hfpCallInitiateLNR ( lApp ) ;	
        break ;
    case EventAnswer:
        EVENTS_DEBUG(("EventAnswer\n" )) ;
        /* Call the HFP lib function, this will determine the AT cmd to send
           depending on whether the profile instance is HSP or HFP compliant. */ 
        hfpCallAnswer( lApp );
        break ; 
    case EventReject:
        EVENTS_DEBUG(("EventReject\n" )) ;
        /* Reject incoming call - only valid for instances of HFP. */ 
        hfpCallReject( lApp );
        break ;
    case EventCancelEnd:
        EVENTS_DEBUG(("EventCancelEnd\n" )) ;
        /* Terminate the current ongoing call process */
        hfpCallHangUp( lApp );
        break ;
    case EventTransferToggle :
	    EVENTS_DEBUG(("EventTransferToggle\n")) ;    

⌨️ 快捷键说明

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