📄 app_device.c
字号:
break;
}
break;
case APP_DEVICE_INTERNAL_CONNECT_IND:
switch (state)
{
case appDevDisconnected:
appDevHandleInternalConnectInd(theDevice, (APP_DEVICE_INTERNAL_CONNECT_IND_T *)message);
break;
default:
appDevRejectInternalConnectInd(theDevice, (APP_DEVICE_INTERNAL_CONNECT_IND_T *)message);
break;
}
break;
case APP_DEVICE_INTERNAL_UNPLUG_REQ:
switch (state)
{
case appDevConnectingLocal:
case appDevConnectingRemote:
case appDevConnectingInitial:
case appDevDisconnectingLocal:
appDevHandleUnplugReqDefer(theDevice);
break;
case appDevConnected:
appDevHandleUnplugReqConnected(theDevice);
break;
case appDevDisconnected:
appDevHandleUnplugReqDisconnected(theDevice);
break;
default:
appDevHandleUnexpected(theDevice, id);
break;
}
break;
/* BT DEVICE ==> DONGLE */
/*
case HID_CONNECT_CFM:
switch (state)
{
case appDevConnectingLocal:
case appDevConnectingRemote:
case appDevConnectingInitial:
appDevHandleHidConnectCfm(theDevice, (HID_CONNECT_CFM_T *)message);
break;
default:
appDevHandleUnexpected(theDevice, id);
break;
}
break;
*/
case CL_L2CAP_CONNECT_CFM:
switch (state)
{
case appDevConnectingLocal:
case appDevConnectingRemote:
case appDevConnectingInitial:
appDevHandleL2capConnectCfm(theDevice, (CL_L2CAP_CONNECT_CFM_T *)message);
break;
default:
appDevHandleUnexpected(theDevice, id);
break;
}
break;
#if 0
case HID_DISCONNECT_IND:
switch (state)
{
case appDevConnected:
case appDevDisconnectingLocal:
appDevHandleHidDisconnectInd(theDevice, (HID_DISCONNECT_IND_T *)message);
break;
default:
appDevHandleUnexpected(theDevice, id);
break;
}
break;
#endif
case CL_L2CAP_DISCONNECT_IND:
switch (state)
{
case appDevConnected:
case appDevDisconnectingLocal:
appDevHandleL2capDisconnectInd(theDevice, (CL_L2CAP_DISCONNECT_IND_T *)message);
break;
default:
appDevHandleUnexpected(theDevice, id);
break;
}
break;
default:
appDevHandleUnexpected(theDevice, id);
break;
}
}
/*************************************************************************
NAME
appDeviceIsEmpty
DESCRIPTION
Checks if the specified device entry is available for the required
class of device.
RETURNS
bool - TRUE if device entry is available, FALSE otherwise.
*/
bool appDeviceIsEmpty(appDeviceTaskData *theDevice, uint32 dev_class)
{
if ((appDevGetState(theDevice) == appDevUnplugged) && ((theDevice->dev_class & dev_class) == theDevice->dev_class))
return TRUE;
else
return FALSE;
}
/*************************************************************************
NAME
appDeviceIsDisconnected
DESCRIPTION
Checks if the specified device is disconnected but virtual cabled.
RETURNS
bool - TRUE if disconnected, FALSE otherwise.
*/
bool appDeviceIsDisconnected(appDeviceTaskData *theDevice)
{
return (appDevGetState(theDevice) == appDevDisconnected);
}
/*************************************************************************
NAME
appDeviceIsBdaddr
DESCRIPTION
Checks if the specified device matches the required Bluetooth address.
RETURNS
bool - TRUE if address matches, FALSE if is doesn't.
*/
bool appDeviceIsBdaddr(appDeviceTaskData *theDevice, const bdaddr *bd_addr)
{
return BdaddrIsSame(&theDevice->dev_info.bd_addr, bd_addr);
}
/*************************************************************************
NAME
appDeviceConnectRequest
DESCRIPTION
This function is called to initate a connection from the specified
device.
胶胶肺 皋技瘤甫 父甸绢辑 朝覆. CON FSM俊 朝赴 巴苞 悼老窃.
RETURNS
void
*/
void appDeviceConnectRequest(appDeviceTaskData *theDevice, const bdaddr *bd_addr, bool initial)
{
MAKE_DEVICE_MESSAGE(APP_DEVICE_INTERNAL_CONNECT_REQ);
message->bd_addr = *bd_addr;
message->initial = initial;
MessageSend(&theDevice->task, APP_DEVICE_INTERNAL_CONNECT_REQ, message);
}
/*************************************************************************
NAME
appDeviceConnectIndication
DESCRIPTION
This function is called to accept an incoming connection to the
specified device.
RETURNS
void
*/
void appDeviceConnectIndication(appDeviceTaskData *theDevice, uint16 cid)
{
MAKE_DEVICE_MESSAGE(APP_DEVICE_INTERNAL_CONNECT_IND);
message->connection_id = cid;
MessageSend(&theDevice->task, APP_DEVICE_INTERNAL_CONNECT_IND, message);
}
/*************************************************************************
NAME
appDeviceInit
DESCRIPTION
This function initialises the specified device structure. It also
attempts to retreive previously pair device information from the
persistent store.
RETURNS
void
*/
void appDeviceInit(appDeviceTaskData *theDevice, uint8 dev_num, uint32 dev_class, appDongleTaskData *theApp, const char *pin)
{
theDevice->task.handler = devHandler;
theDevice->dev_num = dev_num;
theDevice->theApp = theApp;
theDevice->pin = pin;
theDevice->dev_class = dev_class;
theDevice->state = appDevUnplugged;
theDevice->hid = NULL;
theDevice->usb_sink = 0;
theDevice->usb_source = 0;
theDevice->hid_sink = 0;
theDevice->dev_info.hid_virtual_cable = FALSE;
theDevice->dev_info.hid_reconnect_initiate = FALSE;
theDevice->dev_info.hid_normally_connectable = FALSE;
BdaddrSetZero(&theDevice->dev_info.bd_addr);
/* Attempt to read from persistent store */
if (PsRetrieve(theDevice->dev_num, &theDevice->dev_info, sizeof(theDevice->dev_info)) == sizeof(theDevice->dev_info))
{
MAIN_PRINT(("Retrieving device information, nap=%d, uap=%d, lap=%ld\n",
theDevice->dev_info.bd_addr.nap,
theDevice->dev_info.bd_addr.uap,
theDevice->dev_info.bd_addr.lap));
/* Check if device is normally connectable */
if (theDevice->dev_info.hid_normally_connectable)
{
/* Found a device, so go to connecting state */
theDevice->state = appDevConnectingLocal;
}
else
{
/* Found a device, so go to disconnected state */
theDevice->state = appDevDisconnected;
}
}
}
/*************************************************************************
NAME
appDeviceUnplugRequest
DESCRIPTION
This function starts deletion of the specified device, it sends an
internal message to the device task.
RETURNS
void
*/
void appDeviceUnplugRequest(appDeviceTaskData *theDevice)
{
/* Unplug device */
MessageSend(&theDevice->task, APP_DEVICE_INTERNAL_UNPLUG_REQ, 0);
}
/*************************************************************************
NAME
appDeviceHidGetReport
DESCRIPTION
Handles GET REPORT request received via USB.
RETURNS
bool
*/
bool appDeviceHidGetReport(appDeviceTaskData *theDevice, Sink sink, uint16 *length)
{
return FALSE;
}
/*************************************************************************
NAME
appDeviceHidGetIdle
DESCRIPTION
Handles GET IDLE request received via USB.
RETURNS
bool
*/
bool appDeviceHidGetIdle(appDeviceTaskData *theDevice, Sink sink, uint16 *length)
{
/* Check if we are a keyboard */
if (theDevice->dev_class & HID_MINOR_KEYBOARD)
{
uint8 *ptr = SinkMap(sink) + SinkClaim(sink, 1);
ptr[0] = theDevice->settings.keyboard.idle_rate;
*length = 1;
return TRUE;
}
return FALSE;
}
/*************************************************************************
NAME
appDeviceHidGetProtocol
DESCRIPTION
Handles GET PROTOCOL request received via USB.
RETURNS
bool
*/
bool appDeviceHidGetProtocol(appDeviceTaskData *theDevice, Sink sink, uint16 *length)
{
uint8 *ptr = SinkMap(sink) + SinkClaim(sink, 1);
ptr[0] = theDevice->settings.protocol;
*length = 1;
return TRUE;
}
/*************************************************************************
NAME
appDeviceHidSetReport
DESCRIPTION
Handles SET REPORT request received via USB.
RETURNS
bool
*/
bool appDeviceHidSetReport(appDeviceTaskData *theDevice, int report_length, const uint8 *report_data)
{
/* Check if we are a keyboard */
if (theDevice->dev_class & HID_MINOR_KEYBOARD)
{
/* Check we have report data */
if (report_length > 0)
{
/* Store current LED state */
theDevice->settings.keyboard.led_state = report_data[0];
/* Check if device is connected */
if (appDevGetState(theDevice) == appDevConnected)
{
uint8 report[2];
/* Send report to device */
report[0] = 1; /* Report ID */
report[1] = report_data[0];
HidSetReport(theDevice->hid, hid_report_output, sizeof(report), report);
}
}
/* Indicate sucess */
return TRUE;
}
/* Failed, we don't handle this report */
return FALSE;
}
/*************************************************************************
NAME
appDeviceHidSetIdle
DESCRIPTION
This function handles SET IDLE request received via USB.
RETURNS
bool
*/
bool appDeviceHidSetIdle(appDeviceTaskData *theDevice, uint8 idle_rate)
{
/* KEY 夯靛啊 酒聪骨肺 瘤盔窍瘤 臼澜 */
#if 0
/* Check if we are a keyboard */
if (theDevice->dev_class & HID_MINOR_KEYBOARD)
{
/* Set idle rate */
theDevice->settings.keyboard.idle_rate = idle_rate;
/* Set idle to last requested value */
TransformConfigure(theDevice->transform, VM_TRANSFORM_HID_KEYBOARD_IDLE_RATE, theDevice->settings.keyboard.idle_rate);
/* Indicate success */
return TRUE;
}
#endif
/* We don't support Set Idle */
return FALSE;
}
/*************************************************************************
NAME
appDeviceHidSetProtocol
DESCRIPTION
This function handles SET PROTOCOL request via USB.
The new protocol is just stored, as we send same reports for boot
protocol or report protocol.
USB俊辑 夸没窍绰 橇肺配妮, 盔贰绰 悼老茄 鸥涝阑 傈价窃. 快府绰 促弗 鸥涝 傈价 且 巴烙
RETURNS
bool
*/
bool appDeviceHidSetProtocol(appDeviceTaskData *theDevice, hid_protocol protocol)
{
if(protocol){
return FALSE; /* boot */
}else{
return TRUE; /* normal report */
}
#if 0
/* Store protocol */
theDevice->settings.protocol = protocol;
/* Indicate sucess */
return TRUE;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -