summaryrefslogtreecommitdiffstats
path: root/libsensors
diff options
context:
space:
mode:
authorMarty Fouts <mfouts@sta.samsung.com>2011-06-29 18:13:42 -0700
committerArve Hjønnevåg <arve@android.com>2011-06-29 18:52:35 -0700
commit916da294eb330d2c975a17d1524914c62cf4d650 (patch)
tree69e68d197121bd37898f987f84e489e2a349e824 /libsensors
parentaef77a5ab2b36b8e59409b0c39d8bf36b3cfc2b2 (diff)
downloaddevice_samsung_tuna-916da294eb330d2c975a17d1524914c62cf4d650.zip
device_samsung_tuna-916da294eb330d2c975a17d1524914c62cf4d650.tar.gz
device_samsung_tuna-916da294eb330d2c975a17d1524914c62cf4d650.tar.bz2
ARM: omap4: tuna: Add input event reader to sensor HAL
Change-Id: I34a4a4dea8b30b22046889246f164c3ea40ab2a4 Signed-off-by: Danke Xie <d.xie@sta.samsung.com>
Diffstat (limited to 'libsensors')
-rw-r--r--libsensors/Android.mk3
-rw-r--r--libsensors/InputEventReader.cpp111
-rw-r--r--libsensors/InputEventReader.h48
-rw-r--r--libsensors/sensors.cpp11
-rw-r--r--libsensors/sensors.h54
5 files changed, 220 insertions, 7 deletions
diff --git a/libsensors/Android.mk b/libsensors/Android.mk
index 6eb9556..5fe88f4 100644
--- a/libsensors/Android.mk
+++ b/libsensors/Android.mk
@@ -30,7 +30,8 @@ LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := -DLOG_TAG=\"Sensors\"
LOCAL_C_INCLUDES += vendor/invensense/libsensors
LOCAL_SRC_FILES := \
- sensors.cpp
+ sensors.cpp \
+ InputEventReader.cpp
LOCAL_SHARED_LIBRARIES := libinvensense_hal libcutils libutils libdl
diff --git a/libsensors/InputEventReader.cpp b/libsensors/InputEventReader.cpp
new file mode 100644
index 0000000..964eda5
--- /dev/null
+++ b/libsensors/InputEventReader.cpp
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdint.h>
+#include <errno.h>
+#include <unistd.h>
+#include <poll.h>
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <linux/input.h>
+
+#include <cutils/log.h>
+
+#include "InputEventReader.h"
+
+/*****************************************************************************/
+
+template <typename T>
+static inline T min(T a, T b) {
+ return a<b ? a : b;
+}
+
+struct input_event;
+
+InputEventCircularReader::InputEventCircularReader(size_t numEvents)
+ : mBuffer(new input_event[numEvents]),
+ mBufferEnd(mBuffer + numEvents),
+ mHead(mBuffer),
+ mCurr(mBuffer),
+ mEvents(numEvents),
+ mFreeSpace(numEvents)
+{
+}
+
+InputEventCircularReader::~InputEventCircularReader()
+{
+ delete [] mBuffer;
+}
+
+ssize_t InputEventCircularReader::fill(int fd)
+{
+ size_t numEventsRead = 0;
+ if (mFreeSpace) {
+ struct iovec iov[2];
+
+ const size_t numFirst = min(mFreeSpace, (size_t)(mBufferEnd - mHead));
+ const size_t numSecond = mFreeSpace - numFirst;
+
+ int iovcnt = 1;
+ iov[0].iov_base = mHead;
+ iov[0].iov_len = numFirst * sizeof(input_event);
+
+ if (numSecond > 0)
+ {
+ iovcnt++;
+ iov[1].iov_base = mBuffer;
+ iov[1].iov_len = numSecond * sizeof(input_event);
+ }
+
+ const ssize_t nread = readv(fd, iov, iovcnt);
+ if (nread < 0 || nread % sizeof(input_event)) {
+ // we got a partial event!!
+ return nread < 0 ? -errno : -EINVAL;
+ }
+
+ numEventsRead = nread / sizeof(input_event);
+ if (numEventsRead) {
+ mHead += numEventsRead;
+ mFreeSpace -= numEventsRead;
+ if (mHead >= mBufferEnd)
+ mHead -= mBufferEnd - mBuffer;
+ }
+ }
+
+ return numEventsRead;
+}
+
+bool InputEventCircularReader::readEvent(int fd, input_event const** events)
+{
+ if (mFreeSpace >= mEvents) {
+ ssize_t eventCount = fill(fd);
+ if (eventCount <= 0)
+ return false;
+ }
+ *events = mCurr;
+ return true;
+}
+
+void InputEventCircularReader::next()
+{
+ mCurr++;
+ mFreeSpace++;
+ if (mCurr >= mBufferEnd) {
+ mCurr = mBuffer;
+ }
+}
diff --git a/libsensors/InputEventReader.h b/libsensors/InputEventReader.h
new file mode 100644
index 0000000..736cc17
--- /dev/null
+++ b/libsensors/InputEventReader.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INPUT_EVENT_READER_H
+#define ANDROID_INPUT_EVENT_READER_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+/*****************************************************************************/
+
+struct input_event;
+
+class InputEventCircularReader
+{
+ struct input_event* const mBuffer;
+ struct input_event* const mBufferEnd;
+ struct input_event* mHead;
+ struct input_event* mCurr;
+ size_t mEvents;
+ size_t mFreeSpace;
+
+public:
+ InputEventCircularReader(size_t numEvents);
+ ~InputEventCircularReader();
+ ssize_t fill(int fd);
+ bool readEvent(int fd, input_event const** events);
+ void next();
+};
+
+/*****************************************************************************/
+
+#endif /* ANDROID_INPUT_EVENT_READER_H */
diff --git a/libsensors/sensors.cpp b/libsensors/sensors.cpp
index 44697bf..f9dd0ef 100644
--- a/libsensors/sensors.cpp
+++ b/libsensors/sensors.cpp
@@ -1,6 +1,5 @@
-
/*
- * Copyright (C) 2011 Invensense, Inc.
+ * Copyright (C) 2011 The Android Open-Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-/**********Removed the gesture related code from this file for Google code check modified by Meenakshi Ramamoorthi on May 31st **********/
#define LOG_NDEBUG 0
#define LOG_TAG "Sensors"
@@ -60,7 +58,6 @@
#define SENSORS_MAGNETIC_FIELD_HANDLE (ID_M)
#define SENSORS_ORIENTATION_HANDLE (ID_O)
-
#define AKM_FTRACE 0
#define AKM_DEBUG 0
#define AKM_DATA 0
@@ -123,9 +120,11 @@ struct sensors_module_t HAL_MODULE_INFO_SYM = {
version_major: 1,
version_minor: 0,
id: SENSORS_HARDWARE_MODULE_ID,
- name: "Invensense module",
- author: "Invensense Inc.",
+ name: "Samsung Sensor module",
+ author: "Samsung Electronic Company",
methods: &sensors_module_methods,
+ dso: 0,
+ reserved: {},
},
get_sensors_list: sensors__get_sensors_list,
};
diff --git a/libsensors/sensors.h b/libsensors/sensors.h
new file mode 100644
index 0000000..4628865
--- /dev/null
+++ b/libsensors/sensors.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_SAMSUNG_SENSORS_H
+#define ANDROID_SAMSUNG_SENSORS_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <linux/input.h>
+
+#include <hardware/hardware.h>
+#include <hardware/sensors.h>
+
+__BEGIN_DECLS
+
+/*****************************************************************************/
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+
+/*
+ * The MPL-supported sensors need to have same IDs as in Invensense .so
+ * (from ID_MPL_BASE up to ID_O)
+ */
+#define ID_MPL_BASE (0)
+#define ID_RV (ID_MPL_BASE)
+#define ID_LA (ID_RV + 1)
+#define ID_GR (ID_LA + 1)
+#define ID_GY (ID_GR + 1)
+#define ID_A (ID_GY + 1)
+#define ID_M (ID_A + 1)
+#define ID_O (ID_M + 1)
+
+/*****************************************************************************/
+
+
+__END_DECLS
+
+#endif /* ANDROID_SAMSUNG_SENSORS_H */