📄 piohshf_send.c
字号:
#include "piohshf_private.h"
#include "handsfree.h"
#include "handsfree_types.h"
#include <audio.h>
#include <message.h>
#include <print.h>
static const audio_note pair_hs_beep[] =
{
AUDIO_TEMPO(80), AUDIO_VOLUME(32), AUDIO_TIMBRE(sine),
AUDIO_NOTE(F5, QUAVER),
AUDIO_NOTE(F5, QUAVER),
AUDIO_END
};
static const audio_note pair_hf_beep[] =
{
AUDIO_TEMPO(80), AUDIO_VOLUME(32), AUDIO_TIMBRE(sine),
AUDIO_NOTE(C5, QUAVER),
AUDIO_NOTE(C5, QUAVER),
AUDIO_END
};
static const audio_note pair_hshf_beep[] =
{
AUDIO_TEMPO(80), AUDIO_VOLUME(32), AUDIO_TIMBRE(sine),
AUDIO_NOTE(C5, QUAVER),
AUDIO_NOTE(F5, QUAVER),
AUDIO_END
};
/*
pioHsHfPairButton
Send a pair request to the core app
*/
void pioHsHfPairButton(void)
{
framework_role_t pair_role = frameworkRoleUnset;
/* set the pairing timeout */
timeout_t timeout = PIOHSHF_PAIR_TIMEOUT;
/* Check the current role and take appropriate action */
if (HFstate.connectState == pairing)
{
if (HFstate.applicationRole == (frameworkHeadset | frameworkHandsFree))
{
/* Go into pairing as headset mode. */
pair_role = frameworkHeadset;
}
else if (HFstate.applicationRole == frameworkHeadset)
{
/* Go into pairing as hands free mode. */
pair_role = frameworkHandsFree;
}
else if (HFstate.applicationRole == frameworkHandsFree)
{
/* set timeout to zero because we want to cancel pairing */
timeout = 0;
/* Set role to unset because we want to cancel pairing */
pair_role = frameworkRoleUnset;
}
else
{
PRINT(("pair req error %d\n", HFstate.applicationRole));
}
}
else if (HFstate.connectState == connectingAsSlave ||
HFstate.connectState == connectingAsMaster)
{
pair_role = (frameworkHeadset | frameworkHandsFree);
}
else
{
/* Cancel pairing */
timeout = 0;
pair_role = frameworkRoleUnset;
/* Signal an error */
handleErrorInd(HfErrorPairRequestWhenNotIdle);
}
/* Update the current role to that used in pairing */
HFstate.applicationRole = pair_role;
/* Passing in the role lets us choose between pairing as hs, hf or both */
pairReqAction(timeout, pair_role);
/* Play a beep to indicate which role we're pairing as */
if (pair_role == frameworkHeadset)
(void) AudioPlay(pair_hs_beep);
else if (pair_role == frameworkHandsFree)
(void) AudioPlay(pair_hf_beep);
else if (pair_role == (frameworkHeadset | frameworkHandsFree))
(void) AudioPlay(pair_hshf_beep);
}
/*
pioHshfCallAcceptButton
Answer a call or initiate a call to the AG
*/
void pioHshfCallAcceptButton(void)
{
/* Action taken depends on the current state of the Hedaset/ hands free app */
if (HFstate.connectState == connectingAsSlave)
{
/*
If we end up as a headset device send a button press otherwise
assume user wants to do voice dialling (if supported by the AG).
*/
hshfState.hshfButtonPressPending = 1;
connectReqAction();
}
else if (HFstate.connectState == connectingAsMaster)
{
/* reset the button flag */
hshfState.hshfButtonPressPending = 0;
/* Cancel the current state and return to connect as slave */
cancelCurrentStateAction();
}
else if (isLocalStateConnected())
{
/* Check if the app is a hands free device or headset */
if (HFstate.applicationRole == frameworkHandsFree)
{
/*
If there's an active call and we have no SCO it must be
in the AG so request to transfer it to the HF. Otherwise
initiate voice dialling.
*/
if (HFstate.ringing || (HFstate.hfCallSetup==1))
{
callAnswerAction();
}
else if (HFstate.hfCallActive)
{
callTransferReqAction(0x80);
}
else
{
startVoiceDialAction(1);
}
}
else
{
/* Send a button press */
pioHshfSendButtonPress();
/* Reset the ringing flag */
HFstate.ringing = 0;
}
}
}
/*
pioHshfCallRejectButton
Reject a call or terminate an sxisting call
*/
void pioHshfCallRejectButton(void)
{
/* Action taken depends on the current state of the Hedaset/ hands free app */
if (HFstate.connectState == connectingAsMaster)
{
/* Cancel the current state and return to connect as slave */
cancelCurrentStateAction();
}
else if (isLocalStateConnected())
{
/* If ringing, reject the call */
if (HFstate.applicationRole == frameworkHandsFree)
{
if (HFstate.ringing || HFstate.hfCallSetup ||
HFstate.hfCallActive || (HFstate.connectState == scoConnected))
{
PRINT(("Call reject action\n"));
callRejectAction();
/* Unmute the mic, call will be disconnected */
if (HFstate.microphoneMute)
hfToggleMuteMicAction();
}
else if (HFstate.hfCallActive ||(HFstate.connectState == scoConnected))
{
PRINT(("Call reject action(SCO)\n"));
disconnectReqAction(ScoLink);
}
else
{
PRINT(("Call reject action(RFComm)\n"));
disconnectReqAction(RfcommLink);
}
}
}
}
/*
pioHshfVolumeDownButton
Volume down button pressed
*/
void pioHshfVolumeDownButton(void)
{
volumeReqAction(-1, 0);
}
/*
pioHshfVolumeUpButton
Volume up button pressed.
*/
void pioHshfVolumeUpButton(void)
{
volumeReqAction(1, 0);
}
/*
pioHshfSendButtonPress
Send a button press if in headset mode
*/
void pioHshfSendButtonPress(void)
{
MAKE_MSG(HS_BUTTON_REQ) ;
putMsg(msg);
hshfState.hshfButtonPressPending = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -