21 #include "../ConnexionHID.h" 23 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0501) 25 #define _WIN32_WINNT 0x0601 28 #include <mars/utils/Mutex.h> 29 #include <QApplication> 35 namespace connexion_plugin {
48 RAWINPUTDEVICE sRawInputDevices[1];
49 sRawInputDevices[0].usUsagePage = 0x01;
50 sRawInputDevices[0].usUsage = 0x08;
51 sRawInputDevices[0].dwFlags = 0x00;
52 sRawInputDevices[0].hwndTarget = 0x00;
55 unsigned int uiNumDevices =
sizeof(sRawInputDevices)/
sizeof(sRawInputDevices[0]);
56 unsigned int cbSize =
sizeof(sRawInputDevices[0]);
59 for (i = 0; i < uiNumDevices; ++i) {
60 sRawInputDevices[i].hwndTarget = hwndMessagesWindow;
62 return RegisterRawInputDevices(sRawInputDevices, uiNumDevices, cbSize);
78 HWND handleForMessages = (HWND)windowID;
85 for(
int i = 0; i < 3; ++i) {
90 coordinates[0] = tmpValues.
tx * fabs(tmpValues.
tx * 0.001);
91 coordinates[1] = -tmpValues.
tz * fabs(tmpValues.
tz * 0.001);
92 coordinates[2] = -tmpValues.
ty * fabs(tmpValues.
ty * 0.001);
93 coordinates[3] = tmpValues.
rx * fabs(tmpValues.
rx * 0.0008);
94 coordinates[4] = -tmpValues.
rz * fabs(tmpValues.
rz * 0.0008);
95 coordinates[5] = -tmpValues.
ry * fabs(tmpValues.
ry * 0.0008);
97 if(idleFrameCount[0] > idleThreshold) {
102 if(idleFrameCount[1] > idleThreshold) {
107 if(idleFrameCount[2] > idleThreshold) {
120 MSG *msgStruct = (MSG*) message;
122 if (msgStruct->message == WM_INPUT) {
127 unsigned int dwSize = 0;
129 GetRawInputData((HRAWINPUT)msgStruct->lParam, RID_INPUT, NULL,
130 &dwSize,
sizeof(RAWINPUTHEADER));
132 LPBYTE lpb =
new BYTE[dwSize];
134 if (GetRawInputData((HRAWINPUT)msgStruct->lParam, RID_INPUT,
135 lpb, &dwSize,
sizeof(RAWINPUTHEADER))
141 RAWINPUT* raw = (RAWINPUT*) lpb;
143 if (raw->header.dwType != RIM_TYPEHID) {
148 RID_DEVICE_INFO sRidDeviceInfo;
149 sRidDeviceInfo.cbSize =
sizeof(RID_DEVICE_INFO);
150 dwSize =
sizeof(RID_DEVICE_INFO);
152 if (GetRawInputDeviceInfo(raw->header.hDevice,
155 &dwSize) == dwSize) {
157 if (raw->data.hid.bRawData == 0x01) {
160 short *pnData = reinterpret_cast <
short*> (&raw->data.hid.bRawData + 1);
165 tmpValues.
tx = pnData[0];
166 tmpValues.
ty = pnData[1];
167 tmpValues.
tz = pnData[2];
168 idleFrameCount[0] = 0;
170 }
else if (raw->data.hid.bRawData == 0x02) {
172 short *pnData = reinterpret_cast <
short*> (&raw->data.hid.bRawData + 1);
175 tmpValues.
rx = pnData[0];
176 tmpValues.
ry = pnData[1];
177 tmpValues.
rz = pnData[2];
178 idleFrameCount[1] = 0;
180 }
else if (raw->data.hid.bRawData == 0x03) {
182 unsigned long dwKeyState = *reinterpret_cast <
unsigned long*> (&raw->data.hid.bRawData + 1);
183 if (dwKeyState & 1) {
186 idleFrameCount[2] = 0;
189 if (dwKeyState & 2) {
192 idleFrameCount[2] = 0;
static mars::utils::Mutex valueMutex
static connexionValues tmpValues
int registerRawDevices(HWND hwndMessagesWindow)
void getValue(interfaces::sReal *coordiantes, struct connexionValues *rawValues)
int initConnexionHID(void *windowID)
static int idleFrameCount[3]
#define LOGITECH_VENDOR_ID
bool myEventFilter(void *message, long *result)
Copyright 2012, DFKI GmbH Robotics Innovation Center.
MutexError lock()
locks the Mutex