这一篇是关于获取到的数据与虚拟手柄之间通信的过程。首先设置要发送的指令,然后通过WriteFile将指令发送给设备。
DWORD WINAPI SendofBody_left(LPVOID lpParam)
{
DWORD dwWaitResult_Event=1;
static bool mmm=true;
while(true)
{
dwWaitResult_Event=WaitForSingleObject(hEvent_send,INFINITE);
if (dwWaitResult_Event==WAIT_OBJECT_0)
{
*(WORD*)(g_controlreport+LEFTJOYSTICK_X_POS)=nMove_LetfJoystic_X;
*(WORD*)(g_controlreport+LEFTJOYSTICK_Y_POS)=nMove_LetfJoystic_Y;
if (0==nMove_RightJoystic_X)
{
*(UCHAR*)(g_controlreport+Xtion_GamePad_Button)=1;//放氮气
}
*(WORD*)(g_controlreport+LEFTJOYSTICK_X_POS)=nMove_LetfJoystic_X;
*(WORD*)(g_controlreport+LEFTJOYSTICK_Y_POS)=nMove_LetfJoystic_Y;
WriteControlData(g_controlreport);
nMove_LetfJoystic_X=0;
nMove_LetfJoystic_Y=0
nMove_RightJoystic_X=0x80;
nMove_RightJoystic_Y=0x80;
memset(g_controlreport,0,sizeof(g_controlreport));
g_controlreport[0]=REPORTID_CONTROL;
g_controlreport[1]=REPORTLEN_GAMEPAD;
g_controlreport[2]=REPORTID_GAMEPAD;
g_controlreport[6]=0x100;
g_controlreport[7]=0x100;
}
ResetEvent(hEvent_send);
}
}
DWORD WritContorlData(UCHAR* pData)
{
DWORD dwInfo;
WriteFile(g_hControlDevice,g_controlreport,REPORTLEN_CONTROLDEVICE,&dwInfo,NULL);
return GetLastError();
}