summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2010-07-14 16:32:04 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-07-14 16:32:04 -0700
commitc9a11088e503b9e3ae52a3f671b2d21f5cd54f06 (patch)
treed6841ee8f8cf79e7079bfb0f53dc053cc5bd670d /native
parent38eea8bf990540360b45b963195a7766c30b55d2 (diff)
parentb957b9d63c88efd3a961759424987b99219adeed (diff)
downloadframeworks_base-c9a11088e503b9e3ae52a3f671b2d21f5cd54f06.zip
frameworks_base-c9a11088e503b9e3ae52a3f671b2d21f5cd54f06.tar.gz
frameworks_base-c9a11088e503b9e3ae52a3f671b2d21f5cd54f06.tar.bz2
Merge "first step at implementing the native sensor support" into gingerbread
Diffstat (limited to 'native')
-rw-r--r--native/android/Android.mk4
-rw-r--r--native/android/sensor.cpp150
2 files changed, 153 insertions, 1 deletions
diff --git a/native/android/Android.mk b/native/android/Android.mk
index 509a379..2fe0679 100644
--- a/native/android/Android.mk
+++ b/native/android/Android.mk
@@ -9,13 +9,15 @@ LOCAL_SRC_FILES:= \
input.cpp \
looper.cpp \
native_activity.cpp \
- native_window.cpp
+ native_window.cpp \
+ sensor.cpp
LOCAL_SHARED_LIBRARIES := \
libcutils \
libutils \
libbinder \
libui \
+ libgui \
libsurfaceflinger_client \
libandroid_runtime
diff --git a/native/android/sensor.cpp b/native/android/sensor.cpp
new file mode 100644
index 0000000..7a3907e
--- /dev/null
+++ b/native/android/sensor.cpp
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+#define LOG_TAG "sensor"
+#include <utils/Log.h>
+
+#include <android/looper.h>
+#include <android/sensor.h>
+
+#include <utils/RefBase.h>
+#include <utils/PollLoop.h>
+#include <utils/Timers.h>
+
+#include <gui/Sensor.h>
+#include <gui/SensorManager.h>
+#include <gui/SensorEventQueue.h>
+
+#include <poll.h>
+
+using android::sp;
+using android::Sensor;
+using android::SensorManager;
+using android::SensorEventQueue;
+using android::String8;
+
+/*****************************************************************************/
+
+ASensorManager* ASensorManager_getInstance()
+{
+ return &SensorManager::getInstance();
+}
+
+int ASensorManager_getSensorList(ASensorManager* manager, ASensor** list)
+{
+ Sensor* l;
+ int c = static_cast<SensorManager*>(manager)->getSensorList(&l);
+ if (list) {
+ *list = l;
+ }
+ return c;
+}
+
+ASensor* ASensorManager_getDefaultSensor(ASensorManager* manager, int type)
+{
+ return static_cast<SensorManager*>(manager)->getDefaultSensor(type);
+}
+
+ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager,
+ ALooper* looper, ALooper_callbackFunc* callback, void* data)
+{
+ sp<SensorEventQueue> queue =
+ static_cast<SensorManager*>(manager)->createEventQueue();
+ if (queue != 0) {
+ ALooper_addFd(looper, queue->getFd(), POLLIN, callback, data);
+ queue->looper = looper;
+ queue->incStrong(manager);
+ }
+ return static_cast<ASensorEventQueue*>(queue.get());
+}
+
+int ASensorManager_destroyEventQueue(ASensorManager* manager,
+ ASensorEventQueue* inQueue)
+{
+ sp<SensorEventQueue> queue = static_cast<SensorEventQueue*>(inQueue);
+ ALooper_removeFd(queue->looper, queue->getFd());
+ queue->decStrong(manager);
+ return 0;
+}
+
+/*****************************************************************************/
+
+int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor* sensor)
+{
+ return static_cast<SensorEventQueue*>(queue)->enableSensor(
+ static_cast<Sensor*>(sensor));
+}
+
+int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor* sensor)
+{
+ return static_cast<SensorEventQueue*>(queue)->disableSensor(
+ static_cast<Sensor*>(sensor));
+}
+
+int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor* sensor,
+ int32_t usec)
+{
+ return static_cast<SensorEventQueue*>(queue)->setEventRate(
+ static_cast<Sensor*>(sensor), us2ns(usec));
+}
+
+int ASensorEventQueue_hasEvents(ASensorEventQueue* queue)
+{
+ struct pollfd pfd;
+ pfd.fd = static_cast<SensorEventQueue*>(queue)->getFd();
+ pfd.events = POLLIN;
+ pfd.revents = 0;
+
+ int nfd = poll(&pfd, 1, 0);
+
+ if (nfd < 0)
+ return -errno;
+
+ if (pfd.revents != POLLIN)
+ return -1;
+
+ return (nfd == 0) ? 0 : 1;
+}
+
+ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue,
+ ASensorEvent* events, size_t count)
+{
+ return static_cast<SensorEventQueue*>(queue)->read(events, count);
+}
+
+
+/*****************************************************************************/
+
+const char* ASensor_getName(ASensor* sensor)
+{
+ return static_cast<Sensor*>(sensor)->getName().string();
+}
+
+const char* ASensor_getVendor(ASensor* sensor)
+{
+ return static_cast<Sensor*>(sensor)->getVendor().string();
+}
+
+int ASensor_getType(ASensor* sensor)
+{
+ return static_cast<Sensor*>(sensor)->getType();
+}
+
+float ASensor_getResolution(ASensor* sensor)
+{
+ return static_cast<Sensor*>(sensor)->getResolution();
+}
+