From f23fda9118a3ec4d5b07949797dd2a5dbc94e127 Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Fri, 8 Mar 2013 15:35:50 +0100 Subject: sensors: Timed poll, don't return 0 events nor more than count Signed-off-by: Paul Kocialkowski --- sensors/bma250.c | 2 +- sensors/piranha_sensors.c | 40 +++++++++++++++++++++++----------------- sensors/piranha_sensors.h | 2 ++ 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 { -- cgit v1.1