- fd_set readset;
- struct timeval timeout;
-
- int num_warnings = 0;
- int result, iof = -1;
-
- /* enter thread loop */
- while (!stop_me) {
- /* reset the read set */
- FD_ZERO(&readset);
- FD_SET(fd, &readset);
-
- /* reinit the timeout structure */
- timeout.tv_sec = 0;
- timeout.tv_usec = 300000; /* 300 ms */
-
- /* do the select */
- result = select(fd+1, &readset, NULL, NULL, &timeout);
-
- /* see if there was an error or timeout */
- if (result < 0) {
-// perror("select failed");
- } else if (result == 0) {
-// puts("TIMEOUT");
- } else {
- /* we have input */
- if (FD_ISSET(fd, &readset)) {
- /* get fd settings */
- if ((iof = fcntl(fd, F_GETFL, 0)) != -1) {
- /* set fd non blocking */
- fcntl(fd, F_SETFL, iof | O_NONBLOCK);
- /* read input */
+ if (ioctl(fd, EVIOCGRAB, 1) < 0) {
+ fprintf(stderr, "Can't get exclusive access on Jog Shuttle FILE DESCRIPTOR\n");
+ close(fd);
+ return;
+ }
+
+ fd_set readset;
+ struct timeval timeout;
+
+ int num_warnings = 0;
+ int result, iof = -1;
+
+ /* enter thread loop */
+ while (!stop_me) {
+ /* reset the read set */
+ FD_ZERO(&readset);
+ FD_SET(fd, &readset);
+
+ /* reinit the timeout structure */
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 300000; /* 300 ms */
+
+ /* do the select */
+ result = select(fd+1, &readset, NULL, NULL, &timeout);
+
+ /* see if there was an error or timeout */
+ if (result < 0) {
+ // perror("select failed");
+ } else if (result == 0) {
+ //puts("TIMEOUT");
+ } else {
+ /* we have input */
+ if (FD_ISSET(fd, &readset)) {
+ /* get fd settings */
+ if ((iof = fcntl(fd, F_GETFL, 0)) != -1) {
+ /* set fd non blocking */
+ fcntl(fd, F_SETFL, iof | O_NONBLOCK);
+ /* read input */