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

📄 headset_statemanager.c

📁 bc5_stereo:bluetooth stereo Headset CODE 支持A2DP HSP 和 HSP 。可作为车载免提。BlueLab 2007环境下编译
💻 C
📖 第 1 页 / 共 2 页
字号:
{
    stateManagerSetHfpState ( pApp , headsetActiveCall ) ;
	
	/* Update the SCO audio mode if the SCO is already running */
	if ( (pApp->dsp_process == dsp_process_sco) && pApp->cvcEnabled )
	{
		if (pApp->audioData.gMuted)
			AudioSetMode ( AUDIO_MODE_MUTE_MIC , NULL ) ;
		else
			AudioSetMode( AUDIO_MODE_CONNECTED, NULL);
	}
}


/*****************************************************************************/
void stateManagerEnterPoweringOffState ( hsTaskData *pApp )
{
	if ( stateManagerIsA2dpConnected() )
    {      
      	a2dpDisconnectRequest( pApp );
    }
	if ( stateManagerIsHfpConnected() )
    {       
        hfpSlcDisconnect( pApp );
    }
    
    VolumeStoreLevels(pApp);

    /* Now just waiting for switch off */
    stateManagerEnterLimboState ( pApp ) ;
}


/*****************************************************************************/
void stateManagerPowerOff ( hsTaskData * pApp ) 
{
    /* Update state in case we are debugging */
    stateManagerSetHfpState ( pApp , headsetPoweringOn) ;
    /* Attempt to physically power down device - this will fail if the chg is plugged in */
    LEDManagerSetPowerPin   (  pApp , POWER_OFF ) ;
}


/*****************************************************************************/
void stateManagerPowerOn ( hsTaskData * pApp ) 
{
    /* Cancel the event message if there was one so it doesn't power off */
    MessageCancelAll ( &pApp->task , EventLimboTimeout ) ;
    
    LEDManagerSetPowerPin ( pApp , POWER_ON ) ;
    
    stateManagerEnterHfpConnectableState ( pApp, TRUE );
    stateManagerEnterA2dpConnectableState ( pApp, TRUE );
    
    /*MessageSend ( &pApp->task , EventEstablishSLC , 0 ) ;*/
}


/*****************************************************************************/
void stateManagerEnterLimboState ( hsTaskData * pApp )
{
    LEDManagerSetPowerPin ( pApp , POWER_ON ) ;
    
    headsetDisableDiscoverable ( pApp ) ;    
    headsetDisableConnectable  ( pApp ) ;
   
    /* Set a timeout so that we will turn off eventually anyway */
    MessageSendLater ( &pApp->task , EventLimboTimeout , 0 , D_SEC(5) ) ;

    stateManagerSetHfpState ( pApp , headsetPoweringOn) ;
    
    /* Reset SLC settings */
    hfpSlcReset( pApp );
}


/*****************************************************************************/
void stateManagerUpdateLimboState ( hsTaskData * pApp ) 
{
     /* We are entering here as a result of a power off */
     switch (pApp->power->charger.state)
        {
            case disconnected :
                /* Power has been removed and we are logically off so switch off */
                SM_DEBUG(("SM: LimboDiscon\n")) ;
                stateManagerPowerOff ( pApp ) ;
            break ;    
                /* This means connected */
            case trickle_charge:
            case fast_charge:
			case charge_error:
                SM_DEBUG(("SM: LimboConn\n")) ;
                /* Stay in this state until a charger event or a power on occurs */
            break ;
               
            default:
            break ;
        }  
}


/*****************************************************************************/
bool stateManagerIsHfpConnected ( void )
{
    bool lIsConnected = FALSE ;
    
    switch (stateManagerGetHfpState() )
    {
        case headsetPoweringOn:
        case headsetHfpConnectable:
        case headsetConnDiscoverable:  
        case headsetTestMode:
            lIsConnected = FALSE ;    
            break ;
        
        default:
            lIsConnected = TRUE ;
            break ;
    }
    return lIsConnected ;
}


/*****************************************************************************/
bool stateManagerIsA2dpConnected ( void )
{
    bool lIsConnected = FALSE ;
    
    switch (stateManagerGetA2dpState() )
    {
        case headsetA2dpConnectable:   
            lIsConnected = FALSE ;    
            break ;
            
        default:
            lIsConnected = TRUE ;
            break ;
    }
    return lIsConnected ;
}


