📄 main.c
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2005-2006
Part of BlueLab 3.5.2-release
FILE NAME
main.c
DESCRIPTION
This file contains the main HID mouse application.
NOTES
*/
/****************************************************************************
Header files
*/
#include "hid_mouse.h"
#include "hid_mouse_sm.h"
#include "hid_mouse_events.h"
#include "hid_mouse_service_record.h"
static const uint32 app_hid_diac[] =
{
0x9E8B00, 0x9e8b33
};
/* Application SDP record configuration */
static const hid_config app_mouse_config =
{
sizeof(hid_mouse_service_record),
hid_mouse_service_record
};
/* Application power table */
#define APP_POWER_TABLE_ENTRIES (sizeof(app_mouse_power_table) / sizeof(lp_power_table))
static const lp_power_table app_mouse_power_table[]=
{
/* mode, min_interval, max_interval, attempt, timeout, duration */
{lp_sniff, 18, 20, 1, 1, 5},
{lp_sniff, 22, 40, 1, 16, 30},
{lp_sniff, 42, 112, 1, 16, 600},
{lp_sniff, 114, 800, 1, 16, 0},
};
/* Connection library messages application would like */
static const msg_filter app_msg_filter = {msg_group_mode_change};
/* Application HID connection configuration */
static const hid_connection_config app_keyboard_connection_config =
{
APP_POWER_TABLE_ENTRIES, app_mouse_power_table, /* Power table */
11250, /* Latency (11.25ms) */
FALSE, /* Don't use Guaranteed QOS for interrupt channel */
};
#ifdef HW_DEV_1409
/* Agilent 2030/2051 sensor configuration */
HID_AGILENT_AN2051_CONFIG app_hidio_config =
{
sizeof(HID_AGILENT_AN2051_CONFIG),
TRUE, /* 800dpi */
FALSE, /* Don't swap X & Y */
FALSE, /* Don't reverse X */
FALSE, /* Don't reverse Y */
};
#endif
#ifdef HW_CASIRA_ADNS3030
/* Agilent 3030/3040 sensor configuration */
HID_AGILENT_ADNS3030_CONFIG app_hidio_config =
{
sizeof(HID_AGILENT_ADNS3030_CONFIG),
TRUE, /* 800dpi */
FALSE, /* Don't swap X & Y */
FALSE, /* Don't reverse X */
FALSE, /* Don't reverse Y */
};
#endif
/*************************************************************************
NAME
appHandleUnexpected
DESCRIPTION
Called when an unexpected message is received.
RETURNS
void
*/
static void appHandleUnexpected(appTaskData *theApp, MessageId id)
{
MAIN_PRINT(("appHandleUnexpected, id = %x\n", id));
}
/*************************************************************************
NAME
appHandleInternalIdleTimeoutInd
DESCRIPTION
Called when the idle timer has expired, enters the local disconnecting
state. This will automatically release the HID connection.
RETURNS
void
*/
static void appHandleInternalIdleTimeoutInd(appTaskData *theApp)
{
appSetState(theApp, appCabledDisconnecting);
}
/*************************************************************************
NAME
appHandleInternalDiscoverableTimeoutInd
DESCRIPTION
This function is called when discovery mode has timed out.
RETURNS
void
*/
static void appHandleInternalDiscoverableTimeoutInd(appTaskData *theApp)
{
/* Move to idle state */
appSetState(theApp, appIdle);
}
/*************************************************************************
NAME
appHandleInternalUnplugIndDefer
DESCRIPTION
Called to handle the unplug button when the application is not in a
state to handle it immediately. Just sets a flag.
RETURNS
void
*/
static void appHandleInternalUnplugIndDefer(appTaskData *theApp)
{
/* Set unplug flag, we'll handle it later */
theApp->unplug_pending = TRUE;
}
/*************************************************************************
NAME
appHandleInternalUnplugIndConnected
DESCRIPTION
Called when the unplug button is pressed and we are in the connected
state. Sends a virtual unplug request to the host.
RETURNS
void
*/
static void appHandleInternalUnplugIndConnected(appTaskData *theApp)
{
/* Defer unplug */
appHandleInternalUnplugIndDefer(theApp);
/* Start an unplug timer */
MessageSendLater(&theApp->task, APP_INTERNAL_UNPLUG_TIMEOUT_IND, 0, D_SEC(APP_UNPLUG_TIMEOUT));
/* Send virtual unplug to host */
HidControl(theApp->hid, hid_control_op_unplug);
}
/*************************************************************************
NAME
appHandleInternalUnplugIndDisconnected
DESCRIPTION
Called when the connect button is pressed and we are in the connected
state.
RETURNS
void
*/
static void appHandleInternalUnplugIndDisconnected(appTaskData *theApp)
{
MAIN_PRINT(("appHandleInternalUnplugIndDisconnected\n"));
/* Move to discoverable state */
appSetState(theApp, appDiscoverable);
}
/*************************************************************************
NAME
appHandleInternalUnplugIndDiscoverable
DESCRIPTION
Called when the connect button is pressed and we are in the idle or
discoverable state.
RETURNS
void
*/
static void appHandleInternalUnplugIndDiscoverable(appTaskData *theApp)
{
MAIN_PRINT(("appHandleInternalUnplugIndDiscoverable\n"));
/* Move to discoverable state */
appSetState(theApp, appDiscoverable);
}
/*************************************************************************
NAME
appHandleInternalUnplugTimeoutInd
DESCRIPTION
Called when the virtual unplug operation has timeout, moves to
disconnecting state.
RETURNS
void
*/
static void appHandleInternalUnplugTimeoutInd(appTaskData *theApp)
{
MAIN_PRINT(("appHandleInternalUnplugTimeoutInd\n"));
/* Move to disconnecting state */
appSetState(theApp, appCabledDisconnecting);
}
/*************************************************************************
NAME
appHandleInternalShutdownInd
DESCRIPTION
Called when the user has pressed the connect/power button, moves to
idle state to turn off device.
RETURNS
void
*/
static void appHandleInternalShutdownInd(appTaskData *theApp)
{
MAIN_PRINT(("appHandleInternalShutdownInd\n"));
/* Move idle state */
appSetState(theApp, appIdle);
}
/*************************************************************************
NAME
appHandleInternalShutdownIndDefer
DESCRIPTION
Called when the user has pressed the connect/power button and the
shutdown has to be defered to later.
RETURNS
void
*/
static void appHandleInternalShutdownIndDefer(appTaskData *theApp)
{
/* Set shutdown flag, we'll handle it later */
theApp->shutdown_pending = TRUE;
}
/*************************************************************************
NAME
appHandleInternalShutdownIndConnected
DESCRIPTION
Called when the user has pressed the connect/power button and the
device is connected, shutdown has to be defered to later.
RETURNS
void
*/
static void appHandleInternalShutdownIndConnected(appTaskData *theApp)
{
/* Set shutdown flag, we'll handle it later */
theApp->shutdown_pending = TRUE;
/* Start disconnection */
appSetState(theApp, appCabledDisconnecting);
}
/*************************************************************************
NAME
appHandleInternalShutdownIndIdle
DESCRIPTION
Called when the user has pressed the connect/power button, moves to
cabled connecting state to turn on device.
RETURNS
void
*/
static void appHandleInternalShutdownIndIdle(appTaskData *theApp)
{
MAIN_PRINT(("appHandleInternalShutdownIndIdle\n"));
/* Move CabledConnecting state */
appSetState(theApp, appCabledConnecting);
}
/*************************************************************************
NAME
appHandleClInitConfirm
DESCRIPTION
Called once the connection library has been initialised. Starts off
HID library initialisation.
RETURNS
void
*/
static void appHandleClInitConfirm(appTaskData *theApp, CL_INIT_CFM_T *cfm)
{
MAIN_PRINT(("appHandleClInitConfirm\n"));
/* Connection Library initialisation was a success, initialise the HID library */
if (cfm->status == success)
HidInit(&theApp->task, &app_mouse_config);
else
Panic();
}
/*************************************************************************
NAME
appHandleClSmGetMruAttributeConfirm
DESCRIPTION
Called when the connection library passes the application information
on a trusted device, kicks off a HID connection.
RETURNS
void
*/
static void appHandleClSmGetIndexedAttributeConfirm(appTaskData *theApp, CL_SM_GET_INDEXED_ATTRIBUTE_CFM_T *cfm)
{
MAIN_PRINT(("appHandleClSmGetIndexedAttributeConfirm\n"));
if (cfm->status == success)
{
MAIN_PRINT(("Attempt to connect to %d,%d,%ld\n", cfm->bd_addr.nap, cfm->bd_addr.uap, cfm->bd_addr.lap));
/* Store Bluetooth address of host */
theApp->host_bd_addr = cfm->bd_addr;
/* Attempt to connect to host */
HidConnect(theApp->hid_lib, &theApp->task, &theApp->host_bd_addr, &app_keyboard_connection_config);
}
else
{
/* Check if we have paired with any devices */
if (theApp->trusted_device_index)
{
MAIN_PRINT(("Failed to connect\n"));
/* Reset device index */
theApp->trusted_device_index = 0;
/* Move to disconnected state */
appSetState(theApp, appCabledDisconnected);
}
else
{
MAIN_PRINT(("No devices, making discoverable\n"));
/* Make device discoverable */
appSetState(theApp, appDiscoverable);
}
}
}
/*************************************************************************
NAME
appEnterDiscoverable
DESCRIPTION
Called when the connection library requires a pin code from the user.
RETURNS
void
*/
static void appHandleClSmPinCodeIndication(appTaskData *theApp, CL_SM_PIN_CODE_IND_T *ind)
{
MAIN_PRINT(("appHandleClSmPinCodeIndication\n"));
/* Store host bluetooth address */
theApp->auth_bd_addr = ind->bd_addr;
/* Send pin code response */
ConnectionSmPinCodeResponse(&theApp->auth_bd_addr, 4, (uint8 *)"0000");
}
/*************************************************************************
NAME
appHandleClSmAuthenticateConfirm
DESCRIPTION
Handles authentication confirmation, if successful authentication
state is set as trusted, the host is actually mark as trusted only
once the initial connection has been setup successfully.
RETURNS
void
*/
static void appHandleClSmAuthenticateConfirm(appTaskData *theApp, CL_SM_AUTHENTICATE_CFM_T *cfm)
{
MAIN_PRINT(("appHandleClSmAuthenticateConfirm\n"));
}
/*************************************************************************
NAME
appHandleClSmAuthoriseInd
DESCRIPTION
Handles incoming connection authorisation, if connection is from
host we have just authenticated with the connection is accepted,
otherwise it is rejected.
RETURNS
void
*/
static void appHandleClSmAuthoriseInd(appTaskData *theApp, CL_SM_AUTHORISE_IND_T *ind)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -