summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2013-03-08 15:35:50 +0100
committerPaul Kocialkowski <contact@paulk.fr>2013-03-08 15:37:01 +0100
commit3a5c963fcb72dbe5c1c01ca1a4f66de9ed2211db (patch)
treea1adf8a01ecc305bb7acb6025babcd2eeaa17335
parent2ea9f1064e2dc5cc4c922c753922b15a60672475 (diff)
downloaddevice_samsung_p3100-3a5c963fcb72dbe5c1c01ca1a4f66de9ed2211db.zip
device_samsung_p3100-3a5c963fcb72dbe5c1c01ca1a4f66de9ed2211db.tar.gz
device_samsung_p3100-3a5c963fcb72dbe5c1c01ca1a4f66de9ed2211db.tar.bz2
sensors: Timed poll, don't return 0 events nor more than count
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rw-r--r--sensors/bma250.c2
-rw-r--r--sensors/piranha_sensors.c40
-rw-r--r--sensors/piranha_sensors.h2
3 files changed, 26 insertions, 18 deletions
diff --git a/sensors/bma250.c b/sensors/bma250.c
index 09d2f84..d9525cf 100644
--- a/sensors/bma250.c
+++ b/sensors/bma250.c
@@ -243,7 +243,7 @@ int bma250_get_data(struct piranha_sensors_handlers *handlers,
if (flag & FLAG_ALL)
break;
else
- return -EINVAL;
+ return -1;
}
if (input_event.type != EV_ABS)
diff --git a/sensors/piranha_sensors.c b/sensors/piranha_sensors.c
index c1fd534..c08515b 100644
--- a/sensors/piranha_sensors.c
+++ b/sensors/piranha_sensors.c
@@ -137,7 +137,7 @@ int piranha_sensors_poll(struct sensors_poll_device_t *dev,
struct piranha_sensors_device *device;
int i, j;
int c, n;
- int rc;
+ int poll_rc, rc;
// LOGD("%s(%p, %p, %d)", __func__, dev, data, count);
@@ -152,27 +152,33 @@ int piranha_sensors_poll(struct sensors_poll_device_t *dev,
n = 0;
- for (i=0 ; i < device->poll_fds_count ; i++) {
- if (!(device->poll_fds[i].revents & POLLIN))
- continue;
+ do {
+ poll_rc = poll(device->poll_fds, device->poll_fds_count, PIRANHA_POLL_DELAY);
+ if (poll_rc < 0)
+ return -1;
- for (j=0 ; j < device->handlers_count ; j++) {
- if (device->handlers[j] == NULL || device->handlers[j]->poll_fd != device->poll_fds[i].fd || device->handlers[j]->get_data == NULL)
+ for (i=0 ; i < device->poll_fds_count ; i++) {
+ if (!(device->poll_fds[i].revents & POLLIN))
continue;
- rc = device->handlers[j]->get_data(device->handlers[j], &data[n]);
- if (rc < 0) {
- device->poll_fds[i].revents = 0;
- } else {
- n++;
- count--;
+ for (j=0 ; j < device->handlers_count ; j++) {
+ if (device->handlers[j] == NULL || device->handlers[j]->poll_fd != device->poll_fds[i].fd || device->handlers[j]->get_data == NULL)
+ continue;
+
+ rc = device->handlers[j]->get_data(device->handlers[j], &data[n]);
+ if (rc < 0) {
+ device->poll_fds[i].revents = 0;
+ poll_rc = -1;
+ } else {
+ n++;
+ count--;
+ }
}
- }
- }
- rc = poll(device->poll_fds, device->poll_fds_count, n > 0 ? 0 : -1);
- if (rc < 0)
- return -1;
+ if (count <= 0)
+ break;
+ }
+ } while ((poll_rc > 0 || n < 1) && count > 0);
return n;
}
diff --git a/sensors/piranha_sensors.h b/sensors/piranha_sensors.h
index e79f2ce..b93f65e 100644
--- a/sensors/piranha_sensors.h
+++ b/sensors/piranha_sensors.h
@@ -26,6 +26,8 @@
#ifndef _SENSORS_H_
#define _SENSORS_H_
+#define PIRANHA_POLL_DELAY 100
+
struct piranha_sensors_device;
struct piranha_sensors_handlers {