📄 main.c
字号:
}
else if (current_avrcp_state == avHeadsetAvrcpConnected)
{
if (app.play_state && (app.a2dp_state == avHeadsetA2dpStreaming))
{
avHeadsetSendPause(&app);
}
else
{
avHeadsetSendPlay(&app);
}
playButtonTone = TRUE;
}
else if (app.active_profile == av_active)
{
if (app.play_state)
{
avHeadsetUpdateAvrcpPlayState(&app, 0);
avHeadsetAvStreamStop(&app, TRUE);
}
else
{
avHeadsetUpdateAvrcpPlayState(&app, 1);
avHeadsetAvStreamStart(&app);
}
playButtonTone = TRUE;
}
else
{
playButtonTone = TRUE ;
avHeadsetHandleAvConnectRequest(&app);
}
}
break;
}
break;
default:
break ;
}
if (playErrorTone)
headsetPlayTone(&app, tone_type_error);
if (playButtonTone)
headsetPlayTone(&app, tone_type_button_press);
}
/*************************************************************************
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)
{
/*DEBUG(("In App_handler\n"));*/
/* Handle incoming message identified by its message ID */
if ((AVRCP_MESSAGE_BASE <= id) && (id <= AVRCP_MESSAGE_TOP))
{
avrcp_msg_handler(id, message);
}
else if ((A2DP_MESSAGE_BASE <= id) && (id <= A2DP_MESSAGE_TOP))
{
a2dp_msg_handler(id, message);
}
else if ((HFP_MESSAGE_BASE <= id) && (id <= HFP_MESSAGE_TOP))
{
hfp_msg_handler(id, message);
}
else if ((CL_MESSAGE_BASE <= id) && (id <= CL_MESSAGE_TOP))
{
cl_msg_handler(id, message);
}
else if ((HEADSET_MSG_BASE <= id) && (id <= HEADSET_MSG_TOP))
{
app_msg_handler (id , message ) ;
}
else
{
switch(id)
{
case CODEC_INIT_CFM:
MAIN_DEBUG(("CODEC_INIT_CFM\n"));
if(((CODEC_INIT_CFM_T*)message)->status == codec_success)
{
app.codec_task = ((CODEC_INIT_CFM_T*)message)->codecTask;
/* Initialise the headset volume */
initialiseVolume(&app);
/* Initialise the Connection Library */
ConnectionInit(&app.task);
}
else
{
Panic();
}
break;
case BUTTON_VOL_UP:
BUTTON_DEBUG(("BUTTON_VOL_UP\n"));
button_handle_vol_up(&app) ;
break;
case BUTTON_VOL_DOWN:
BUTTON_DEBUG(("BUTTON_VOL_DOWN\n"));
button_handle_vol_down(&app) ;
break;
case BUTTON_FORWARD_PRESS:
BUTTON_DEBUG(("BUTTON_FORWARD_PRESS\n"));
break;
case BUTTON_FORWARD_RELEASE:
MAIN_DEBUG(("BUTTON_FORWARD_RELEASE\n"));
button_handle_forward_release(&app) ;
break;
case BUTTON_FORWARD_LONG:
BUTTON_DEBUG(("BUTTON_FORWARD_LONG\n"));
button_handle_forward_long(&app) ;
break ;
case BUTTON_FORWARD_LONG_REPEAT:
BUTTON_DEBUG(("BUTTON_FORWARD_LONG_REPEAT\n"));
button_handle_forward_long(&app) ;
break;
case BUTTON_FORWARD_LONG_RELEASE:
BUTTON_DEBUG(("BUTTON_FORWARD_LONG_RELEASE\n"));
button_handle_forward_long_release(&app) ;
break ;
case BUTTON_FORWARD_LONG_REPEAT_RELEASE:
BUTTON_DEBUG(("BUTTON_FORWARD_LONG_REPEAT_RELEASE\n"));
button_handle_forward_long_release(&app) ;
break;
case BUTTON_BACKWARD_PRESS:
BUTTON_DEBUG(("BUTTON_BACKWARD_PRESS\n"));
break;
case BUTTON_BACKWARD_RELEASE:
BUTTON_DEBUG(("BUTTON_BACKWARD_RELEASE\n"));
button_handle_backward_release(&app) ;
break;
case BUTTON_BACKWARD_LONG:
BUTTON_DEBUG(("BUTTON_BACKWARD_LONG\n"));
button_handle_backward_long(&app) ;
break ;
case BUTTON_BACKWARD_LONG_REPEAT:
BUTTON_DEBUG(("BUTTON_BACKWARD_LONG_REPEAT\n"));
button_handle_backward_long(&app) ;
break ;
case BUTTON_BACKWARD_LONG_RELEASE:
BUTTON_DEBUG(("BUTTON_BACKWARD_LONG_RELEASE\n"));
button_handle_backward_long_release(&app) ;
break ;
case BUTTON_BACKWARD_LONG_REPEAT_RELEASE:
BUTTON_DEBUG(("BUTTON_BACKWARD_LONG_REPEAT_RELEASE\n"));
button_handle_backward_long_release(&app) ;
break;
case BUTTON_MFB_PRESS:
BUTTON_DEBUG(("BUTTON_MFB_PRESS\n"));
button_handle_mfb_press(&app) ;
break;
case BUTTON_MFB_SHORT:
BUTTON_DEBUG(("BUTTON_MFB_SHORT\n"));
button_handle_mfb_short(&app) ;
break;
case BUTTON_MFB_LONG_HELD:
BUTTON_DEBUG(("BUTTON_MFB_LONG_HELD\n"));
button_handle_mfb_long_held(&app) ;
break;
case BUTTON_MFB_LONG_RELEASE:
BUTTON_DEBUG(("BUTTON_MFB_LONG_RELEASE\n"));
button_handle_mfb_long_release(&app) ;
break;
case BUTTON_MFB_VERY_LONG:
BUTTON_DEBUG(("BUTTON_MFB_VERY_LONG\n"));
button_handle_mfb_very_long(&app) ;
break;
case BUTTON_PLAY_PAUSE_PRESS:
BUTTON_DEBUG(("BUTTON_PLAY_PAUSE_PRESS\n"));
button_handle_play_pause_press(&app) ;
break;
case BUTTON_PLAY_PAUSE_SHORT:
BUTTON_DEBUG(("BUTTON_PLAY_PAUSE_SHORT\n"));
button_handle_play_pause_short(&app) ;
break;
case BUTTON_PLAY_PAUSE_LONG:
BUTTON_DEBUG(("BUTTON_PLAY_PAUSE_LONG\n"));
button_handle_play_pause_long(&app) ;
break;
case BUTTON_FORWARD_BACKWARD_HELD:
BUTTON_DEBUG(("BUTTON_FORWARD_BACKWARD_HELD\n"));
button_handle_forward_backward_held(&app) ;
break;
#ifdef DEV_1645
case CHARGER_RAW:
MAIN_DEBUG(("CHARGER 0x%x\n",((CHARGER_RAW_T*)message)->chg));
if (((CHARGER_RAW_T*)message)->chg)
{
MessageSend(getAppTask(), APP_CHARGER_CONNECTED_IND, 0);
}
else
{
MessageSend(getAppTask(), APP_CHARGER_DISCONNECTED_IND, 0);
}
break;
#endif
#ifdef DEV_1508
case PIO_RAW:
MAIN_DEBUG(("PIO_RAW 0x%x\n",((PIO_RAW_T*)message)->pio));
if (((PIO_RAW_T*)message)->pio & PIO_AIO3)
{
MessageSend(getAppTask(), APP_CHARGER_CONNECTED_IND, 0);
}
else
{
MessageSend(getAppTask(), APP_CHARGER_DISCONNECTED_IND, 0);
}
break;
#endif
default:
MAIN_DEBUG(("AV Headset - Unhandled msg 0x%x\n",id));
break;
}
}
#ifdef TEST_HARNESS
if (((HFP_MESSAGE_BASE <= id) && (id <= HFP_MESSAGE_TOP))||
((CL_MESSAGE_BASE <= id) && (id <= CL_MESSAGE_TOP))||
((A2DP_MESSAGE_BASE <= id) && (id <= A2DP_MESSAGE_TOP)))
{
test_handle_lib_message(task, id, message);
}
#endif
}
/**************************************************************************/
static void headsetReadPsFeatures(headsetTaskData *app)
{
uint16 ps_read;
bool ps_set = FALSE;
/* Read Auto Reconnect Value */
if (PsRetrieve(AUTO_RECONNECT, &ps_read, 1))
{
if (ps_read == 1)
ps_set = TRUE;
}
if (ps_set)
app->features.auto_reconnect = 0x1;
else
app->features.auto_reconnect = 0x0;
MAIN_DEBUG(("Features, auto_reconnect %d\n",app->features.auto_reconnect));
ps_set = FALSE;
ps_read = 0;
/* Read Ring Tone Select Value */
if (PsRetrieve(RING_TONE_SELECT, &ps_read, 1))
{
switch (ps_read)
{
case 1:
app->features.ring_tone_select = 0x1;
ps_set = TRUE;
break;
default:
break;
}
}
if (!ps_set)
app->features.ring_tone_select = 0x0;
MAIN_DEBUG(("Features, ring_tone_select %d\n",app->features.ring_tone_select));
ps_set = FALSE;
ps_read = 0;
/* Read Auto Switch Off Enabled Value */
if (PsRetrieve(AUTO_SWITCH_OFF_ENABLED, &ps_read, 1))
{
if (ps_read == 1)
ps_set = TRUE;
}
if (ps_set)
app->features.auto_switch_off_enabled = 0x1;
else
app->features.auto_switch_off_enabled = 0x0;
MAIN_DEBUG(("Features, auto_switch_off_enabled %d\n",app->features.auto_switch_off_enabled));
ps_read = 0;
/* Read Auto Switch Off Timeout Value */
if (PsRetrieve(AUTO_SWITCH_OFF_TIMEOUT, &ps_read, 1))
app->features.auto_switch_off_timeout = ps_read;
else
app->features.auto_switch_off_timeout = 0;
MAIN_DEBUG(("Features, auto_switch_off_timeout %d\n",app->features.auto_switch_off_timeout));
}
/**************************************************************************/
static void headsetInitialiseStates(headsetTaskData *app)
{
/* Set up the Application task handler */
app->task.handler = app_handler;
/* Reset the codec task ptr. */
app->codec_task = 0;
/* Set up common states */
app->speaker_volume.hfp_volume = 0;
app->speaker_volume.av_volume = 0;
app->pairing_enabled = 0;
app->active_profile = hfp_active;
app->mic_volume = 8;
/* Init the AV state */
app->a2dp = 0;
app->avrcp = 0;
setA2dpState(app, avHeadsetA2dpInitialising);
setAvrcpState(app, avHeadsetAvrcpInitialising);
app->sig_sink = 0;
app->media_sink = 0;
app->channel_mode = a2dp_mono;
app->rate = 8000;
app->avrcp_pending = FALSE;
app->av_stream_stopped = TRUE;
app->sent_suspend = FALSE;
app->play_state = 0;
app->headset_connecting_av = FALSE;
avHeadsetUpdateAvrcpPlayState(app, 0);
/* Init the HFP state */
setHfpState(app, headsetInitialising);
app->in_band_ring_enabled = 0;
app->voice_recognition_enabled = FALSE;
app->headset_connecting_hfp = 0;
app->slc_sink = 0;
app->sco_sink = 0;
app->supp_features_0 = 0;
app->profile_connected = hfp_no_profile;
app->hfp = 0;
app->hsp = 0;
app->mic_mute_on = FALSE;
app->charger_connected = 0;
app->battery_full = 0;
app->connect_av = 0;
app->av_stream_connected = FALSE;
}
/* The Stereo Headset Application starts here...*/
int main(void)
{
/* Initialise the app states */
headsetInitialiseStates(&app);
/*Power on and send a message to check that a power-on event has been seen*/
#ifdef SOFT_POWER
PioSetDir(POWER_HOLD, POWER_HOLD);
PioSet(POWER_HOLD, POWER_HOLD);
#endif
/*Send a message to check if we have seen a power on event, if this isn't seen
the headset will power down*/
MessageSendLater(getAppTask(), APP_POWER_ON_EVENT_SEEN, 0, (uint32) 15000);
#ifdef TEST_HARNESS
test_register(getAppTask());
#endif
#ifdef WOLFSON_CODEC_WM8731
/* Init the Wolfson codec with default params. */
CodecInitWolfson(&app.task, 0);
#else
/* Initialise the Codec Library */
CodecInitCsrInternal(&app.task);
#endif
/* Read feature values from the PS */
headsetReadPsFeatures(&app);
#ifdef DEV_1645
/*Disable the built-in charger indications*/
ChargerSupressLed0(TRUE);
#endif
/* Initialise the battery voltage polling */
batteryInit(&app.power_source);
/* Initialise PIO */
pioInit(&app.pio_state, &app.task);
/* Start the message scheduler loop */
MessageLoop();
/* Never get here...*/
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -