📄 headset_power.c
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.6.2-release
FILE NAME
headset_power.c
DESCRIPTION
Deals with powering the headset.
*/
/****************************************************************************
Header files
*/
#include "headset_private.h"
#include "av_stream_control.h"
#include "headset_common.h"
#include "leds.h"
#include "headset_tones.h"
#include "headset_power.h"
#include "hfp_slc.h"
#include <stdlib.h>
#include <string.h>
#include <panic.h>
#include <pio.h>
#include <codec.h>
#include <ps.h>
#ifdef DEBUG_POWER
#define POWER_DEBUG(x) DEBUG(x)
#else
#define POWER_DEBUG(x)
#endif
/**************************************************************************/
void headsetSetPowerState(headsetTaskData *app, power_state state)
{
/* {
power_state_off,
power_state_off_charging,
power_state_on,
power_state_on_charging
}power_state */
POWER_DEBUG(("POWER: Set power state old = %d new = %d\n",app->headset_power_state, state));
app->headset_power_state = state;
}
/**************************************************************************/
void headsetPowerOn(headsetTaskData *app)
{
#ifdef SOFT_POWER
/* Hold power on */
PioSetDir(POWER_HOLD, POWER_HOLD);
PioSet (POWER_HOLD, POWER_HOLD);
#endif
MessageCancelAll(&app->task, APP_POWER_ON_EVENT_SEEN) ;
POWER_DEBUG(("POWER: ***ON***\n")) ;
/*Indicate the Power on event*/
ledsPlay( BLUE_TWO_FLASHES ) ;
headsetPlayTone(app, tone_type_power_on);
/* Call the function that will enable page scanning*/
updateHeadsetScanning(app);
}
/**************************************************************************/
void headsetPowerOff ( headsetTaskData *app )
{
POWER_DEBUG(("POWER: PowerOff\n")) ;
if (app->headset_power_state == power_state_off )
{
/*then physically power down the device*/
POWER_DEBUG(("POWER: ***OFF***\n")) ;
/* Power down the codec */
CodecPowerDown(app->codec_task);
/* Store the current volume */
(void) PsStore(VOLUME_LEVEL, &app->speaker_volume, sizeof(app->speaker_volume));
/* Cancel messages we may have queued */
MessageCancelAll(getAppTask(), APP_MUSIC_RESTART_IND);
MessageCancelAll(getAppTask(), APP_HFP_SLC_REQ);
MessageCancelAll(getAppTask(), APP_HFP_SLC_TIMEOUT_IND);
MessageCancelAll(getAppTask(), APP_AUTO_SWITCH_OFF_IND);
MessageCancelAll(getAppTask(), APP_PAIR_MODE_END_IND);
/* Call the function that will disable page scanning*/
updateHeadsetScanning(app);
/* Finally turn off audio supply if it's still active */
headsetPowerAmp(app, FALSE);
#ifdef SOFT_POWER
if (!app->charger_connected)
PioSet(POWER_HOLD,0);
#endif
}
else /*close any active links and schedule the power down again for later*/
{
POWER_DEBUG(("POWER: Schedule OFF\n")) ;
headsetSetPowerState ( app , power_state_off ) ;
/*indicate the power off event*/
ledsPlay( BLUE_TWO_FLASHES ) ;
ledsPlay(LEDS_OFF) ;
headsetPlayTone(app, tone_type_power_off);
/* Close down any active AV link */
if ( (app->a2dp_state == avHeadsetA2dpConnected) ||
(app->a2dp_state == avHeadsetA2dpStreaming) ||
(app->a2dp_state == avHeadsetA2dpSignallingActive))
{
A2dpCloseAll(app->a2dp);
}
/* Close down any active AVRCP link */
if (app->avrcp_state == avHeadsetAvrcpConnected)
{
AvrcpDisconnect(app->avrcp);
}
/* Close down any active AG link */
if ( (app->hfp_state != headsetInitialising) &&
(app->hfp_state != headsetReady))
{
hfpHeadsetDisconnectSlc(app);
}
MessageCancelAll(getAppTask(), APP_POWER_OFF_IND );
MessageSendLater(getAppTask(), APP_POWER_OFF_IND, 0, (uint32) 5000);
}
}
/**************************************************************************/
void headsetPowerAmp(headsetTaskData *app, bool enable)
{
if (enable)
{
SET_AMP(AUDIO_AMP_LINE);
MessageCancelAll ( getAppTask() , APP_AMP_IDLE_IND ) ;
MessageSendLater(getAppTask(), APP_AMP_IDLE_IND, 0, AMP_IDLE_TIMER);
}
else
{
SET_AMP(0);
MessageCancelAll ( getAppTask() , APP_AMP_IDLE_IND ) ;
}
}
/**************************************************************************/
void headsetPowerCheckAutoOff(const headsetTaskData *app)
{
if (app->features.auto_switch_off_enabled &&
(app->features.auto_switch_off_timeout != 0) &&
((app->headset_power_state == power_state_on) || (app->headset_power_state == power_state_on_charging)))
{
POWER_DEBUG(("POWER: Cancel auto power off\n"));
MessageCancelAll(getAppTask(), APP_AUTO_SWITCH_OFF_IND);
if ((app->hfp_state == headsetReady) && (app->a2dp_state == avHeadsetA2dpReady))
{
POWER_DEBUG(("POWER: Auto power off in %d secs\n",app->features.auto_switch_off_timeout));
MessageSendLater(getAppTask(), APP_AUTO_SWITCH_OFF_IND, 0, D_SEC(app->features.auto_switch_off_timeout));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -