📄 headset_button_handler.c
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.6.2-release
FILE NAME
headset_button_handler.c
DESCRIPTION
handles all heasdet button presses
*/
/****************************************************************************
Header files
*/
#include "headset_private.h"
#include "headset_button_handler.h"
#include "headset_volume.h"
#include "headset_tones.h"
#include "headset_power.h"
#include "headset_common.h"
#include "hfp_slc.h"
#include "hfp_audio.h"
#include "a2dp_handler.h"
#include "headset_security.h"
#include "hfp_handler.h"
#include "avrcp_handler.h"
#include "av_stream_control.h"
#include "leds.h"
#include <connection.h>
#include <hfp.h>
#include <panic.h>
#include <ps.h>
#include <stdlib.h>
/****************************************************************************
*/
void button_handle_vol_up( headsetTaskData *app )
{
if (app->active_profile == av_active)
{
if (app->a2dp_state != avHeadsetA2dpInitialising )
{
headsetHandleAvVolUp(app);
}
}
else if ((app->active_profile == hfp_active) && !app->headset_connecting_hfp)
{
switch(app->hfp_state)
{
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);
}
break;
default:
break ;
}
}
}
/****************************************************************************
*/
void button_handle_vol_down( headsetTaskData *app )
{
if (app->active_profile == av_active)
{
if ( app->a2dp_state != avHeadsetA2dpInitialising )
{
headsetHandleAvVolDown(app);
}
}
else if ((app->active_profile == hfp_active) && !app->headset_connecting_hfp)
{
switch( app->hfp_state )
{
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;
default:
break ;
}
}
}
/****************************************************************************
*/
void button_handle_forward_release ( headsetTaskData *app )
{
switch (app->headset_power_state)
{
case power_state_on:
case power_state_on_charging:
{
if (app->avrcp_state == avHeadsetAvrcpConnected)
{
avHeadsetForwardPress(app);
avHeadsetForwardRelease(app);
headsetPlayTone(app, tone_type_button_press);
}
}
break;
default:
break;
}
}
/****************************************************************************
*/
void button_handle_forward_long( headsetTaskData *app )
{
switch (app->headset_power_state)
{
case power_state_on:
case power_state_on_charging:
{
if ( app->avrcp_state == avHeadsetAvrcpConnected)
{
avHeadsetFastForwardPress(app);
headsetPlayTone(app, tone_type_button_press);
}
}
break;
default:
break;
}
}
/****************************************************************************
*/
void button_handle_forward_long_release( headsetTaskData *app )
{
switch (app->headset_power_state)
{
case power_state_on:
case power_state_on_charging:
{
if (app->avrcp_state == avHeadsetAvrcpConnected)
{
avHeadsetFastForwardRelease(app);
}
}
break;
default:
break;
}
}
/****************************************************************************
*/
void button_handle_backward_release( headsetTaskData *app )
{
if (app->active_profile == av_active)
{
if ( app->avrcp_state == avHeadsetAvrcpConnected )
{
avHeadsetBackwardPress(app);
avHeadsetBackwardRelease(app);
headsetPlayTone(app, tone_type_button_press);
}
}
}
/****************************************************************************
*/
void button_handle_backward_long( headsetTaskData *app )
{
switch (app->headset_power_state)
{
case power_state_on:
case power_state_on_charging:
{
if (app->avrcp_state == avHeadsetAvrcpConnected)
{
avHeadsetFastRewindPress(app);
headsetPlayTone(app, tone_type_button_press);
}
}
break;
default:
break ;
}
}
/****************************************************************************
*/
void button_handle_backward_long_release( headsetTaskData *app )
{
switch (app->headset_power_state)
{
case power_state_on:
case power_state_on_charging:
{
if (app->avrcp_state == avHeadsetAvrcpConnected)
{
avHeadsetFastRewindRelease(app);
}
}
break;
default:
break;
}
}
/****************************************************************************
*/
void button_handle_mfb_press( headsetTaskData *app )
{
headsetPowerAmp(app , TRUE);
}
/****************************************************************************
*/
void button_handle_mfb_short( headsetTaskData *app )
{
bool playErrorTone = FALSE ;
bool playButtonTone = FALSE;
headsetHfpState current_hfp_state = app->hfp_state;
switch (app->headset_power_state)
{
case power_state_off:
case power_state_off_charging:
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:
{
playButtonTone = TRUE;
/* If we're already streaming music pause it. */
if (app->a2dp_state == avHeadsetA2dpStreaming)
{
avHeadsetAvStreamStop(app, TRUE);
(void) MessageCancelAll(getAppTask(), APP_MUSIC_RESTART_IND);
MessageSendLater(getAppTask(), APP_MUSIC_RESTART_IND, 0, (uint32) 10000);
}
/* 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, APP_VOICE_DIAL, 0, &app->headset_connecting_hfp);
/* Initiate the HFP SLC */
hfpHeadsetHandleSlcConnectRequest(app, hfp_handsfree_profile);
}
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) */
MessageSendLater(getAppTask(), APP_VOICE_DIAL, 0, 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:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -