📄 main.c
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004
FILE NAME
main.c
DESCRIPTION
This file contains the main AV Headset Application
NOTES
*/
/****************************************************************************
Header files
*/
#include "av_headset_private.h"
#include "av_headset_init.h"
#include "av_headset_sep.h"
#include "av_headset_auth.h"
#include "av_headset_controls.h"
#include "av_headset_buttons.h"
#include "av_headset_remote_control.h"
#include "av_headset_led.h"
#include "av_headset_scan.h"
#include <a2dp.h>
#include <avrcp.h>
#include <bdaddr.h>
#include <connection.h>
#include <panic.h>
#include <stream.h>
#include <ps.h>
#include <pio.h>
/* Single instance of AV Headset state */
static avTaskData theAvApp;
/*************************************************************************
NAME
getAppTask
DESCRIPTION
Returns the AV application main task.
RETURNS
Task
*/
Task getAppTask(void)
{
return &theAvApp.task;
}
/*************************************************************************
NAME
getApp
DESCRIPTION
Returns the AV headset application state
RETURNS
avTaskData
*/
avTaskData *getApp(void)
{
return &theAvApp;
}
/*************************************************************************
NAME
avHeadsetSetA2dpState
DESCRIPTION
Set the AV Headset A2DP State to the specified state
RETURNS
*/
void avHeadsetSetA2dpState(const avHeadsetA2dpState state)
{
DEBUG(("AV Headset A2DP State - C=%d N=%d\n",theAvApp.a2dp_state, state));
theAvApp.a2dp_state = state;
}
/*************************************************************************
NAME
avHeadsetSetAvrcpState
DESCRIPTION
Set the AV Headset AVRCP State to the specified state
RETURNS
*/
void avHeadsetSetAvrcpState(const avHeadsetAvrcpState state)
{
DEBUG(("AV Headset AVRCP State - C=%d N=%d\n",theAvApp.avrcp_state, state));
theAvApp.avrcp_state = state;
}
/*************************************************************************
NAME
unhandledA2dpState
DESCRIPTION
This function is called when a message arrives and the AV Headset is
in an unexpected state. The error condition is reported and then the
AV Application will Panic
RETURNS
*/
static void unhandledA2dpState(avHeadsetA2dpState state, MessageId id)
{
state = state;
id = id;
DEBUG(("A2DP current state %d message id 0x%x\n", state, id));
}
/*************************************************************************
NAME
unhandledAvrcpState
DESCRIPTION
This function is called when a message arrives and the AV Headset is
in an unexpected state. The error condition is reported and then the
AV Application will Panic
RETURNS
*/
static void unhandledAvrcpState(avHeadsetAvrcpState state, MessageId id)
{
state = state;
id = id;
DEBUG(("AVRCP current state %d message id 0x%x\n", state, id));
}
/*************************************************************************
NAME
app_handler
DESCRIPTION
This is the main message handler for the AV Headset Application. All
messages pass through this handler.
RETURNS
*/
static void app_handler(Task task, MessageId id, Message message)
{
/* Get the current AV A2dp Headset state */
avHeadsetA2dpState current_a2dp_state = theAvApp.a2dp_state;
avHeadsetAvrcpState current_avrcp_state = theAvApp.avrcp_state;
task = task;
/* Handle incoming message identified by its message ID */
switch(id)
{
case CL_INIT_CFM:
DEBUG(("CL_INIT_CFM\n"));
if(((CL_INIT_CFM_T*)message)->status == success)
{
/* Connection Library initialisation was a success, initailise the
A2DP library */
a2dp_init_params a2dp_config;
a2dp_config.role = a2dp_sink;
a2dp_config.size_service_record = 0;
a2dp_config.service_record = 0;
a2dp_config.priority = 512;
A2dpInit(getAppTask(), &a2dp_config);
if (theAvApp.pairing_enabled)
headsetEnableDiscoverable(&theAvApp);
else
headsetDisableDiscoverable(&theAvApp);
}
else
{
Panic();
}
break;
case A2DP_INIT_CFM:
DEBUG(("A2DP_INIT_CFM\n"));
switch(current_a2dp_state)
{
case avHeadsetA2dpInitialising:
avHeadsetHandleA2dpInitCfm(&theAvApp, (A2DP_INIT_CFM_T*) message);
break;
case avHeadsetA2dpReady:
case avHeadsetA2dpConnected:
case avHeadsetA2dpStreaming:
case avHeadsetA2dpDisconnecting:
case avHeadsetA2dpInitiating:
case avHeadsetA2dpPairing:
default:
unhandledA2dpState(current_a2dp_state, id);
break;
}
break;
case A2DP_ADD_SEP_CFM:
DEBUG(("A2DP_ADD_SEP_CFM\n"));
switch(current_a2dp_state)
{
case avHeadsetA2dpInitialising:
avHeadsetHandleA2dpAddSepCfm(&theAvApp, (A2DP_ADD_SEP_CFM_T*) message);
break;
case avHeadsetA2dpReady:
case avHeadsetA2dpConnected:
case avHeadsetA2dpStreaming:
case avHeadsetA2dpDisconnecting:
case avHeadsetA2dpInitiating:
case avHeadsetA2dpPairing:
default:
unhandledA2dpState(current_a2dp_state, id);
break;
}
break;
case A2DP_OPEN_IND:
DEBUG(("A2DP_OPEN_IND\n"));
switch(current_a2dp_state)
{
case avHeadsetA2dpReady:
avHeadsetHandleA2dpOpenInd(&theAvApp, (A2DP_OPEN_IND_T*) message);
break;
case avHeadsetA2dpInitialising:
case avHeadsetA2dpConnected:
case avHeadsetA2dpStreaming:
case avHeadsetA2dpDisconnecting:
case avHeadsetA2dpInitiating:
case avHeadsetA2dpPairing:
default:
unhandledA2dpState(current_a2dp_state, id);
break;
}
break;
case A2DP_OPEN_CFM:
DEBUG(("A2DP_OPEN_CFM\n"));
switch(current_a2dp_state)
{
case avHeadsetA2dpInitiating:
avHeadsetHandleA2dpOpenCfm(&theAvApp, (A2DP_OPEN_CFM_T*) message);
break;
case avHeadsetA2dpStreaming:
case avHeadsetA2dpConnected:
case avHeadsetA2dpReady:
case avHeadsetA2dpInitialising:
case avHeadsetA2dpDisconnecting:
case avHeadsetA2dpPairing:
default:
unhandledA2dpState(current_a2dp_state, id);
break;
}
break;
case A2DP_START_IND:
DEBUG(("A2DP_START_IND\n"));
switch(current_a2dp_state)
{
case avHeadsetA2dpConnected:
avHeadsetHandleA2dpStartInd(&theAvApp);
break;
case avHeadsetA2dpReady:
case avHeadsetA2dpInitialising:
case avHeadsetA2dpStreaming:
case avHeadsetA2dpDisconnecting:
case avHeadsetA2dpInitiating:
case avHeadsetA2dpPairing:
default:
unhandledA2dpState(current_a2dp_state, id);
break;
}
break;
case A2DP_START_CFM:
DEBUG(("A2DP_START_CFM\n"));
switch(current_a2dp_state)
{
case avHeadsetA2dpInitiating:
avHeadsetHandleA2dpStartCfm(&theAvApp, (A2DP_START_CFM_T*) message);
break;
case avHeadsetA2dpReady:
case avHeadsetA2dpInitialising:
case avHeadsetA2dpStreaming:
case avHeadsetA2dpDisconnecting:
case avHeadsetA2dpConnected:
case avHeadsetA2dpPairing:
default:
unhandledA2dpState(current_a2dp_state, id);
break;
}
break;
case A2DP_SUSPEND_IND:
DEBUG(("A2DP_SUSPEND_IND\n"));
switch(current_a2dp_state)
{
case avHeadsetA2dpStreaming:
avHeadsetHandleA2dpSuspendInd();
break;
case avHeadsetA2dpReady:
case avHeadsetA2dpInitialising:
case avHeadsetA2dpConnected:
case avHeadsetA2dpDisconnecting:
case avHeadsetA2dpInitiating:
case avHeadsetA2dpPairing:
default:
unhandledA2dpState(current_a2dp_state, id);
break;
}
break;
case A2DP_CLOSE_IND:
DEBUG(("A2DP_CLOSE_IND\n"));
switch(current_a2dp_state)
{
case avHeadsetA2dpStreaming:
case avHeadsetA2dpConnected:
avHeadsetHandleA2dpCloseInd(&theAvApp);
break;
case avHeadsetA2dpReady:
case avHeadsetA2dpInitialising:
case avHeadsetA2dpDisconnecting:
case avHeadsetA2dpInitiating:
case avHeadsetA2dpPairing:
default:
unhandledA2dpState(current_a2dp_state, id);
break;
}
break;
case A2DP_CLOSE_CFM:
DEBUG(("A2DP_CLOSE_CFM\n"));
switch(current_a2dp_state)
{
case avHeadsetA2dpStreaming:
case avHeadsetA2dpConnected:
avHeadsetHandleA2dpCloseCfm(&theAvApp);
avHeadsetCheckPowerDownStatus(&theAvApp);
break;
case avHeadsetA2dpReady:
case avHeadsetA2dpInitialising:
case avHeadsetA2dpDisconnecting:
case avHeadsetA2dpInitiating:
case avHeadsetA2dpPairing:
default:
unhandledA2dpState(current_a2dp_state, id);
break;
}
break;
case A2DP_CODEC_SETTINGS_IND:
switch(current_a2dp_state)
{
case avHeadsetA2dpReady:
case avHeadsetA2dpConnected:
case avHeadsetA2dpInitiating:
case avHeadsetA2dpStreaming:
avHeadsetHandleA2dpCodecSettingsInd(&theAvApp, (A2DP_CODEC_SETTINGS_IND_T *) message);
break;
case avHeadsetA2dpInitialising:
case avHeadsetA2dpDisconnecting:
case avHeadsetA2dpPairing:
default:
unhandledA2dpState(current_a2dp_state, id);
break;
}
break;
case AVRCP_INIT_CFM:
DEBUG(("AVRCP_INIT_CFM\n"));
switch(current_avrcp_state)
{
case avHeadsetAvrcpInitialising:
avHeadsetHandleAvrcpInitCfm(&theAvApp, (AVRCP_INIT_CFM_T*) message);
break;
case avHeadsetAvrcpReady:
case avHeadsetAvrcpConnecting:
case avHeadsetAvrcpConnected:
case avHeadsetAvrcpDisconnecting:
default:
unhandledAvrcpState(current_avrcp_state, id);
break;
}
break;
case AVRCP_CONNECT_CFM:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -