summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2013-07-29 12:15:29 +0200
committerPaul Kocialkowski <contact@paulk.fr>2013-07-29 12:15:29 +0200
commit7f91db2576025429a54729af4516eb5afdb502a4 (patch)
tree1b5306e033143c93059030794180373706d2194c
parent355efe26a63e6df9069e1d9f6ff28eff8718b7a6 (diff)
downloaddevice_samsung_i9300-7f91db2576025429a54729af4516eb5afdb502a4.zip
device_samsung_i9300-7f91db2576025429a54729af4516eb5afdb502a4.tar.gz
device_samsung_i9300-7f91db2576025429a54729af4516eb5afdb502a4.tar.bz2
sensors: Common functions to create/destroy uinput
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rw-r--r--sensors/akm8975.c35
-rw-r--r--sensors/cm36651_light.c1
-rw-r--r--sensors/cm36651_proximity.c1
-rw-r--r--sensors/exynos_sensors.h2
-rw-r--r--sensors/input.c67
-rw-r--r--sensors/lsm330dlc_acceleration.c35
-rw-r--r--sensors/orientation.c35
7 files changed, 78 insertions, 98 deletions
diff --git a/sensors/akm8975.c b/sensors/akm8975.c
index 822ef61..95efb23 100644
--- a/sensors/akm8975.c
+++ b/sensors/akm8975.c
@@ -248,7 +248,6 @@ int akm8975_init(struct exynos_sensors_handlers *handlers,
{
struct akm8975_data *data = NULL;
pthread_attr_t thread_attr;
- struct uinput_user_dev uinput_dev;
char i2c_data[4] = { 0 };
short mode;
int device_fd = -1;
@@ -326,40 +325,12 @@ int akm8975_init(struct exynos_sensors_handlers *handlers,
goto error;
}
- memset(&uinput_dev, 0, sizeof(uinput_dev));
-
- strncpy(uinput_dev.name, "magnetic", sizeof(uinput_dev.name));
- uinput_dev.id.bustype = BUS_I2C;
- uinput_dev.id.vendor = 0;
- uinput_dev.id.product = 0;
- uinput_dev.id.version = 0;
-
- uinput_fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
+ uinput_fd = uinput_rel_create("magnetic");
if (uinput_fd < 0) {
- LOGE("%s: Unable to open uinput device", __func__);
- goto error;
- }
-
- ioctl(uinput_fd, UI_SET_EVBIT, EV_REL);
- ioctl(uinput_fd, UI_SET_RELBIT, REL_X);
- ioctl(uinput_fd, UI_SET_RELBIT, REL_Y);
- ioctl(uinput_fd, UI_SET_RELBIT, REL_Z);
- ioctl(uinput_fd, UI_SET_EVBIT, EV_SYN);
-
- rc = write(uinput_fd, &uinput_dev, sizeof(uinput_dev));
- if (rc < 0) {
- LOGE("%s: Unable to write uinput device", __func__);
- goto error;
- }
-
- rc = ioctl(uinput_fd, UI_DEV_CREATE);
- if (rc < 0) {
- LOGE("%s: Unable to create uinput device", __func__);
+ LOGD("%s: Unable to create uinput", __func__);
goto error;
}
- usleep(3000);
-
input_fd = input_open("magnetic");
if (input_fd < 0) {
LOGE("%s: Unable to open magnetic input", __func__);
@@ -427,7 +398,7 @@ int akm8975_deinit(struct exynos_sensors_handlers *handlers)
pthread_mutex_destroy(&data->mutex);
if (data->uinput_fd >= 0) {
- ioctl(data->uinput_fd, UI_DEV_DESTROY);
+ uinput_destroy(data->uinput_fd);
close(data->uinput_fd);
}
data->uinput_fd = -1;
diff --git a/sensors/cm36651_light.c b/sensors/cm36651_light.c
index a2538f2..90adf75 100644
--- a/sensors/cm36651_light.c
+++ b/sensors/cm36651_light.c
@@ -22,7 +22,6 @@
#include <errno.h>
#include <sys/types.h>
#include <linux/ioctl.h>
-#include <linux/uinput.h>
#include <linux/input.h>
#include <hardware/sensors.h>
diff --git a/sensors/cm36651_proximity.c b/sensors/cm36651_proximity.c
index aae9c1c..96ee663 100644
--- a/sensors/cm36651_proximity.c
+++ b/sensors/cm36651_proximity.c
@@ -22,7 +22,6 @@
#include <errno.h>
#include <sys/types.h>
#include <linux/ioctl.h>
-#include <linux/uinput.h>
#include <linux/input.h>
#include <hardware/sensors.h>
diff --git a/sensors/exynos_sensors.h b/sensors/exynos_sensors.h
index 827e4fa..65aed7f 100644
--- a/sensors/exynos_sensors.h
+++ b/sensors/exynos_sensors.h
@@ -74,6 +74,8 @@ int exynos_sensors_poll(struct sensors_poll_device_t *dev,
void input_event_set(struct input_event *event, int type, int code, int value);
long int timestamp(struct timeval *time);
long int input_timestamp(struct input_event *event);
+int uinput_rel_create(const char *name);
+void uinput_destroy(int uinput_fd);
int input_open(char *name);
int sysfs_path_prefix(char *name, char *path_prefix);
int sysfs_value_read(char *path);
diff --git a/sensors/input.c b/sensors/input.c
index c2e267b..a9a5376 100644
--- a/sensors/input.c
+++ b/sensors/input.c
@@ -23,6 +23,7 @@
#include <dirent.h>
#include <linux/ioctl.h>
#include <linux/input.h>
+#include <linux/uinput.h>
#define LOG_TAG "exynos_sensors"
#include <utils/Log.h>
@@ -59,6 +60,72 @@ long int input_timestamp(struct input_event *event)
return timestamp(&event->time);
}
+int uinput_rel_create(const char *name)
+{
+ struct uinput_user_dev uinput_dev;
+ int uinput_fd;
+ int rc;
+
+ if (name == NULL)
+ return -1;
+
+ uinput_fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
+ if (uinput_fd < 0) {
+ LOGE("%s: Unable to open uinput device", __func__);
+ goto error;
+ }
+
+ memset(&uinput_dev, 0, sizeof(uinput_dev));
+
+ strncpy(uinput_dev.name, name, sizeof(uinput_dev.name));
+ uinput_dev.id.bustype = BUS_I2C;
+ uinput_dev.id.vendor = 0;
+ uinput_dev.id.product = 0;
+ uinput_dev.id.version = 0;
+
+ rc = 0;
+ rc |= ioctl(uinput_fd, UI_SET_EVBIT, EV_REL);
+ rc |= ioctl(uinput_fd, UI_SET_RELBIT, REL_X);
+ rc |= ioctl(uinput_fd, UI_SET_RELBIT, REL_Y);
+ rc |= ioctl(uinput_fd, UI_SET_RELBIT, REL_Z);
+ rc |= ioctl(uinput_fd, UI_SET_EVBIT, EV_SYN);
+
+ if (rc < 0) {
+ LOGE("%s: Unable to set uinput bits", __func__);
+ goto error;
+ }
+
+ rc = write(uinput_fd, &uinput_dev, sizeof(uinput_dev));
+ if (rc < 0) {
+ LOGE("%s: Unable to write uinput device", __func__);
+ goto error;
+ }
+
+ rc = ioctl(uinput_fd, UI_DEV_CREATE);
+ if (rc < 0) {
+ LOGE("%s: Unable to create uinput device", __func__);
+ goto error;
+ }
+
+ usleep(3000);
+
+ return uinput_fd;
+
+error:
+ if (uinput_fd >= 0)
+ close(uinput_fd);
+
+ return -1;
+}
+
+void uinput_destroy(int uinput_fd)
+{
+ if (uinput_fd < 0)
+ return;
+
+ ioctl(uinput_fd, UI_DEV_DESTROY);
+}
+
int input_open(char *name)
{
DIR *d;
diff --git a/sensors/lsm330dlc_acceleration.c b/sensors/lsm330dlc_acceleration.c
index 3642740..4fa0951 100644
--- a/sensors/lsm330dlc_acceleration.c
+++ b/sensors/lsm330dlc_acceleration.c
@@ -119,7 +119,6 @@ int lsm330dlc_acceleration_init(struct exynos_sensors_handlers *handlers,
{
struct lsm330dlc_acceleration_data *data = NULL;
pthread_attr_t thread_attr;
- struct uinput_user_dev uinput_dev;
int device_fd = -1;
int uinput_fd = -1;
int input_fd = -1;
@@ -147,40 +146,12 @@ int lsm330dlc_acceleration_init(struct exynos_sensors_handlers *handlers,
goto error;
}
- memset(&uinput_dev, 0, sizeof(uinput_dev));
-
- strncpy(uinput_dev.name, "acceleration", sizeof(uinput_dev.name));
- uinput_dev.id.bustype = BUS_I2C;
- uinput_dev.id.vendor = 0;
- uinput_dev.id.product = 0;
- uinput_dev.id.version = 0;
-
- uinput_fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
+ uinput_fd = uinput_rel_create("acceleration");
if (uinput_fd < 0) {
- LOGE("%s: Unable to open uinput device", __func__);
- goto error;
- }
-
- ioctl(uinput_fd, UI_SET_EVBIT, EV_REL);
- ioctl(uinput_fd, UI_SET_RELBIT, REL_X);
- ioctl(uinput_fd, UI_SET_RELBIT, REL_Y);
- ioctl(uinput_fd, UI_SET_RELBIT, REL_Z);
- ioctl(uinput_fd, UI_SET_EVBIT, EV_SYN);
-
- rc = write(uinput_fd, &uinput_dev, sizeof(uinput_dev));
- if (rc < 0) {
- LOGE("%s: Unable to write uinput device", __func__);
- goto error;
- }
-
- rc = ioctl(uinput_fd, UI_DEV_CREATE);
- if (rc < 0) {
- LOGE("%s: Unable to create uinput device", __func__);
+ LOGD("%s: Unable to create uinput", __func__);
goto error;
}
- usleep(3000);
-
input_fd = input_open("acceleration");
if (input_fd < 0) {
LOGE("%s: Unable to open acceleration input", __func__);
@@ -246,7 +217,7 @@ int lsm330dlc_acceleration_deinit(struct exynos_sensors_handlers *handlers)
pthread_mutex_destroy(&data->mutex);
if (data->uinput_fd >= 0) {
- ioctl(data->uinput_fd, UI_DEV_DESTROY);
+ uinput_destroy(data->uinput_fd);
close(data->uinput_fd);
}
data->uinput_fd = -1;
diff --git a/sensors/orientation.c b/sensors/orientation.c
index 732fb20..411f537 100644
--- a/sensors/orientation.c
+++ b/sensors/orientation.c
@@ -182,7 +182,6 @@ int orientation_init(struct exynos_sensors_handlers *handlers,
{
struct orientation_data *data = NULL;
pthread_attr_t thread_attr;
- struct uinput_user_dev uinput_dev;
int uinput_fd = -1;
int input_fd = -1;
int rc;
@@ -210,40 +209,12 @@ int orientation_init(struct exynos_sensors_handlers *handlers,
goto error;
}
- memset(&uinput_dev, 0, sizeof(uinput_dev));
-
- strncpy(uinput_dev.name, "orientation", sizeof(uinput_dev.name));
- uinput_dev.id.bustype = BUS_I2C;
- uinput_dev.id.vendor = 0;
- uinput_dev.id.product = 0;
- uinput_dev.id.version = 0;
-
- uinput_fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
+ uinput_fd = uinput_rel_create("orientation");
if (uinput_fd < 0) {
- LOGE("%s: Unable to open uinput device", __func__);
- goto error;
- }
-
- ioctl(uinput_fd, UI_SET_EVBIT, EV_REL);
- ioctl(uinput_fd, UI_SET_RELBIT, REL_X);
- ioctl(uinput_fd, UI_SET_RELBIT, REL_Y);
- ioctl(uinput_fd, UI_SET_RELBIT, REL_Z);
- ioctl(uinput_fd, UI_SET_EVBIT, EV_SYN);
-
- rc = write(uinput_fd, &uinput_dev, sizeof(uinput_dev));
- if (rc < 0) {
- LOGE("%s: Unable to write uinput device", __func__);
- goto error;
- }
-
- rc = ioctl(uinput_fd, UI_DEV_CREATE);
- if (rc < 0) {
- LOGE("%s: Unable to create uinput device", __func__);
+ LOGD("%s: Unable to create uinput", __func__);
goto error;
}
- usleep(3000);
-
input_fd = input_open("orientation");
if (input_fd < 0) {
LOGE("%s: Unable to open orientation input", __func__);
@@ -305,7 +276,7 @@ int orientation_deinit(struct exynos_sensors_handlers *handlers)
pthread_mutex_destroy(&data->mutex);
if (data->uinput_fd >= 0) {
- ioctl(data->uinput_fd, UI_DEV_DESTROY);
+ uinput_destroy(data->uinput_fd);
close(data->uinput_fd);
}
data->uinput_fd = -1;