📄 avrcp_handler.c
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.4.2-release
FILE NAME
avrcp_handler.c
DESCRIPTION
Deals with AVRCP connection.
NOTES
*/
/****************************************************************************
Header files
*/
#include "headset_private.h"
#include "avrcp_handler.h"
#include "headset_common.h"
#include "headset_power.h"
#include <stdlib.h>
#ifdef DEBUG_AVRCP
#define AVRCP_DEBUG(x) DEBUG(x)
#else
#define AVRCP_DEBUG(x)
#endif
enum
{
PAUSE_PRESS,
PAUSE_RELEASE,
PLAY_PRESS,
PLAY_RELEASE,
FORWARD_PRESS,
FORWARD_RELEASE,
BACKWARD_PRESS,
BACKWARD_RELEASE,
STOP_PRESS,
STOP_RELEASE
};
/*
Send remote control command to remote device
*/
static void sendAVRCP(headsetTaskData* app, avc_operation_id op_id, uint8 state)
{
app->avrcp_pending = TRUE;
/* Send a key press */
AvrcpPassthrough(app->avrcp, subunit_panel, 0, state, op_id, 0, 0);
}
/**************************************************************************/
void controls_handler(Task task, MessageId id, Message message)
{
task = task;
message = message;
switch (id)
{
case PAUSE_PRESS:
AVRCP_DEBUG(("AVRCP: Sending Pause Pressed\n"));
sendAVRCP(getApp(), opid_pause, 0);
break;
case PAUSE_RELEASE:
AVRCP_DEBUG(("AVRCP: Sending Pause Released\n"));
sendAVRCP(getApp(), opid_pause, 1);
break;
case PLAY_PRESS:
AVRCP_DEBUG(("AVRCP: Sending Play Pressed\n"));
sendAVRCP(getApp(), opid_play, 0);
break;
case PLAY_RELEASE:
AVRCP_DEBUG(("AVRCP: Sending Play Released\n"));
sendAVRCP(getApp(), opid_play, 1);
break;
case FORWARD_PRESS:
AVRCP_DEBUG(("AVRCP: Sending Forward Pressed\n"));
sendAVRCP(getApp(), opid_forward, 0);
break;
case FORWARD_RELEASE:
AVRCP_DEBUG(("AVRCP: Sending Forward Released\n"));
sendAVRCP(getApp(), opid_forward, 1);
break;
case BACKWARD_PRESS:
AVRCP_DEBUG(("AVRCP: Sending Backward Pressed\n"));
sendAVRCP(getApp(), opid_backward, 0);
break;
case BACKWARD_RELEASE:
AVRCP_DEBUG(("AVRCP: Sending Backward Released\n"));
sendAVRCP(getApp(), opid_backward, 1);
break;
case STOP_PRESS:
AVRCP_DEBUG(("AVRCP: Sending Stop Pressed\n"));
sendAVRCP(getApp(), opid_stop, 0);
break;
case STOP_RELEASE:
AVRCP_DEBUG(("AVRCP: Sending Stop Released\n"));
sendAVRCP(getApp(), opid_stop, 1);
break;
default:
break;
}
}
/* Send response to the AVRCP lib */
static void sendRcpConnectResponse(AVRCP *avrcp, const AVRCP_CONNECT_IND_T *ind, bool accept)
{
/* Send the connect response */
AvrcpConnectResponse(avrcp, ind->connection_id, accept);
}
/**************************************************************************/
void avHeadsetHandleAvrcpConnectCfm(headsetTaskData *app, const AVRCP_CONNECT_CFM_T *cfm)
{
if(cfm->status == avrcp_success)
/* Change to Connected state */
setAvrcpState(app, avHeadsetAvrcpConnected);
else
/* Change to Ready state */
setAvrcpState(app, avHeadsetAvrcpReady);
}
/**************************************************************************/
void avHeadsetHandleAvrcpConnectInd(const headsetTaskData *app, const AVRCP_CONNECT_IND_T *ind)
{
sendRcpConnectResponse(app->avrcp, ind, 1);
}
/**************************************************************************/
void avHeadsetHandleAvrcpConnectIndReject(AVRCP *avrcp, const AVRCP_CONNECT_IND_T *ind)
{
sendRcpConnectResponse(avrcp, ind, 0);
}
/**************************************************************************/
void avHeadsetHandleAvrcpDisconnectInd(headsetTaskData *app)
{
/* Change to Ready state */
setAvrcpState(app, avHeadsetAvrcpReady);
/* If we're ready to power down don't wait any longer */
headsetCheckPowerDownStatus(app);
}
/**************************************************************************/
void avHeadsetHandleAvrcpPassthroughInd(const AVRCP_PASSTHROUGH_IND_T *ind)
{
/* Acknowledge the request */
AvrcpPassthroughResponse(ind->avrcp, avctp_response_not_implemented);
}
/**************************************************************************/
void avHeadetHandleAvrcpUnitInfo(const AVRCP_UNITINFO_IND_T *ind)
{
/*
We are not a target so reject UnitInfo requests
*/
AvrcpUnitInfoResponse(ind->avrcp, FALSE, subunit_monitor, 0, (uint32) 0);
}
/**************************************************************************/
void avHeadetHandleAvrcpSubUnitInfo(const AVRCP_SUBUNITINFO_IND_T *ind)
{
/*
We are not a target so reject SubUnitInfo requests
*/
AvrcpSubUnitInfoResponse(ind->avrcp, FALSE, 0);
}
/**************************************************************************/
void avHeadetHandleAvrcpVendorDependent(const AVRCP_VENDORDEPENDENT_IND_T *ind)
{
/*
We are not a target so reject vendor requests
*/
AvrcpVendorDependentResponse(ind->avrcp, avctp_response_not_implemented);
}
/**************************************************************************/
void avHeadsetPausePress(headsetTaskData* app)
{
/* see controls_handler description */
MessageSendConditionally(&app->controls_task, PAUSE_PRESS, NULL, &app->avrcp_pending);
}
/**************************************************************************/
void avHeadsetPauseRelease(headsetTaskData* app)
{
/* see button_handler message queue description */
MessageSendConditionally(&app->controls_task, PAUSE_RELEASE, NULL, &app->avrcp_pending);
}
/**************************************************************************/
void avHeadsetPlayPress(headsetTaskData* app)
{
/* see controls_handler description */
MessageSendConditionally(&app->controls_task, PLAY_PRESS, NULL, &app->avrcp_pending);
}
/**************************************************************************/
void avHeadsetPlayRelease(headsetTaskData* app)
{
/* see button_handler message queue description */
MessageSendConditionally(&app->controls_task, PLAY_RELEASE, NULL, &app->avrcp_pending);
}
/**************************************************************************/
void avHeadsetForwardPress(headsetTaskData* app)
{
/* see controls_handler description */
MessageSendConditionally(&app->controls_task, FORWARD_PRESS, NULL, &app->avrcp_pending);
}
/**************************************************************************/
void avHeadsetForwardRelease(headsetTaskData* app)
{
/* see button_handler message queue description */
MessageSendConditionally(&app->controls_task, FORWARD_RELEASE, NULL, &app->avrcp_pending);
}
/**************************************************************************/
void avHeadsetBackwardPress(headsetTaskData* app)
{
/* see controls_handler description */
MessageSendConditionally(&app->controls_task, BACKWARD_PRESS, NULL, &app->avrcp_pending);
}
/**************************************************************************/
void avHeadsetBackwardRelease(headsetTaskData* app)
{
/* see button_handler message queue description */
MessageSendConditionally(&app->controls_task, BACKWARD_RELEASE, NULL, &app->avrcp_pending);
}
/**************************************************************************/
void avHeadsetStopPress(headsetTaskData* app)
{
/* see controls_handler description */
MessageSendConditionally(&app->controls_task, STOP_PRESS, NULL, &app->avrcp_pending);
}
/**************************************************************************/
void avHeadsetStopRelease(headsetTaskData* app)
{
/* see button_handler message queue description */
MessageSendConditionally(&app->controls_task, STOP_RELEASE, NULL, &app->avrcp_pending);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -