?? headset_common.c
字號:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.6.2-release
FILE NAME
headset_common.c
DESCRIPTION
Deals with general headset functionality.
NOTES
*/
/****************************************************************************
Header files
*/
#include "headset_private.h"
#include "a2dp_handler.h"
#include "headset_common.h"
#include "headset_power.h"
#include "headset_volume.h"
#include "hfp_slc.h"
#include "leds.h"
#include <bdaddr.h>
#include <connection.h>
#include <hfp.h>
#include <kalimba.h>
#include <ps.h>
#ifdef DEBUG_COMMON
#define COMMON_DEBUG(x) DEBUG(x)
#else
#define COMMON_DEBUG(x)
#endif
#define SCAN_INTERVAL_NORMAL (0x800)
#define SCAN_WINDOW_NORMAL (0x12)
#define SCAN_INTERVAL_PAIRING (0x400)
#define SCAN_WINDOW_PAIRING (0x200)
/*define local functions*/
static void indicateConnected(headsetTaskData *app);
static void indicateIdle(headsetTaskData *app);
static void indicateOff(headsetTaskData *app);
/*****************************************************************************/
void updateHeadsetScanning(headsetTaskData *app)
{
hci_scan_enable scan = hci_scan_enable_off;
if ((app->a2dp_state >= avHeadsetA2dpSignallingActive) &&
(app->hfp_state >= headsetConnected))
{
COMMON_DEBUG(("COMMON: both active\n"));
/* If AV and HFP connected disable all scanning */
scan = hci_scan_enable_off;
}
else if ((app->a2dp_state >= avHeadsetA2dpSignallingActive))
{
/* If only one profile connected disable inquiry scan */
COMMON_DEBUG(("COMMON: av active\n"));
scan = hci_scan_enable_page;
}
else if ((app->hfp_state >= headsetConnected))
{
scan = hci_scan_enable_inq_and_page;
}
else
{
COMMON_DEBUG(("COMMON: hf idle, initialising or connecting\n"));
/* Enable both page and inquiry scan */
scan = hci_scan_enable_inq_and_page;
}
/*Disable all scanning if the headset is off*/
if ((app->headset_power_state != power_state_on) && (app->headset_power_state != power_state_on_charging))
{
scan = hci_scan_enable_off;
}
COMMON_DEBUG(("COMMON: scan = %d\n",scan));
/*As the state has changed, we need to indicate this*/
headsetIndicateState(app);
if ((app->a2dp_state != avHeadsetA2dpInitialising) &&
(app->avrcp_state != avHeadsetAvrcpInitialising) &&
(app->hfp_state != headsetInitialising))
{
/* If headset is initialising don't attempt to enter any scan mode */
ConnectionWriteScanEnable(scan);
COMMON_DEBUG(("COMMON: Write scan enable\n"));
}
}
/**************************************************************************/
void setA2dpState(headsetTaskData *app, const headsetA2dpState state)
{
COMMON_DEBUG(("COMMON: AV Headset A2DP State - C=%d N=%d\n", app->a2dp_state, state));
app->a2dp_state = state;
/* Check if we should be setting the idle timer running */
headsetPowerCheckAutoOff(app);
/* Check to see if we need to update out page/ inquiry scan settings */
updateHeadsetScanning(app);
}
/**************************************************************************/
void setAvrcpState(headsetTaskData *app, const headsetAvrcpState state)
{
COMMON_DEBUG(("COMMON: AV Headset AVRCP State - C=%d N=%d\n", app->avrcp_state, state));
app->avrcp_state = state;
/* Check to see if we need to update out page/ inquiry scan settings */
updateHeadsetScanning(app);
}
/**************************************************************************/
void setHfpState(headsetTaskData *app, const headsetHfpState state)
{
COMMON_DEBUG(("COMMON: AV Headset HFP State - C=%d N=%d\n", app->hfp_state, state));
app->hfp_state = state;
/* Check if we should be setting the idle timer running */
headsetPowerCheckAutoOff(app);
/* Check to see if we need to update out page/ inquiry scan settings */
updateHeadsetScanning(app);
}
/*****************************************************************************/
void headsetHandleRemoteSuppFeatures(headsetTaskData *app, const CL_DM_REMOTE_FEATURES_CFM_T *cfm)
{
/*
If the read request succeeded then store the first work of the supported features
We should in theory store all four words but currently we only need the info in
the first word so for the sake of efficiency for the moment only store that.
*/
if (cfm->status == hci_success)
app->supp_features_0 = cfm->features[0];
}
/*****************************************************************************/
bool isHeadsetIdle(const headsetTaskData *app)
{
if ((app->a2dp_state == avHeadsetA2dpReady) &&
(app->avrcp_state == avHeadsetAvrcpReady) &&
(app->hfp_state == headsetReady))
return TRUE;
else
return FALSE;
}
/*****************************************************************************/
bool isHeadsetPairing(const headsetTaskData *app)
{
return app->pairing_enabled;
}
/*****************************************************************************/
void headsetConnectToLastDevices(headsetTaskData *app)
{
if (app->features.auto_reconnect == 1)
{
app->connect_av = 1;
COMMON_DEBUG(("COMMON: Connect to last devices\n"));
hfpHeadsetHandleSlcConnectRequest(app, hfp_handsfree_profile);
}
}
/*****************************************************************************/
void headsetRestartAV(headsetTaskData *app)
{
(void) MessageCancelAll(&app->task, APP_MUSIC_RESTART_IND);
MessageSendLater(&app->task, APP_MUSIC_RESTART_IND, 0, (uint32) MUSIC_RESTART_DELAY);
}
/*****************************************************************************/
bool headsetIsA2dpSourceAnAg(headsetTaskData *app)
{
bdaddr bdaddr_sig, bdaddr_slc;
if (!SinkGetBdAddr(app->sig_sink, &bdaddr_sig))
return FALSE;
if (!SinkGetBdAddr(app->slc_sink, &bdaddr_slc))
return FALSE;
if (BdaddrIsSame(&bdaddr_sig, &bdaddr_slc))
return TRUE;
return FALSE;
}
/******************************************************************************/
void headsetIndicateState(headsetTaskData *app)
{
if ((app->headset_power_state != power_state_on)
&& (app->headset_power_state != power_state_on_charging))
{
indicateOff(app);
}
else if ((app->hfp_state >= headsetConnected) || (app->a2dp_state >= avHeadsetA2dpSignallingActive))
{
if (!app->pairing_enabled)
indicateConnected(app);
}
else /*headset must be idle*/
{
if (!app->pairing_enabled)
indicateIdle(app);
}
}
/*****************************************************************************/
static void indicateIdle(headsetTaskData *app)
{
if ((app->charger_connected) && (app->battery_full))
{
ledsPlay(RED_CONT_BLUE_SHORT_ON_RPT) ;
}
else if (app->charger_connected)
{
ledsPlay(RED_BLUE_SHORT_ON_RPT) ;
}
else
{
ledsPlay(BLUE_SHORT_ON_RPT) ;
}
}
/*****************************************************************************/
static void indicateConnected(headsetTaskData *app)
{
if ((app->charger_connected) && (app->battery_full))
{
ledsPlay(RED_CONT_BLUE_ONE_SEC_ON_RPT) ;
}
else if (app->charger_connected)
{
ledsPlay(RED_BLUE_ONE_SEC_ON_RPT) ;
}
else
{
ledsPlay(BLUE_ONE_SEC_ON_RPT) ;
}
}
/*****************************************************************************/
static void indicateOff(headsetTaskData *app)
{
if ((app->charger_connected) && (app->battery_full))
{
ledsPlay(RED_ON);
}
else if (app->charger_connected)
{
ledsPlay(RED_ONE_SEC_ON_RPT) ;
}
else
{
ledsPlay(LEDS_OFF) ;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -