summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--BoardConfig.mk3
-rw-r--r--sensors/Android.mk3
-rw-r--r--sensors/akm8963.c30
-rw-r--r--sensors/bmp180.c7
-rw-r--r--sensors/cm36651_light.c9
-rw-r--r--sensors/cm36651_proximity.c7
-rw-r--r--sensors/input.c16
-rw-r--r--sensors/lsm330dlc_acceleration.c20
-rw-r--r--sensors/lsm330dlc_gyroscope.c11
-rw-r--r--sensors/orientation.c444
-rw-r--r--sensors/smdk4x12_sensors.c33
-rw-r--r--sensors/smdk4x12_sensors.h17
-rw-r--r--sensors/ssp.h1
13 files changed, 70 insertions, 531 deletions
diff --git a/BoardConfig.mk b/BoardConfig.mk
index 456d709..85b1da8 100644
--- a/BoardConfig.mk
+++ b/BoardConfig.mk
@@ -49,9 +49,6 @@ TARGET_RECOVERY_FSTAB := device/samsung/n7100/rootdir/fstab.smdk4x12
TARGET_USERIMAGES_USE_F2FS := true
RECOVERY_FSTAB_VERSION := 2
-# Compatibility with pre-kitkat Sensor HALs
-SENSORS_NEED_SETRATE_ON_ENABLE := true
-
# Selinux
BOARD_SEPOLICY_DIRS += \
device/samsung/n7100/selinux
diff --git a/sensors/Android.mk b/sensors/Android.mk
index ab30bf0..9d7dde2 100644
--- a/sensors/Android.mk
+++ b/sensors/Android.mk
@@ -20,7 +20,6 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
smdk4x12_sensors.c \
input.c \
- orientation.c \
ssp.c \
akm8963.c \
cm36651_proximity.c \
@@ -35,7 +34,7 @@ LOCAL_C_INCLUDES := \
LOCAL_SHARED_LIBRARIES := libutils libcutils liblog libhardware
LOCAL_PRELINK_MODULE := false
-LOCAL_MODULE := sensors.smdk4x12
+LOCAL_MODULE := sensors.$(TARGET_BOOTLOADER_BOARD_NAME)
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_MODULE_TAGS := optional
diff --git a/sensors/akm8963.c b/sensors/akm8963.c
index d5cad3f..c3a1851 100644
--- a/sensors/akm8963.c
+++ b/sensors/akm8963.c
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <fcntl.h>
#include <errno.h>
+#include <string.h>
#include <hardware/sensors.h>
#include <hardware/hardware.h>
@@ -33,7 +34,6 @@
#define AKM8963_CONFIG_PATH "/data/misc/akmd_set.txt"
struct akm8963_data {
- struct smdk4x12_sensors_handlers *orientation_sensor;
sensors_vec_t magnetic;
short magnetic_data[4][3];
@@ -44,7 +44,7 @@ struct akm8963_data {
unsigned char asa[3];
int ho[3];
- long int delay;
+ int64_t delay;
int device_fd;
int uinput_fd;
@@ -363,6 +363,8 @@ void *akm8963_thread(void *thread_data)
write(uinput_fd, &event, sizeof(event));
input_event_set(&event, EV_REL, REL_Z, (int) (data->magnetic.z * 1000));
write(uinput_fd, &event, sizeof(event));
+ input_event_set(&event, EV_REL, REL_MISC, (int) data->magnetic.status);
+ write(uinput_fd, &event, sizeof(event));
input_event_set(&event, EV_SYN, 0, 0);
write(uinput_fd, &event, sizeof(event));
@@ -398,14 +400,6 @@ int akm8963_init(struct smdk4x12_sensors_handlers *handlers,
data = (struct akm8963_data *) calloc(1, sizeof(struct akm8963_data));
- for (i = 0; i < device->handlers_count; i++) {
- if (device->handlers[i] == NULL)
- continue;
-
- if (device->handlers[i]->handle == SENSOR_TYPE_ORIENTATION)
- data->orientation_sensor = device->handlers[i];
- }
-
device_fd = open("/dev/akm8963", O_RDONLY);
if (device_fd < 0) {
ALOGE("%s: Unable to open device", __func__);
@@ -421,13 +415,13 @@ int akm8963_init(struct smdk4x12_sensors_handlers *handlers,
ALOGD("AKM8963 ASA (Sensitivity Adjustment) values are: (%d, %d, %d)",
data->asa[0], data->asa[1], data->asa[2]);
- uinput_fd = uinput_rel_create("magnetic");
+ uinput_fd = uinput_rel_create("magnetic_sensor");
if (uinput_fd < 0) {
ALOGD("%s: Unable to create uinput", __func__);
goto error;
}
- input_fd = input_open("magnetic");
+ input_fd = input_open("magnetic_sensor");
if (input_fd < 0) {
ALOGE("%s: Unable to open magnetic input", __func__);
goto error;
@@ -581,13 +575,13 @@ int akm8963_deactivate(struct smdk4x12_sensors_handlers *handlers)
return 0;
}
-int akm8963_set_delay(struct smdk4x12_sensors_handlers *handlers, long int delay)
+int akm8963_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay)
{
struct akm8963_data *data;
char path_delay[PATH_MAX] = "/sys/class/sensors/ssp_sensor/mag_poll_delay";
int rc;
- ALOGD("%s(%p, %ld)", __func__, handlers, delay);
+ ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay);
if (handlers == NULL || handlers->data == NULL)
return -EINVAL;
@@ -634,8 +628,6 @@ int akm8963_get_data(struct smdk4x12_sensors_handlers *handlers,
event->sensor = handlers->handle;
event->type = handlers->handle;
- event->magnetic.status = SENSOR_STATUS_ACCURACY_MEDIUM;
-
do {
rc = read(input_fd, &input_event, sizeof(input_event));
if (rc < (int) sizeof(input_event))
@@ -652,6 +644,9 @@ int akm8963_get_data(struct smdk4x12_sensors_handlers *handlers,
case REL_Z:
event->magnetic.z = akm8963_convert(input_event.value);
break;
+ case REL_MISC:
+ event->magnetic.status = input_event.value;
+ break;
default:
continue;
}
@@ -661,9 +656,6 @@ int akm8963_get_data(struct smdk4x12_sensors_handlers *handlers,
}
} while (input_event.type != EV_SYN);
- if (data->orientation_sensor != NULL)
- orientation_fill(data->orientation_sensor, NULL, &event->magnetic);
-
return 0;
}
diff --git a/sensors/bmp180.c b/sensors/bmp180.c
index c50474c..909480a 100644
--- a/sensors/bmp180.c
+++ b/sensors/bmp180.c
@@ -21,6 +21,7 @@
#include <fcntl.h>
#include <errno.h>
#include <math.h>
+#include <string.h>
#include <sys/types.h>
#include <linux/ioctl.h>
#include <linux/input.h>
@@ -65,7 +66,7 @@ int bmp180_init(struct smdk4x12_sensors_handlers *handlers,
goto error;
}
- snprintf(data->path_delay, PATH_MAX, "%s/pressure_poll_delay", path);
+ snprintf(data->path_delay, PATH_MAX, "%s/poll_delay", path);
handlers->poll_fd = input_fd;
handlers->data = (void *) data;
@@ -149,12 +150,12 @@ int bmp180_deactivate(struct smdk4x12_sensors_handlers *handlers)
return 0;
}
-int bmp180_set_delay(struct smdk4x12_sensors_handlers *handlers, long int delay)
+int bmp180_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay)
{
struct bmp180_data *data;
int rc;
- ALOGD("%s(%p, %ld)", __func__, handlers, delay);
+ ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay);
if (handlers == NULL || handlers->data == NULL)
return -EINVAL;
diff --git a/sensors/cm36651_light.c b/sensors/cm36651_light.c
index 421a276..8d37b54 100644
--- a/sensors/cm36651_light.c
+++ b/sensors/cm36651_light.c
@@ -21,6 +21,7 @@
#include <fcntl.h>
#include <errno.h>
#include <math.h>
+#include <string.h>
#include <sys/types.h>
#include <linux/ioctl.h>
#include <linux/input.h>
@@ -65,7 +66,7 @@ int cm36651_light_init(struct smdk4x12_sensors_handlers *handlers,
goto error;
}
- snprintf(data->path_delay, PATH_MAX, "%s/light_poll_delay", path);
+ snprintf(data->path_delay, PATH_MAX, "%s/poll_delay", path);
handlers->poll_fd = input_fd;
handlers->data = (void *) data;
@@ -149,19 +150,19 @@ int cm36651_light_deactivate(struct smdk4x12_sensors_handlers *handlers)
return 0;
}
-int cm36651_light_set_delay(struct smdk4x12_sensors_handlers *handlers, long int delay)
+int cm36651_light_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay)
{
struct cm36651_light_data *data;
int rc;
- ALOGD("%s(%p, %ld)", __func__, handlers, delay);
+ ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay);
if (handlers == NULL || handlers->data == NULL)
return -EINVAL;
data = (struct cm36651_light_data *) handlers->data;
- rc = sysfs_value_write(data->path_delay, (int) delay);
+ rc = sysfs_value_write(data->path_delay, delay);
if (rc < 0) {
ALOGE("%s: Unable to write sysfs value", __func__);
return -1;
diff --git a/sensors/cm36651_proximity.c b/sensors/cm36651_proximity.c
index 108f00b..163042a 100644
--- a/sensors/cm36651_proximity.c
+++ b/sensors/cm36651_proximity.c
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <fcntl.h>
#include <errno.h>
+#include <string.h>
#include <sys/types.h>
#include <linux/ioctl.h>
#include <linux/input.h>
@@ -64,7 +65,7 @@ int cm36651_proximity_init(struct smdk4x12_sensors_handlers *handlers,
goto error;
}
- snprintf(data->path_delay, PATH_MAX, "%s/prox_poll_delay", path);
+ snprintf(data->path_delay, PATH_MAX, "%s/poll_delay", path);
handlers->poll_fd = input_fd;
handlers->data = (void *) data;
@@ -148,12 +149,12 @@ int cm36651_proximity_deactivate(struct smdk4x12_sensors_handlers *handlers)
return 0;
}
-int cm36651_proximity_set_delay(struct smdk4x12_sensors_handlers *handlers, long int delay)
+int cm36651_proximity_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay)
{
struct cm36651_proximity_data *data;
int rc;
- ALOGD("%s(%p, %ld)", __func__, handlers, delay);
+ ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay);
if (handlers == NULL || handlers->data == NULL)
return -EINVAL;
diff --git a/sensors/input.c b/sensors/input.c
index 5199b28..a370807 100644
--- a/sensors/input.c
+++ b/sensors/input.c
@@ -21,6 +21,7 @@
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
+#include <string.h>
#include <linux/ioctl.h>
#include <linux/input.h>
#include <linux/uinput.h>
@@ -44,7 +45,7 @@ void input_event_set(struct input_event *event, int type, int code, int value)
gettimeofday(&event->time, NULL);
}
-long int timestamp(struct timeval *time)
+int64_t timestamp(struct timeval *time)
{
if (time == NULL)
return -1;
@@ -52,7 +53,7 @@ long int timestamp(struct timeval *time)
return time->tv_sec * 1000000000LL + time->tv_usec * 1000;
}
-long int input_timestamp(struct input_event *event)
+int64_t input_timestamp(struct input_event *event)
{
if (event == NULL)
return -1;
@@ -88,6 +89,7 @@ int uinput_rel_create(const char *name)
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_RELBIT, REL_MISC);
rc |= ioctl(uinput_fd, UI_SET_EVBIT, EV_SYN);
if (rc < 0) {
@@ -213,10 +215,10 @@ int sysfs_path_prefix(char *name, char *path_prefix)
return -1;
}
-int sysfs_value_read(char *path)
+int64_t sysfs_value_read(char *path)
{
char buffer[100];
- int value;
+ int64_t value;
int fd = -1;
int rc;
int i;
@@ -236,7 +238,7 @@ int sysfs_value_read(char *path)
while (buffer[i] == ' ' || buffer[i] == '\t')
i++;
- value = atoi(&buffer[i]);
+ value = (int64_t)strtoimax(&buffer[i], NULL, 10);
goto complete;
error:
@@ -249,7 +251,7 @@ complete:
return value;
}
-int sysfs_value_write(char *path, int value)
+int sysfs_value_write(char *path, int64_t value)
{
char buffer[100];
int fd = -1;
@@ -262,7 +264,7 @@ int sysfs_value_write(char *path, int value)
if (fd < 0)
goto error;
- snprintf((char *) &buffer, sizeof(buffer), "%d\n", value);
+ snprintf((char *) &buffer, sizeof(buffer), "%" PRId64 "\n", value);
rc = write(fd, buffer, strlen(buffer));
if (rc < (int) strlen(buffer))
diff --git a/sensors/lsm330dlc_acceleration.c b/sensors/lsm330dlc_acceleration.c
index efb0388..5e571c7 100644
--- a/sensors/lsm330dlc_acceleration.c
+++ b/sensors/lsm330dlc_acceleration.c
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <fcntl.h>
#include <errno.h>
+#include <string.h>
#include <hardware/sensors.h>
#include <hardware/hardware.h>
@@ -31,8 +32,6 @@
#include "ssp.h"
struct lsm330dlc_acceleration_data {
- struct smdk4x12_sensors_handlers *orientation_sensor;
-
char path_delay[PATH_MAX];
sensors_vec_t acceleration;
@@ -54,14 +53,6 @@ int lsm330dlc_acceleration_init(struct smdk4x12_sensors_handlers *handlers,
data = (struct lsm330dlc_acceleration_data *) calloc(1, sizeof(struct lsm330dlc_acceleration_data));
- for (i = 0; i < device->handlers_count; i++) {
- if (device->handlers[i] == NULL)
- continue;
-
- if (device->handlers[i]->handle == SENSOR_TYPE_ORIENTATION)
- data->orientation_sensor = device->handlers[i];
- }
-
input_fd = input_open("accelerometer_sensor");
if (input_fd < 0) {
ALOGE("%s: Unable to open input", __func__);
@@ -74,7 +65,7 @@ int lsm330dlc_acceleration_init(struct smdk4x12_sensors_handlers *handlers,
goto error;
}
- snprintf(data->path_delay, PATH_MAX, "%s/acc_poll_delay", path);
+ snprintf(data->path_delay, PATH_MAX, "%s/poll_delay", path);
handlers->poll_fd = input_fd;
handlers->data = (void *) data;
@@ -158,12 +149,12 @@ int lsm330dlc_acceleration_deactivate(struct smdk4x12_sensors_handlers *handlers
return 0;
}
-int lsm330dlc_acceleration_set_delay(struct smdk4x12_sensors_handlers *handlers, long int delay)
+int lsm330dlc_acceleration_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay)
{
struct lsm330dlc_acceleration_data *data;
int rc;
- ALOGD("%s(%p, %ld)", __func__, handlers, delay);
+ ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay);
if (handlers == NULL || handlers->data == NULL)
return -EINVAL;
@@ -243,9 +234,6 @@ int lsm330dlc_acceleration_get_data(struct smdk4x12_sensors_handlers *handlers,
data->acceleration.y = event->acceleration.y;
data->acceleration.z = event->acceleration.z;
- if (data->orientation_sensor != NULL)
- orientation_fill(data->orientation_sensor, &event->acceleration, NULL);
-
return 0;
}
diff --git a/sensors/lsm330dlc_gyroscope.c b/sensors/lsm330dlc_gyroscope.c
index da2d81d..ffc0037 100644
--- a/sensors/lsm330dlc_gyroscope.c
+++ b/sensors/lsm330dlc_gyroscope.c
@@ -21,6 +21,7 @@
#include <fcntl.h>
#include <errno.h>
#include <math.h>
+#include <string.h>
#include <sys/types.h>
#include <linux/ioctl.h>
#include <linux/input.h>
@@ -67,7 +68,7 @@ int lsm330dlc_gyroscope_init(struct smdk4x12_sensors_handlers *handlers,
goto error;
}
- snprintf(data->path_delay, PATH_MAX, "%s/gyro_poll_delay", path);
+ snprintf(data->path_delay, PATH_MAX, "%s/poll_delay", path);
handlers->poll_fd = input_fd;
handlers->data = (void *) data;
@@ -151,19 +152,19 @@ int lsm330dlc_gyroscope_deactivate(struct smdk4x12_sensors_handlers *handlers)
return 0;
}
-int lsm330dlc_gyroscope_set_delay(struct smdk4x12_sensors_handlers *handlers, long int delay)
+int lsm330dlc_gyroscope_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay)
{
struct lsm330dlc_gyroscope_data *data;
int rc;
- ALOGD("%s(%p, %ld)", __func__, handlers, delay);
+ ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay);
if (handlers == NULL || handlers->data == NULL)
return -EINVAL;
data = (struct lsm330dlc_gyroscope_data *) handlers->data;
- rc = sysfs_value_write(data->path_delay, (int) delay);
+ rc = sysfs_value_write(data->path_delay, delay);
if (rc < 0) {
ALOGE("%s: Unable to write sysfs value", __func__);
return -1;
@@ -205,6 +206,8 @@ int lsm330dlc_gyroscope_get_data(struct smdk4x12_sensors_handlers *handlers,
event->gyro.y = data->gyro.y;
event->gyro.z = data->gyro.z;
+ event->gyro.status = SENSOR_STATUS_ACCURACY_MEDIUM;
+
do {
rc = read(input_fd, &input_event, sizeof(input_event));
if (rc < (int) sizeof(input_event))
diff --git a/sensors/orientation.c b/sensors/orientation.c
deleted file mode 100644
index e3529bd..0000000
--- a/sensors/orientation.c
+++ /dev/null
@@ -1,444 +0,0 @@
-/*
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <stddef.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <math.h>
-#include <linux/ioctl.h>
-#include <linux/uinput.h>
-#include <linux/input.h>
-
-#include <hardware/sensors.h>
-#include <hardware/hardware.h>
-
-#define LOG_TAG "smdk4x12_sensors"
-#include <utils/Log.h>
-
-#include "smdk4x12_sensors.h"
-
-struct orientation_data {
- struct smdk4x12_sensors_handlers *acceleration_sensor;
- struct smdk4x12_sensors_handlers *magnetic_sensor;
-
- sensors_vec_t orientation;
- sensors_vec_t acceleration;
- sensors_vec_t magnetic;
-
- long int delay;
- int uinput_fd;
-
- pthread_t thread;
- pthread_mutex_t mutex;
- int thread_continue;
-};
-
-static float rad2deg(float v)
-{
- return (v * 180.0f / 3.1415926535f);
-}
-
-static float vector_scalar(sensors_vec_t *v, sensors_vec_t *d)
-{
- return v->x * d->x + v->y * d->y + v->z * d->z;
-}
-
-static float vector_length(sensors_vec_t *v)
-{
- return sqrtf(vector_scalar(v, v));
-}
-
-void orientation_calculate(sensors_vec_t *a, sensors_vec_t *m, sensors_vec_t *o)
-{
- float azimuth, pitch, roll;
- float la, sinp, cosp, sinr, cosr, x, y;
-
- if (a == NULL || m == NULL || o == NULL)
- return;
-
- la = vector_length(a);
- pitch = asinf(-(a->y) / la);
- roll = asinf((a->x) / la);
-
- sinp = sinf(pitch);
- cosp = cosf(pitch);
- sinr = sinf(roll);
- cosr = cosf(roll);
-
- y = -(m->x) * cosr + m->z * sinr;
- x = m->x * sinp * sinr + m->y * cosp + m->z * sinp * cosr;
- azimuth = atan2f(y, x);
-
- o->azimuth = rad2deg(azimuth);
- o->pitch = rad2deg(pitch);
- o->roll = rad2deg(roll);
-
- if (o->azimuth < 0)
- o->azimuth += 360.0f;
-}
-
-void *orientation_thread(void *thread_data)
-{
- struct smdk4x12_sensors_handlers *handlers = NULL;
- struct orientation_data *data = NULL;
- struct input_event event;
- struct timeval time;
- long int before, after;
- int diff;
- int uinput_fd;
-
- if (thread_data == NULL)
- return NULL;
-
- handlers = (struct smdk4x12_sensors_handlers *) thread_data;
- if (handlers->data == NULL)
- return NULL;
-
- data = (struct orientation_data *) handlers->data;
-
- uinput_fd = data->uinput_fd;
- if (uinput_fd < 0)
- return NULL;
-
- while (data->thread_continue) {
- pthread_mutex_lock(&data->mutex);
- if (!data->thread_continue)
- break;
-
- while (handlers->activated) {
- gettimeofday(&time, NULL);
- before = timestamp(&time);
-
- orientation_calculate(&data->acceleration, &data->magnetic, &data->orientation);
-
- input_event_set(&event, EV_REL, REL_X, (int) (data->orientation.azimuth * 1000));
- write(uinput_fd, &event, sizeof(event));
- input_event_set(&event, EV_REL, REL_Y, (int) (data->orientation.pitch * 1000));
- write(uinput_fd, &event, sizeof(event));
- input_event_set(&event, EV_REL, REL_Z, (int) (data->orientation.roll * 1000));
- write(uinput_fd, &event, sizeof(event));
- input_event_set(&event, EV_SYN, 0, 0);
- write(uinput_fd, &event, sizeof(event));
-
- gettimeofday(&time, NULL);
- after = timestamp(&time);
-
- diff = (int) (data->delay - (after - before)) / 1000;
- if (diff <= 0)
- continue;
-
- usleep(diff);
- }
- }
-
- return NULL;
-}
-
-int orientation_fill(struct smdk4x12_sensors_handlers *handlers,
- sensors_vec_t *acceleration, sensors_vec_t *magnetic)
-{
- struct orientation_data *data;
-
-// ALOGD("%s(%p, %p, %p)", __func__, handlers, acceleration, magnetic);
-
- if (handlers == NULL || handlers->data == NULL)
- return -EINVAL;
-
- data = (struct orientation_data *) handlers->data;
-
- if (acceleration != NULL) {
- data->acceleration.x = acceleration->x;
- data->acceleration.y = acceleration->y;
- data->acceleration.z = acceleration->z;
- }
-
- if (magnetic != NULL) {
- data->magnetic.x = magnetic->x;
- data->magnetic.y = magnetic->y;
- data->magnetic.z = magnetic->z;
- }
-
- return 0;
-}
-
-int orientation_init(struct smdk4x12_sensors_handlers *handlers,
- struct smdk4x12_sensors_device *device)
-{
- struct orientation_data *data = NULL;
- pthread_attr_t thread_attr;
- int uinput_fd = -1;
- int input_fd = -1;
- int rc;
- int i;
-
- ALOGD("%s(%p, %p)", __func__, handlers, device);
-
- if (handlers == NULL || device == NULL)
- return -EINVAL;
-
- data = (struct orientation_data *) calloc(1, sizeof(struct orientation_data));
-
- for (i = 0; i < device->handlers_count; i++) {
- if (device->handlers[i] == NULL)
- continue;
-
- if (device->handlers[i]->handle == SENSOR_TYPE_ACCELEROMETER)
- data->acceleration_sensor = device->handlers[i];
- else if (device->handlers[i]->handle == SENSOR_TYPE_MAGNETIC_FIELD)
- data->magnetic_sensor = device->handlers[i];
- }
-
- if (data->acceleration_sensor == NULL || data->magnetic_sensor == NULL) {
- ALOGE("%s: Missing sensors for orientation", __func__);
- goto error;
- }
-
- uinput_fd = uinput_rel_create("orientation");
- if (uinput_fd < 0) {
- ALOGD("%s: Unable to create uinput", __func__);
- goto error;
- }
-
- input_fd = input_open("orientation");
- if (input_fd < 0) {
- ALOGE("%s: Unable to open orientation input", __func__);
- goto error;
- }
-
- data->thread_continue = 1;
-
- pthread_mutex_init(&data->mutex, NULL);
- pthread_mutex_lock(&data->mutex);
-
- pthread_attr_init(&thread_attr);
- pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
-
- rc = pthread_create(&data->thread, &thread_attr, orientation_thread, (void *) handlers);
- if (rc < 0) {
- ALOGE("%s: Unable to create orientation thread", __func__);
- pthread_mutex_destroy(&data->mutex);
- goto error;
- }
-
- data->uinput_fd = uinput_fd;
- handlers->poll_fd = input_fd;
- handlers->data = (void *) data;
-
- return 0;
-
-error:
- if (data != NULL)
- free(data);
-
- if (uinput_fd >= 0)
- close(uinput_fd);
-
- if (input_fd >= 0)
- close(input_fd);
-
- handlers->poll_fd = -1;
- handlers->data = NULL;
-
- return -1;
-}
-
-int orientation_deinit(struct smdk4x12_sensors_handlers *handlers)
-{
- struct orientation_data *data;
-
- ALOGD("%s(%p)", __func__, handlers);
-
- if (handlers == NULL || handlers->data == NULL)
- return -EINVAL;
-
- data = (struct orientation_data *) handlers->data;
-
- handlers->activated = 0;
- data->thread_continue = 0;
- pthread_mutex_unlock(&data->mutex);
-
- pthread_mutex_destroy(&data->mutex);
-
- if (data->uinput_fd >= 0) {
- uinput_destroy(data->uinput_fd);
- close(data->uinput_fd);
- }
- data->uinput_fd = -1;
-
- if (handlers->poll_fd >= 0)
- close(handlers->poll_fd);
- handlers->poll_fd = -1;
-
- free(handlers->data);
- handlers->data = NULL;
-
- return 0;
-}
-
-int orientation_activate(struct smdk4x12_sensors_handlers *handlers)
-{
- struct orientation_data *data;
-
- ALOGD("%s(%p)", __func__, handlers);
-
- if (handlers == NULL || handlers->data == NULL)
- return -EINVAL;
-
- data = (struct orientation_data *) handlers->data;
-
- if (data->acceleration_sensor == NULL || data->magnetic_sensor == NULL)
- return -1;
-
- data->acceleration_sensor->needed |= SMDK4x12_SENSORS_NEEDED_ORIENTATION;
- if (data->acceleration_sensor->needed == SMDK4x12_SENSORS_NEEDED_ORIENTATION)
- data->acceleration_sensor->activate(data->acceleration_sensor);
-
- data->magnetic_sensor->needed |= SMDK4x12_SENSORS_NEEDED_ORIENTATION;
- if (data->magnetic_sensor->needed == SMDK4x12_SENSORS_NEEDED_ORIENTATION)
- data->magnetic_sensor->activate(data->magnetic_sensor);
-
- handlers->activated = 1;
- pthread_mutex_unlock(&data->mutex);
-
- return 0;
-}
-
-int orientation_deactivate(struct smdk4x12_sensors_handlers *handlers)
-{
- struct orientation_data *data;
-
- ALOGD("%s(%p)", __func__, handlers);
-
- if (handlers == NULL || handlers->data == NULL)
- return -EINVAL;
-
- data = (struct orientation_data *) handlers->data;
-
- if (data->acceleration_sensor == NULL || data->magnetic_sensor == NULL)
- return -1;
-
- data->acceleration_sensor->needed &= ~(SMDK4x12_SENSORS_NEEDED_ORIENTATION);
- if (data->acceleration_sensor->needed == 0)
- data->acceleration_sensor->deactivate(data->acceleration_sensor);
-
- data->magnetic_sensor->needed &= ~(SMDK4x12_SENSORS_NEEDED_ORIENTATION);
- if (data->magnetic_sensor->needed == 0)
- data->magnetic_sensor->deactivate(data->magnetic_sensor);
-
- handlers->activated = 0;
-
- return 0;
-}
-
-int orientation_set_delay(struct smdk4x12_sensors_handlers *handlers,
- long int delay)
-{
- struct orientation_data *data;
-
- ALOGD("%s(%p)", __func__, handlers);
-
- if (handlers == NULL || handlers->data == NULL)
- return -EINVAL;
-
- data = (struct orientation_data *) handlers->data;
-
- if (data->acceleration_sensor == NULL || data->magnetic_sensor == NULL)
- return -1;
-
- if (data->acceleration_sensor->needed == SMDK4x12_SENSORS_NEEDED_ORIENTATION)
- data->acceleration_sensor->set_delay(data->acceleration_sensor, delay);
-
- if (data->magnetic_sensor->needed == SMDK4x12_SENSORS_NEEDED_ORIENTATION)
- data->magnetic_sensor->set_delay(data->magnetic_sensor, delay);
-
- data->delay = delay;
-
- return 0;
-}
-
-float orientation_convert(int value)
-{
- return (float) value / 1000.0f;
-}
-
-int orientation_get_data(struct smdk4x12_sensors_handlers *handlers,
- struct sensors_event_t *event)
-{
- struct input_event input_event;
- int input_fd = -1;
- int rc;
-
-// ALOGD("%s(%p, %p)", __func__, handlers, event);
-
- if (handlers == NULL || event == NULL)
- return -EINVAL;
-
- input_fd = handlers->poll_fd;
- 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;
-
- event->orientation.status = SENSOR_STATUS_ACCURACY_MEDIUM;
-
- do {
- rc = read(input_fd, &input_event, sizeof(input_event));
- if (rc < (int) sizeof(input_event))
- break;
-
- if (input_event.type == EV_REL) {
- switch (input_event.code) {
- case REL_X:
- event->orientation.azimuth = orientation_convert(input_event.value);
- break;
- case REL_Y:
- event->orientation.pitch = orientation_convert(input_event.value);
- break;
- case REL_Z:
- event->orientation.roll = orientation_convert(input_event.value);
- break;
- default:
- continue;
- }
- } else if (input_event.type == EV_SYN) {
- if (input_event.code == SYN_REPORT)
- event->timestamp = input_timestamp(&input_event);
- }
- } while (input_event.type != EV_SYN);
-
- return 0;
-}
-
-struct smdk4x12_sensors_handlers orientation = {
- .name = "Orientation",
- .handle = SENSOR_TYPE_ORIENTATION,
- .init = orientation_init,
- .deinit = orientation_deinit,
- .activate = orientation_activate,
- .deactivate = orientation_deactivate,
- .set_delay = orientation_set_delay,
- .get_data = orientation_get_data,
- .activated = 0,
- .needed = 0,
- .poll_fd = -1,
- .data = NULL,
-};
diff --git a/sensors/smdk4x12_sensors.c b/sensors/smdk4x12_sensors.c
index 29de591..623a43d 100644
--- a/sensors/smdk4x12_sensors.c
+++ b/sensors/smdk4x12_sensors.c
@@ -35,20 +35,24 @@
*/
struct sensor_t smdk4x12_sensors[] = {
- { "LSM330DLC Acceleration Sensor", "STMicroelectronics", 1, SENSOR_TYPE_ACCELEROMETER,
- SENSOR_TYPE_ACCELEROMETER, 2 * GRAVITY_EARTH, 0.0096f, 0.25f, 10000, {}, },
- { "AKM8963 Magnetic Sensor", "Asahi Kasei Microdevices", 1, SENSOR_TYPE_MAGNETIC_FIELD,
- SENSOR_TYPE_MAGNETIC_FIELD, 2000.0f, 0.06f, 6.0f, 10000, {}, },
- { "Orientation Sensor", "SMDK4x12 Sensors", 1, SENSOR_TYPE_ORIENTATION,
- SENSOR_TYPE_ORIENTATION, 360.0f, 0.1f, 0.0f, 10000, {}, },
- { "CM36651 Light Sensor", "Capella Microsystems", 1, SENSOR_TYPE_LIGHT,
- SENSOR_TYPE_LIGHT, 3000.0f, 1.0f, 0.2f, 0, {}, },
- { "CM36651 Proximity Sensor", "Capella Microsystems", 1, SENSOR_TYPE_PROXIMITY,
- SENSOR_TYPE_PROXIMITY, 6.0f, 6.0f, 1.3f, 0, {}, },
+ { "LSM330DLC 3-Axis Accelerometer", "STMicroelectronics", 1, SENSOR_TYPE_ACCELEROMETER,
+ SENSOR_TYPE_ACCELEROMETER, 2 * GRAVITY_EARTH, 0.0096f, 0.25f, 10000, 0, 0, SENSOR_STRING_TYPE_ACCELEROMETER, 0, 0,
+ SENSOR_FLAG_CONTINUOUS_MODE, {}, },
+ { "AKM8963 Magnetic Sensor", "Asahi Kasei", 1, SENSOR_TYPE_MAGNETIC_FIELD,
+ SENSOR_TYPE_MAGNETIC_FIELD, 2000.0f, 0.06f, 6.0f, 10000, 0, 0, SENSOR_STRING_TYPE_MAGNETIC_FIELD, 0, 0,
+ SENSOR_FLAG_CONTINUOUS_MODE, {}, },
+ { "CM36651 Light Sensor", "Capella", 1, SENSOR_TYPE_LIGHT,
+ SENSOR_TYPE_LIGHT, 3000.0f, 1.0f, 0.2f, 0, 0, 0, SENSOR_STRING_TYPE_LIGHT, 0, 0,
+ SENSOR_FLAG_ON_CHANGE_MODE, {}, },
+ { "CM36651 Proximity Sensor", "Capella", 1, SENSOR_TYPE_PROXIMITY,
+ SENSOR_TYPE_PROXIMITY, 8.0f, 8.0f, 1.3f, 0, 0, 0, SENSOR_STRING_TYPE_PROXIMITY, 0, 0,
+ SENSOR_FLAG_WAKE_UP | SENSOR_FLAG_ON_CHANGE_MODE, {}, },
{ "LSM330DLC Gyroscope Sensor", "STMicroelectronics", 1, SENSOR_TYPE_GYROSCOPE,
- SENSOR_TYPE_GYROSCOPE, 500.0f * (3.1415926535f / 180.0f), (70.0f / 4000.0f) * (3.1415926535f / 180.0f), 6.1f, 5000, {}, },
+ SENSOR_TYPE_GYROSCOPE, 500.0f * (3.1415926535f / 180.0f), (70.0f / 4000.0f) * (3.1415926535f / 180.0f), 6.1f, 5000, 0, 0, SENSOR_STRING_TYPE_GYROSCOPE, 0, 0,
+ SENSOR_FLAG_CONTINUOUS_MODE, {}, },
{ "BMP180 Pressure Sensor", "Bosch", 1, SENSOR_TYPE_PRESSURE,
- SENSOR_TYPE_PRESSURE, 1000.0f, 1.0f, 1.0f, 66700, {}, },
+ SENSOR_TYPE_PRESSURE, 1000.0f, 1.0f, 1.0f, 66700, 0, 0, SENSOR_STRING_TYPE_PRESSURE, 0, 20000,
+ SENSOR_FLAG_CONTINUOUS_MODE, {}, },
};
int smdk4x12_sensors_count = sizeof(smdk4x12_sensors) / sizeof(struct sensor_t);
@@ -56,7 +60,6 @@ int smdk4x12_sensors_count = sizeof(smdk4x12_sensors) / sizeof(struct sensor_t);
struct smdk4x12_sensors_handlers *smdk4x12_sensors_handlers[] = {
&lsm330dlc_acceleration,
&akm8963,
- &orientation,
&cm36651_proximity,
&cm36651_light,
&lsm330dlc_gyroscope,
@@ -116,7 +119,7 @@ int smdk4x12_sensors_set_delay(struct sensors_poll_device_t *dev, int handle,
struct smdk4x12_sensors_device *device;
int i;
- ALOGD("%s(%p, %d, %ld)", __func__, dev, handle, (long int) ns);
+ ALOGD("%s(%p, %d, %" PRId64 ")", __func__, dev, handle, ns);
if (dev == NULL)
return -EINVAL;
@@ -131,7 +134,7 @@ int smdk4x12_sensors_set_delay(struct sensors_poll_device_t *dev, int handle,
continue;
if (device->handlers[i]->handle == handle && device->handlers[i]->set_delay != NULL)
- return device->handlers[i]->set_delay(device->handlers[i], (long int) ns);
+ return device->handlers[i]->set_delay(device->handlers[i], ns);
}
return 0;
diff --git a/sensors/smdk4x12_sensors.h b/sensors/smdk4x12_sensors.h
index 5dc54d8..d8e20c4 100644
--- a/sensors/smdk4x12_sensors.h
+++ b/sensors/smdk4x12_sensors.h
@@ -18,6 +18,8 @@
#include <stdint.h>
#include <poll.h>
#include <linux/input.h>
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
#include <hardware/sensors.h>
#include <hardware/hardware.h>
@@ -26,7 +28,6 @@
#define _SMDK4x12_SENSORS_H_
#define SMDK4x12_SENSORS_NEEDED_API (1 << 0)
-#define SMDK4x12_SENSORS_NEEDED_ORIENTATION (1 << 1)
struct smdk4x12_sensors_device;
@@ -40,7 +41,7 @@ struct smdk4x12_sensors_handlers {
int (*activate)(struct smdk4x12_sensors_handlers *handlers);
int (*deactivate)(struct smdk4x12_sensors_handlers *handlers);
int (*set_delay)(struct smdk4x12_sensors_handlers *handlers,
- long int delay);
+ int64_t delay);
int (*get_data)(struct smdk4x12_sensors_handlers *handlers,
struct sensors_event_t *event);
@@ -76,14 +77,14 @@ int smdk4x12_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);
+int64_t timestamp(struct timeval *time);
+int64_t 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);
-int sysfs_value_write(char *path, int value);
+int64_t sysfs_value_read(char *path);
+int sysfs_value_write(char *path, int64_t value);
int sysfs_string_read(char *path, char *buffer, size_t length);
int sysfs_string_write(char *path, char *buffer, size_t length);
@@ -91,15 +92,11 @@ int sysfs_string_write(char *path, char *buffer, size_t length);
* Sensors
*/
-int orientation_fill(struct smdk4x12_sensors_handlers *handlers,
- sensors_vec_t *acceleration, sensors_vec_t *magnetic);
-
int ssp_sensor_enable(int sensor_type);
int ssp_sensor_disable(int sensor_type);
extern struct smdk4x12_sensors_handlers lsm330dlc_acceleration;
extern struct smdk4x12_sensors_handlers akm8963;
-extern struct smdk4x12_sensors_handlers orientation;
extern struct smdk4x12_sensors_handlers cm36651_proximity;
extern struct smdk4x12_sensors_handlers cm36651_light;
extern struct smdk4x12_sensors_handlers lsm330dlc_gyroscope;
diff --git a/sensors/ssp.h b/sensors/ssp.h
index 48c9ad9..043a62e 100644
--- a/sensors/ssp.h
+++ b/sensors/ssp.h
@@ -132,7 +132,6 @@ enum {
PROXIMITY_SENSOR,
LIGHT_SENSOR,
PROXIMITY_RAW,
- ORIENTATION_SENSOR,
SENSOR_MAX,
};