/*****************************************************************************/
bool stateManagerIsAvrcpConnected ( void )
{
	return (stateManagerGetAvrcpState() == avrcpConnected);
}


/****************************************************************************/
bool stateManagerIsA2dpStreaming(void)
{
	bool lRet = FALSE;
	if ((stateManagerGetA2dpState() == headsetA2dpStreaming) || (stateManagerGetA2dpState() == headsetA2dpPaused))
		lRet = TRUE;
		
	return lRet;
}

/****************************************************************************/
bool stateManagerIsA2dpSignallingActive(hsTaskData * pApp)
{
	bool lRet = FALSE;
	
	if (pApp->a2dp.sig_sink)
		lRet = TRUE;
		
	return lRet;
}


/*****************************************************************************/
void stateManagerEnterTestModeState ( hsTaskData * pApp )
{
	/* Cancel the event message if there was one so it doesn't power off */
    MessageCancelAll ( &pApp->task , EventLimboTimeout ) ;
	
    stateManagerSetHfpState (pApp , headsetTestMode ) ;
}


/*****************************************************************************/
void stateManagerSetAvrcpState ( hsTaskData* pApp, headsetAvrcpState state )
{
	SM_DEBUG(("SM (AVRCP): AvrcpSetState : From %d to %d\n", appStates.gTheAvrcpState, state));	
	appStates.gTheAvrcpState = state;
}


/*****************************************************************************/
headsetAvrcpState stateManagerGetAvrcpState ( void )
{
	return appStates.gTheAvrcpState;
}


/****************************************************************************
NAME	
	stateManagerSetHfpState

DESCRIPTION
	Helper function to Set the current hfp headset state
    provides a single state change point and passes the information
    on to the managers requiring state based responses. 
    
*/
static void stateManagerSetHfpState ( hsTaskData * pApp , headsetHfpState pNewState )
{
	SM_DEBUG(("SM (HFP):[%s]->[%s][%d]\n",gHSStateStrings[stateManagerGetHfpState()] , gHSStateStrings[pNewState] , pNewState ));
    
    if ( pNewState < HEADSET_NUM_HFP_STATES )
    {

        if (pNewState != appStates.gTheHfpState )
        {
            /* Inform the LED manager of the current state to be displayed */
            LEDManagerIndicateState ( &pApp->theLEDTask , pNewState , stateManagerGetA2dpState () ) ;
        }
        else
        {
            /* We are already indicating this state no need to set */
        }
   
        appStates.gTheHfpState = pNewState ;
   
    }
    else
    {
        SM_DEBUG(("SM (HFP): ? [%s] [%x]\n",gHSStateStrings[ pNewState] , pNewState)) ;
    }
    
    /*if we are in chargererror then reset the leds and reset the error*/
    if (pApp->power->charger.state == charge_error )
    {
       /* Cancel current LED indication */
	   MessageSend(getAppTask(), EventCancelLedIndication, 0);
	   /* Indicate charger error */
	   MessageSend(getAppTask(), EventChargeError, 0);
    }
}


/****************************************************************************
NAME	
	stateManagerSetA2dpState

DESCRIPTION
	Helper function to Set the current a2dp headset state
    provides a single state change point and passes the information
    on to the managers requiring state based responses. 
    
*/
static void stateManagerSetA2dpState ( hsTaskData * pApp , headsetA2dpState pNewState )
{
	SM_ASSERT((pNewState < HEADSET_NUM_A2DP_STATES), ("SM (A2DP): Invalid New State [%d]\n", pNewState));
	
	if (pNewState != appStates.gTheA2dpState )
    {
        /* Inform the LED manager of the current state to be displayed */
        LEDManagerIndicateState ( &pApp->theLEDTask , stateManagerGetHfpState () , pNewState ) ;
    }
    else
    {
        /* We are already indicating this state no need to set */
    }
	
    SM_DEBUG(("SM (A2DP):[%s]->[%s][%d]\n",gA2DPStateStrings[stateManagerGetA2dpState()] , gA2DPStateStrings[pNewState] , pNewState ));
	appStates.gTheA2dpState = pNewState ;
	
	/*if we are in chargererror then reset the leds and reset the error*/
    if (pApp->power->charger.state == charge_error )
    {
       /* Cancel current LED indication */
	   MessageSend(getAppTask(), EventCancelLedIndication, 0);
	   /* Indicate charger error */
	   MessageSend(getAppTask(), EventChargeError, 0);
    }
}



⌨️ 快捷键说明

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