21 #include "../ConnexionHID.h" 23 #include <mars/interfaces/MARSDefs.h> 25 #include <linux/input.h> 33 #define PATH_BUFFER_SIZE (1024) 38 namespace connexion_plugin {
51 struct input_id device_info;
52 const char *devDirectory =
"/dev/input/";
55 dp = opendir(devDirectory);
60 while((entry = readdir(dp))) {
61 strncpy(path, devDirectory,
sizeof(path));
66 strncat(path, entry->d_name,
sizeof(path));
68 fd = open(path, O_RDONLY | O_NONBLOCK);
75 if(!ioctl(fd, EVIOCGID, &device_info)) {
88 "ERROR: could not find SpaceMouse! \n" 89 " Do you have read permission on the /dev/input/ device?\n");
122 struct input_event events[64];
128 bytesRead = read(fd, events,
sizeof(
struct input_event) * 64);
129 eventCnt = (int) ((
long)bytesRead / (long)
sizeof(
struct input_event));
130 if (bytesRead < (
int)
sizeof(
struct input_event)) {
131 perror(
"evtest: short read");
136 for(i = 0; i < 6; ++i) {
141 for(i = 0; i < eventCnt; ++i) {
142 if(EV_KEY == events[i].type) {
143 switch(events[i].code) {
145 rawValues->
button1 = events[i].value;
148 rawValues->
button2 = events[i].value;
151 }
else if(EV_REL == events[i].type || EV_ABS == events[i].type) {
152 switch(events[i].code) {
154 rawValues->
tx = events[i].value;
155 idleFrameCount[0] = 0;
158 rawValues->
ty = events[i].value;
159 idleFrameCount[1] = 0;
162 rawValues->
tz = events[i].value;
163 idleFrameCount[2] = 0;
166 rawValues->
rx = events[i].value;
167 idleFrameCount[3] = 0;
170 rawValues->
ry = events[i].value;
171 idleFrameCount[4] = 0;
174 rawValues->
rz = events[i].value;
175 idleFrameCount[5] = 0;
182 for(i = 0; i < 6; ++i) {
183 if(idleFrameCount[i] >= idleThreshold) {
200 coordinates[0] = rawValues->
tx * fabs(rawValues->
tx * 0.001);
201 coordinates[1] = -rawValues->
tz * fabs(rawValues->
tz * 0.001);
202 coordinates[2] = -rawValues->
ty * fabs(rawValues->
ty * 0.001);
203 coordinates[3] = rawValues->
rx * fabs(rawValues->
rx * 0.0008);
204 coordinates[4] = -rawValues->
rz * fabs(rawValues->
rz * 0.0008);
205 coordinates[5] = -rawValues->
ry * fabs(rawValues->
ry * 0.0008);
static int getFileDescriptor()
void getValue(interfaces::sReal *coordiantes, struct connexionValues *rawValues)
#define LOGITECH_SPACE_NAVIGATOR_DEVICE_ID
int initConnexionHID(void *windowID)
static int idleFrameCount[3]
#define LOGITECH_VENDOR_ID
Copyright 2012, DFKI GmbH Robotics Innovation Center.