aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/accelerometers.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/accelerometers.c b/src/accelerometers.c
index a285574..14921c6 100644
--- a/src/accelerometers.c
+++ b/src/accelerometers.c
@@ -77,7 +77,7 @@ AccelHandle *accelerometer_open() {
return accel;
}
- accel->fd = open("/dev/input/event3", O_RDONLY, O_NONBLOCK);
+ accel->fd = open("/dev/input/event3", O_RDONLY, 0);
if ( accel->fd != -1 ) {
accel->type = ACCEL_FREERUNNER;
printf("Neo Freerunner detected\n");
@@ -139,10 +139,22 @@ int accelerometer_moo_freerunner(AccelHandle *accel) {
fd_set fds;
struct timeval t;
- rval = read(accel->fd, &ev, sizeof(ev));
- if ( rval != sizeof(ev) ) {
- fprintf(stderr, "Couldn't read accelerometer data");
- return 0;
+ FD_ZERO(&fds);
+ FD_SET(accel->fd, &fds);
+ t.tv_sec = 0;
+ t.tv_usec = 0;
+ select(1+accel->fd, &fds, NULL, NULL, &t);
+
+ if ( FD_ISSET(accel->fd, &fds) ) {
+
+ rval = read(accel->fd, &ev, sizeof(ev));
+ if ( rval != sizeof(ev) ) {
+ fprintf(stderr, "Couldn't read accelerometer data");
+ return 0;
+ }
+
+ } else {
+ return 0; /* No data */
}
if ( ev.type == EV_REL ) {