diff options
author | Javi Ferrer <javi.f.o@gmail.com> | 2015-05-12 19:40:59 +0200 |
---|---|---|
committer | forkbomb <keepcalm444@gmail.com> | 2015-11-25 08:33:40 +1100 |
commit | 948970715990bde9caf07377f928530848d19a36 (patch) | |
tree | 8ed27e6116225749dab0ac6de29b640e9617bfab /libsensors/lps331ap.c | |
parent | ef3bca4b0959df074d5b0867b95699c330b5779e (diff) | |
download | device_samsung_i9300-948970715990bde9caf07377f928530848d19a36.zip device_samsung_i9300-948970715990bde9caf07377f928530848d19a36.tar.gz device_samsung_i9300-948970715990bde9caf07377f928530848d19a36.tar.bz2 |
i9300: update libsensors from replicant
- Orientation sensor still broken
Change-Id: I7d20afbbc1f8b1ca5d046a38c0c3b7ce824c12cd
Diffstat (limited to 'libsensors/lps331ap.c')
-rw-r--r-- | libsensors/lps331ap.c | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/libsensors/lps331ap.c b/libsensors/lps331ap.c index aed233d..5c3007b 100644 --- a/libsensors/lps331ap.c +++ b/libsensors/lps331ap.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Paul Kocialkowski + * Copyright (C) 2013 Paul Kocialkowski <contact@paulk.fr> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,26 +20,26 @@ #include <stdint.h> #include <fcntl.h> #include <errno.h> +#include <math.h> #include <sys/types.h> #include <linux/ioctl.h> -#include <linux/uinput.h> #include <linux/input.h> #include <hardware/sensors.h> #include <hardware/hardware.h> -#define LOG_TAG "exynos_sensors" +#define LOG_TAG "smdk4x12_sensors" #include <utils/Log.h> -#include "exynos_sensors.h" +#include "smdk4x12_sensors.h" struct lps331ap_data { char path_enable[PATH_MAX]; char path_delay[PATH_MAX]; }; -int lps331ap_init(struct exynos_sensors_handlers *handlers, - struct exynos_sensors_device *device) +int lps331ap_init(struct smdk4x12_sensors_handlers *handlers, + struct smdk4x12_sensors_device *device) { struct lps331ap_data *data = NULL; char path[PATH_MAX] = { 0 }; @@ -86,7 +86,7 @@ error: return -1; } -int lps331ap_deinit(struct exynos_sensors_handlers *handlers) +int lps331ap_deinit(struct smdk4x12_sensors_handlers *handlers) { ALOGD("%s(%p)", __func__, handlers); @@ -104,8 +104,7 @@ int lps331ap_deinit(struct exynos_sensors_handlers *handlers) return 0; } - -int lps331ap_activate(struct exynos_sensors_handlers *handlers) +int lps331ap_activate(struct smdk4x12_sensors_handlers *handlers) { struct lps331ap_data *data; int rc; @@ -128,7 +127,7 @@ int lps331ap_activate(struct exynos_sensors_handlers *handlers) return 0; } -int lps331ap_deactivate(struct exynos_sensors_handlers *handlers) +int lps331ap_deactivate(struct smdk4x12_sensors_handlers *handlers) { struct lps331ap_data *data; int rc; @@ -151,9 +150,10 @@ int lps331ap_deactivate(struct exynos_sensors_handlers *handlers) return 0; } -int lps331ap_set_delay(struct exynos_sensors_handlers *handlers, long int delay) +int lps331ap_set_delay(struct smdk4x12_sensors_handlers *handlers, long int delay) { struct lps331ap_data *data; + int d; int rc; ALOGD("%s(%p, %ld)", __func__, handlers, delay); @@ -163,7 +163,12 @@ int lps331ap_set_delay(struct exynos_sensors_handlers *handlers, long int delay) data = (struct lps331ap_data *) handlers->data; - rc = sysfs_value_write(data->path_delay, (int) delay / 1000000); + if (delay < 10000000) + d = 10; + else + d = delay / 1000000; + + rc = sysfs_value_write(data->path_delay, d); if (rc < 0) { ALOGE("%s: Unable to write sysfs value", __func__); return -1; @@ -174,10 +179,10 @@ int lps331ap_set_delay(struct exynos_sensors_handlers *handlers, long int delay) float lps331ap_convert(int value) { - return (float) value / 4096.0f; + return value / 4096.0f; } -int lps331ap_get_data(struct exynos_sensors_handlers *handlers, +int lps331ap_get_data(struct smdk4x12_sensors_handlers *handlers, struct sensors_event_t *event) { struct input_event input_event; @@ -193,6 +198,7 @@ int lps331ap_get_data(struct exynos_sensors_handlers *handlers, if (input_fd < 0) return -EINVAL; + memset(event, 0, sizeof(struct sensors_event_t)); event->version = sizeof(struct sensors_event_t); event->sensor = handlers->handle; event->type = handlers->handle; @@ -203,18 +209,27 @@ int lps331ap_get_data(struct exynos_sensors_handlers *handlers, break; if (input_event.type == EV_REL) { - if (input_event.code == REL_X) - event->pressure = lps331ap_convert(input_event.value); + switch (input_event.code) { + case REL_X: + event->pressure = lps331ap_convert(input_event.value); + break; + default: + continue; + } } else if (input_event.type == EV_SYN) { - if (input_event.code == SYN_REPORT) + if (input_event.code == SYN_REPORT && event->pressure != 0) { event->timestamp = input_timestamp(&input_event); + break; + } else { + return -1; + } } - } while (input_event.type != EV_SYN); + } while (1); return 0; } -struct exynos_sensors_handlers lps331ap = { +struct smdk4x12_sensors_handlers lps331ap = { .name = "LPS331AP", .handle = SENSOR_TYPE_PRESSURE, .init = lps331ap_init, |