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

📄 main.c

📁 针对bluelab3.42的handsfree车载蓝牙的参考
💻 C
📖 第 1 页 / 共 5 页
字号:
			else
			{
				MessageSendLater(getAppTask(), APP_LED_OFF_PANIC, 0, 0); 				
			}
			break;
            
		case APP_PAIR_RESET_LED_UPDATE_IND:
			m = (APP_ON_EVENT_LED_UPDATE_IND_T *) message;
			MAIN_DEBUG(("APP_PAIR_RESET_LED_UPDATE_IND\n"));
			MAIN_DEBUG(("PAIR_LIST_RESET count %x\n",m->count));
			if ((m->count)<8)
			{
				app.led_state = updateBlueLedOnEvent(&app, app.led_state, m); 
			}
			else
			{
				app.led_state &= ~LED_DEL_PAIRED_LIST;
				MessageSend(getAppTask(), APP_LED_UPDATE_IND, 0);
			}
			break;
            
        case APP_BATTERY_DEAD_IND:
            MAIN_DEBUG(("APP_BATTERY_DEAD_IND\n"));
            if ((app.headset_power_state == power_state_on_charging) || (app.headset_power_state == power_state_on))
            {
                playPowerOffTone(&app);
                headsetStartPowerDown(&app);
            }
            break;
            
        case APP_BATTERY_LOW_IND:
            MAIN_DEBUG(("APP_BATTERY_LOW_IND\n"));
            app.led_state |= LED_BATTERY_LOW;
            if ((app.headset_power_state == power_state_on_charging) || (app.headset_power_state == power_state_on))
                playBatteryLowTone(&app);
            break;
        
        case APP_BATTERY_LOW_END_IND:
            MAIN_DEBUG(("APP_BATTERY_LOW_CANCEL_IND\n"));
            app.led_state &= ~LED_BATTERY_LOW;
            break;
            
        case APP_BATTERY_FULL_IND:
            MAIN_DEBUG(("APP_BATTERY_FULL_IND\n"));
            /* TODO - Correct LED indication, only show battery full indication
                      if charger plugged in. */
            if ((app.headset_power_state == power_state_off_charging)||
                (app.headset_power_state == power_state_on_charging))
            {
                app.led_state &= ~LED_CHARGING;
				app.led_state |= LED_BATTERY_FULL;
				PioSet(LED_RED, LED_RED);
            }
            break;
            
        case APP_LED_UPDATE_IND:
			/*MAIN_DEBUG(("APP_LED_UPDATE_IND %x \n", app.led_state));*/
			if ((app.led_state & LED_DEL_PAIRED_LIST)!=LED_DEL_PAIRED_LIST)
				app.led_state = updateLed(&app, app.led_state); 
			else
				PioSet(LED_BLUE, 0);
			break;

        case APP_RED_LED_UPDATE_IND:
			if ((app.headset_power_state != power_state_powering_down) | (app.led_state & LED_CHARGING))
            	app.led_state = updateRedLed(&app, app.led_state);
			else
			{
				MAIN_DEBUG(("RED_LED_OFF \n"));	
				PioSet(LED_RED, 0);
			}
            break;

        case APP_MUSIC_RESTART_IND:
            MAIN_DEBUG(("APP_MUSIC_RESTART_IND\n"));
            if (app.a2dp_state != avHeadsetA2dpStreaming)
            {
                MAIN_DEBUG(("Av not streaming\n"));
                if(app.sent_suspend && app.av_stream_stopped)
                    avHeadsetAvStreamStart(&app);
            }
            else
            {
                avHeadsetAvStreamStart(&app);
            }
            break;
            
        case APP_CHARGER_CONNECTED_IND:
            MAIN_DEBUG(("APP_CHARGER_CONNECTED_IND\n"));
            switch (app.headset_power_state)
            {
            case power_state_off:
                headsetSetPowerState(&app, power_state_off_charging);
                startRedLed();	
				break;

            case power_state_on:
                headsetSetPowerState(&app, power_state_on_charging);
                break;

            /* Ignore the message in these states */
            case power_state_off_charging:
            case power_state_on_charging:
            case power_state_powering_down:   
                break;
            }
            break;
            
        case APP_CHARGER_DISCONNECTED_IND:
            MAIN_DEBUG(("APP_CHARGER_DISCONNECTED_IND\n"));
            switch (app.headset_power_state)
            {
            case power_state_off_charging:
                headsetSetPowerState(&app, power_state_off);
                app.led_state &= ~LED_BATTERY_FULL;
                headsetStartPowerDown(&app);
                break;

            case power_state_on_charging:
                headsetSetPowerState(&app, power_state_on);
				app.led_state &= ~LED_BATTERY_FULL;
				PioSet(LED_RED, 0);
                break;

            /* Ignore the message in these states */
            case power_state_off:
            case power_state_on:
            case power_state_powering_down:   
                break;
            }
            break;
            
        case APP_DISCONNECT_HFP_SLC_IND:
            MAIN_DEBUG(("APP_DISCONNECT_HFP_SLC_IND\n"));
            /* The remote end disabled encryption so close down the SLC */
            hfpHeadsetDisconnectSlc(&app);
            break;
            
        case APP_HFP_SLC_REQ:
            MAIN_DEBUG(("APP_HFP_SLC_REQ\n"));
            switch(current_hfp_state)
            {           
            case headsetReady:
                hfpHeadsetHandleSlcConnectRequest(&app, hfp_handsfree_profile);
                break;
                
            case headsetConnecting:
                app.headset_connecting_hfp = 1;
                break;
                
            case headsetConnected:
            case headsetIncomingCallEstablish:
            case headsetActiveCall:
            case headsetOutgoingCallEstablish:
            case headsetInitialising:
            default:
                app.headset_connecting_hfp = 0;
            }    
            break;
            
        case APP_HFP_SLC_TIMEOUT_IND:
            MAIN_DEBUG(("APP_HFP_SLC_TIMEOUT_IND\n"));
            switch(current_hfp_state)
            {           
                case headsetConnecting:  
                    /* Now connect timeout has occured, don't try another reconnect attempt */
                    app.headset_connecting_hfp = 1;
                    break;   
                    
                case headsetReady:
                case headsetConnected:
                case headsetIncomingCallEstablish:
                case headsetActiveCall:
                case headsetOutgoingCallEstablish:
                case headsetInitialising:
                default:
                    app.headset_connecting_hfp = 0;
            }    
            break;
            
        case APP_PAIR_MODE_END_IND:
            MAIN_DEBUG(("APP_PAIR_MODE_END_IND\n"));
            
            /* PAiring mode has timed out */
            headsetExitPairingMode(&app);    
            headsetPowerCheckAutoOff(&app);
            break;
        
        case APP_POWER_OFF_IND:
            MAIN_DEBUG(("APP_POWER_OFF_IND\n"));
            headsetPowerDown(&app);
			app.led_state |=LED_POWER_DOWN;
			if (isHeadsetPairing(&app))
				MessageSend(getAppTask(), APP_PAIR_MODE_END_IND, 0);
            break;
			
		case APP_INIT_END:
			MAIN_DEBUG(("APP_INIT_END_IND\n"));
			app.led_state &= ~LED_INIT;
            headsetPowerCheckAutoOff(&app);
			break;

		case APP_LED_OFF_PANIC:
			MAIN_DEBUG(("APP_LED_OFF_PANIC\n"));
			headsetPowerDownLEDs(&app);
			break;

		case APP_POWER_CHARGING_OFF:
            MAIN_DEBUG(("APP_POWER_CHARGING_OFF\n"));
			headsetSetPowerState(&app, power_state_off_charging);
			break;

		case APP_POWER_OFF:
            MAIN_DEBUG(("APP_POWER_OFF\n"));
			headsetSetPowerState(&app, power_state_off);
			break;
            
        case APP_AUTO_SWITCH_OFF_IND:
            MAIN_DEBUG(("APP_AUTO_SWITCH_OFF_IND\n"));
            headsetStartPowerDown(&app);   
            playPowerOffTone(&app);
            break;
            
        case APP_AMP_IDLE_IND:
            MAIN_DEBUG(("APP_AMP_IDLE_IND\n"));
            headsetPowerAmp(&app, FALSE);
            break;
			
		case APP_POWER_ON_EVENT_SEEN:
			MAIN_DEBUG(("APP_CHECK_POWER_ON_EVENT_SEEN\n"));
			if (app.headset_power_state == power_state_off)
			{
			    /*
                    If there has been no power on event and the headset is not 
			        charging switch off
                */
				headsetStartPowerDown(&app);
			}
			break;
		case APP_UNMUTE_MIC:
			MAIN_DEBUG(("APP_UNMUTE_MIC\n"));
			headsetVolumeCompleteUnmuteMicrophone(&app);
			break;
			
		case APP_MUTE_REMINDER:
			MAIN_DEBUG(("APP_MUTE_REMINDER\n"));
            if (app.hfp_state == headsetActiveCall)
            {
			    playMuteRemindTone(&app);
			    VolumeMuteRemind(&app);
            }
			break;	
            
		case APP_PREVENT_POWER_ON:
			MAIN_DEBUG(("APP_PREVENT_POWER_ON\n"));
			break;
            
        case APP_A2DP_CLOSE_TIMER:
            MAIN_DEBUG(("APP_A2DP_CLOSE_TIMER\n"));
            break;
            
        case APP_VOICE_DIAL:
            MAIN_DEBUG(("APP_VOICE_DIAL\n"));
			voice_recog = (APP_VOICE_DIAL_T *) message;
            if (((app.headset_power_state == power_state_on) ||
                (app.headset_power_state == power_state_on_charging)) &&
                (current_hfp_state == headsetConnected))
            {
				app.voice.voice_recognition_enabled = voice_recog->voice_recog_enabled;
                if (app.profile_connected == hfp_handsfree_profile) 
                {
                    hfpHeadsetVoiceRecognitionEnable(&app, app.voice.voice_recognition_enabled);
                }
                else
                    /* Send an HSP button press */
                    HfpSendHsButtonPress(app.hsp);
					
            } 
			else
            {
				app.voice.voice_recognition_enabled = app.voice.old_voice_recognition_enabled;
                headsetRestartAV(&app);
            }
            break;
            
        case APP_RING_TIMEOUT_IND:
            MAIN_DEBUG(("APP_RING_TIMEOUT_IND\n"));
            if ((app.profile_connected == hfp_headset_profile) && 
                !app.sco_sink &&
                (app.hfp_state == headsetIncomingCallEstablish))
            {
                headsetRestartAV(&app);
            }
            break;
            
        case APP_TONE_TO_PLAY_IND:
            MAIN_DEBUG(("APP_TONE_TO_PLAY_IND\n"));
            headsetPlayTone(&app, ((APP_TONE_TO_PLAY_IND_T *)message)->id);
            break;

        case BUTTON_VOL_UP:
            MAIN_DEBUG(("BUTTON_VOL_UP\n"));
            if (app.active_profile == av_active)
            {
                switch(current_a2dp_state)
                {
                    case avHeadsetA2dpReady:
                    case avHeadsetA2dpConnected:
                    case avHeadsetA2dpStreaming:
                    case avHeadsetA2dpInitiating:
                        headsetHandleAvVolUp(&app);
                        break;
                    
                    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 up request */
                        headsetHandleHfVolUp(&app);

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

                case headsetInitialising:
                default:
                    unhandledHfpState(current_hfp_state, id);
                }
            }
            break;
            
        case BUTTON_VOL_DOWN:
            MAIN_DEBUG(("BUTTON_VOL_DOWN\n"));
            if (app.active_profile == av_active)
            {
                switch(current_a2dp_state)
                {
                    case avHeadsetA2dpReady:
                    case avHeadsetA2dpConnected:
                    case avHeadsetA2dpStreaming:
                    case avHeadsetA2dpInitiating:
                        headsetHandleAvVolDown(&app);
                        break;
                    

⌨️ 快捷键说明

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