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

📄 main.c

📁 针对bluelab3.42的handsfree车载蓝牙的参考
💻 C
📖 第 1 页 / 共 5 页
字号:
                    case avHeadsetA2dpInitialising:
                    default:
                        unhandledA2dpState(current_a2dp_state, id);
                        break;      
                }
            }
            else if ((app.active_profile == hfp_active) && !app.headset_connecting_hfp)
            {
                switch(current_hfp_state)
                {           
                case headsetReady:
                case headsetConnecting:
                    break;

                case headsetConnected:
                case headsetIncomingCallEstablish:
                case headsetActiveCall:
                case headsetOutgoingCallEstablish:
                    {
                        HFP *instance = 0;

                        /* If HFP send volume cmd but if HSP make sure we have a SCO open. */
                        if (app.profile_connected == hfp_handsfree_profile)
                            instance = app.hfp;
                        else if ((app.profile_connected == hfp_headset_profile) && app.sco_sink)
                            instance = app.hsp;
                        else 
                            break;

                        /* Send a volume down request */
                        headsetHandleHfVolDown(&app);

                        /* Send the AT cmd to inform the AG of the vol change */
                        HfpSendSpeakerVolume(instance, (uint16)app.speaker_volume.hfp_volume);
                    }
                    break;

                case headsetInitialising:
                default:
                    unhandledHfpState(current_hfp_state, id);
                }
            }
            break;

        case BUTTON_FORWARD_PRESS:
            MAIN_DEBUG(("BUTTON_FORWARD_PRESS\n"));
            if (app.active_profile == av_active)
            {
                switch(current_avrcp_state)
                {
                    case avHeadsetAvrcpConnected:
                        avHeadsetForwardPress(&app);
                        break;
                    case avHeadsetAvrcpReady:
                    case avHeadsetAvrcpInitialising:
                    case avHeadsetAvrcpConnecting:
                    default:
                        unhandledAvrcpState(current_avrcp_state, id);
                        break;      
                }
                playButtonTone = TRUE;
            }
            else
            {
                switch (app.headset_power_state)
                {
                case power_state_off:
                case power_state_off_charging:
                case power_state_powering_down:
                    /* Ignore the button press in this state. Powered off so don't play tone. */
                    break;
                default:
                    playErrorTone = TRUE;
                    break;
                }
            }
            break;

        case BUTTON_FORWARD_RELEASE:
            MAIN_DEBUG(("BUTTON_FORWARD_RELEASE\n"));

            if (app.active_profile == av_active)
            {
                switch(current_avrcp_state)
                {
                    case avHeadsetAvrcpConnected:
                        avHeadsetForwardRelease(&app);
                        break;
                    case avHeadsetAvrcpReady:
                    case avHeadsetAvrcpInitialising:
                    case avHeadsetAvrcpConnecting:
                    default:
                        unhandledAvrcpState(current_avrcp_state, id);
                        break;      
                }
            }
            break;

        case BUTTON_BACKWARD_PRESS:
            MAIN_DEBUG(("BUTTON_BACKWARD_PRESS\n"));
            if (app.active_profile == av_active)
            {
                switch(current_avrcp_state)
                {
                    case avHeadsetAvrcpConnected:
                        avHeadsetBackwardPress(&app);
                        break;
                    case avHeadsetAvrcpReady:
                    case avHeadsetAvrcpInitialising:
                    case avHeadsetAvrcpConnecting:
                    default:
                        unhandledAvrcpState(current_avrcp_state, id);
                        break;      
                }
                playButtonTone = TRUE;
            }
            else
            {
                switch (app.headset_power_state)
                {
                case power_state_off:
                case power_state_off_charging:
                case power_state_powering_down:
                    /* Ignore the button press in this state. Powered off so don't play tone. */
                    break;
                default:
                    playErrorTone = TRUE;
                    break;
                }
            }
            break;

        case BUTTON_BACKWARD_RELEASE:
            MAIN_DEBUG(("BUTTON_BACKWARD_RELEASE\n"));

            if (app.active_profile == av_active)
            {
                switch(current_avrcp_state)
                {
                    case avHeadsetAvrcpConnected:
                        avHeadsetBackwardRelease(&app);
                        break;
                    case avHeadsetAvrcpReady:
                    case avHeadsetAvrcpInitialising:
                    case avHeadsetAvrcpConnecting:
                    default:
                        unhandledAvrcpState(current_avrcp_state, id);
                        break;      
                }
            }
            break;
            
        case BUTTON_MFB_PRESS:
            MAIN_DEBUG(("BUTTON_MFB_PRESS\n"));
            headsetPowerAmpOnOnly(&app);
            break;

        case BUTTON_MFB_SHORT:
            MAIN_DEBUG(("BUTTON_MFB_SHORT\n"));            

            switch (app.headset_power_state)
            {
            case power_state_off:
            case power_state_off_charging:
            case power_state_powering_down:
                /* Ignore the button press in this state. Powered off so don't play tone. */
                break;

            case power_state_on:
            case power_state_on_charging:
                if (!app.headset_connecting_hfp)
                {
                    if (isHeadsetPairing(&app))
                    {
                        playErrorTone = TRUE;
                    }
                    else
                    {                    
                        /* Headset not idle, must have some connection active */
                        switch(current_hfp_state)
                        {
                            case headsetReady:
                                playButtonSuccessTone(&app);
                                /* If we're already streaming music pause it. */
                                if (app.a2dp_state == avHeadsetA2dpStreaming)
                                {
                                    avHeadsetAvStreamStop(&app, TRUE);
                                    (void) MessageCancelAll(getAppTask(), APP_MUSIC_RESTART_IND);
                                }

                                /* Headset is idle initiate Last number redial */
                                app.headset_connecting_hfp = 1;
                        
                                /* Queue a voice request message so we can act on it on SLC connect */
                                MessageSendConditionally(&app.task, BUTTON_MFB_SHORT, 0, &app.headset_connecting_hfp);
                        
                                /* Initiate the HFP SLC */
                                hfpHeadsetHandleSlcConnectRequest(&app, hfp_handsfree_profile);
                        
                                break;

                            case headsetConnecting:
                                break;

                            case headsetConnected:
                                /* Delay sending a voice dial request in case connection
                                   has just been established (some AG's refuse voice dial
                                   if you send request too early) */
								
								v = malloc(sizeof(APP_VOICE_DIAL_T));
								if (app.voice.voice_recognition_enabled)
								{
                        			v->voice_recog_enabled=0;
									app.voice.voice_recognition_enabled = 0;
								}
                   				else  
								{
                        			v->voice_recog_enabled=1;
									app.voice.voice_recognition_enabled = 1;
								}
								
                                MessageSendLater(getAppTask(), APP_VOICE_DIAL, v, 800);
                                
                                /* Suspend the AV now to ease CPU load */
                                avHeadsetAvStreamStop(&app,TRUE);
                                
                                playButtonTone = TRUE;
                                break;
                
                            case headsetIncomingCallEstablish:
                                if (app.profile_connected == hfp_handsfree_profile)
                                    hfpHeadsetAnswerCall(&app);
                                else
                                    /* Send an HSP button press */
                                    HfpSendHsButtonPress(app.hsp);

                                playButtonTone = TRUE;
                                break;

                            case headsetOutgoingCallEstablish:
                                if (app.profile_connected == hfp_handsfree_profile)
                                    hfpHeadsetHangUpCall(&app);
                                else
                                    /* Send an HSP button press */
                                    HfpSendHsButtonPress(app.hsp);

                                playButtonTone = TRUE;
                                break;

                            case headsetActiveCall:
                                if (app.profile_connected == hfp_handsfree_profile)
                                    hfpHeadsetHangUpCall(&app);
                                else
                                    /* Send an HSP button press */
                                    HfpSendHsButtonPress(app.hsp);

                                playButtonTone = TRUE;
                                break;

                            case headsetInitialising:
                            default:
                                unhandledHfpState(current_hfp_state, id);
                        }
                        if (!playButtonTone && (current_hfp_state != headsetReady))
                            playErrorTone = TRUE;
                    }
                }
                break;

            default:
                break;
            }
            break;

        case BUTTON_MFB_LONG_HELD:
            MAIN_DEBUG(("BUTTON_MFB_LONG_HELD\n"));
            
            headsetPowerUpdateAmpOnFlag(&app);

            switch (app.headset_power_state)
            {
            case power_state_off:
            case power_state_off_charging:
                headsetPowerOn(&app);
                break;
			case power_state_powering_down:
				MessageSendLater(getAppTask(), APP_PREVENT_POWER_ON, 0, (uint32) 4000);
				break;
            case power_state_on:
            case power_state_on_charging:
         /*   case power_state_powering_down:*/
            default:
                /* 
                    We act on the button release - play tone to indicate button has been 
                    held for required time.
                */
                playButtonTone = TRUE;
                break;
            }
            break;

        case BUTTON_MFB_LONG_RELEASE:
            MAIN_DEBUG(("BUTTON_MFB_LONG_RELEASE\n"));


            switch (app.headset_power_state)
            {
            case power_state_off:
                /* Update the local state to show we're now powered on */
                headsetSetPowerState(&app, power_state_on);
                /* Check to see if page scanning should be enabled */
  				updateHeadsetScanning(&app);
                /* Auto connect to the last used devices if functionality is enabled */
                headsetConnectToLastDevices(&app);
                break;
            case power_state_off_charging:
                /* Update the local state to show we're now powered on */
                headsetSetPowerState(&app, power_state_on_charging);
                /* Check to see if page scanning should be enabled */
  				updateHeadsetScanning(&app);
                /* Auto connect to the last used devices if functionality is enabled */
                headsetConnectToLastDevices(&app);
                break;

            case power_state_on:
            case power_state_on_charging:
                if (!app.headset_connecting_hfp)
                {
                    if (isHeadsetPairing(&app))
                    {
                        playErrorTone = TRUE;
                    }
                    else
                    {
                        /* Headset not idle, must have some connection active */
                        switch(current_hfp_state)
                        {
                            case headsetReady:
                                /* If we're already streaming music pause it. */
                                if (app.a2dp_state == avHeadsetA2dpStreaming)
                                {
                                    avHeadsetAvStreamStop(&app, TRUE);
                                    (void) MessageCancelAll(getAppTask(), APP_MUSIC_RESTART_IND);
                                }

                                /* Headset is idle initiate Last number redial */
                                app.headset_connecting_hfp = 1;
                        
                                /* Requeue the message so we can act on it on SLC connect */
                                MessageSendConditionally(&app.task, BUTTON_MFB_LONG_RELEASE, 0, &app.headset_connecting_hfp);
                        
                                /* Initiate the HFP SLC */
                                hfpHeadsetHandleSlcConnectRequest(&app, hfp_handsfree_profile);
                                break;

                            case headsetConnecting:
                                break;

                            case headsetConnected:
                                if (app.profile_connected == hfp_handsfree_profile) 
                                {
                                    hfpHeadsetLastNumberRedial(&app);
                                }
                                else
                                {
                                    playErrorTone = TRUE;
                                }
                                break;
                
    

⌨️ 快捷键说明

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