summaryrefslogtreecommitdiff
path: root/src/udev/accelerometer/accelerometer.c
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2014-07-08 18:29:06 +0200
committerKay Sievers <kay@vrfy.org>2014-07-08 18:36:53 +0200
commita545c6e1aa31b4d7e80c9d3609d9fc4fc9921498 (patch)
tree5691f9ad71c2f4cb08bdaf016719175687a89298 /src/udev/accelerometer/accelerometer.c
parent9a8c867fecec55998b7a78470aebdede2db0673e (diff)
accelerometer: Don't wait for new data from the sensor
Instead of waiting for new data from the sensor, which might be a long time coming, depending on the sensor device, ask the kernel for the last state for that particular input device.
Diffstat (limited to 'src/udev/accelerometer/accelerometer.c')
-rw-r--r--src/udev/accelerometer/accelerometer.c33
1 files changed, 6 insertions, 27 deletions
diff --git a/src/udev/accelerometer/accelerometer.c b/src/udev/accelerometer/accelerometer.c
index 925d38de1f..32adf27777 100644
--- a/src/udev/accelerometer/accelerometer.c
+++ b/src/udev/accelerometer/accelerometer.c
@@ -180,7 +180,7 @@ get_prev_orientation(struct udev_device *dev)
return string_to_orientation(value);
}
-#define SET_AXIS(axis, code_) if (ev[i].code == code_) { if (got_##axis == 0) { axis = ev[i].value; got_##axis = true; } }
+#define READ_AXIS(axis, var) { memzero(&abs_info, sizeof(abs_info)); r = ioctl(fd, EVIOCGABS(axis), &abs_info); if (r < 0) return; var = abs_info.value; }
/* accelerometers */
static void test_orientation(struct udev *udev,
@@ -189,10 +189,9 @@ static void test_orientation(struct udev *udev,
{
OrientationUp old, new;
_cleanup_close_ int fd = -1;
- struct input_event ev[64];
- bool got_syn = false;
- bool got_x = false, got_y = false, got_z = false;
+ struct input_absinfo abs_info;
int x = 0, y = 0, z = 0;
+ int r;
char text[64];
old = get_prev_orientation(dev);
@@ -201,30 +200,10 @@ static void test_orientation(struct udev *udev,
if (fd < 0)
return;
- while (1) {
- int i, r;
-
- r = read(fd, ev, sizeof(struct input_event) * 64);
-
- if (r < (int) sizeof(struct input_event))
- return;
-
- for (i = 0; i < r / (int) sizeof(struct input_event); i++) {
- if (got_syn) {
- if (ev[i].type == EV_ABS) {
- SET_AXIS(x, ABS_X);
- SET_AXIS(y, ABS_Y);
- SET_AXIS(z, ABS_Z);
- }
- }
- if (ev[i].type == EV_SYN && ev[i].code == SYN_REPORT)
- got_syn = true;
- if (got_x && got_y && got_z)
- goto read_dev;
- }
- }
+ READ_AXIS(ABS_X, x);
+ READ_AXIS(ABS_Y, y);
+ READ_AXIS(ABS_Z, z);
-read_dev:
new = orientation_calc(old, x, y, z);
snprintf(text, sizeof(text),
"ID_INPUT_ACCELEROMETER_ORIENTATION=%s", orientation_to_string(new));