[Feature]add MT2731_MP2_MR2_SVN388 baseline version
Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/navigation/sensor/sensor_hal/LICENSE b/src/navigation/sensor/sensor_hal/LICENSE
new file mode 100644
index 0000000..77f59ed
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/LICENSE
@@ -0,0 +1,31 @@
+Copyright Statement:
+
+This software/firmware and related documentation ("MediaTek Software") are
+protected under relevant copyright laws. The information contained herein is
+confidential and proprietary to MediaTek Inc. and/or its licensors. Without
+the prior written permission of MediaTek inc. and/or its licensors, any
+reproduction, modification, use or disclosure of MediaTek Software, and
+information contained herein, in whole or in part, shall be strictly
+prohibited.
+
+MediaTek Inc. (C) 2015. All rights reserved.
+
+BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
+WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
+RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
+TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
+SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
+RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
+ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
+RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
+MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
diff --git a/src/navigation/sensor/sensor_hal/Makefile.am b/src/navigation/sensor/sensor_hal/Makefile.am
new file mode 100644
index 0000000..68c6397
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/Makefile.am
@@ -0,0 +1,45 @@
+lib_LTLIBRARIES = libsensorhal.la
+libsensorhal_la_SOURCES = ./src/sensors.c \
+ ./src/hwmsen_chip_info.c \
+ ./src/nusensors.cpp \
+ ./src/InputEventReader.cpp \
+ ./src/SensorBase.cpp \
+ ./src/Hwmsen.cpp \
+ ./src/Acceleration.cpp \
+ ./src/Magnetic.cpp \
+ ./src/Gyroscope.cpp \
+ ./src/AmbienteLight.cpp \
+ ./src/Proximity.cpp \
+ ./src/Pressure.cpp \
+ ./src/Temperature.cpp \
+ ./src/sensordebug.cpp \
+ ./src/BatchSensor.cpp \
+ ./src/StepCounter.cpp \
+ ./src/Shake.cpp \
+ ./src/Activity.cpp \
+ ./src/FaceDown.cpp \
+ ./src/InPocket.cpp \
+ ./src/Pedometer.cpp \
+ ./src/PickUp.cpp \
+ ./src/HeartRate.cpp \
+ ./src/Tilt.cpp \
+ ./src/WakeGesture.cpp \
+ ./src/GlanceGesture.cpp \
+ ./src/Humidity.cpp \
+ ./src/GameRotationVector.cpp \
+ ./src/Linearacceleration.cpp \
+ ./src/GeomagneticRotationVector.cpp \
+ ./src/RotationVector.cpp \
+ ./src/Bringtosee.cpp \
+ ./src/Gravity.cpp \
+ ./src/Uncaligyro.cpp \
+ ./src/Uncalimag.cpp \
+ ./src/AnswerCall.cpp \
+ ./src/Pdr.cpp \
+ ./src/Gesture.cpp \
+ ./src/hwmsen_custom.c
+include_HEADERS = ./inc/sensors.h
+AM_CFLAGS = -I./inc
+AM_CPPFLAGS = -I./inc
+libsensorhal_la_LDFLAGS = -weak -shared
+libsensorhal_la_LIBADD = -lm -lrt -lpthread -lc
diff --git a/src/navigation/sensor/sensor_hal/NOTICE b/src/navigation/sensor/sensor_hal/NOTICE
new file mode 100644
index 0000000..0519ecb
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/NOTICE
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/navigation/sensor/sensor_hal/README b/src/navigation/sensor/sensor_hal/README
new file mode 100644
index 0000000..cf8a484
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/README
@@ -0,0 +1,15 @@
+Sensor HAL code
+
+WHAT IT DOES?
+=============
+This is sensor hardware abstract layer, it provider commuicate interface with SensorService,e.g. enable(),setDelay()...
+
+HOW IT WAS BUILT?
+==================
+It needs the following library from AOSP:
+liblog libcutils libutils
+
+
+HOW TO USE IT?
+==============
+It compile to path of "/system/lib/hw", and it will be link to system when boot up.
diff --git a/src/navigation/sensor/sensor_hal/configure.ac b/src/navigation/sensor/sensor_hal/configure.ac
new file mode 100644
index 0000000..f0d8d6d
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/configure.ac
@@ -0,0 +1,9 @@
+AC_INIT([sensorhal], [1.0])
+AUTOMAKE_OPTIONS = foreign subdir-objects
+AM_INIT_AUTOMAKE([foreign])
+LT_INIT([dlopen shared disable-static])
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_LIBTOOL
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/src/navigation/sensor/sensor_hal/inc/Acceleration.h b/src/navigation/sensor/sensor_hal/inc/Acceleration.h
new file mode 100644
index 0000000..59c653d
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Acceleration.h
@@ -0,0 +1,99 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_ACCELERATION_SENSOR_H
+#define ANDROID_ACCELERATION_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+//#define ACC_DIV 1000000L
+struct input_event;
+
+class AccelerationSensor : public SensorBase {
+ int mEnabled;
+ int mOrientationEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+ int mTempDiv;
+ int batchMode;
+ int firstData;
+ int mAllInputDataCompleteFlag;
+ enum {
+ restart = 0,
+ x = 1,
+ y = 2,
+ z = 3,
+ status = 4,
+ update = 5,
+ hi = 6,
+ lo = 7,
+ all_complete = 7,
+ };
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ AccelerationSensor();
+ virtual ~AccelerationSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ virtual int getODR(int handle, int *odr);
+
+ void processEvent(int type, int code, int value);
+ int enableNoHALDataAcc(int en);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_ACCELERATION_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Activity.h b/src/navigation/sensor/sensor_hal/inc/Activity.h
new file mode 100644
index 0000000..8d08200
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Activity.h
@@ -0,0 +1,64 @@
+/*
+ * 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_ACTIVITY_SENSOR_H
+#define ANDROID_ACTIVITY_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+struct input_event;
+
+class ActivitySensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+ int64_t m_act_last_ts;
+ int64_t m_act_delay;
+ int batchMode;
+ int firstData;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ ActivitySensor();
+ virtual ~ActivitySensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_ACTIVITY_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/AmbienteLight.h b/src/navigation/sensor/sensor_hal/inc/AmbienteLight.h
new file mode 100644
index 0000000..d3791e9
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/AmbienteLight.h
@@ -0,0 +1,80 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_AMBILIGHT_SENSOR_H
+#define ANDROID_AMBILIGHT_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+struct input_event;
+
+class AmbiLightSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+
+ sensors_event_t mPendingEvent;
+
+ AmbiLightSensor();
+ virtual ~AmbiLightSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ int FindDataFd();
+ void processEvent(int code, int value);
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_AMBILIGHT_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/AnswerCall.h b/src/navigation/sensor/sensor_hal/inc/AnswerCall.h
new file mode 100644
index 0000000..97e0715
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/AnswerCall.h
@@ -0,0 +1,61 @@
+/*
+ * 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_ANSWER_CALL_SENSOR_H
+#define ANDROID_ANSWER_CALL_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+//#define ACC_DIV 1000
+struct input_event;
+
+class AnswerCallSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ AnswerCallSensor();
+ virtual ~AnswerCallSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_GLANCE_GESTURE_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/BatchSensor.h b/src/navigation/sensor/sensor_hal/inc/BatchSensor.h
new file mode 100644
index 0000000..6144d89
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/BatchSensor.h
@@ -0,0 +1,115 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_BATCH_SENSOR_H
+#define ANDROID_BATCH_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+struct input_event;
+
+class BatchSensor : public SensorBase {
+
+ enum {
+ Accelerometer = 0,
+ MagneticField = 1,
+ Orientation = 2,
+ Gyro = 3,
+ light = 4,
+ proximity = 5,
+ pressure = 6,
+ temperature = 7,
+ Gravity = 8,
+ LinearAccelerometer = 9,
+ RotationVector = 10,
+ GameRotationVector = 14,
+ SignificantMotion = 16,
+ StepDetector = 17,
+ StepCounter = 18,
+ GeomagneticRotationVector = 19,
+ Pedometer = 20,
+ Activity = 21,
+ InPocket = 22,
+ Pickup = 23,
+ Facedown = 24,
+ Shake = 25,
+ Heartrate = 26,
+ BringtoSee = 27,
+ numSensors = 28,
+ };
+
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv[numSensors];
+ int flushSensorReq[ID_SENSOR_MAX_HANDLE];
+ bool mHasPendingEvent;
+ int64_t mTimestampHi;
+
+public:
+ int mdata_fd;
+ sensors_meta_data_event_t mPendingEvent;
+
+ BatchSensor();
+ virtual ~BatchSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ void handleEvent(sensors_meta_data_event_t* data, hwm_sensor_data *sensors_data);
+ int TypeToSensor(int type);
+ void GetSensorDiv(int div[]);
+ virtual bool hasPendingEvents() const;
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_BATCH_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Bringtosee.h b/src/navigation/sensor/sensor_hal/inc/Bringtosee.h
new file mode 100644
index 0000000..e9273d2
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Bringtosee.h
@@ -0,0 +1,65 @@
+/*
+ * 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_BRIGTOSEE_SENSOR_H
+#define ANDROID_BRIGTOSEE_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+#define BTS_DIV 1000
+struct input_event;
+
+class BringtoseeSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+ int64_t m_bts_last_ts;
+ int64_t m_bts_delay;
+ int batchMode;
+ int firstData;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ BringtoseeSensor();
+ virtual ~BringtoseeSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_BRIGTOSEE_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/FaceDown.h b/src/navigation/sensor/sensor_hal/inc/FaceDown.h
new file mode 100644
index 0000000..3510fcd
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/FaceDown.h
@@ -0,0 +1,61 @@
+/*
+ * 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_FACE_DOWN_SENSOR_H
+#define ANDROID_FACE_DOWN_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+//#define ACC_DIV 1000
+struct input_event;
+
+class FaceDownSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ FaceDownSensor();
+ virtual ~FaceDownSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_FACE_DOWN_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/GameRotationVector.h b/src/navigation/sensor/sensor_hal/inc/GameRotationVector.h
new file mode 100644
index 0000000..dc6daa4
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/GameRotationVector.h
@@ -0,0 +1,60 @@
+/*
+ * 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_GRV_SENSOR_H
+#define ANDROID_GRV_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+struct input_event;
+
+class GameRotationVectorSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ GameRotationVectorSensor();
+ virtual ~GameRotationVectorSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_GRV_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/GeomagneticRotationVector.h b/src/navigation/sensor/sensor_hal/inc/GeomagneticRotationVector.h
new file mode 100644
index 0000000..974349a
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/GeomagneticRotationVector.h
@@ -0,0 +1,60 @@
+/*
+ * 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_GMRV_SENSOR_H
+#define ANDROID_GMRV_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+struct input_event;
+
+class GeomagneticRotationVectorSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ GeomagneticRotationVectorSensor();
+ virtual ~ GeomagneticRotationVectorSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_GMRV_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Gesture.h b/src/navigation/sensor/sensor_hal/inc/Gesture.h
new file mode 100644
index 0000000..a75ae45
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Gesture.h
@@ -0,0 +1,85 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef __GESTURE_SENSOR_H__
+#define __GESTURE_SENSOR_H__
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+#define MAX_GESTURE_SUPPORT 16
+/*****************************************************************************/
+
+class GestureSensor : public SensorBase {
+ enum {
+ inpocket = 0,
+ stationary = 1,
+ numSensors,
+ };
+
+ uint64_t mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ uint64_t mPendingMask;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvents[MAX_GESTURE_SUPPORT];
+ GestureSensor();
+ virtual ~GestureSensor();
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ void SelectGestureEvent(int code);
+ int HandleToIndex(int handle);
+ int IndexToHandle(int index);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif
diff --git a/src/navigation/sensor/sensor_hal/inc/GlanceGesture.h b/src/navigation/sensor/sensor_hal/inc/GlanceGesture.h
new file mode 100644
index 0000000..39b90ce
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/GlanceGesture.h
@@ -0,0 +1,61 @@
+/*
+ * 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_GLANCE_GESTURE_SENSOR_H
+#define ANDROID_GLANCE_GESTURE_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+//#define ACC_DIV 1000
+struct input_event;
+
+class GlanceGestureSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ GlanceGestureSensor();
+ virtual ~GlanceGestureSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_GLANCE_GESTURE_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Gravity.h b/src/navigation/sensor/sensor_hal/inc/Gravity.h
new file mode 100644
index 0000000..46a3b85
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Gravity.h
@@ -0,0 +1,63 @@
+/*
+ * 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_GRAVITY_SENSOR_H
+#define ANDROID_GRAVITY_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+#define GRAV_DIV 1000
+struct input_event;
+
+class GravitySensor : public SensorBase {
+ int mEnabled;
+ int mOrientationEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ GravitySensor();
+ virtual ~GravitySensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int enableNoHALDataAcc(int en);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_GRAVITY_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Gyroscope.h b/src/navigation/sensor/sensor_hal/inc/Gyroscope.h
new file mode 100644
index 0000000..c03946c
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Gyroscope.h
@@ -0,0 +1,95 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_GYROSCOPE_SENSOR_H
+#define ANDROID_GYROSCOPE_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+struct input_event;
+
+class GyroscopeSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+ int mTempDiv;
+ int mAllInputDataCompleteFlag;
+ enum {
+ restart = 0,
+ x = 1,
+ y = 2,
+ z = 3,
+ status = 4,
+ update = 5,
+ hi = 6,
+ lo = 7,
+ all_complete = 7,
+ };
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ GyroscopeSensor();
+ virtual ~GyroscopeSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ virtual int getODR(int handle, int *odr);
+
+ void processEvent(int type, int code, int value);
+ int FindDataFd();
+ int enableNoHALData(int en);
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_GYROSCOPE_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/HeartRate.h b/src/navigation/sensor/sensor_hal/inc/HeartRate.h
new file mode 100644
index 0000000..c5e251f
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/HeartRate.h
@@ -0,0 +1,60 @@
+/*
+ * 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_HEARTRATE_SENSOR_H
+#define ANDROID_HEARTRATE_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+struct input_event;
+
+class HeartRateSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ HeartRateSensor();
+ virtual ~HeartRateSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_HEARTRATE_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Humidity.h b/src/navigation/sensor/sensor_hal/inc/Humidity.h
new file mode 100644
index 0000000..185975b
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Humidity.h
@@ -0,0 +1,81 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_HUMIDITY_SENSOR_H
+#define ANDROID_HUMIDITY_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+struct input_event;
+
+class HumiditySensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+ int64_t m_hmdy_last_ts;
+ int64_t m_hmdy_delay;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ HumiditySensor();
+ virtual ~HumiditySensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_HUMIDITY_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Hwmsen.h b/src/navigation/sensor/sensor_hal/inc/Hwmsen.h
new file mode 100644
index 0000000..f05cd7b
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Hwmsen.h
@@ -0,0 +1,115 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef __HWM_SENSOR_H__
+#define __HWM_SENSOR_H__
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include "sensordebug.h"
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+
+/*****************************************************************************/
+
+struct input_event;
+
+//static uint32_t g_active_sensors;
+
+
+struct sensor_delay
+{
+ int handle;
+ uint32_t delay;
+};
+
+class Hwmsen : public SensorBase {
+
+ enum {
+ Accelerometer = 0,
+ MagneticField = 1,
+ Orientation = 2,
+ Gyro = 3,
+ light = 4,
+ proximity = 5,
+ numSensors = 6,//hwmsen driver process 6 device data
+ };
+
+ uint32_t mActiveSensors;
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+
+ bool mHasPendingEvent;
+
+ uint64_t mDelays[numSensors];
+ uint32_t mPendingMask;
+
+
+ float indexToValue(size_t index) const;
+ void processEvent(int code, int value);
+ int update_delay(int what);
+
+ int64_t m_hwm_last_ts[numSensors];
+ uint64_t data_type;
+
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvents[numSensors];
+ SensorDebugObject *mHwmSensorDebug;
+
+ Hwmsen();
+ virtual ~Hwmsen();
+ virtual int readEvents(sensors_event_t* data, int count);
+ void readSensorData(void);
+ virtual bool hasPendingEvents() const;
+ virtual int enable(int32_t handle, int enabled);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+
+ int enableNoHALDataAcc(int en);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_LIGHT_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/InPocket.h b/src/navigation/sensor/sensor_hal/inc/InPocket.h
new file mode 100644
index 0000000..cbaa410
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/InPocket.h
@@ -0,0 +1,61 @@
+/*
+ * 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_IN_POCKET_SENSOR_H
+#define ANDROID_IN_POCKET_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+
+struct input_event;
+
+class InPocketSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ InPocketSensor();
+ virtual ~InPocketSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_IN_POCKET_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/InputEventReader.h b/src/navigation/sensor/sensor_hal/inc/InputEventReader.h
new file mode 100644
index 0000000..1109a3c
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/InputEventReader.h
@@ -0,0 +1,66 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#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;
+ ssize_t mFreeSpace;
+
+public:
+ InputEventCircularReader(size_t numEvents);
+ ~InputEventCircularReader();
+ ssize_t fill(int fd);
+ ssize_t readEvent(input_event const** events);
+ void next();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_INPUT_EVENT_READER_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Linearacceleration.h b/src/navigation/sensor/sensor_hal/inc/Linearacceleration.h
new file mode 100644
index 0000000..7099497
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Linearacceleration.h
@@ -0,0 +1,63 @@
+/*
+ * 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_LINEARACC_SENSOR_H
+#define ANDROID_LINEARACC_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+#define LA_DIV 1000
+struct input_event;
+
+class LinearaccelSensor : public SensorBase {
+ int mEnabled;
+ int mOrientationEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ LinearaccelSensor();
+ virtual ~LinearaccelSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int enableNoHALDataAcc(int en);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_LINEARACC_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Magnetic.h b/src/navigation/sensor/sensor_hal/inc/Magnetic.h
new file mode 100644
index 0000000..85f4aab
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Magnetic.h
@@ -0,0 +1,107 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_MAGNETIC_SENSOR_H
+#define ANDROID_MAGNETIC_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include "sensordebug.h"
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+#include "Acceleration.h"
+
+/*****************************************************************************/
+//#define MAG_DIV 1000
+#define MAX_M_V_SENSOR 5
+
+struct input_event;
+
+class MagneticSensor : public SensorBase {
+ int mEnabled;
+ int mOrientationEnabled;
+ InputEventCircularReader mInputReader;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ uint32_t mPendingMask;
+ enum {
+ MagneticField = 0,
+ Orientation = 1,
+ numSensors
+ };
+ int64_t mEnabledTime[numSensors];
+ int mAllInputDataCompleteFlag[numSensors];
+ enum {
+ restart = 0,
+ x = 1,
+ y = 2,
+ z = 3,
+ status = 4,
+ update = 5,
+ hi = 6,
+ lo = 7,
+ all_complete = 7,
+ };
+
+ int mDataDiv_M;
+ int mDataDiv_O;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent[MAX_M_V_SENSOR];
+ SensorDebugObject *mMagSensorDebug;
+
+
+ MagneticSensor();
+ virtual ~MagneticSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int type, int code, int value);
+ int write_attr(char* path, char* buf,int len);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_MAGNETIC_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Pdr.h b/src/navigation/sensor/sensor_hal/inc/Pdr.h
new file mode 100644
index 0000000..41b239a
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Pdr.h
@@ -0,0 +1,60 @@
+/*
+ * 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_PDR_SENSOR_H
+#define ANDROID_PDR_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+struct input_event;
+
+class PdrSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ PdrSensor();
+ virtual ~PdrSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_PDR_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Pedometer.h b/src/navigation/sensor/sensor_hal/inc/Pedometer.h
new file mode 100644
index 0000000..60007ba
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Pedometer.h
@@ -0,0 +1,60 @@
+/*
+ * 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_PEDOMETER_SENSOR_H
+#define ANDROID_PEDOMETER_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+struct input_event;
+
+class PedometerSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ PedometerSensor();
+ virtual ~PedometerSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_PEDOMETER_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/PickUp.h b/src/navigation/sensor/sensor_hal/inc/PickUp.h
new file mode 100644
index 0000000..875897c
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/PickUp.h
@@ -0,0 +1,61 @@
+/*
+ * 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_PICK_UP_SENSOR_H
+#define ANDROID_PICK_UP_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+//#define ACC_DIV 1000
+struct input_event;
+
+class PickUpSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ PickUpSensor();
+ virtual ~PickUpSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_PICK_UP_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Pressure.h b/src/navigation/sensor/sensor_hal/inc/Pressure.h
new file mode 100644
index 0000000..6cb100b
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Pressure.h
@@ -0,0 +1,91 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_PRESSURE_SENSOR_H
+#define ANDROID_PRESSURE_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+//#define PRESS_DIV 1000
+struct input_event;
+
+class PressureSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+ int mTempDiv;
+ int mAllInputDataCompleteFlag;
+ enum {
+ restart = 0,
+ val = 1,
+ status = 2,
+ update = 3,
+ hi = 4,
+ lo = 5,
+ all_complete = 5,
+ };
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ PressureSensor();
+ virtual ~PressureSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int type, int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_PRESSURE_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Proximity.h b/src/navigation/sensor/sensor_hal/inc/Proximity.h
new file mode 100644
index 0000000..4cfeab3
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Proximity.h
@@ -0,0 +1,80 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_PROXIMITY_SENSOR_H
+#define ANDROID_PROXIMITY_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+
+struct input_event;
+
+class ProximitySensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ ProximitySensor();
+ virtual ~ProximitySensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_PROXIMITY_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/RotationVector.h b/src/navigation/sensor/sensor_hal/inc/RotationVector.h
new file mode 100644
index 0000000..d23a57e
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/RotationVector.h
@@ -0,0 +1,60 @@
+/*
+ * 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_RV_SENSOR_H
+#define ANDROID_RV_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+struct input_event;
+
+class RotationVectorSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ RotationVectorSensor();
+ virtual ~RotationVectorSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_RV_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/SensorBase.h b/src/navigation/sensor/sensor_hal/inc/SensorBase.h
new file mode 100644
index 0000000..03facbe
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/SensorBase.h
@@ -0,0 +1,86 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_SENSOR_BASE_H
+#define ANDROID_SENSOR_BASE_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include "sensors.h"
+
+/*****************************************************************************/
+
+struct sensors_event_t;
+
+class SensorBase {
+protected:
+ const char* dev_name;
+ const char* data_name;
+ int dev_fd;
+ int data_fd;
+
+ static int openInput(const char* inputName);
+ static int64_t getTimestamp();
+
+
+ static int64_t timevalToNano(timeval const& t) {
+ return t.tv_sec*1000000000LL + t.tv_usec*1000;
+ }
+
+ int open_device();
+ int close_device();
+
+public:
+ SensorBase(
+ const char* dev_name,
+ const char* data_name);
+
+ virtual ~SensorBase();
+
+ virtual int readEvents(sensors_event_t* data, int count) = 0;
+ virtual bool hasPendingEvents() const;
+ virtual int getFd() const;
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled) = 0;
+ virtual int getODR(int32_t handle, int *odr);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs) = 0;
+ virtual int flush(int handle) = 0;
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_SENSOR_BASE_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Shake.h b/src/navigation/sensor/sensor_hal/inc/Shake.h
new file mode 100644
index 0000000..6050399
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Shake.h
@@ -0,0 +1,61 @@
+/*
+ * 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_SHAKE_SENSOR_H
+#define ANDROID_SHAKE_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+//#define ACC_DIV 1000
+struct input_event;
+
+class ShakeSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ ShakeSensor();
+ virtual ~ShakeSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_SHAKE_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/StepCounter.h b/src/navigation/sensor/sensor_hal/inc/StepCounter.h
new file mode 100644
index 0000000..3f74a07
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/StepCounter.h
@@ -0,0 +1,62 @@
+/*
+ * 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_STEP_C_SENSOR_H
+#define ANDROID_STEP_C_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+//#define ACC_DIV 1000
+struct input_event;
+
+class StepCounterSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+ pthread_mutex_t mSensorMutex;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ StepCounterSensor();
+ virtual ~StepCounterSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_STEP_C_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Temperature.h b/src/navigation/sensor/sensor_hal/inc/Temperature.h
new file mode 100644
index 0000000..1c3d293
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Temperature.h
@@ -0,0 +1,90 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_TEMPERATURE_SENSOR_H
+#define ANDROID_TEMPERATURE_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+//#define ACC_DIV 1000
+struct input_event;
+
+class TemperatureSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+ int mAllInputDataCompleteFlag;
+ enum {
+ restart = 0,
+ val = 1,
+ status = 2,
+ update = 3,
+ hi = 4,
+ lo = 5,
+ all_complete = 5,
+ };
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ TemperatureSensor();
+ virtual ~TemperatureSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int type, int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_TEMPERATURE_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Tilt.h b/src/navigation/sensor/sensor_hal/inc/Tilt.h
new file mode 100644
index 0000000..a6891b7
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Tilt.h
@@ -0,0 +1,61 @@
+/*
+ * 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_TILT_SENSOR_H
+#define ANDROID_TILT_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+//#define ACC_DIV 1000
+struct input_event;
+
+class TiltSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ TiltSensor();
+ virtual ~TiltSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_TILT_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Uncaligyro.h b/src/navigation/sensor/sensor_hal/inc/Uncaligyro.h
new file mode 100644
index 0000000..a4c7c9c
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Uncaligyro.h
@@ -0,0 +1,82 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_UNCALIGYRO_SENSOR_H
+#define ANDROID_UNCALIGYRO_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+struct input_event;
+
+class UncaligyroSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+ int64_t m_uncali_gyro_last_ts;
+ int64_t m_uncali_gyro_delay;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ UncaligyroSensor();
+ virtual ~UncaligyroSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_GYROSCOPE_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/Uncalimag.h b/src/navigation/sensor/sensor_hal/inc/Uncalimag.h
new file mode 100644
index 0000000..af5bc8a
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/Uncalimag.h
@@ -0,0 +1,82 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_UNCALIMAG_SENSOR_H
+#define ANDROID_UNCALIMAG_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+struct input_event;
+
+class UncalimagSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+ int64_t m_uncali_mag_last_ts;
+ int64_t m_uncali_mag_delay;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ UncalimagSensor();
+ virtual ~UncalimagSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_GYROSCOPE_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/WakeGesture.h b/src/navigation/sensor/sensor_hal/inc/WakeGesture.h
new file mode 100644
index 0000000..763f1d5
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/WakeGesture.h
@@ -0,0 +1,61 @@
+/*
+ * 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_WAKE_GESTURE_SENSOR_H
+#define ANDROID_WAKE_GESTURE_SENSOR_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+
+#include "nusensors.h"
+#include "SensorBase.h"
+#include "InputEventReader.h"
+#include "hwmsensor.h"
+
+/*****************************************************************************/
+//#define ACC_DIV 1000
+struct input_event;
+
+class WakeGestureSensor : public SensorBase {
+ int mEnabled;
+ InputEventCircularReader mInputReader;
+ int64_t mEnabledTime;
+ char input_sysfs_path[PATH_MAX];
+ int input_sysfs_path_len;
+ int mDataDiv;
+
+public:
+ int mdata_fd;
+ sensors_event_t mPendingEvent;
+
+ WakeGestureSensor();
+ virtual ~WakeGestureSensor();
+
+ virtual int readEvents(sensors_event_t* data, int count);
+ virtual int setDelay(int32_t handle, int64_t ns);
+ virtual int enable(int32_t handle, int enabled);
+ virtual int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ virtual int flush(int handle);
+ void processEvent(int code, int value);
+ int FindDataFd();
+};
+
+/*****************************************************************************/
+
+#endif // ANDROID_WAKE_GESTURE_SENSOR_H
diff --git a/src/navigation/sensor/sensor_hal/inc/hardware.h b/src/navigation/sensor/sensor_hal/inc/hardware.h
new file mode 100644
index 0000000..1a6f3b4
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/hardware.h
@@ -0,0 +1,233 @@
+/*
+ * 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_INCLUDE_HARDWARE_HARDWARE_H
+#define ANDROID_INCLUDE_HARDWARE_HARDWARE_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+__BEGIN_DECLS
+
+/*
+ * Value for the hw_module_t.tag field
+ */
+
+#define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
+
+#define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T')
+#define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T')
+
+#define HARDWARE_MAKE_API_VERSION(maj,min) \
+ ((((maj) & 0xff) << 8) | ((min) & 0xff))
+
+#define HARDWARE_MAKE_API_VERSION_2(maj,min,hdr) \
+ ((((maj) & 0xff) << 24) | (((min) & 0xff) << 16) | ((hdr) & 0xffff))
+#define HARDWARE_API_VERSION_2_MAJ_MIN_MASK 0xffff0000
+#define HARDWARE_API_VERSION_2_HEADER_MASK 0x0000ffff
+
+
+/*
+ * The current HAL API version.
+ *
+ * All module implementations must set the hw_module_t.hal_api_version field
+ * to this value when declaring the module with HAL_MODULE_INFO_SYM.
+ *
+ * Note that previous implementations have always set this field to 0.
+ * Therefore, libhardware HAL API will always consider versions 0.0 and 1.0
+ * to be 100% binary compatible.
+ *
+ */
+#define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0)
+
+/*
+ * Helper macros for module implementors.
+ *
+ * The derived modules should provide convenience macros for supported
+ * versions so that implementations can explicitly specify module/device
+ * versions at definition time.
+ *
+ * Use this macro to set the hw_module_t.module_api_version field.
+ */
+#define HARDWARE_MODULE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
+#define HARDWARE_MODULE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
+
+/*
+ * Use this macro to set the hw_device_t.version field
+ */
+#define HARDWARE_DEVICE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
+#define HARDWARE_DEVICE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
+
+struct hw_module_t;
+struct hw_module_methods_t;
+struct hw_device_t;
+
+/**
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+typedef struct hw_module_t {
+ /** tag must be initialized to HARDWARE_MODULE_TAG */
+ uint32_t tag;
+
+ /**
+ * The API version of the implemented module. The module owner is
+ * responsible for updating the version when a module interface has
+ * changed.
+ *
+ * The derived modules such as gralloc and audio own and manage this field.
+ * The module user must interpret the version field to decide whether or
+ * not to inter-operate with the supplied module implementation.
+ * For example, SurfaceFlinger is responsible for making sure that
+ * it knows how to manage different versions of the gralloc-module API,
+ * and AudioFlinger must know how to do the same for audio-module API.
+ *
+ * The module API version should include a major and a minor component.
+ * For example, version 1.0 could be represented as 0x0100. This format
+ * implies that versions 0x0100-0x01ff are all API-compatible.
+ *
+ * In the future, libhardware will expose a hw_get_module_version()
+ * (or equivalent) function that will take minimum/maximum supported
+ * versions as arguments and would be able to reject modules with
+ * versions outside of the supplied range.
+ */
+ uint16_t module_api_version;
+#define version_major module_api_version
+ /**
+ * version_major/version_minor defines are supplied here for temporary
+ * source code compatibility. They will be removed in the next version.
+ * ALL clients must convert to the new version format.
+ */
+
+ /**
+ * The API version of the HAL module interface. This is meant to
+ * version the hw_module_t, hw_module_methods_t, and hw_device_t
+ * structures and definitions.
+ *
+ * The HAL interface owns this field. Module users/implementations
+ * must NOT rely on this value for version information.
+ *
+ * Presently, 0 is the only valid value.
+ */
+ uint16_t hal_api_version;
+#define version_minor hal_api_version
+
+ /** Identifier of module */
+ const char *id;
+
+ /** Name of this module */
+ const char *name;
+
+ /** Author/owner/implementor of the module */
+ const char *author;
+
+ /** Modules methods */
+ struct hw_module_methods_t* methods;
+
+ /** module's dso */
+ void* dso;
+
+#ifdef __LP64__
+ uint64_t reserved[32-7];
+#else
+ /** padding to 128 bytes, reserved for future use */
+ uint32_t reserved[32-7];
+#endif
+
+} hw_module_t;
+
+typedef struct hw_module_methods_t {
+ /** Open a specific device */
+ int (*open)(const struct hw_module_t* module, const char* id,
+ struct hw_device_t** device);
+
+} hw_module_methods_t;
+
+/**
+ * Every device data structure must begin with hw_device_t
+ * followed by module specific public methods and attributes.
+ */
+typedef struct hw_device_t {
+ /** tag must be initialized to HARDWARE_DEVICE_TAG */
+ uint32_t tag;
+
+ /**
+ * Version of the module-specific device API. This value is used by
+ * the derived-module user to manage different device implementations.
+ *
+ * The module user is responsible for checking the module_api_version
+ * and device version fields to ensure that the user is capable of
+ * communicating with the specific module implementation.
+ *
+ * One module can support multiple devices with different versions. This
+ * can be useful when a device interface changes in an incompatible way
+ * but it is still necessary to support older implementations at the same
+ * time. One such example is the Camera 2.0 API.
+ *
+ * This field is interpreted by the module user and is ignored by the
+ * HAL interface itself.
+ */
+ uint32_t version;
+
+ /** reference to the module this device belongs to */
+ struct hw_module_t* module;
+
+ /** padding reserved for future use */
+#ifdef __LP64__
+ uint64_t reserved[12];
+#else
+ uint32_t reserved[12];
+#endif
+
+ /** Close this device */
+ int (*close)(struct hw_device_t* device);
+
+} hw_device_t;
+
+/**
+ * Name of the hal_module_info
+ */
+#define HAL_MODULE_INFO_SYM HMI
+
+/**
+ * Name of the hal_module_info as a string
+ */
+#define HAL_MODULE_INFO_SYM_AS_STR "HMI"
+
+/**
+ * Get the module info associated with a module by id.
+ *
+ * @return: 0 == success, <0 == error and *module == NULL
+ */
+int hw_get_module(const char *id, const struct hw_module_t **module);
+
+/**
+ * Get the module info associated with a module instance by class 'class_id'
+ * and instance 'inst'.
+ *
+ * Some modules types necessitate multiple instances. For example audio supports
+ * multiple concurrent interfaces and thus 'audio' is the module class
+ * and 'primary' or 'a2dp' are module interfaces. This implies that the files
+ * providing these modules would be named audio.primary.<variant>.so and
+ * audio.a2dp.<variant>.so
+ *
+ * @return: 0 == success, <0 == error and *module == NULL
+ */
+int hw_get_module_by_class(const char *class_id, const char *inst,
+ const struct hw_module_t **module);
+
+__END_DECLS
+#endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */
diff --git a/src/navigation/sensor/sensor_hal/inc/hwmsen_chip_info.h b/src/navigation/sensor/sensor_hal/inc/hwmsen_chip_info.h
new file mode 100644
index 0000000..19b6626
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/hwmsen_chip_info.h
@@ -0,0 +1,22 @@
+/*
+ * 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 __HWMSEN_CHIP_INFO_H__
+#define __HWMSEN_CHIP_INFO_H__
+
+
+#endif
+
diff --git a/src/navigation/sensor/sensor_hal/inc/hwmsen_custom.h b/src/navigation/sensor/sensor_hal/inc/hwmsen_custom.h
new file mode 100644
index 0000000..f77c2b3
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/hwmsen_custom.h
@@ -0,0 +1,24 @@
+/*
+ * 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 __HWMSEN_CUSTOM_H__
+#define __HWMSEN_CUSTOM_H__
+
+#define MAX_NUM_SENSORS 1
+#define MSENSOR_AMI_LIB
+
+#endif
+
diff --git a/src/navigation/sensor/sensor_hal/inc/hwmsensor.h b/src/navigation/sensor/sensor_hal/inc/hwmsensor.h
new file mode 100644
index 0000000..2a4b4ab
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/hwmsensor.h
@@ -0,0 +1,319 @@
+/*
+ * Copyright (c) 2020, MediaTek Inc. All rights reserved.
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws.
+ * The information contained herein is confidential and proprietary to
+ * MediaTek Inc. and/or its licensors.
+ * Except as otherwise provided in the applicable licensing terms with
+ * MediaTek Inc. and/or its licensors, any reproduction, modification, use or
+ * disclosure of MediaTek Software, and information contained herein, in whole
+ * or in part, shall be strictly prohibited.
+ */
+
+#ifndef __HWMSENSOR_H__
+#define __HWMSENSOR_H__
+
+#include <linux/ioctl.h>
+#include <stdint.h>
+
+#define SENSOR_TYPE_PEDOMETER (35)
+#define SENSOR_STRING_TYPE_PEDOMETER "android.sensor.pedometer"
+#define SENSOR_TYPE_IN_POCKET (36)
+#define SENSOR_STRING_TYPE_IN_POCKET "android.sensor.in_pocket"
+#define SENSOR_TYPE_ACTIVITY (37)
+#define SENSOR_STRING_TYPE_ACTIVITY "android.sensor.activity"
+#define SENSOR_TYPE_PDR 38 /*Add kernel driver*/
+#define SENSOR_STRING_TYPE_PDR "android.sensor.pdr"
+#define SENSOR_TYPE_FREEFALL 39
+#define SENSOR_STRING_TYPE_FREEFALL "android.sensor.freefall"
+#define SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED 40 /*Add kernel driver*/
+#define SENSOR_STRING_TYPE_ACCELEROMETER_UNCALIBRATED "android.sensor.accelerometer_uncalibrated"
+
+#define SENSOR_TYPE_FACE_DOWN (41)
+#define SENSOR_STRING_TYPE_FACE_DOWN "android.sensor.face_down"
+#define SENSOR_TYPE_SHAKE (42)
+#define SENSOR_STRING_TYPE_SHAKE "android.sensor.shake"
+#define SENSOR_TYPE_BRINGTOSEE (43)
+#define SENSOR_STRING_TYPE_BRINGTOSEE "android.sensor.bring_to_see"
+#define SENSOR_TYPE_ANSWER_CALL (44)
+#define SENSOR_STRING_TYPE_ANSWERCALL "android.sensor.answer_call"
+#define SENSOR_TYPE_STATIONARY (45)
+#define SENSOR_STRING_TYPE_STATIONARY "android.sensor.stationary"
+
+/*---------------------------------------------------------------------------*/
+#define ID_BASE 0
+#define ID_ACCELEROMETER (ID_BASE+SENSOR_TYPE_ACCELEROMETER-1)
+#define ID_MAGNETIC (ID_BASE+SENSOR_TYPE_MAGNETIC_FIELD-1)
+#define ID_ORIENTATION (ID_BASE+SENSOR_TYPE_ORIENTATION-1)
+#define ID_GYROSCOPE (ID_BASE+SENSOR_TYPE_GYROSCOPE-1)
+#define ID_LIGHT (ID_BASE+SENSOR_TYPE_LIGHT-1)
+#define ID_PRESSURE (ID_BASE+SENSOR_TYPE_PRESSURE-1)
+#define ID_TEMPERATURE (ID_BASE+SENSOR_TYPE_TEMPERATURE-1)
+#define ID_HUMIDITY (ID_BASE+SENSOR_TYPE_HUMIDITY-1)
+#define ID_PROXIMITY (ID_BASE+SENSOR_TYPE_PROXIMITY-1)
+#define ID_GRAVITY (ID_BASE+SENSOR_TYPE_GRAVITY-1)
+#define ID_LINEAR_ACCELERATION (ID_BASE+SENSOR_TYPE_LINEAR_ACCELERATION-1)
+#define ID_ROTATION_VECTOR (ID_BASE+SENSOR_TYPE_ROTATION_VECTOR-1)
+#define ID_RELATIVE_HUMIDITY (ID_BASE+SENSOR_TYPE_HUMIDITY-1)
+#define ID_AMBIENT_TEMPERATURE (ID_BASE+SENSOR_TYPE_AMBIENT_TEMPERATURE-1)
+#define ID_MAGNETIC_UNCALIBRATED (ID_BASE+SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED-1)
+#define ID_GAME_ROTATION_VECTOR (ID_BASE+SENSOR_TYPE_GAME_ROTATION_VECTOR-1)
+#define ID_GYROSCOPE_UNCALIBRATED (ID_BASE+SENSOR_TYPE_GYROSCOPE_UNCALIBRATED-1)
+#define ID_SIGNIFICANT_MOTION (ID_BASE+SENSOR_TYPE_SIGNIFICANT_MOTION-1)
+#define ID_STEP_DETECTOR (ID_BASE+SENSOR_TYPE_STEP_DETECTOR-1)
+#define ID_STEP_COUNTER (ID_BASE+SENSOR_TYPE_STEP_COUNTER-1)
+#define ID_GEOMAGNETIC_ROTATION_VECTOR (ID_BASE+SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR-1)
+#define ID_HEART_RATE (ID_BASE+SENSOR_TYPE_HEART_RATE-1)
+#define ID_TILT_DETECTOR (ID_BASE+SENSOR_TYPE_TILT_DETECTOR-1)
+#define ID_WAKE_GESTURE (ID_BASE+SENSOR_TYPE_WAKE_GESTURE-1)
+#define ID_GLANCE_GESTURE (ID_BASE+SENSOR_TYPE_GLANCE_GESTURE-1)
+#define ID_PICK_UP_GESTURE (ID_BASE+SENSOR_TYPE_PICK_UP_GESTURE-1)
+#define ID_WRIST_TITL_GESTURE (ID_BASE+SENSOR_TYPE_WRIST_TILT_GESTURE-1)
+
+#define ID_PEDOMETER (ID_BASE+SENSOR_TYPE_PEDOMETER-1)
+#define ID_IN_POCKET (ID_BASE+SENSOR_TYPE_IN_POCKET-1)
+#define ID_ACTIVITY (ID_BASE+SENSOR_TYPE_ACTIVITY-1)
+#define ID_PDR (ID_BASE+SENSOR_TYPE_PDR-1)
+#define ID_FREEFALL (ID_BASE+SENSOR_TYPE_FREEFALL-1)
+#define ID_ACCELEROMETER_UNCALIBRATED (ID_BASE+SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED-1)
+#define ID_FACE_DOWN (ID_BASE+SENSOR_TYPE_FACE_DOWN-1)
+#define ID_SHAKE (ID_BASE+SENSOR_TYPE_SHAKE-1)
+#define ID_BRINGTOSEE (ID_BASE+SENSOR_TYPE_BRINGTOSEE-1)
+#define ID_ANSWER_CALL (ID_BASE+SENSOR_TYPE_ANSWER_CALL-1)
+#define ID_STATIONARY (ID_BASE+SENSOR_TYPE_STATIONARY-1)
+#define ID_SENSOR_MAX_HANDLE (ID_BASE+SENSOR_TYPE_STATIONARY)
+#define ID_NONE (ID_SENSOR_MAX_HANDLE+1)
+
+#define ID_OFFSET (1)
+
+#define MAX_ANDROID_SENSOR_NUM (ID_SENSOR_MAX_HANDLE +1)
+#define MAX_SENSOR_DATA_UPDATE_ONCE (20)
+
+/*---------------------------------------------------------------------------*/
+#define SENSOR_ACCELEROMETER (1 << ID_ACCELEROMETER)
+#define SENSOR_MAGNETIC (1 << ID_MAGNETIC)
+#define SENSOR_ORIENTATION (1 << ID_ORIENTATION)
+#define SENSOR_GYROSCOPE (1 << ID_GYROSCOPE)
+#define SENSOR_LIGHT (1 << ID_LIGHT)
+#define SENSOR_HUMIDITY (1 << ID_HUMIDITY)
+#define SENSOR_PRESSURE (1 << ID_PRESSURE)
+#define SENSOR_TEMPERATURE (1 << ID_TEMPERATURE)
+#define SENSOR_PROXIMITY (1 << ID_PROXIMITY)
+#define SENSOR_GRAVITY (1 << ID_GRAVITY)
+#define SENSOR_LINEAR_ACCELERATION (1 << ID_LINEAR_ACCELERATION)
+#define SENSOR_ROTATION_VECTOR (1 << ID_ROTATION_VECTOR)
+#define SENSOR_RELATIVE_HUMIDITY (1 << ID_RELATIVE_HUMIDITY)
+#define SENSOR_AMBIENT_TEMPERATURE (1 << ID_AMBIENT_TEMPERATURE)
+#define SENSOR_MAGNETIC_UNCALIBRATED (1 << ID_MAGNETIC_UNCALIBRATED)
+#define SENSOR_GAME_ROTATION_VECTOR (1 << ID_GAME_ROTATION_VECTOR)
+#define SENSOR_GYROSCOPE_UNCALIBRATED (1 << ID_GYROSCOPE_UNCALIBRATED)
+
+#define SENSOR_SIGNIFICANT_MOTION (1 << ID_SIGNIFICANT_MOTION)
+#define SENSOR_STEP_DETECTOR (1 << ID_STEP_DETECTOR)
+#define SENSOR_STEP_COUNTER (1 << ID_STEP_COUNTER)
+#define SENSOR_GEOMAGNETIC_ROTATION_VECTOR (1 << ID_GEOMAGNETIC_ROTATION_VECTOR)
+
+#define SENSOR_HEART_RATE (1 << ID_HEART_RATE)
+#define SENSOR_TILT_DETECTOR (1 << ID_TILT_DETECTOR)
+#define SENSOR_WAKE_GESTURE (1 << ID_WAKE_GESTURE)
+#define SENSOR_GLANCE_GESTURE (1 << ID_GLANCE_GESTURE)
+#define SENSOR_PICK_UP_GESTURE (1 << ID_PICK_UP_GESTURE)
+#define SENSOR_WRIST_TITL_GESTURE (1 << ID_WRIST_TITL_GESTURE)
+
+#define SENSOR_PEDOMETER (1 << ID_PEDOMETER)
+#define SENSOR_IN_POCKET (1 << ID_IN_POCKET)
+#define SENSOR_ACTIVITY (1 << ID_ACTIVITY)
+#define SENSOR_PDR (1 << ID_PDR)
+#define SENSOR_FREEFALL (1 << ID_FREEFALL)
+#define SENSOR_ACCELEROMETER_UNCALIBRATED (1 << ID_ACCELEROMETER_UNCALIBRATED)
+#define SENSOR_FACE_DOWN (1 << ID_FACE_DOWN)
+#define SENSOR_SHAKE (1 << ID_SHAKE)
+#define SENSOR_BRINGTOSEE (1 << ID_BRINGTOSEE)
+#define SENSOR_ANSWER_CALL (1 << ID_ANSWER_CALL)
+
+/*----------------------------------------------------------------------------*/
+#define HWM_INPUTDEV_NAME "hwmdata"
+#define HWM_SENSOR_DEV_NAME "hwmsensor"
+#define HWM_SENSOR_DEV "/dev/hwmsensor"
+#define C_MAX_HWMSEN_EVENT_NUM 4
+/*----------------------------------------------------------------------------*/
+#define ACC_PL_DEV_NAME "m_acc_pl"
+#define ACC_INPUTDEV_NAME "m_acc_input"
+#define ACC_MISC_DEV_NAME "m_acc_misc"
+#define MAG_PL_DEV_NAME "m_mag_pl"
+#define MAG_INPUTDEV_NAME "m_mag_input"
+#define MAG_MISC_DEV_NAME "m_mag_misc"
+#define GYRO_PL_DEV_NAME "m_gyro_pl"
+#define GYRO_INPUTDEV_NAME "m_gyro_input"
+#define GYRO_MISC_DEV_NAME "m_gyro_misc"
+#define ALSPS_PL_DEV_NAME "m_alsps_pl"
+#define ALSPS_INPUTDEV_NAME "m_alsps_input"
+#define ALSPS_MISC_DEV_NAME "m_alsps_misc"
+#define BARO_PL_DEV_NAME "m_baro_pl"
+#define BARO_INPUTDEV_NAME "m_baro_input"
+#define BARO_MISC_DEV_NAME "m_baro_misc"
+
+#define STEP_C_PL_DEV_NAME "m_step_c_pl"
+#define STEP_C_INPUTDEV_NAME "m_step_c_input"
+#define STEP_C_MISC_DEV_NAME "m_step_c_misc"
+
+#define INPK_PL_DEV_NAME "m_inpk_pl"
+#define INPK_INPUTDEV_NAME "m_inpk_input"
+#define INPK_MISC_DEV_NAME "m_inpk_misc"
+
+#define SHK_PL_DEV_NAME "m_shk_pl"
+#define SHK_INPUTDEV_NAME "m_shk_input"
+#define SHK_MISC_DEV_NAME "m_shk_misc"
+
+#define FDN_PL_DEV_NAME "m_fdn_pl"
+#define FDN_INPUTDEV_NAME "m_fdn_input"
+#define FDN_MISC_DEV_NAME "m_fdn_misc"
+
+#define PKUP_PL_DEV_NAME "m_pkup_pl"
+#define PKUP_INPUTDEV_NAME "m_pkup_input"
+#define PKUP_MISC_DEV_NAME "m_pkup_misc"
+
+#define ACT_PL_DEV_NAME "m_act_pl"
+#define ACT_INPUTDEV_NAME "m_act_input"
+#define ACT_MISC_DEV_NAME "m_act_misc"
+
+#define PDR_PL_DEV_NAME "m_pdr_pl"
+#define PDR_INPUTDEV_NAME "m_pdr_input"
+#define PDR_MISC_DEV_NAME "m_pdr_misc"
+
+#define HRM_PL_DEV_NAME "m_hrm_pl"
+#define HRM_INPUTDEV_NAME "m_hrm_input"
+#define HRM_MISC_DEV_NAME "m_hrm_misc"
+
+#define TILT_PL_DEV_NAME "m_tilt_pl"
+#define TILT_INPUTDEV_NAME "m_tilt_input"
+#define TILT_MISC_DEV_NAME "m_tilt_misc"
+
+#define WAG_PL_DEV_NAME "m_wag_pl"
+#define WAG_INPUTDEV_NAME "m_wag_input"
+#define WAG_MISC_DEV_NAME "m_wag_misc"
+
+#define GLG_PL_DEV_NAME "m_glg_pl"
+#define GLG_INPUTDEV_NAME "m_glg_input"
+#define GLG_MISC_DEV_NAME "m_glg_misc"
+
+#define ANSWERCALL_PL_DEV_NAME "m_ancall_pl"
+#define ANSWERCALL_INPUTDEV_NAME "m_ancall_input"
+#define ANSWERCALL_MISC_DEV_NAME "m_ancall_misc"
+
+#define TEMP_PL_DEV_NAME "m_temp_pl"
+#define TEMP_INPUTDEV_NAME "m_temp_input"
+#define TEMP_MISC_DEV_NAME "m_temp_misc"
+
+#define BATCH_PL_DEV_NAME "m_batch_pl"
+#define BATCH_INPUTDEV_NAME "m_batch_input"
+#define BATCH_MISC_DEV_NAME "m_batch_misc"
+
+#define BTS_PL_DEV_NAME "m_bts_pl"
+#define BTS_INPUTDEV_NAME "m_bts_input"
+#define BTS_MISC_DEV_NAME "m_bts_misc"
+
+#define GRV_PL_DEV_NAME "m_grv_pl"
+#define GRV_INPUTDEV_NAME "m_grv_input"
+#define GRV_MISC_DEV_NAME "m_grv_misc"
+
+#define GMRV_PL_DEV_NAME "m_gmrv_pl"
+#define GMRV_INPUTDEV_NAME "m_gmrv_input"
+#define GMRV_MISC_DEV_NAME "m_gmrv_misc"
+
+#define GRAV_PL_DEV_NAME "m_grav_pl"
+#define GRAV_INPUTDEV_NAME "m_grav_input"
+#define GRAV_MISC_DEV_NAME "m_grav_misc"
+
+#define LA_PL_DEV_NAME "m_la_pl"
+#define LA_INPUTDEV_NAME "m_la_input"
+#define LA_MISC_DEV_NAME "m_la_misc"
+
+#define RV_PL_DEV_NAME "m_rv_pl"
+#define RV_INPUTDEV_NAME "m_rv_input"
+#define RV_MISC_DEV_NAME "m_rv_misc"
+
+#define GES_PL_DEV_NAME "m_ges_pl"
+#define GES_INPUTDEV_NAME "m_ges_input"
+#define GES_MISC_DEV_NAME "m_ges_misc"
+
+#define EVENT_TYPE_SENSOR 0x01
+#define EVENT_TYPE_SENSOR_EXT 0x02
+#define EVENT_SENSOR_ACCELERATION SENSOR_ACCELEROMETER
+#define EVENT_SENSOR_MAGNETIC SENSOR_MAGNETIC
+#define EVENT_SENSOR_ORIENTATION SENSOR_ORIENTATION
+#define EVENT_SENSOR_GYROSCOPE SENSOR_GYROSCOPE
+#define EVENT_SENSOR_LIGHT SENSOR_LIGHT
+#define EVENT_SENSOR_PRESSURE SENSOR_PRESSURE
+#define EVENT_SENSOR_TEMPERATURE SENSOR_TEMPERATURE
+#define EVENT_SENSOR_PROXIMITY SENSOR_PROXIMITY
+#define EVENT_SENSOR_GRAVITY SENSOR_PRESSURE
+#define EVENT_SENSOR_LINEAR_ACCELERATION SENSOR_LINEAR_ACCELERATION
+#define EVENT_SENSOR_ROTATION_VECTOR SENSOR_ROTATION_VECTOR
+/*-----------------------------------------------------------------------------*/
+
+enum {
+ HWM_MODE_DISABLE = 0,
+ HWM_MODE_ENABLE = 1,
+};
+
+/*------------sensors data----------------------------------------------------*/
+typedef struct {
+ /* sensor identifier */
+ int sensor;
+ /* sensor values */
+ union {
+ int values[6];
+ uint8_t probability[12];
+ };
+ /* sensor values divide */
+ uint32_t value_divide;
+ /* sensor accuracy*/
+ int8_t status;
+ /* whether updata? */
+ int update;
+ /* time is in nanosecond */
+ int64_t time;
+
+ uint32_t reserved;
+}hwm_sensor_data;
+
+typedef struct {
+ hwm_sensor_data data[MAX_SENSOR_DATA_UPDATE_ONCE];
+ uint64_t data_type;
+}hwm_trans_data;
+
+#define MAX_BATCH_DATA_PER_QUREY 18
+typedef struct {
+ int numOfDataReturn;
+ int numOfDataLeft;
+ hwm_sensor_data data[MAX_BATCH_DATA_PER_QUREY];
+}batch_trans_data;
+
+/*----------------------------------------------------------------------------*/
+#define HWM_IOC_MAGIC 0x91
+
+/* set delay */
+#define HWM_IO_SET_DELAY _IOW(HWM_IOC_MAGIC, 0x01, uint32_t)
+
+/* wake up */
+#define HWM_IO_SET_WAKE _IO(HWM_IOC_MAGIC, 0x02)
+
+/* Enable/Disable sensor */
+#define HWM_IO_ENABLE_SENSOR _IOW(HWM_IOC_MAGIC, 0x03, uint32_t)
+#define HWM_IO_DISABLE_SENSOR _IOW(HWM_IOC_MAGIC, 0x04, uint32_t)
+
+/* Enable/Disable sensor */
+#define HWM_IO_ENABLE_SENSOR_NODATA _IOW(HWM_IOC_MAGIC, 0x05, uint32_t)
+#define HWM_IO_DISABLE_SENSOR_NODATA _IOW(HWM_IOC_MAGIC, 0x06, uint32_t)
+/* Get sensors data */
+#define HWM_IO_GET_SENSORS_DATA _IOWR(HWM_IOC_MAGIC, 0x07, hwm_trans_data)
+
+/*----------------------------------------------------------------------------*/
+#define BATCH_IOC_MAGIC 0x92
+
+/* Get sensor data */
+#define BATCH_IO_GET_SENSORS_DATA _IOWR(BATCH_IOC_MAGIC, 0x01, batch_trans_data)
+
+#endif // __HWMSENSOR_H__
diff --git a/src/navigation/sensor/sensor_hal/inc/nusensors.h b/src/navigation/sensor/sensor_hal/inc/nusensors.h
new file mode 100644
index 0000000..b047628
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/nusensors.h
@@ -0,0 +1,264 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_SENSORS_H
+#define ANDROID_SENSORS_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <linux/input.h>
+#include "sensors.h"
+
+__BEGIN_DECLS
+/*****************************************************************************/
+
+int init_nusensors(sensors_poll_device_1_t** device);
+//static int g_sensor_user_count[32];
+
+/*****************************************************************************/
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+/*
+#define ID_A (0)
+#define ID_M (1)
+#define ID_O (2)
+#define ID_Gyro (3)
+
+#define ID_P (7)
+#define ID_L (4)
+*/
+
+/*****************************************************************************/
+
+/*
+ * The SENSORS Module
+ */
+
+/* the CM3602 is a binary proximity sensor that triggers around 9 cm on
+ * this hardware */
+
+/*****************************************************************************/
+
+#define CM_DEVICE_NAME "/dev/hwmsensor"
+#define LS_DEVICE_NAME "/dev/hwmsensor"
+
+
+#define EVENT_TYPE_ACCEL_X ABS_X
+#define EVENT_TYPE_ACCEL_Y ABS_Y
+#define EVENT_TYPE_ACCEL_Z ABS_Z
+#define EVENT_TYPE_ACCEL_T ABS_RX
+#define EVENT_TYPE_ACCEL_UPDATE REL_X
+#define EVENT_TYPE_ACCEL_STATUS ABS_WHEEL
+#define EVENT_TYPE_ACCEL_TIMESTAMP_HI REL_HWHEEL
+#define EVENT_TYPE_ACCEL_TIMESTAMP_LO REL_DIAL
+
+#define EVENT_TYPE_GYRO_X ABS_X
+#define EVENT_TYPE_GYRO_Y ABS_Y
+#define EVENT_TYPE_GYRO_Z ABS_Z
+#define EVENT_TYPE_GYRO_T ABS_RX
+#define EVENT_TYPE_GYRO_UPDATE REL_X
+#define EVENT_TYPE_GYRO_STATUS ABS_WHEEL
+#define EVENT_TYPE_GYRO_TIMESTAMP_HI REL_HWHEEL
+#define EVENT_TYPE_GYRO_TIMESTAMP_LO REL_DIAL
+
+#define EVENT_TYPE_ORIENT_X ABS_RX
+#define EVENT_TYPE_ORIENT_Y ABS_RY
+#define EVENT_TYPE_ORIENT_Z ABS_RZ
+#define EVENT_TYPE_ORIENT_UPDATE REL_RX
+#define EVENT_TYPE_ORIENT_STATUS ABS_THROTTLE
+#define EVENT_TYPE_ORIENT_TIMESTAMP_HI REL_WHEEL
+#define EVENT_TYPE_ORIENT_TIMESTAMP_LO REL_MISC
+
+#define EVENT_TYPE_MAG_X ABS_X
+#define EVENT_TYPE_MAG_Y ABS_Y
+#define EVENT_TYPE_MAG_Z ABS_Z
+#define EVENT_TYPE_MAG_UPDATE REL_X
+#define EVENT_TYPE_MAG_STATUS ABS_WHEEL
+#define EVENT_TYPE_MAG_TIMESTAMP_HI REL_HWHEEL
+#define EVENT_TYPE_MAG_TIMESTAMP_LO REL_DIAL
+
+#define EVENT_TYPE_TEMPERATURE_VALUE ABS_X
+#define EVENT_TYPE_TEMPERATURE_STATUS ABS_WHEEL
+#define EVENT_TYPE_TEMPERATURE_TIMESTAMP_HI REL_HWHEEL
+#define EVENT_TYPE_TEMPERATURE_TIMESTAMP_LO REL_DIAL
+
+#define EVENT_TYPE_BARO_VALUE ABS_X
+#define EVENT_TYPE_BARO_VALUE_T ABS_Y
+#define EVENT_TYPE_BARO_STATUS ABS_WHEEL
+#define EVENT_TYPE_BARO_TIMESTAMP_HI REL_HWHEEL
+#define EVENT_TYPE_BARO_TIMESTAMP_LO REL_DIAL
+
+#define EVENT_TYPE_HMDY_VALUE REL_X
+#define EVENT_TYPE_HMDY_STATUS ABS_WHEEL
+
+
+#define EVENT_TYPE_STEP_COUNTER_VALUE ABS_X
+#define EVENT_TYPE_STEP_DETECTOR_VALUE REL_Y
+#define EVENT_TYPE_SIGNIFICANT_VALUE REL_Z
+
+#define EVENT_TYPE_INPK_VALUE 0x1
+#define EVENT_TYPE_STATIONARY_VALUE 0x2
+
+#define EVENT_TYPE_SHK_VALUE REL_X
+#define EVENT_TYPE_FDN_VALUE REL_X
+#define EVENT_TYPE_PKUP_VALUE REL_X
+#define EVENT_TYPE_BTS_VALUE REL_X
+
+#define EVENT_TYPE_PEDO_LENGTH REL_X
+#define EVENT_TYPE_PEDO_FREQUENCY REL_Y
+#define EVENT_TYPE_PEDO_COUNT REL_Z
+#define EVENT_TYPE_PEDO_DISTANCE REL_RX
+
+#define EVENT_TYPE_PDR_X ABS_RY
+#define EVENT_TYPE_PDR_Y ABS_RZ
+#define EVENT_TYPE_PDR_Z ABS_THROTTLE
+#define EVENT_TYPE_PDR_SCALAR ABS_RUDDER
+#define EVENT_TYPE_PDR_STATUS REL_X
+#define EVENT_TYPE_ACT_IN_VEHICLE ABS_X
+#define EVENT_TYPE_ACT_ON_BICYCLE ABS_Y
+#define EVENT_TYPE_ACT_ON_FOOT ABS_Z
+#define EVENT_TYPE_ACT_STILL ABS_RX
+#define EVENT_TYPE_ACT_UNKNOWN ABS_RY
+#define EVENT_TYPE_ACT_TILTING ABS_RZ
+#define EVENT_TYPE_ACT_WALKING ABS_HAT0X
+#define EVENT_TYPE_ACT_STANDING ABS_HAT0Y
+#define EVENT_TYPE_ACT_LYING ABS_HAT1X
+#define EVENT_TYPE_ACT_RUNNING ABS_HAT1Y
+#define EVENT_TYPE_ACT_CLIMBING ABS_HAT2X
+#define EVENT_TYPE_ACT_SITTING ABS_HAT2Y
+#define EVENT_TYPE_ACT_STATUS ABS_WHEEL
+
+#define EVENT_TYPE_HRM_BPM ABS_X
+#define EVENT_TYPE_HRM_STATUS ABS_Y
+
+
+#define EVENT_TYPE_TILT_VALUE ABS_X
+#define EVENT_TYPE_WAG_VALUE ABS_X
+#define EVENT_TYPE_GLG_VALUE ABS_X
+#define EVENT_TYPE_ANSWER_CALL_VALUE REL_X
+
+#define EVENT_TYPE_ALS_VALUE ABS_X
+#define EVENT_TYPE_PS_VALUE REL_Z
+#define EVENT_TYPE_ALS_STATUS ABS_WHEEL
+#define EVENT_TYPE_PS_STATUS REL_Y
+
+#define EVENT_TYPE_BATCH_X ABS_X
+#define EVENT_TYPE_BATCH_Y ABS_Y
+#define EVENT_TYPE_BATCH_Z ABS_Z
+#define EVENT_TYPE_BATCH_STATUS ABS_WHEEL
+#define EVENT_TYPE_SENSORTYPE REL_RZ
+#define EVENT_TYPE_BATCH_VALUE ABS_RX
+#define EVENT_TYPE_END_FLAG REL_RY
+#define EVENT_TYPE_TIMESTAMP_HI REL_HWHEEL
+#define EVENT_TYPE_TIMESTAMP_LO REL_DIAL
+#define EVENT_TYPE_BATCH_READY REL_X
+
+#define EVENT_TYPE_GRV_X ABS_RY
+#define EVENT_TYPE_GRV_Y ABS_RZ
+#define EVENT_TYPE_GRV_Z ABS_THROTTLE
+#define EVENT_TYPE_GRV_SCALAR ABS_RUDDER
+#define EVENT_TYPE_GRV_STATUS REL_X
+
+#define EVENT_TYPE_GRAV_X ABS_RX
+#define EVENT_TYPE_GRAV_Y ABS_Y
+#define EVENT_TYPE_GRAV_Z ABS_Z
+#define EVENT_TYPE_GRAV_STATUS REL_X
+
+#define EVENT_TYPE_LA_X ABS_RX
+#define EVENT_TYPE_LA_Y ABS_Y
+#define EVENT_TYPE_LA_Z ABS_Z
+#define EVENT_TYPE_LA_STATUS REL_X
+
+#define EVENT_TYPE_GMRV_X ABS_RY
+#define EVENT_TYPE_GMRV_Y ABS_RZ
+#define EVENT_TYPE_GMRV_Z ABS_THROTTLE
+#define EVENT_TYPE_GMRV_SCALAR ABS_RUDDER
+#define EVENT_TYPE_GMRV_STATUS REL_X
+
+#define EVENT_TYPE_RV_X ABS_RY
+#define EVENT_TYPE_RV_Y ABS_RZ
+#define EVENT_TYPE_RV_Z ABS_THROTTLE
+#define EVENT_TYPE_RV_SCALAR ABS_RUDDER
+#define EVENT_TYPE_RV_STATUS REL_X
+
+#define EVENT_TYPE_UNCALI_GYRO_X ABS_X
+#define EVENT_TYPE_UNCALI_GYRO_Y ABS_Y
+#define EVENT_TYPE_UNCALI_GYRO_Z ABS_Z
+#define EVENT_TYPE_UNCALI_GYRO_X_BIAS ABS_RX
+#define EVENT_TYPE_UNCALI_GYRO_Y_BIAS ABS_RY
+#define EVENT_TYPE_UNCALI_GYRO_Z_BIAS ABS_RZ
+#define EVENT_TYPE_UNCALI_GYRO_UPDATE REL_X
+
+#define EVENT_TYPE_UNCALI_MAG_X ABS_X
+#define EVENT_TYPE_UNCALI_MAG_Y ABS_Y
+#define EVENT_TYPE_UNCALI_MAG_Z ABS_Z
+#define EVENT_TYPE_UNCALI_MAG_X_BIAS ABS_RX
+#define EVENT_TYPE_UNCALI_MAG_Y_BIAS ABS_RY
+#define EVENT_TYPE_UNCALI_MAG_Z_BIAS ABS_RZ
+#define EVENT_TYPE_UNCALI_MAG_UPDATE REL_X
+
+#define EVENT_TYPE_STEP_COUNT ABS_GAS
+
+
+// 720 LSG = 1G
+#define LSG (720.0f)
+
+
+// conversion of acceleration data to SI units (m/s^2)
+#define CONVERT_A (GRAVITY_EARTH / LSG)
+#define CONVERT_A_X (-CONVERT_A)
+#define CONVERT_A_Y (CONVERT_A)
+#define CONVERT_A_Z (-CONVERT_A)
+
+// conversion of magnetic data to uT units
+#define CONVERT_M (1.0f/16.0f)
+#define CONVERT_M_X (-CONVERT_M)
+#define CONVERT_M_Y (-CONVERT_M)
+#define CONVERT_M_Z (CONVERT_M)
+
+#define CONVERT_O (1.0f)
+#define CONVERT_O_Y (CONVERT_O)
+#define CONVERT_O_P (CONVERT_O)
+#define CONVERT_O_R (-CONVERT_O)
+
+#define SENSOR_STATE_MASK (0x7FFF)
+
+/*****************************************************************************/
+
+__END_DECLS
+#endif // ANDROID_SENSORS_H
diff --git a/src/navigation/sensor/sensor_hal/inc/sensordebug.h b/src/navigation/sensor/sensor_hal/inc/sensordebug.h
new file mode 100644
index 0000000..66846f7
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/sensordebug.h
@@ -0,0 +1,102 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef ANDROID_SENSOR_DEBUG_H
+#define ANDROID_SENSOR_DEBUG_H
+
+#include <fcntl.h>
+#include <errno.h>
+#include <dirent.h>
+#include <math.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <poll.h>
+#include <pthread.h>
+
+#include <linux/input.h>
+#include <signal.h>
+#include <pthread.h>
+
+#include "SensorBase.h"
+
+//for M-sensor Accurancy Debug log
+#define SENSOR_LOG "/data/msensor1.log"
+#define SENSOR_LOG2 "/data/msensor2.log"
+#define MAX_RECORD_LEN 1048576//5242880(5MB) //2097152 (2MB)/ 1048576(1MB)
+#define TEMP_BUFFER_SIZE 2048
+
+
+/*****************************************************************************/
+
+class SensorDebugObject {
+protected:
+ int m_G_active_log_path_id;
+ int m_MSENSOR_ACCURANCY;
+ int m_Mode_value;
+ int m_Data_len;
+ bool m_Is_old_m_driver;
+ bool m_Is_old_g_driver;
+
+ double m_MAG_DATA;
+
+ char m_Data_buffer[TEMP_BUFFER_SIZE+100];
+ char m_Record_path[2][20];
+
+ static unsigned int SensorDebugBit;
+ static SensorBase* mDebugsensorlist[3];
+
+ pthread_t mThread;
+ pthread_cond_t m_Sensor_event_cond;
+ pthread_mutex_t m_Sensor_mutex;
+
+ void write_sensor_log(char *buf,int len);
+ void m_sensor_debug_func();
+ void g_sensor_debug_func();
+ bool is_old_structure(int sensor);
+ static void * sensors_debug(void *para);
+
+public:
+
+ SensorDebugObject(SensorBase* sensorbaseList, int sensor);
+ virtual ~SensorDebugObject();
+ void send_singnal(int i);
+};
+
+
+
+/*****************************************************************************/
+
+#endif // ANDROID_SENSOR_DEBUG_H
diff --git a/src/navigation/sensor/sensor_hal/inc/sensors.h b/src/navigation/sensor/sensor_hal/inc/sensors.h
new file mode 100644
index 0000000..bfcfa0a
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/inc/sensors.h
@@ -0,0 +1,1459 @@
+/*
+ * Copyright (C) 2012 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_SENSORS_INTERFACE_H
+#define ANDROID_SENSORS_INTERFACE_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stddef.h> // offsetof
+#include <stdarg.h>
+#include <sys/time.h>
+#include <time.h>
+
+
+__BEGIN_DECLS
+
+#define CONFIG_CUSTOM_KERNEL_ACCGYRO
+#define CUSTOM_KERNEL_BARO_TEMP
+
+/*****************************************************************************/
+
+#define SENSORS_HEADER_VERSION 1
+#define SENSORS_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
+#define SENSORS_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, SENSORS_HEADER_VERSION)
+#define SENSORS_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, SENSORS_HEADER_VERSION)
+#define SENSORS_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION_2(1, 1, SENSORS_HEADER_VERSION)
+#define SENSORS_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION_2(1, 2, SENSORS_HEADER_VERSION)
+#define SENSORS_DEVICE_API_VERSION_1_3 HARDWARE_DEVICE_API_VERSION_2(1, 3, SENSORS_HEADER_VERSION)
+#define SENSORS_DEVICE_API_VERSION_1_4 HARDWARE_DEVICE_API_VERSION_2(1, 4, SENSORS_HEADER_VERSION)
+
+/**
+ * Please see the Sensors section of source.android.com for an
+ * introduction to and detailed descriptions of Android sensor types:
+ * http://source.android.com/devices/sensors/index.html
+ */
+
+/**
+ * The id of this module
+ */
+#define SENSORS_HARDWARE_MODULE_ID "sensors"
+
+/**
+ * Name of the sensors device to open
+ */
+#define SENSORS_HARDWARE_POLL "poll"
+
+/**
+ * Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
+ * A Handle identifies a given sensors. The handle is used to activate
+ * and/or deactivate sensors.
+ * In this version of the API there can only be 256 handles.
+ */
+#define SENSORS_HANDLE_BASE 0
+#define SENSORS_HANDLE_BITS 8
+#define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS)
+
+
+/*
+ * **** Deprecated *****
+ * flags for (*batch)()
+ * Availability: SENSORS_DEVICE_API_VERSION_1_0
+ * see (*batch)() documentation for details.
+ * Deprecated as of SENSORS_DEVICE_API_VERSION_1_3.
+ * WAKE_UP_* sensors replace WAKE_UPON_FIFO_FULL concept.
+ */
+enum {
+ SENSORS_BATCH_DRY_RUN = 0x00000001,
+ SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002
+};
+
+/*
+ * what field for meta_data_event_t
+ */
+enum {
+ /* a previous flush operation has completed */
+ META_DATA_FLUSH_COMPLETE = 1,
+ META_DATA_VERSION /* always last, leave auto-assigned */
+};
+
+/*
+ * The permission to use for body sensors (like heart rate monitors).
+ * See sensor types for more details on what sensors should require this
+ * permission.
+ */
+#define SENSOR_PERMISSION_BODY_SENSORS "android.permission.BODY_SENSORS"
+
+/*
+ * Availability: SENSORS_DEVICE_API_VERSION_1_4
+ * Sensor HAL modes used in set_operation_mode method
+ */
+enum {
+ /*
+ * Operating modes for the HAL.
+ */
+
+ /*
+ * Normal mode operation. This is the default state of operation.
+ * The HAL shall initialize into this mode on device startup.
+ */
+ SENSOR_HAL_NORMAL_MODE = 0,
+
+ /*
+ * Data Injection mode. In this mode, the device shall not source data from the
+ * physical sensors as it would in normal mode. Instead sensor data is
+ * injected by the sensor service.
+ */
+ SENSOR_HAL_DATA_INJECTION_MODE = 0x1
+};
+
+#define SENSOR_FLAG_MASK(nbit, shift) (((1<<(nbit))-1)<<(shift))
+#define SENSOR_FLAG_MASK_1(shift) SENSOR_FLAG_MASK(1, shift)
+
+/*
+ * Mask and shift for reporting mode sensor flags defined above.
+ */
+#define REPORTING_MODE_SHIFT (1)
+#define REPORTING_MODE_NBIT (3)
+#define REPORTING_MODE_MASK SENSOR_FLAG_MASK(REPORTING_MODE_NBIT, REPORTING_MODE_SHIFT)
+ // 0xE
+
+/*
+ * Mask and shift for data_injection mode sensor flags defined above.
+ */
+#define DATA_INJECTION_SHIFT (4)
+#define DATA_INJECTION_MASK SENSOR_FLAG_MASK_1(DATA_INJECTION_SHIFT) //0x10
+
+/*
+ * Mask and shift for dynamic sensor flag.
+ */
+#define DYNAMIC_SENSOR_SHIFT (5)
+#define DYNAMIC_SENSOR_MASK SENSOR_FLAG_MASK_1(DYNAMIC_SENSOR_SHIFT) //0x20
+
+/*
+ * Mask and shift for sensor additional information support.
+ */
+#define ADDITIONAL_INFO_SHIFT (6)
+#define ADDITIONAL_INFO_MASK SENSOR_FLAG_MASK_1(ADDITIONAL_INFO_SHIFT) //0x40
+
+/*
+ * Availability: SENSORS_DEVICE_API_VERSION_1_3
+ * Sensor flags used in sensor_t.flags.
+ */
+enum {
+ /*
+ * Whether this sensor wakes up the AP from suspend mode when data is available. Whenever
+ * sensor events are delivered from a wake_up sensor, the driver needs to hold a wake_lock till
+ * the events are read by the SensorService i.e till sensors_poll_device_t.poll() is called the
+ * next time. Once poll is called again it means events have been read by the SensorService, the
+ * driver can safely release the wake_lock. SensorService will continue to hold a wake_lock till
+ * the app actually reads the events.
+ */
+ SENSOR_FLAG_WAKE_UP = 1U << 0,
+ /*
+ * Reporting modes for various sensors. Each sensor will have exactly one of these modes set.
+ * The least significant 2nd, 3rd and 4th bits are used to represent four possible reporting
+ * modes.
+ */
+ SENSOR_FLAG_CONTINUOUS_MODE = 0, // 0000
+ SENSOR_FLAG_ON_CHANGE_MODE = 0x2, // 0010
+ SENSOR_FLAG_ONE_SHOT_MODE = 0x4, // 0100
+ SENSOR_FLAG_SPECIAL_REPORTING_MODE = 0x6, // 0110
+
+ /*
+ * Set this flag if the sensor supports data_injection mode and allows data to be injected
+ * from the SensorService. When in data_injection ONLY sensors with this flag set are injected
+ * sensor data and only sensors with this flag set are activated. Eg: Accelerometer and Step
+ * Counter sensors can be set with this flag and SensorService will inject accelerometer data
+ * and read the corresponding step counts.
+ */
+ SENSOR_FLAG_SUPPORTS_DATA_INJECTION = DATA_INJECTION_MASK, // 1 0000
+
+ /*
+ * Set this flag if the sensor is a dynamically connected sensor. See
+ * dynamic_sensor_meta_event_t and SENSOR_TYPE_DYNAMIC_SENSOR_META for details.
+ */
+ SENSOR_FLAG_DYNAMIC_SENSOR = DYNAMIC_SENSOR_MASK,
+
+ /*
+ * Set this flag if sensor additional information is supported. See SENSOR_TYPE_ADDITIONAL_INFO
+ * and additional_info_event_t for details.
+ */
+ SENSOR_FLAG_ADDITIONAL_INFO = ADDITIONAL_INFO_MASK
+};
+
+
+/*
+ * Sensor type
+ *
+ * Each sensor has a type which defines what this sensor measures and how
+ * measures are reported. See the Base sensors and Composite sensors lists
+ * for complete descriptions:
+ * http://source.android.com/devices/sensors/base_triggers.html
+ * http://source.android.com/devices/sensors/composite_sensors.html
+ *
+ * Device manufacturers (OEMs) can define their own sensor types, for
+ * their private use by applications or services provided by them. Such
+ * sensor types are specific to an OEM and can't be exposed in the SDK.
+ * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE.
+ *
+ * All sensors defined outside of the device private range must correspond to
+ * a type defined in this file, and must satisfy the characteristics listed in
+ * the description of the sensor type.
+ *
+ * Starting with version SENSORS_DEVICE_API_VERSION_1_2, each sensor also
+ * has a stringType.
+ * - StringType of sensors inside of the device private range MUST be prefixed
+ * by the sensor provider's or OEM reverse domain name. In particular, they
+ * cannot use the "android.sensor" prefix.
+ * - StringType of sensors outside of the device private range MUST correspond
+ * to the one defined in this file (starting with "android.sensor").
+ * For example, accelerometers must have
+ * type=SENSOR_TYPE_ACCELEROMETER and
+ * stringType=SENSOR_STRING_TYPE_ACCELEROMETER
+ *
+ * When android introduces a new sensor type that can replace an OEM-defined
+ * sensor type, the OEM must use the official sensor type and stringType on
+ * versions of the HAL that support this new official sensor type.
+ *
+ * Example (made up): Suppose Google's Glass team wants to surface a sensor
+ * detecting that Glass is on a head.
+ * - Such a sensor is not officially supported in android KitKat
+ * - Glass devices launching on KitKat can implement a sensor with
+ * type = 0x10001 and stringType = "com.google.glass.onheaddetector"
+ * - In L android release, if android decides to define
+ * SENSOR_TYPE_ON_HEAD_DETECTOR and STRING_SENSOR_TYPE_ON_HEAD_DETECTOR,
+ * those types should replace the Glass-team-specific types in all future
+ * launches.
+ * - When launching Glass on the L release, Google should now use the official
+ * type (SENSOR_TYPE_ON_HEAD_DETECTOR) and stringType.
+ * - This way, all applications can now use this sensor.
+ */
+
+/*
+ * Base for device manufacturers private sensor types.
+ * These sensor types can't be exposed in the SDK.
+ */
+#define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000
+
+/*
+ * SENSOR_TYPE_META_DATA
+ * reporting-mode: n/a
+ * wake-up sensor: n/a
+ *
+ * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
+ *
+ * SENSOR_TYPE_META_DATA is a special token used to populate the
+ * sensors_meta_data_event structure. It doesn't correspond to a physical
+ * sensor. sensors_meta_data_event are special, they exist only inside
+ * the HAL and are generated spontaneously, as opposed to be related to
+ * a physical sensor.
+ *
+ * sensors_meta_data_event_t.version must be META_DATA_VERSION
+ * sensors_meta_data_event_t.sensor must be 0
+ * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA
+ * sensors_meta_data_event_t.reserved must be 0
+ * sensors_meta_data_event_t.timestamp must be 0
+ *
+ * The payload is a meta_data_event_t, where:
+ * meta_data_event_t.what can take the following values:
+ *
+ * META_DATA_FLUSH_COMPLETE
+ * This event indicates that a previous (*flush)() call has completed for the sensor
+ * handle specified in meta_data_event_t.sensor.
+ * see (*flush)() for more details
+ *
+ * All other values for meta_data_event_t.what are reserved and
+ * must not be used.
+ *
+ */
+#define SENSOR_TYPE_META_DATA (0)
+
+/*
+ * Wake up sensors.
+ * Each sensor may have either or both a wake-up and a non-wake variant.
+ * When registered in batch mode, wake-up sensors will wake up the AP when
+ * their FIFOs are full or when the batch timeout expires. A separate FIFO has
+ * to be maintained for wake up sensors and non wake up sensors. The non wake-up
+ * sensors need to overwrite their FIFOs when they are full till the AP wakes up
+ * and the wake-up sensors will wake-up the AP when their FIFOs are full or when
+ * the batch timeout expires without losing events. Wake-up and non wake-up variants
+ * of each sensor can be activated at different rates independently of each other.
+ *
+ * Note: Proximity sensor and significant motion sensor which were defined in previous
+ * releases are also wake-up sensors and should be treated as such. Wake-up one-shot
+ * sensors like SIGNIFICANT_MOTION cannot be batched, hence the text about batch above
+ * doesn't apply to them. See the definitions of SENSOR_TYPE_PROXIMITY and
+ * SENSOR_TYPE_SIGNIFICANT_MOTION for more info.
+ *
+ * Set SENSOR_FLAG_WAKE_UP flag for all wake-up sensors.
+ *
+ * For example, A device can have two sensors both of SENSOR_TYPE_ACCELEROMETER and
+ * one of them can be a wake_up sensor (with SENSOR_FLAG_WAKE_UP flag set) and the other
+ * can be a regular non wake_up sensor. Both of these sensors must be activated/deactivated
+ * independently of the other.
+ */
+
+/*
+ * SENSOR_TYPE_ACCELEROMETER
+ * reporting-mode: continuous
+ *
+ * All values are in SI units (m/s^2) and measure the acceleration of the
+ * device minus the force of gravity.
+ *
+ * Implement the non-wake-up version of this sensor and implement the wake-up
+ * version if the system possesses a wake up fifo.
+ */
+#define SENSOR_TYPE_ACCELEROMETER (1)
+#define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer"
+
+/*
+ * SENSOR_TYPE_GEOMAGNETIC_FIELD
+ * reporting-mode: continuous
+ *
+ * All values are in micro-Tesla (uT) and measure the geomagnetic
+ * field in the X, Y and Z axis.
+ *
+ * Implement the non-wake-up version of this sensor and implement the wake-up
+ * version if the system possesses a wake up fifo.
+ */
+#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
+#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
+#define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field"
+
+/*
+ * SENSOR_TYPE_ORIENTATION
+ * reporting-mode: continuous
+ *
+ * All values are angles in degrees.
+ *
+ * Orientation sensors return sensor events for all 3 axes at a constant
+ * rate defined by setDelay().
+ *
+ * Implement the non-wake-up version of this sensor and implement the wake-up
+ * version if the system possesses a wake up fifo.
+ */
+#define SENSOR_TYPE_ORIENTATION (3)
+#define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation"
+
+/*
+ * SENSOR_TYPE_GYROSCOPE
+ * reporting-mode: continuous
+ *
+ * All values are in radians/second and measure the rate of rotation
+ * around the X, Y and Z axis.
+ *
+ * Implement the non-wake-up version of this sensor and implement the wake-up
+ * version if the system possesses a wake up fifo.
+ */
+#define SENSOR_TYPE_GYROSCOPE (4)
+#define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope"
+
+/*
+ * SENSOR_TYPE_LIGHT
+ * reporting-mode: on-change
+ *
+ * The light sensor value is returned in SI lux units.
+ *
+ * Both wake-up and non wake-up versions are useful.
+ */
+#define SENSOR_TYPE_LIGHT (5)
+#define SENSOR_STRING_TYPE_LIGHT "android.sensor.light"
+
+/*
+ * SENSOR_TYPE_PRESSURE
+ * reporting-mode: continuous
+ *
+ * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
+ *
+ * Implement the non-wake-up version of this sensor and implement the wake-up
+ * version if the system possesses a wake up fifo.
+ */
+#define SENSOR_TYPE_PRESSURE (6)
+#define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure"
+
+/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
+#define SENSOR_TYPE_TEMPERATURE (7)
+#define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature"
+
+/*
+ * SENSOR_TYPE_PROXIMITY
+ * reporting-mode: on-change
+ *
+ * The proximity sensor which turns the screen off and back on during calls is the
+ * wake-up proximity sensor. Implement wake-up proximity sensor before implementing
+ * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag
+ * SENSOR_FLAG_WAKE_UP.
+ * The value corresponds to the distance to the nearest object in centimeters.
+ */
+#define SENSOR_TYPE_PROXIMITY (8)
+#define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity"
+
+/*
+ * SENSOR_TYPE_GRAVITY
+ * reporting-mode: continuous
+ *
+ * A gravity output indicates the direction of and magnitude of gravity in
+ * the devices's coordinates.
+ *
+ * Implement the non-wake-up version of this sensor and implement the wake-up
+ * version if the system possesses a wake up fifo.
+ */
+#define SENSOR_TYPE_GRAVITY (9)
+#define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity"
+
+/*
+ * SENSOR_TYPE_LINEAR_ACCELERATION
+ * reporting-mode: continuous
+ *
+ * Indicates the linear acceleration of the device in device coordinates,
+ * not including gravity.
+ *
+ * Implement the non-wake-up version of this sensor and implement the wake-up
+ * version if the system possesses a wake up fifo.
+ */
+#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
+#define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration"
+
+
+/*
+ * SENSOR_TYPE_ROTATION_VECTOR
+ * reporting-mode: continuous
+ *
+ * The rotation vector symbolizes the orientation of the device relative to the
+ * East-North-Up coordinates frame.
+ *
+ * Implement the non-wake-up version of this sensor and implement the wake-up
+ * version if the system possesses a wake up fifo.
+ */
+#define SENSOR_TYPE_ROTATION_VECTOR (11)
+#define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector"
+
+/*
+ * SENSOR_TYPE_RELATIVE_HUMIDITY
+ * reporting-mode: on-change
+ *
+ * A relative humidity sensor measures relative ambient air humidity and
+ * returns a value in percent.
+ *
+ * Both wake-up and non wake-up versions are useful.
+ */
+#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
+#define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity"
+
+/*
+ * SENSOR_TYPE_AMBIENT_TEMPERATURE
+ * reporting-mode: on-change
+ *
+ * The ambient (room) temperature in degree Celsius.
+ *
+ * Both wake-up and non wake-up versions are useful.
+ */
+#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
+#define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature"
+
+/*
+ * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
+ * reporting-mode: continuous
+ *
+ * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
+ * reported separately instead of being included in the measurement.
+ *
+ * Implement the non-wake-up version of this sensor and implement the wake-up
+ * version if the system possesses a wake up fifo.
+ */
+#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
+#define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated"
+
+/*
+ * SENSOR_TYPE_GAME_ROTATION_VECTOR
+ * reporting-mode: continuous
+ *
+ * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
+ * field.
+ *
+ * Implement the non-wake-up version of this sensor and implement the wake-up
+ * version if the system possesses a wake up fifo.
+ */
+#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
+#define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector"
+
+/*
+ * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
+ * reporting-mode: continuous
+ *
+ * All values are in radians/second and measure the rate of rotation
+ * around the X, Y and Z axis.
+ *
+ * Implement the non-wake-up version of this sensor and implement the wake-up
+ * version if the system possesses a wake up fifo.
+ */
+#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
+#define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated"
+
+/*
+ * SENSOR_TYPE_SIGNIFICANT_MOTION
+ * reporting-mode: one-shot
+ *
+ * A sensor of this type triggers an event each time significant motion
+ * is detected and automatically disables itself.
+ * For Significant Motion sensor to be useful, it must be defined as a
+ * wake-up sensor. (set SENSOR_FLAG_WAKE_UP). Implement the wake-up significant motion
+ * sensor. A non wake-up version is not useful.
+ * The only allowed value to return is 1.0.
+ */
+
+#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
+#define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion"
+
+/*
+ * SENSOR_TYPE_STEP_DETECTOR
+ * reporting-mode: special
+ *
+ * A sensor of this type triggers an event each time a step is taken
+ * by the user. The only allowed value to return is 1.0 and an event
+ * is generated for each step.
+ *
+ * Both wake-up and non wake-up versions are useful.
+ */
+
+#define SENSOR_TYPE_STEP_DETECTOR (18)
+#define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector"
+
+
+/*
+ * SENSOR_TYPE_STEP_COUNTER
+ * reporting-mode: on-change
+ *
+ * A sensor of this type returns the number of steps taken by the user since
+ * the last reboot while activated. The value is returned as a uint64_t and is
+ * reset to zero only on a system / android reboot.
+ *
+ * Implement the non-wake-up version of this sensor and implement the wake-up
+ * version if the system possesses a wake up fifo.
+ */
+
+#define SENSOR_TYPE_STEP_COUNTER (19)
+#define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter"
+
+/*
+ * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
+ * reporting-mode: continuous
+ *
+ * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
+ * of using a gyroscope.
+ *
+ * Implement the non-wake-up version of this sensor and implement the wake-up
+ * version if the system possesses a wake up fifo.
+ */
+#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
+#define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector"
+
+/*
+ * SENSOR_TYPE_HEART_RATE
+ * reporting-mode: on-change
+ *
+ * A sensor of this type returns the current heart rate.
+ * The events contain the current heart rate in beats per minute (BPM) and the
+ * status of the sensor during the measurement. See heart_rate_event_t for more
+ * details.
+ *
+ * Because this sensor is on-change, events must be generated when and only
+ * when heart_rate.bpm or heart_rate.status have changed since the last
+ * event. In particular, upon the first activation, unless the device is known
+ * to not be on the body, the status field of the first event must be set to
+ * SENSOR_STATUS_UNRELIABLE. The event should be generated no faster than every
+ * period_ns passed to setDelay() or to batch().
+ * See the definition of the on-change reporting mode for more information.
+ *
+ * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS.
+ *
+ * Both wake-up and non wake-up versions are useful.
+ */
+#define SENSOR_TYPE_HEART_RATE (21)
+#define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
+
+/*
+ * SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
+ * reporting-mode: special (setDelay has no impact)
+ *
+ * A sensor of this type generates an event each time a tilt event is detected. A tilt event
+ * should be generated if the direction of the 2-seconds window average gravity changed by at least
+ * 35 degrees since the activation or the last trigger of the sensor.
+ * reference_estimated_gravity = average of accelerometer measurements over the first
+ * 1 second after activation or the estimated gravity at the last
+ * trigger.
+ * current_estimated_gravity = average of accelerometer measurements over the last 2 seconds.
+ * trigger when angle (reference_estimated_gravity, current_estimated_gravity) > 35 degrees
+ *
+ * Large accelerations without a change in phone orientation should not trigger a tilt event.
+ * For example, a sharp turn or strong acceleration while driving a car should not trigger a tilt
+ * event, even though the angle of the average acceleration might vary by more than 35 degrees.
+ *
+ * Typically, this sensor is implemented with the help of only an accelerometer. Other sensors can
+ * be used as well if they do not increase the power consumption significantly. This is a low power
+ * sensor that should allow the AP to go into suspend mode. Do not emulate this sensor in the HAL.
+ * Like other wake up sensors, the driver is expected to a hold a wake_lock with a timeout of 200 ms
+ * while reporting this event. The only allowed return value is 1.0.
+ *
+ * Implement only the wake-up version of this sensor.
+ */
+#define SENSOR_TYPE_TILT_DETECTOR (22)
+#define SENSOR_STRING_TYPE_TILT_DETECTOR "android.sensor.tilt_detector"
+
+/*
+ * SENSOR_TYPE_WAKE_GESTURE
+ * reporting-mode: one-shot
+ *
+ * A sensor enabling waking up the device based on a device specific motion.
+ *
+ * When this sensor triggers, the device behaves as if the power button was
+ * pressed, turning the screen on. This behavior (turning on the screen when
+ * this sensor triggers) might be deactivated by the user in the device
+ * settings. Changes in settings do not impact the behavior of the sensor:
+ * only whether the framework turns the screen on when it triggers.
+ *
+ * The actual gesture to be detected is not specified, and can be chosen by
+ * the manufacturer of the device.
+ * This sensor must be low power, as it is likely to be activated 24/7.
+ * The only allowed value to return is 1.0.
+ *
+ * Implement only the wake-up version of this sensor.
+ */
+#define SENSOR_TYPE_WAKE_GESTURE (23)
+#define SENSOR_STRING_TYPE_WAKE_GESTURE "android.sensor.wake_gesture"
+
+/*
+ * SENSOR_TYPE_GLANCE_GESTURE
+ * reporting-mode: one-shot
+ *
+ * A sensor enabling briefly turning the screen on to enable the user to
+ * glance content on screen based on a specific motion. The device should
+ * turn the screen off after a few moments.
+ *
+ * When this sensor triggers, the device turns the screen on momentarily
+ * to allow the user to glance notifications or other content while the
+ * device remains locked in a non-interactive state (dozing). This behavior
+ * (briefly turning on the screen when this sensor triggers) might be deactivated
+ * by the user in the device settings. Changes in settings do not impact the
+ * behavior of the sensor: only whether the framework briefly turns the screen on
+ * when it triggers.
+ *
+ * The actual gesture to be detected is not specified, and can be chosen by
+ * the manufacturer of the device.
+ * This sensor must be low power, as it is likely to be activated 24/7.
+ * The only allowed value to return is 1.0.
+ *
+ * Implement only the wake-up version of this sensor.
+ */
+#define SENSOR_TYPE_GLANCE_GESTURE (24)
+#define SENSOR_STRING_TYPE_GLANCE_GESTURE "android.sensor.glance_gesture"
+
+/**
+ * SENSOR_TYPE_PICK_UP_GESTURE
+ * reporting-mode: one-shot
+ *
+ * A sensor of this type triggers when the device is picked up regardless of wherever is was
+ * before (desk, pocket, bag). The only allowed return value is 1.0.
+ * This sensor de-activates itself immediately after it triggers.
+ *
+ * Implement only the wake-up version of this sensor.
+ */
+#define SENSOR_TYPE_PICK_UP_GESTURE (25)
+#define SENSOR_STRING_TYPE_PICK_UP_GESTURE "android.sensor.pick_up_gesture"
+
+/*
+ * SENSOR_TYPE_WRIST_TILT_GESTURE
+ * trigger-mode: special
+ * wake-up sensor: yes
+ *
+ * A sensor of this type triggers an event each time a tilt of the wrist-worn
+ * device is detected.
+ *
+ * This sensor must be low power, as it is likely to be activated 24/7.
+ * The only allowed value to return is 1.0.
+ *
+ * Implement only the wake-up version of this sensor.
+ */
+#define SENSOR_TYPE_WRIST_TILT_GESTURE (26)
+#define SENSOR_STRING_TYPE_WRIST_TILT_GESTURE "android.sensor.wrist_tilt_gesture"
+
+/*
+ * SENSOR_TYPE_DEVICE_ORIENTATION
+ * reporting-mode: on-change
+ *
+ * The current orientation of the device. The value should be reported in the
+ * first element of the 'data' member variable in sensors_event_t. The only
+ * values that can be reported are (please refer to Android Sensor Coordinate
+ * System to understand the X and Y axis direction with respect to default
+ * orientation):
+ * - 0: device is in default orientation (Y axis is vertical and points up)
+ * - 1: device is rotated 90 degrees counter-clockwise from default
+ * orientation (X axis is vertical and points up)
+ * - 2: device is rotated 180 degrees from default orientation (Y axis is
+ * vertical and points down)
+ * - 3: device is rotated 90 degrees clockwise from default orientation (X axis
+ * is vertical and points down)
+ *
+ * Moving the device to an orientation where the Z axis is vertical (either up
+ * or down) should not cause a new event to be reported.
+ *
+ * To improve the user experience of this sensor, it is recommended to implement
+ * some physical (i.e., rotation angle) and temporal (i.e., delay) hysteresis.
+ * In other words, minor or transient rotations should not cause a new event to
+ * be reported.
+ *
+ * This sensor should only be implemented with the help of an accelerometer.
+ * This is a low power sensor that should reduce the number of interrupts of the
+ * AP. Do not emulate this sensor in the HAL.
+ *
+ * Both wake-up and non wake-up versions are useful.
+ */
+#define SENSOR_TYPE_DEVICE_ORIENTATION (27)
+#define SENSOR_STRING_TYPE_DEVICE_ORIENTATION "android.sensor.device_orientation"
+
+/*
+ * SENSOR_TYPE_POSE_6DOF
+ * trigger-mode: continuous
+ *
+ * A sensor of this type returns the pose of the device.
+ * Pose of the device is defined as the orientation of the device from a
+ * Earth Centered Earth Fixed frame and the translation from an arbitrary
+ * point at subscription.
+ *
+ * This sensor can be high power. It can use any and all of the following
+ * . Accelerometer
+ * . Gyroscope
+ * . Camera
+ * . Depth Camera
+ *
+ */
+#define SENSOR_TYPE_POSE_6DOF (28)
+#define SENSOR_STRING_TYPE_POSE_6DOF "android.sensor.pose_6dof"
+
+/*
+ * SENSOR_TYPE_STATIONARY_DETECT
+ * trigger mode: one shot
+ *
+ * A sensor of this type returns an event if the device is still/stationary for
+ * a while. The period of time to monitor for statinarity should be greater than
+ * 5 seconds, and less than 10 seconds.
+ *
+ * Stationarity here refers to absolute stationarity. eg: device on desk.
+ *
+ * The only allowed value to return is 1.0.
+ */
+#define SENSOR_TYPE_STATIONARY_DETECT (29)
+#define SENSOR_STRING_TYPE_STATIONARY_DETECT "android.sensor.stationary_detect"
+
+/*
+ * SENSOR_TYPE_MOTION_DETECT
+ * trigger mode: one shot
+ *
+ * A sensor of this type returns an event if the device is not still for
+ * a while. The period of time to monitor for statinarity should be greater than
+ * 5 seconds, and less than 10 seconds.
+ *
+ * Motion here refers to any mechanism in which the device is causes to be
+ * moved in its inertial frame. eg: Pickin up the device and walking with it
+ * to a nearby room may trigger motion wherewas keeping the device on a table
+ * on a smooth train moving at constant velocity may not trigger motion.
+ *
+ * The only allowed value to return is 1.0.
+ */
+#define SENSOR_TYPE_MOTION_DETECT (30)
+#define SENSOR_STRING_TYPE_MOTION_DETECT "android.sensor.motion_detect"
+
+/*
+ * SENSOR_TYPE_HEART_BEAT
+ * trigger mode: continuous
+ *
+ * A sensor of this type returns an event everytime a hear beat peak is
+ * detected.
+ *
+ * Peak here ideally corresponds to the positive peak in the QRS complex of
+ * and ECG signal.
+ *
+ * The sensor is not expected to be optimized for latency. As a guide, a
+ * latency of up to 10 seconds is acceptable. However the timestamp attached
+ * to the event should be accurate and should correspond to the time the peak
+ * occured.
+ *
+ * The sensor event contains a parameter for the confidence in the detection
+ * of the peak where 0.0 represent no information at all, and 1.0 represents
+ * certainty.
+ */
+#define SENSOR_TYPE_HEART_BEAT (31)
+#define SENSOR_STRING_TYPE_HEART_BEAT "android.sensor.heart_beat"
+
+/**
+ * SENSOR_TYPE_DYNAMIC_SENSOR_META
+ * trigger-mode: special
+ *
+ * A sensor event of this type is received when a dynamic sensor is added to or removed from the
+ * system. At most one sensor of this type can be present in one sensor HAL implementation and
+ * presence of a sensor of this type in sensor HAL implementation indicates that this sensor HAL
+ * supports dynamic sensor feature. Operations, such as batch, activate and setDelay, to this
+ * special purpose sensor should be treated as no-op and return successful.
+ *
+ * A dynamic sensor connection indicates connection of a physical device or instantiation of a
+ * virtual sensor backed by algorithm; and a dynamic sensor disconnection indicates the the
+ * opposite. A sensor event of SENSOR_TYPE_DYNAMIC_SENSOR_META type should be delivered regardless
+ * of the activation status of the sensor in the event of dynamic sensor connection and
+ * disconnection. In the sensor event, besides the common data entries, "dynamic_sensor_meta", which
+ * includes fields for connection status, handle of the sensor involved, pointer to sensor_t
+ * structure and a uuid field, should be populated.
+ *
+ * At a dynamic sensor connection event, fields of sensor_t structure referenced by a pointer in
+ * dynamic_sensor_meta should be filled as if it was regular sensors. Sensor HAL is responsible for
+ * recovery of memory if the corresponding data is dynamicially allocated. However, the the pointer
+ * must be valid until the first activate call to the sensor reported in this connection event. At a
+ * dynamic sensor disconnection, the sensor_t pointer should be NULL.
+ *
+ * The sensor handle assigned to dynamic sensors should never be the same as that of any regular
+ * static sensors, and should be unique until next boot. In another word, if a handle h is used for
+ * a dynamic sensor A, that same number cannot be used for the same dynamic sensor A or another
+ * dynamic sensor B even after disconnection of A until reboot.
+ *
+ * The UUID field will be used for identifying the sensor in addition to name, vendor and version
+ * and type. For physical sensors of the same model, all sensors will have the same values in
+ * sensor_t, but the UUID should be unique and persistent for each individual unit. An all zero UUID
+ * indicates it is not possible to differentiate individual sensor unit.
+ *
+ */
+#define SENSOR_TYPE_DYNAMIC_SENSOR_META (32)
+#define SENSOR_STRING_TYPE_DYNAMIC_SENSOR_META "android.sensor.dynamic_sensor_meta"
+
+/**
+ * SENSOR_TYPE_ADDITIONAL_INFO
+ * reporting-mode: N/A
+ *
+ * This sensor type is for delivering additional sensor information aside from sensor event data.
+ * Additional information may include sensor front-end group delay, internal calibration parameters,
+ * noise level metrics, device internal temperature, etc.
+ *
+ * This type will never bind to a sensor. In other words, no sensor in the sensor list should be of
+ * the type SENSOR_TYPE_ADDITIONAL_INFO. If a sensor HAL supports sensor additional information
+ * feature, it reports sensor_event_t with "sensor" field set to handle of the reporting sensor and
+ * "type" field set to SENSOR_TYPE_ADDITIONAL_INFO. Delivery of additional information events is
+ * triggered under two conditions: an enable activate() call or a flush() call to the corresponding
+ * sensor.
+ *
+ * A single additional information report consists of multiple frames. Sequences of these frames are
+ * ordered using timestamps, which means the timestamps of sequential frames have to be at least 1
+ * nanosecond apart from each other. Each frame is a sensor_event_t delivered through the HAL
+ * interface, with related data stored in the "additional_info" field, which is of type
+ * additional_info_event_t. The "type" field of additional_info_event_t denotes the nature of the
+ * payload data (see additional_info_type_t). The "serial" field is used to keep the sequence of
+ * payload data that spans multiple frames. The first frame of the entire report is always of type
+ * AINFO_BEGIN, and the last frame is always AINFO_END.
+ *
+ * All additional information frames have to be delivered after flush complete event if flush() was
+ * triggering the report.
+ */
+#define SENSOR_TYPE_ADDITIONAL_INFO (33)
+#define SENSOR_STRING_TYPE_ADDITIONAL_INFO "android.sensor.additional_info"
+
+/**
+ * Values returned by the accelerometer in various locations in the universe.
+ * all values are in SI units (m/s^2)
+ */
+#define GRAVITY_SUN (275.0f)
+#define GRAVITY_EARTH (9.80665f)
+
+/** Maximum magnetic field on Earth's surface */
+#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
+
+/** Minimum magnetic field on Earth's surface */
+#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
+
+/**
+ * Possible values of the status field of sensor events.
+ */
+#define SENSOR_STATUS_NO_CONTACT -1
+#define SENSOR_STATUS_UNRELIABLE 0
+#define SENSOR_STATUS_ACCURACY_LOW 1
+#define SENSOR_STATUS_ACCURACY_MEDIUM 2
+#define SENSOR_STATUS_ACCURACY_HIGH 3
+
+#define SENSOR_TYPE_HUMIDITY 12
+
+#define ID_BASE 0
+#define ID_ACCELEROMETER (ID_BASE+SENSOR_TYPE_ACCELEROMETER-1)
+#define ID_MAGNETIC (ID_BASE+SENSOR_TYPE_MAGNETIC_FIELD-1)
+#define ID_ORIENTATION (ID_BASE+SENSOR_TYPE_ORIENTATION-1)
+#define ID_GYROSCOPE (ID_BASE+SENSOR_TYPE_GYROSCOPE-1)
+#define ID_LIGHT (ID_BASE+SENSOR_TYPE_LIGHT-1)
+#define ID_PRESSURE (ID_BASE+SENSOR_TYPE_PRESSURE-1)
+#define ID_TEMPERATURE (ID_BASE+SENSOR_TYPE_TEMPERATURE-1)
+#define ID_HUMIDITY (ID_BASE+SENSOR_TYPE_HUMIDITY-1)
+#define ID_PROXIMITY (ID_BASE+SENSOR_TYPE_PROXIMITY-1)
+#define ID_GRAVITY (ID_BASE+SENSOR_TYPE_GRAVITY-1)
+#define ID_LINEAR_ACCELERATION (ID_BASE+SENSOR_TYPE_LINEAR_ACCELERATION-1)
+#define ID_ROTATION_VECTOR (ID_BASE+SENSOR_TYPE_ROTATION_VECTOR-1)
+#define ID_RELATIVE_HUMIDITY (ID_BASE+SENSOR_TYPE_HUMIDITY-1)
+#define ID_AMBIENT_TEMPERATURE (ID_BASE+SENSOR_TYPE_AMBIENT_TEMPERATURE-1)
+#define ID_MAGNETIC_UNCALIBRATED (ID_BASE+SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED-1)
+#define ID_GAME_ROTATION_VECTOR (ID_BASE+SENSOR_TYPE_GAME_ROTATION_VECTOR-1)
+#define ID_GYROSCOPE_UNCALIBRATED (ID_BASE+SENSOR_TYPE_GYROSCOPE_UNCALIBRATED-1)
+#define ID_SIGNIFICANT_MOTION (ID_BASE+SENSOR_TYPE_SIGNIFICANT_MOTION-1)
+#define ID_STEP_DETECTOR (ID_BASE+SENSOR_TYPE_STEP_DETECTOR-1)
+#define ID_STEP_COUNTER (ID_BASE+SENSOR_TYPE_STEP_COUNTER-1)
+#define ID_GEOMAGNETIC_ROTATION_VECTOR (ID_BASE+SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR-1)
+#define ID_HEART_RATE (ID_BASE+SENSOR_TYPE_HEART_RATE-1)
+#define ID_TILT_DETECTOR (ID_BASE+SENSOR_TYPE_TILT_DETECTOR-1)
+#define ID_WAKE_GESTURE (ID_BASE+SENSOR_TYPE_WAKE_GESTURE-1)
+#define ID_GLANCE_GESTURE (ID_BASE+SENSOR_TYPE_GLANCE_GESTURE-1)
+#define ID_PICK_UP_GESTURE (ID_BASE+SENSOR_TYPE_PICK_UP_GESTURE-1)
+#define ID_WRIST_TITL_GESTURE (ID_BASE+SENSOR_TYPE_WRIST_TILT_GESTURE-1)
+
+#define ID_PEDOMETER (ID_BASE+SENSOR_TYPE_PEDOMETER-1)
+#define ID_IN_POCKET (ID_BASE+SENSOR_TYPE_IN_POCKET-1)
+#define ID_ACTIVITY (ID_BASE+SENSOR_TYPE_ACTIVITY-1)
+#define ID_PDR (ID_BASE+SENSOR_TYPE_PDR-1)
+#define ID_FREEFALL (ID_BASE+SENSOR_TYPE_FREEFALL-1)
+#define ID_ACCELEROMETER_UNCALIBRATED (ID_BASE+SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED-1)
+#define ID_FACE_DOWN (ID_BASE+SENSOR_TYPE_FACE_DOWN-1)
+#define ID_SHAKE (ID_BASE+SENSOR_TYPE_SHAKE-1)
+#define ID_BRINGTOSEE (ID_BASE+SENSOR_TYPE_BRINGTOSEE-1)
+#define ID_ANSWER_CALL (ID_BASE+SENSOR_TYPE_ANSWER_CALL-1)
+#define ID_STATIONARY (ID_BASE+SENSOR_TYPE_STATIONARY-1)
+#define ID_SENSOR_MAX_HANDLE (ID_BASE+SENSOR_TYPE_STATIONARY)
+#define ID_NONE (ID_SENSOR_MAX_HANDLE+1)
+
+#define ID_OFFSET (1)
+
+
+/**
+ * sensor event data
+ */
+typedef struct {
+ union {
+ float v[4];
+ struct {
+ float x;
+ float y;
+ float z;
+ float t;
+ };
+ struct {
+ float azimuth;
+ float pitch;
+ float roll;
+ float temperature;
+ };
+ };
+ int8_t status;
+ uint8_t reserved[3];
+} sensors_vec_t;
+
+typedef struct {
+ union {
+ float v[2];
+ struct {
+ float data;
+ float temperature;
+ };
+ };
+ int8_t status;
+ uint8_t reserved[3];
+} sensors_vec_t_t;
+
+/**
+ * uncalibrated gyroscope and magnetometer event data
+ */
+typedef struct {
+ union {
+ float uncalib[3];
+ struct {
+ float x_uncalib;
+ float y_uncalib;
+ float z_uncalib;
+ };
+ };
+ union {
+ float bias[3];
+ struct {
+ float x_bias;
+ float y_bias;
+ float z_bias;
+ };
+ };
+} uncalibrated_event_t;
+
+/**
+ * Meta data event data
+ */
+typedef struct meta_data_event {
+ int32_t what;
+ int32_t sensor;
+} meta_data_event_t;
+
+/**
+ * Dynamic sensor meta event. See the description of SENSOR_TYPE_DYNAMIC_SENSOR_META type for
+ * details.
+ */
+typedef struct dynamic_sensor_meta_event {
+ int32_t connected;
+ int32_t handle;
+ const struct sensor_t * sensor; // should be NULL if connected == false
+ uint8_t uuid[16]; // UUID of a dynamic sensor (using RFC 4122 byte order)
+ // For UUID 12345678-90AB-CDEF-1122-334455667788 the uuid field
+ // should be initialized as:
+ // {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x11, ...}
+} dynamic_sensor_meta_event_t;
+
+/**
+ * Heart rate event data
+ */
+typedef struct {
+ // Heart rate in beats per minute.
+ // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
+ float bpm;
+ // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
+ // Note that this value should only be set for sensors that explicitly define
+ // the meaning of this field. This field is not piped through the framework
+ // for other sensors.
+ int8_t status;
+} heart_rate_event_t;
+
+typedef struct {
+ int32_t type; // type of payload data, see additional_info_type_t
+ int32_t serial; // sequence number of this frame for this type
+ union {
+ // for each frame, a single data type, either int32_t or float, should be used.
+ int32_t data_int32[14];
+ float data_float[14];
+ };
+} additional_info_event_t;
+
+typedef enum additional_info_type {
+ //
+ AINFO_BEGIN = 0x0, // Marks the beginning of additional information frames
+ AINFO_END = 0x1, // Marks the end of additional information frames
+ // Basic information
+ AINFO_UNTRACKED_DELAY = 0x10000, // Estimation of the delay that is not tracked by sensor
+ // timestamps. This includes delay introduced by
+ // sensor front-end filtering, data transport, etc.
+ // float[2]: delay in seconds
+ // standard deviation of estimated value
+ //
+ AINFO_INTERNAL_TEMPERATURE, // float: Celsius temperature.
+ //
+ AINFO_VEC3_CALIBRATION, // First three rows of a homogeneous matrix, which
+ // represents calibration to a three-element vector
+ // raw sensor reading.
+ // float[12]: 3x4 matrix in row major order
+ //
+ AINFO_SENSOR_PLACEMENT, // Location and orientation of sensor element in the
+ // device frame: origin is the geometric center of the
+ // mobile device screen surface; the axis definition
+ // corresponds to Android sensor definitions.
+ // float[12]: 3x4 matrix in row major order
+ //
+ AINFO_SAMPLING, // float[2]: raw sample period in seconds,
+ // standard deviation of sampling period
+
+ // Sampling channel modeling information
+ AINFO_CHANNEL_NOISE = 0x20000, // int32_t: noise type
+ // float[n]: parameters
+ //
+ AINFO_CHANNEL_SAMPLER, // float[3]: sample period
+ // standard deviation of sample period,
+ // quantization unit
+ //
+ AINFO_CHANNEL_FILTER, // Represents a filter:
+ // \sum_j a_j y[n-j] == \sum_i b_i x[n-i]
+ //
+ // int32_t[3]: number of feedforward coefficients, M,
+ // number of feedback coefficients, N, for
+ // FIR filter, N=1.
+ // bit mask that represents which element to
+ // which the filter is applied, bit 0 == 1
+ // means this filter applies to vector
+ // element 0.
+ // float[M+N]: filter coefficients (b0, b1, ..., BM-1),
+ // then (a0, a1, ..., aN-1), a0 is always 1.
+ // Multiple frames may be needed for higher
+ // number of taps.
+ //
+ AINFO_CHANNEL_LINEAR_TRANSFORM, // int32_t[2]: size in (row, column) ... 1st frame
+ // float[n]: matrix element values in row major order.
+ //
+ AINFO_CHANNEL_NONLINEAR_MAP, // int32_t[2]: extrapolate method
+ // interpolate method
+ // float[n]: mapping key points in pairs, (in, out)...
+ // (may be used to model saturation)
+ //
+ AINFO_CHANNEL_RESAMPLER, // int32_t: resample method (0-th order, 1st order...)
+ // float[1]: resample ratio (upsampling if < 1.0;
+ // downsampling if > 1.0).
+ //
+
+ // Custom information
+ AINFO_CUSTOM_START = 0x10000000, //
+ // Debugging
+ AINFO_DEBUGGING_START = 0x40000000, //
+} additional_info_type_t;
+
+/**
+ * Union of the various types of sensor data
+ * that can be returned.
+ */
+typedef struct sensors_event_t {
+ /* must be sizeof(struct sensors_event_t) */
+ int32_t version;
+
+ /* sensor identifier */
+ int32_t sensor;
+
+ /* sensor type */
+ int32_t type;
+
+ /* reserved */
+ int32_t reserved0;
+
+ /* time is in nanosecond */
+ int64_t timestamp;
+
+ union {
+ union {
+ float data[16];
+
+ /* acceleration values are in meter per second per second (m/s^2) */
+ sensors_vec_t acceleration;
+
+ /* magnetic vector values are in micro-Tesla (uT) */
+ sensors_vec_t magnetic;
+
+ /* orientation values are in degrees */
+ sensors_vec_t orientation;
+
+ /* gyroscope values are in rad/s */
+ sensors_vec_t gyro;
+
+ /* temperature is in degrees centigrade (Celsius) */
+ float temperature;
+
+ /* distance in centimeters */
+ float distance;
+
+ /* light in SI lux units */
+ float light;
+
+ /* pressure in hectopascal (hPa) */
+ sensors_vec_t_t pressure;
+
+ /* relative humidity in percent */
+ float relative_humidity;
+
+ /* uncalibrated gyroscope values are in rad/s */
+ uncalibrated_event_t uncalibrated_gyro;
+
+ /* uncalibrated magnetometer values are in micro-Teslas */
+ uncalibrated_event_t uncalibrated_magnetic;
+
+ /* heart rate data containing value in bpm and status */
+ heart_rate_event_t heart_rate;
+
+ /* this is a special event. see SENSOR_TYPE_META_DATA above.
+ * sensors_meta_data_event_t events are all reported with a type of
+ * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
+ */
+ meta_data_event_t meta_data;
+
+ /* dynamic sensor meta event. See SENSOR_TYPE_DYNAMIC_SENSOR_META type for details */
+ dynamic_sensor_meta_event_t dynamic_sensor_meta;
+
+ /*
+ * special additional sensor information frame, see
+ * SENSOR_TYPE_ADDITIONAL_INFO for details.
+ */
+ additional_info_event_t additional_info;
+ };
+
+ union {
+ uint64_t data[8];
+
+ /* step-counter */
+ uint64_t step_counter;
+ } u64;
+ };
+
+ /* Reserved flags for internal use. Set to zero. */
+ uint32_t flags;
+
+ uint32_t reserved1[3];
+} sensors_event_t;
+
+
+/* see SENSOR_TYPE_META_DATA */
+typedef sensors_event_t sensors_meta_data_event_t;
+
+
+/**
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+struct sensors_module_t {
+ /**
+ * Enumerate all available sensors. The list is returned in "list".
+ * @return number of sensors in the list
+ */
+ int (*get_sensors_list)(struct sensors_module_t* module,
+ struct sensor_t const** list);
+
+ /**
+ * Place the module in a specific mode. The following modes are defined
+ *
+ * 0 - Normal operation. Default state of the module.
+ * 1 - Loopback mode. Data is injected for the supported
+ * sensors by the sensor service in this mode.
+ * @return 0 on success
+ * -EINVAL if requested mode is not supported
+ * -EPERM if operation is not allowed
+ */
+ int (*set_operation_mode)(unsigned int mode);
+};
+
+struct sensor_t {
+
+ /* Name of this sensor.
+ * All sensors of the same "type" must have a different "name".
+ */
+ const char* name;
+
+ /* vendor of the hardware part */
+ const char* vendor;
+
+ /* version of the hardware part + driver. The value of this field
+ * must increase when the driver is updated in a way that changes the
+ * output of this sensor. This is important for fused sensors when the
+ * fusion algorithm is updated.
+ */
+ int version;
+
+ /* handle that identifies this sensors. This handle is used to reference
+ * this sensor throughout the HAL API.
+ */
+ int handle;
+
+ /* this sensor's type. */
+ int type;
+
+ /* maximum range of this sensor's value in SI units */
+ float maxRange;
+
+ /* smallest difference between two values reported by this sensor */
+ float resolution;
+
+ /* rough estimate of this sensor's power consumption in mA */
+ float power;
+
+ /* this value depends on the reporting mode:
+ *
+ * continuous: minimum sample period allowed in microseconds
+ * on-change : 0
+ * one-shot :-1
+ * special : 0, unless otherwise noted
+ */
+ int32_t minDelay;
+
+ /* number of events reserved for this sensor in the batch mode FIFO.
+ * If there is a dedicated FIFO for this sensor, then this is the
+ * size of this FIFO. If the FIFO is shared with other sensors,
+ * this is the size reserved for that sensor and it can be zero.
+ */
+ uint32_t fifoReservedEventCount;
+
+ /* maximum number of events of this sensor that could be batched.
+ * This is especially relevant when the FIFO is shared between
+ * several sensors; this value is then set to the size of that FIFO.
+ */
+ uint32_t fifoMaxEventCount;
+
+ /* type of this sensor as a string. Set to corresponding
+ * SENSOR_STRING_TYPE_*.
+ * When defining an OEM specific sensor or sensor manufacturer specific
+ * sensor, use your reserve domain name as a prefix.
+ * ex: com.google.glass.onheaddetector
+ * For sensors of known type, the android framework might overwrite this
+ * string automatically.
+ */
+ const char* stringType;
+
+ /* permission required to see this sensor, register to it and receive data.
+ * Set to "" if no permission is required. Some sensor types like the
+ * heart rate monitor have a mandatory require_permission.
+ * For sensors that always require a specific permission, like the heart
+ * rate monitor, the android framework might overwrite this string
+ * automatically.
+ */
+ const char* requiredPermission;
+
+ /* This value is defined only for continuous mode and on-change sensors. It is the delay between
+ * two sensor events corresponding to the lowest frequency that this sensor supports. When lower
+ * frequencies are requested through batch()/setDelay() the events will be generated at this
+ * frequency instead. It can be used by the framework or applications to estimate when the batch
+ * FIFO may be full.
+ *
+ * NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.
+ * continuous, on-change: maximum sampling period allowed in microseconds.
+ * one-shot, special : 0
+ * 2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit
+ * on 64 bit architectures only for binary compatibility reasons.
+ * Availability: SENSORS_DEVICE_API_VERSION_1_3
+ */
+ #ifdef __LP64__
+ int64_t maxDelay;
+ #else
+ int32_t maxDelay;
+ #endif
+
+ /* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here.
+ * It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons.
+ * Availability: SENSORS_DEVICE_API_VERSION_1_3
+ */
+ #ifdef __LP64__
+ uint64_t flags;
+ #else
+ uint32_t flags;
+ #endif
+
+ /* reserved fields, must be zero */
+ void* reserved[2];
+};
+
+
+/*
+ * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
+ * and is present for backward binary and source compatibility.
+ * See the Sensors HAL interface section for complete descriptions of the
+ * following functions:
+ * http://source.android.com/devices/sensors/index.html#hal
+ */
+struct sensors_poll_device_t {
+ int (*activate)(struct sensors_poll_device_t *dev,
+ int sensor_handle, int enabled);
+ int (*setDelay)(struct sensors_poll_device_t *dev,
+ int sensor_handle, int64_t sampling_period_ns);
+ int (*poll)(struct sensors_poll_device_t *dev,
+ sensors_event_t* data, int count);
+ int (*getODR)(struct sensors_poll_device_t *dev,
+ int sensor_handle, int *odr);
+};
+
+/*
+ * struct sensors_poll_device_1 is used in HAL versions >= SENSORS_DEVICE_API_VERSION_1_0
+ */
+typedef struct sensors_poll_device_1 {
+ union {
+ /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
+ * and can be down-cast to it
+ */
+ struct sensors_poll_device_t v0;
+
+ struct {
+
+ /* Activate/de-activate one sensor. Return 0 on success, negative
+ *
+ * sensor_handle is the handle of the sensor to change.
+ * enabled set to 1 to enable, or 0 to disable the sensor.
+ *
+ * Return 0 on success, negative errno code otherwise.
+ */
+ int (*activate)(struct sensors_poll_device_t *dev,
+ int sensor_handle, int enabled);
+
+ /**
+ * Set the events's period in nanoseconds for a given sensor.
+ * If sampling_period_ns > max_delay it will be truncated to
+ * max_delay and if sampling_period_ns < min_delay it will be
+ * replaced by min_delay.
+ */
+ int (*setDelay)(struct sensors_poll_device_t *dev,
+ int sensor_handle, int64_t sampling_period_ns);
+ /**
+ * Returns an array of sensor data.
+ */
+ int (*poll)(struct sensors_poll_device_t *dev,
+ sensors_event_t* data, int count);
+ int (*getODR)(struct sensors_poll_device_t *dev,
+ int sensor_handle, int *odr);
+ };
+ };
+
+
+ /*
+ * Sets a sensor’s parameters, including sampling frequency and maximum
+ * report latency. This function can be called while the sensor is
+ * activated, in which case it must not cause any sensor measurements to
+ * be lost: transitioning from one sampling rate to the other cannot cause
+ * lost events, nor can transitioning from a high maximum report latency to
+ * a low maximum report latency.
+ * See the Batching sensor results page for details:
+ * http://source.android.com/devices/sensors/batching.html
+ */
+ int (*batch)(struct sensors_poll_device_1* dev,
+ int sensor_handle, int flags, int64_t sampling_period_ns,
+ int64_t max_report_latency_ns);
+
+ /*
+ * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
+ * to the end of the "batch mode" FIFO for the specified sensor and flushes
+ * the FIFO.
+ * If the FIFO is empty or if the sensor doesn't support batching (FIFO size zero),
+ * it should return SUCCESS along with a trivial META_DATA_FLUSH_COMPLETE event added to the
+ * event stream. This applies to all sensors other than one-shot sensors.
+ * If the sensor is a one-shot sensor, flush must return -EINVAL and not generate
+ * any flush complete metadata.
+ * If the sensor is not active at the time flush() is called, flush() should return
+ * -EINVAL.
+ */
+ int (*flush)(struct sensors_poll_device_1* dev, int sensor_handle);
+
+ /*
+ * Inject a single sensor sample to be to this device.
+ * data points to the sensor event to be injected
+ * @return 0 on success
+ * -EPERM if operation is not allowed
+ * -EINVAL if sensor event cannot be injected
+ */
+ int (*inject_sensor_data)(struct sensors_poll_device_1 *dev, const sensors_event_t *data);
+ void (*reserved_procs[7])(void);
+
+} sensors_poll_device_1_t;
+
+#ifndef UNUSED
+#define UNUSED(x) (x)=(x)
+#endif
+
+/*************************************************
+* Basic Utilities
+**************************************************/
+void tag_log(int type, const char* tag, const char *fmt, ...);
+
+#define ALOGD(...) tag_log(1, "[sensor-hal][DBG]", __VA_ARGS__);
+#define ALOGW(...) tag_log(1, "[sensor-hal][WARN]", __VA_ARGS__);
+#define ALOGE(...) tag_log(1, "[sensor-hal][ERR]", __VA_ARGS__);
+
+
+__END_DECLS
+#endif // ANDROID_SENSORS_INTERFACE_H
diff --git a/src/navigation/sensor/sensor_hal/src/Acceleration.cpp b/src/navigation/sensor/sensor_hal/src/Acceleration.cpp
new file mode 100644
index 0000000..554966b
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Acceleration.cpp
@@ -0,0 +1,437 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include "Acceleration.h"
+#include <string.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "Accel"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+/*****************************************************************************/
+AccelerationSensor::AccelerationSensor()
+ : SensorBase(NULL, "m_acc_input"),//ACC_INPUTDEV_NAME
+ mEnabled(0),
+ mOrientationEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_ACCELEROMETER;
+ mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER;
+ mPendingEvent.acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ firstData = 0;
+ mEnabledTime = 0;
+ mDataDiv = 1;
+ mTempDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ batchMode = 0;
+
+ mAllInputDataCompleteFlag = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+ char datapath[64]={"/sys/class/misc/m_acc_misc/accactive"};
+ int fd = -1;
+ char buf[64]={0};
+ int len;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_acc_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ else
+ {
+ ALOGE("couldn't find input device accel");
+ return;
+ }
+ ALOGD("acc misc path =%s", input_sysfs_path);
+
+ fd = open(datapath, O_RDWR);
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if (len <= 0)
+ {
+ ALOGE("read dev err, len = %d", len);
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d %d", &mDataDiv, &mTempDiv);
+ ALOGD("read div buf(%s), mdiv %d, tdiv %d", datapath, mDataDiv, mTempDiv);
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open acc misc path %s fail ", datapath);
+ }
+}
+
+AccelerationSensor::~AccelerationSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int AccelerationSensor::FindDataFd()
+{
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_acc_misc/accdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find acc input device: %s \n", buf_s);
+ return fd;
+}
+int AccelerationSensor::enableNoHALDataAcc(int en)
+{
+ int fd = 0;
+ char buf[2] = {0};
+ ALOGD("ACC enable nodata en(%d) \r\n",en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "accenablenodata");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no ACC enable nodata control attr\r\n" );
+ return -1;
+ }
+
+ buf[1] = 0;
+ if(1==en)
+ {
+ buf[0] = '1';
+ }
+ if(0==en)
+ {
+ buf[0] = '0';
+ }
+
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("ACC enable nodata done");
+ return 0;
+}
+
+int AccelerationSensor::enable(int32_t handle, int en)
+{
+ int fd = -1;
+ int flags = en ? 1 : 0;
+ char buf[2] = {0};
+
+ ALOGD("ACC enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "accactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no ACC enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ return 0;
+}
+int AccelerationSensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd = -1;
+ ALOGD("setDelay: (handle=%d, ns=%lld)\n",handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "accdelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no ACC setDelay control attr \r\n" );
+ return -1;
+ }
+
+ char buf[80] = {0};
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+
+int AccelerationSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd = -1;
+ int flag = 0;
+ char buf[2] = {0};
+
+ ALOGE("ACC batch: handle:%d, en:%d,samplingPeriodNs:%lld maxBatchReportLatencyNs:%lld \r\n",handle, flags,samplingPeriodNs, maxBatchReportLatencyNs);
+
+ //Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ batchMode = flag;
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "accbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no ACC batch control attr\r\n" );
+ return -1;
+ }
+
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("ACC batch(%d) done", flag );
+ return 0;
+
+}
+
+int AccelerationSensor::flush(int handle)
+{
+ ALOGD("handle=%d\n",handle);
+ return -errno;
+}
+
+int AccelerationSensor::getODR(int32_t handle, int *odr)
+{
+ int fd = -1;
+ int len;
+ char buf[64] = {0};
+ const char *odr_dir = NULL;
+
+ odr_dir = "/sys/class/misc/m_acc_misc/accgetodr";
+ ALOGD("acc getODR path: %s\n", odr_dir);
+ fd = open(odr_dir, O_RDONLY);
+ if(fd < 0) {
+ ALOGE("no ACC getODR control attr \r\n" );
+ return -1;
+ }
+
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read accgetodr err, len = %d", len);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%x %x %x %x %x %x %x %x\n",
+ &odr[0], &odr[1], &odr[2], &odr[3],
+ &odr[4], &odr[5], &odr[6], &odr[7]);
+ }
+
+ ALOGD("ACC getODR ok [%d, %d, %d, %d, %d, %d, %d, %d]\n",
+ odr[0], odr[1], odr[2], odr[3],
+ odr[4], odr[5], odr[6], odr[7]);
+ return 0;
+}
+
+int AccelerationSensor::readEvents(sensors_event_t* data, int count)
+{
+ //ALOGE("acc read Event1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(type, event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (time >= mEnabledTime)
+ {
+ if (mAllInputDataCompleteFlag == all_complete) {
+ //Assign timestamp if kernel is not assigned.
+ if (0 == mPendingEvent.timestamp)
+ mPendingEvent.timestamp=time;
+ if (mPendingEvent.timestamp > mEnabledTime) {
+ //ALOGD("acc[%6f, %6f, %6f, %6f][%lld]\n",
+ // mPendingEvent.acceleration.x, mPendingEvent.acceleration.y, mPendingEvent.acceleration.z,
+ // mPendingEvent.acceleration.t, mPendingEvent.timestamp);
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ mPendingEvent.timestamp = 0;
+ count--;
+ }
+ } else {
+ ALOGE("accelerometer dropped data due to mAllInputDataCompleteFlag(%d) is not all_complete\n",
+ mAllInputDataCompleteFlag);
+ }
+ }
+ mAllInputDataCompleteFlag = restart;
+ }
+ }
+ else
+ {
+ ALOGE("AccelerationSensor: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void AccelerationSensor::processEvent(int type, int code, int value)
+{
+ //ALOGD("processEvent code=%d,value=%d\r\n",code, value);
+ if (EV_ABS == type)
+ {
+ switch (code) {
+ case EVENT_TYPE_ACCEL_STATUS:
+ mPendingEvent.acceleration.status = value;
+ mAllInputDataCompleteFlag = status;
+ break;
+ case EVENT_TYPE_ACCEL_X:
+ mPendingEvent.acceleration.x = (float)value / mDataDiv ;
+ mAllInputDataCompleteFlag = x;
+ break;
+ case EVENT_TYPE_ACCEL_Y:
+ mPendingEvent.acceleration.y = (float)value / mDataDiv;
+ mAllInputDataCompleteFlag = y;
+ break;
+ case EVENT_TYPE_ACCEL_Z:
+ mPendingEvent.acceleration.z = (float)value / mDataDiv;
+ mAllInputDataCompleteFlag = z;
+ //ALOGD("acc_xyz=%f, %f, %f", mPendingEvent.acceleration.x, mPendingEvent.acceleration.y, mPendingEvent.acceleration.z);
+ break;
+ case EVENT_TYPE_ACCEL_T:
+ mPendingEvent.acceleration.t = (float)value / mTempDiv;
+ break;
+ default:
+ ALOGE("AccelerationSensor: unknown event (type=%d, code=%d)", type, code);
+ break;
+ }
+ }
+ else if (EV_REL == type)
+ {
+ switch (code) {
+ case EVENT_TYPE_ACCEL_TIMESTAMP_HI:
+ mPendingEvent.timestamp = (mPendingEvent.timestamp & 0xFFFFFFFFLL) | ((int64_t)value << 32);
+ mAllInputDataCompleteFlag = hi;
+ break;
+ case EVENT_TYPE_ACCEL_TIMESTAMP_LO:
+ mPendingEvent.timestamp =
+ (mPendingEvent.timestamp & 0xFFFFFFFF00000000LL) | ((int64_t)value & 0xFFFFFFFFLL);
+ if (mAllInputDataCompleteFlag == hi)
+ mAllInputDataCompleteFlag = lo;
+ //ALOGD("acc_t=%lld", mPendingEvent.timestamp/1000000LL);
+ break;
+ case EVENT_TYPE_ACCEL_UPDATE:
+ break;
+ default:
+ ALOGE("AccelerationSensor: unknown event (type=%d, code=%d)", type, code);
+ break;
+ }
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Activity.cpp b/src/navigation/sensor/sensor_hal/src/Activity.cpp
new file mode 100644
index 0000000..93029f6
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Activity.cpp
@@ -0,0 +1,335 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+
+#include "Activity.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "ACT"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+ActivitySensor::ActivitySensor()
+ : SensorBase(NULL, "m_act_input"),//ACT_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_ACTIVITY;
+ mPendingEvent.type = SENSOR_TYPE_ACTIVITY;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ //input_sysfs_path[PATH_MAX] = {0};
+ memset(input_sysfs_path, 0, sizeof(char)*PATH_MAX);
+ m_act_last_ts = 0;
+ m_act_delay= 0;
+ batchMode=0;
+ firstData = 1;
+ char datapath[64]={"/sys/class/misc/m_act_misc/actactive"};
+ int fd = -1;
+ char buf[64];
+ int len;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_act_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ else
+ {
+ ALOGE("couldn't find input device ActivitySensor");
+ return;
+ }
+ ALOGD("act misc path =%s", input_sysfs_path);
+
+ fd = open(datapath, O_RDWR);
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if(len<=0)
+ {
+ ALOGD("read div err buf(%s)",buf );
+ }
+ else
+ {
+ buf[len] = '\0';
+ ALOGE("len = %d, buf = %s",len, buf);
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d",mDataDiv );
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open activity misc path %s fail ", datapath);
+ }
+}
+
+ActivitySensor::~ActivitySensor() {
+if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+int ActivitySensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_act_misc/actdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err buf(%s)", buf);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ ALOGE("len = %d, buf = %s",len, buf);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int ActivitySensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ ALOGD("Act enable: handle:%d, en:%d \r\n",handle, en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "actactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no Act enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("Act enable(%d) done", mEnabled );
+ return 0;
+
+}
+
+int ActivitySensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd;
+ ALOGD("setDelay: (handle=%d, ns=%lld)", handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "actdelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no ACT setDelay control attr \r\n" );
+ return -1;
+ }
+ char buf[80];
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+
+int ActivitySensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd=-1;
+ int flag=0;
+
+ ALOGE("ACT batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ //From batch mode to normal mode.
+ if (1 == batchMode && 0 == flag)
+ {
+ firstData = 1;
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ batchMode = flag;
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "actbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no act batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("ACT batch(%d) done", flag );
+ return 0;
+}
+
+int ActivitySensor::flush(int handle)
+{
+ return -errno;
+}
+
+int ActivitySensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+ }
+ }
+ else if (type != EV_ABS)
+ {
+ ALOGE("ActivitySensor: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void ActivitySensor::processEvent(int code, int value)
+{
+ ALOGD("processEvent::processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_ACT_STILL:
+ mPendingEvent.data[0] = value;
+ break;
+ case EVENT_TYPE_ACT_STANDING:
+ mPendingEvent.data[1] = value;
+ break;
+ case EVENT_TYPE_ACT_SITTING:
+ mPendingEvent.data[2] = value;
+ break;
+ case EVENT_TYPE_ACT_LYING:
+ mPendingEvent.data[3] = value;
+ break;
+ case EVENT_TYPE_ACT_ON_FOOT:
+ mPendingEvent.data[4] = value;
+ break;
+ case EVENT_TYPE_ACT_WALKING:
+ mPendingEvent.data[5] = value;
+ break;
+ case EVENT_TYPE_ACT_RUNNING:
+ mPendingEvent.data[6] = value;
+ break;
+ case EVENT_TYPE_ACT_CLIMBING:
+ mPendingEvent.data[7] = value;
+ break;
+ case EVENT_TYPE_ACT_ON_BICYCLE:
+ mPendingEvent.data[8] = value;
+ break;
+ case EVENT_TYPE_ACT_IN_VEHICLE:
+ mPendingEvent.data[9] = value;
+ break;
+ case EVENT_TYPE_ACT_TILTING:
+ mPendingEvent.data[10] = value;
+ break;
+ case EVENT_TYPE_ACT_UNKNOWN:
+ mPendingEvent.data[11] = value;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/AmbienteLight.cpp b/src/navigation/sensor/sensor_hal/src/AmbienteLight.cpp
new file mode 100644
index 0000000..6473a80
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/AmbienteLight.cpp
@@ -0,0 +1,310 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include "AmbienteLight.h"
+#include <string.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "LIGHT"
+#endif
+
+#define IGNORE_EVENT_TIME 0//350000000
+#define SYSFS_PATH "/sys/class/input"
+
+/*****************************************************************************/
+AmbiLightSensor::AmbiLightSensor()
+ : SensorBase(NULL, "m_alsps_input"),
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_LIGHT;
+ mPendingEvent.type = SENSOR_TYPE_LIGHT;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+
+ char datapath[64]={"/sys/class/misc/m_alsps_misc/alsactive"};
+ int fd = -1;
+ char buf[64] = {0};
+ int len;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_alsps_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ else
+ {
+ ALOGE("couldn't find input device AmbilightSensor");
+ return;
+ }
+ ALOGD("light misc path =%s", input_sysfs_path);
+
+ fd = open(datapath, O_RDWR);
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if (len <= 0)
+ {
+ ALOGD("read div err, len = %d", len);
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s),mdiv %d", datapath,mDataDiv);
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open light misc path %s fail ", datapath);
+ }
+}
+
+AmbiLightSensor::~AmbiLightSensor() {if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int AmbiLightSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_alsps_misc/alsdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err buf(%s)", buf);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ ALOGE("len = %d, buf = %s",len, buf);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int AmbiLightSensor::enable(int32_t handle, int en)
+{
+ int fd=-1;
+ int flags = en ? 1 : 0;
+
+ ALOGD("ALS enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "alsactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no ALS enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("ACC enable(%d) done", mEnabled );
+ return 0;
+
+}
+int AmbiLightSensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd=-1;
+ ALOGD("setDelay: (handle=%d, ns=%lld)",handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "alsdelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no ALS setDelay control attr \r\n" );
+ return -1;
+ }
+
+ char buf[80]={0};
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+int AmbiLightSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd;
+ int flag;
+
+ ALOGE("ALS batch: handle:%d, en:%d,samplingPeriodNs:%lld, maxBatchReportLatencyNs:%lld \r\n",handle, flags, samplingPeriodNs,maxBatchReportLatencyNs);
+
+ //Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "alsbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no ALSbatch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+ ALOGD("ALS batch(%d) done", flag );
+ return 0;
+}
+
+int AmbiLightSensor::flush(int handle)
+{
+ ALOGD("handle=%d\n",handle);
+ return -errno;
+}
+
+int AmbiLightSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+
+ }
+ }
+ else if (type != EV_ABS)
+ {
+ ALOGE("LightSensor: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void AmbiLightSensor::processEvent(int code, int value)
+{
+ //ALOGD("processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_ALS_VALUE:
+ mPendingEvent.light = value;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/AnswerCall.cpp b/src/navigation/sensor/sensor_hal/src/AnswerCall.cpp
new file mode 100644
index 0000000..47dd2d8
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/AnswerCall.cpp
@@ -0,0 +1,234 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+
+#include "AnswerCall.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "ANSWER_CALL"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+AnswerCallSensor::AnswerCallSensor()
+ : SensorBase(NULL, "m_ancall_input"),
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_ANSWER_CALL;
+ mPendingEvent.type = SENSOR_TYPE_ANSWER_CALL;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime = 0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp = 0;
+ input_sysfs_path_len = 0;
+
+ memset(input_sysfs_path, 0, sizeof(char)*PATH_MAX);
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_ancall_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ ALOGD("AnswerCallSensor misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_ancall_misc/ancallactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf) - 1);
+ if (len <= 0) {
+ ALOGD("read div err buf(%s)", buf);
+ } else {
+ buf[len] = '\0';
+ ALOGE("len = %d, buf = %s", len, buf);
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d", mDataDiv);
+ }
+ close(fd);
+ } else {
+ ALOGE("open misc path %s fail ", datapath);
+ }
+}
+
+AnswerCallSensor::~AnswerCallSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int AnswerCallSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64] = {0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_ancall_misc/ancalldevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ } else {
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int AnswerCallSensor::enable(int32_t handle, int en) {
+ int fd;
+ int flags = en ? 1 : 0;
+
+ ALOGD("ancall enable: handle:%d, en:%d \r\n", handle, en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "ancallactive");
+ ALOGD("path:%s \r\n", input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0) {
+ ALOGD("no ancall enable control attr\r\n");
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags) {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ } else {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+ ALOGD("ancall enable(%d) done", mEnabled);
+ return 0;
+}
+
+int AnswerCallSensor::setDelay(int32_t handle, int64_t ns) {
+ ALOGD("setDelay: regardless of the setDelay() value (handle=%d, ns=%lld)", handle, ns);
+ return 0;
+}
+
+int AnswerCallSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs) {
+ int flag;
+ int fd;
+
+ ALOGE("ancall batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0) {
+ flag = 0;
+ } else {
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "ancallbatch");
+ ALOGD("path:%s \r\n", input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0) {
+ ALOGD("no ancall batch control attr\r\n");
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag) {
+ buf[0] = '1';
+ } else {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("ancall batch(%d) done", flag);
+ return 0;
+}
+
+int AnswerCallSensor::flush(int handle) {
+ return -errno;
+}
+
+int AnswerCallSensor::readEvents(sensors_event_t* data, int count) {
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ if (type == EV_ABS || type == EV_REL) {
+ processEvent(event->code, event->value);
+ } else if (type == EV_SYN) {
+ int64_t time = getTimestamp();
+
+ mPendingEvent.timestamp = time;
+ if (mEnabled) {
+ if (mPendingEvent.timestamp >= mEnabledTime) {
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ if(mPendingEvent.sensor == ID_ANSWER_CALL)
+ enable(ID_ANSWER_CALL, false);
+ }
+ count--;
+ }
+ }
+ else {
+ ALOGE("ancall: unknown event (type=%d, code=%d)", type, event->code);
+ }
+ mInputReader.next();
+ }
+ return numEventReceived;
+}
+
+void AnswerCallSensor::processEvent(int code, int value) {
+ ALOGE("AnswerCallSensor::processEvent code=%d,value=%d\r\n", code, value);
+ switch (code) {
+ case EVENT_TYPE_ANSWER_CALL_VALUE:
+ mPendingEvent.data[0] = (float) value;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/BatchSensor.cpp b/src/navigation/sensor/sensor_hal/src/BatchSensor.cpp
new file mode 100644
index 0000000..9815f84
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/BatchSensor.cpp
@@ -0,0 +1,650 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "BatchSensor.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "BATCH"
+#endif
+#define SYSFS_PATH "/sys/class/input"
+#define SYSFS_NODE "/sys/class/misc/m_batch_misc/"
+
+
+/*****************************************************************************/
+BatchSensor::BatchSensor()
+ : SensorBase("/dev/m_batch_misc", "m_batch_input"),//BATCH_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(128),//temp value for 128
+ mHasPendingEvent(false)
+{
+ int handle=0;
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = 0;
+ mPendingEvent.type = SENSOR_TYPE_META_DATA;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mTimestampHi = 0;
+
+ mPendingEvent.timestamp =0;
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_batch_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ char datapath[64]={"/sys/class/misc/m_batch_misc/batchactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+
+ for(int i=0;i<ID_SENSOR_MAX_HANDLE;i++)
+ {
+ flushSensorReq[i] = 0;
+ }
+
+ if (fd >= 0)
+ {
+ for(int i=0; i<numSensors;i++)
+ {
+ lseek(fd,0,SEEK_SET);
+ sprintf(buf, "%d,%d", i, 2);//write 2 means notify driver I want to read whitch handle
+ write(fd, buf, strlen(buf)+1);
+ lseek(fd,0,SEEK_SET);
+ len = read(fd,buf,sizeof(buf)-1);
+ if(len<=0)
+ {
+ ALOGD("read div err, i = %d, len = %d", i, len);
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv[i]);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("fwq!!mdiv[%d] %d",i,mDataDiv[i] );
+ }
+ }
+
+ close(fd);
+ }
+ open_device();
+ ALOGD("batch misc path =%s", input_sysfs_path);
+
+}
+
+BatchSensor::~BatchSensor() {
+if (mdata_fd >= 0)
+ close(mdata_fd);
+
+}
+int BatchSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_batch_misc/batchdevnum";
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf));
+ close(fd);
+ if (len <= 0 || len == sizeof(buf))
+ {
+ ALOGD("read devnum err buf(%s), len = %d\n", buf, len);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ ALOGE("len = %d, buf = %s",len, buf);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+/*
+void BatchSensor::GetSensorDiv(int div[])
+{
+
+}
+*/
+
+bool BatchSensor::hasPendingEvents() const {
+ return mHasPendingEvent;
+}
+
+int BatchSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+ char buf_path[64] = {0};
+
+ if (mdata_fd < 0)
+ {
+ ALOGD("no batch control attr\r\n" );
+ return 0;
+ }
+
+ ALOGD("batch enable: handle:%d, en:%d \r\n",handle,en);
+ sprintf(buf_path, "%s%s", SYSFS_NODE, "batchactive");
+ ALOGD("[batchactive] path:%s \r\n",buf_path);
+
+ fd = open(buf_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no batch enable control attr\r\n" );
+ return -1;
+ }
+
+ char buf[120] = {0};
+ sprintf(buf, "%d,%d", handle, en);
+ ALOGD("batch value:%s ,size: %d \r\n",buf, strlen(buf)+1);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ ALOGD("batch enable(%d) done", mEnabled );
+ return 0;
+}
+
+
+int BatchSensor::setDelay(int32_t handle, int64_t ns)
+{
+ ALOGD("handle=%d,ns=%lld\n",handle,ns);
+ return -errno;
+}
+
+
+int BatchSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int res = 0;
+ int fd = 0;
+ char buf_path[64] = {0};
+
+ if (mdata_fd < 0)
+ {
+ ALOGD("no batch control attr\r\n" );
+
+ if (maxBatchReportLatencyNs != 0)
+ return -1;
+ else
+ return 0;
+ }
+
+ if(maxBatchReportLatencyNs != 0)mEnabled = 1;
+ else mEnabled = 0;
+ if(flags & SENSORS_BATCH_DRY_RUN || flags & SENSORS_BATCH_WAKE_UPON_FIFO_FULL || (flags == 0)){
+
+ sprintf(buf_path, "%s%s", SYSFS_NODE, "batchbatch");
+ ALOGD("[batchbatch] path:%s \r\n",buf_path);
+ fd = open(buf_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no batch batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[120] = {0};
+ sprintf(buf, "%d,%d,%lld,%lld", handle, flags, samplingPeriodNs, maxBatchReportLatencyNs);
+ ALOGD("batch value:%s ,size: %d \r\n",buf, strlen(buf)+1);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+
+ fd = open(buf_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no batch batch control attr\r\n" );
+ return -1;
+ }
+ char buf2[120] = {0};
+ int len;
+ len = read(fd, buf2, sizeof(buf2));
+ if (len <= 0) {
+ ALOGD("wrong len");
+ } else {
+ ALOGD("read value:%s \r\n",buf2);
+ sscanf(buf2, "%d", &res);
+ ALOGD("return value:%d \r\n",res);
+ }
+ close(fd);
+ }else{
+ ALOGD("batch mode is using invaild flag value for this operation!");
+ res = -errno;
+ }
+ return res;
+}
+
+int BatchSensor::flush(int handle)
+{
+ int res = 0;
+ int fd = 0;
+ char buf_path[64] = {0};
+
+ if (mdata_fd < 0)
+ {
+ flushSensorReq[handle]++;
+ mHasPendingEvent = true;
+ ALOGD("BatchSensor::flush, handle = %d\r\n", handle);
+ return 0;
+ }
+
+ sprintf(buf_path, "%s%s", SYSFS_NODE, "batchflush");
+ ALOGD("[batchflush] path:%s \r\n",buf_path);
+ fd = open(buf_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no batch flush control attr\r\n" );
+ return -1;
+ }
+ char buf[11] = {0};
+ sprintf(buf, "%d", handle);
+ ALOGD("flush value:%s ,size: %d \r\n",buf, strlen(buf)+1);
+ res=write(fd, buf, strlen(buf)+1);
+ ALOGD("flush write (%d) \r\n",res);
+ close(fd);
+
+ ALOGD("read path:%s \r\n",buf_path);
+ fd = open(buf_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no batch batch control attr\r\n" );
+ return -1;
+ }
+ char buf2[5] = {0};
+ int len;
+ len = read(fd, buf2, sizeof(buf2));
+ close(fd);
+ if (len <= 0 || len == sizeof(buf2))
+ {
+ ALOGD("read batchflush err buf(%s)", buf);
+ return -1;
+ }
+ else
+ {
+ buf2[len] = '\0';
+ sscanf(buf2, "%d", &res);
+ ALOGD("return value:%d \r\n",res);
+ }
+ return res;
+}
+
+int BatchSensor::readEvents(sensors_meta_data_event_t* data, int count)
+{
+ int numEventReceived = 0;
+ batch_trans_data sensors_data;
+ int err;
+ int i;
+
+ if (mdata_fd < 0)
+ {
+ int handle;
+ for (handle=0;handle<ID_SENSOR_MAX_HANDLE && count!=0;handle++)
+ {
+ for (;flushSensorReq[handle]>0 && count>0;flushSensorReq[handle]--)
+ {
+ mPendingEvent.timestamp = getTimestamp();//time;
+ processEvent(EVENT_TYPE_END_FLAG, handle);
+ ALOGD("BatchSensor::readEvents, handle = %d\r\n", handle);
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ count--;
+ }
+ }
+ if (handle == ID_SENSOR_MAX_HANDLE && flushSensorReq[handle-1]==0)
+ mHasPendingEvent = false;
+ return numEventReceived;
+ }
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ while(count)
+ {
+ sensors_data.numOfDataReturn = count<MAX_BATCH_DATA_PER_QUREY?count:MAX_BATCH_DATA_PER_QUREY;
+ sensors_data.numOfDataLeft = 0;
+
+ //ALOGD("BatchSensor::getBatchData1, %d, %d, %d\r\n", sensors_data.numOfDataReturn, sensors_data.numOfDataLeft, count);
+ err = ioctl(dev_fd, BATCH_IO_GET_SENSORS_DATA, &sensors_data);
+ //ALOGD("BatchSensor::getBatchData2, %d, %d\r\n", sensors_data.numOfDataReturn, sensors_data.numOfDataLeft);
+
+ if (err || (sensors_data.numOfDataReturn < 0) || (count < sensors_data.numOfDataReturn) || (sensors_data.numOfDataLeft < 0))
+ {
+ ALOGE("BatchSensor: ioctl fail : err = %d, numOfDataReturn = %d, numOfDataLeft = %d",
+ err, sensors_data.numOfDataReturn, sensors_data.numOfDataLeft);
+ break;
+ }
+ else
+ {
+ for (i=0;count&&i<sensors_data.numOfDataReturn;i++)
+ {
+ data->version = sizeof(sensors_event_t);
+ if(TypeToSensor(sensors_data.data[i].sensor)<0)
+ {
+ ALOGE("BatchSensor: unknown sensor: %d, value:%d", TypeToSensor(sensors_data.data[i].sensor), sensors_data.data[i].sensor);
+ continue;
+ }
+ else
+ {
+ data->sensor = TypeToSensor(sensors_data.data[i].sensor);
+ data->type = sensors_data.data[i].sensor;
+ }
+
+ data->timestamp = sensors_data.data[i].time;
+
+ if (SENSOR_TYPE_STEP_COUNTER==data->type)
+ {
+ data->u64.step_counter = sensors_data.data[i].values[0];
+ }else
+ {
+ if (data->sensor >= 0 && data->sensor < numSensors && mDataDiv[data->sensor] != 0)
+ {
+ handleEvent(data, &sensors_data.data[i]);
+ }
+ }
+
+ data++;
+ count--;
+ numEventReceived++;
+
+ //ALOGD("BatchSensor::getBatchData, %d, %d, %lld, %f, %f, %f\r\n", data->sensor, data->type, data->timestamp, data->data[0], data->data[1], data->data[2]);
+ }
+
+ if (sensors_data.numOfDataLeft == 0)
+ break;
+ }
+ }
+
+ //ALOGD("BatchSensor::readEvents, %d, %d\r\n", count, numEventReceived);
+
+ if (count < 1)
+ return numEventReceived;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0 && numEventReceived==0)
+ return n;
+
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("debug.... type\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ switch (event->code) {
+ case EVENT_TYPE_BATCH_READY:
+ break;
+ case EVENT_TYPE_END_FLAG:
+ data->version = META_DATA_VERSION;
+ data->sensor = 0;
+ data->type = SENSOR_TYPE_META_DATA;
+ data->reserved0 = 0;
+ data->timestamp = 0;
+ data->meta_data.what = META_DATA_FLUSH_COMPLETE;
+ data->meta_data.sensor = event->value&0xffff;
+ ALOGD("metadata.sensor =%d\r\n",data->meta_data.sensor);
+ data++;
+ numEventReceived++;
+ count--;
+ break;
+ default:
+ break;
+ }
+ }
+ else if (type == EV_SYN)
+ {
+ }
+ else
+ {
+ ALOGE("BatchSensor: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void BatchSensor::processEvent(int code, int value)
+{
+ //ALOGD("processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_SENSORTYPE:
+ if(TypeToSensor(value)<0)
+ {
+ ALOGE("BatchSensor: unknown sensor: %d, value:%d", TypeToSensor(value), value);
+ return;
+ }
+ mPendingEvent.type = value;
+ mPendingEvent.sensor= TypeToSensor(value);
+
+ break;
+ case EVENT_TYPE_BATCH_X:
+
+ mPendingEvent.acceleration.x = (float)value / mDataDiv[mPendingEvent.sensor];
+ break;
+ case EVENT_TYPE_BATCH_Y:
+ mPendingEvent.acceleration.y = (float)value/ mDataDiv[mPendingEvent.sensor];
+ break;
+ case EVENT_TYPE_BATCH_Z:
+ mPendingEvent.acceleration.z = (float)value/ mDataDiv[mPendingEvent.sensor];
+ break;
+ case EVENT_TYPE_BATCH_VALUE:
+ if( SENSOR_TYPE_STEP_COUNTER==mPendingEvent.type )
+ {
+ mPendingEvent.u64.step_counter = value;
+ }else
+ {
+ mPendingEvent.data[0]= (float)value;
+ }
+ break;
+ case EVENT_TYPE_TIMESTAMP_HI:
+ mTimestampHi = ((uint64_t)value << 32) & 0xFFFFFFFF00000000LL;
+ //ALOGE("mTimestampHi = %lld", mTimestampHi);
+ break;
+ case EVENT_TYPE_TIMESTAMP_LO:
+ mPendingEvent.timestamp = mTimestampHi | ((uint64_t) value & 0xFFFFFFFF);
+ //ALOGE("mPendingEvent.timestamp = %lld", mPendingEvent.timestamp);
+ break;
+ case EVENT_TYPE_END_FLAG:
+
+ //mPendingEvent.type = SENSOR_TYPE_META_DATA;
+ //mPendingEvent.sensor = value&0xffff;
+ mPendingEvent.version = META_DATA_VERSION;
+ mPendingEvent.sensor = 0;
+ mPendingEvent.type = SENSOR_TYPE_META_DATA;
+ mPendingEvent.meta_data.what = META_DATA_FLUSH_COMPLETE;
+ mPendingEvent.meta_data.sensor = value&0xffff;
+ ALOGD("metadata.sensor =%d\r\n",mPendingEvent.meta_data.sensor);
+ }
+
+ return;
+}
+
+void BatchSensor::handleEvent(sensors_meta_data_event_t* data, hwm_sensor_data *sensors_data) {
+ switch (data->type) {
+ case SENSOR_TYPE_ACCELEROMETER:
+ case SENSOR_TYPE_MAGNETIC_FIELD:
+ case SENSOR_TYPE_GYROSCOPE:
+ case SENSOR_TYPE_ORIENTATION:
+ data->data[0] = (float)sensors_data->values[0] / mDataDiv[data->sensor];
+ data->data[1] = (float)sensors_data->values[1] / mDataDiv[data->sensor];
+ data->data[2] = (float)sensors_data->values[2] / mDataDiv[data->sensor];
+ data->acceleration.status = sensors_data->status;
+ break;
+ case SENSOR_TYPE_ACTIVITY:
+ data->data[0] = sensors_data->probability[0];
+ data->data[1] = sensors_data->probability[1];
+ data->data[2] = sensors_data->probability[2];
+ data->data[3] = sensors_data->probability[3];
+ data->data[4] = sensors_data->probability[4];
+ data->data[5] = sensors_data->probability[5];
+ data->data[6] = sensors_data->probability[6];
+ data->data[7] = sensors_data->probability[7];
+ data->data[8] = sensors_data->probability[8];
+ data->data[9] = sensors_data->probability[9];
+ data->data[10] = sensors_data->probability[10];
+ data->data[11] = sensors_data->probability[11];
+ break;
+ default:
+ data->data[0] = (float)sensors_data->values[0] / mDataDiv[data->sensor];
+ data->data[1] = (float)sensors_data->values[1] / mDataDiv[data->sensor];
+ data->data[2] = (float)sensors_data->values[2] / mDataDiv[data->sensor];
+ data->data[3] = (float)sensors_data->values[3] / mDataDiv[data->sensor];
+ data->data[4] = (float)sensors_data->values[4] / mDataDiv[data->sensor];
+ data->data[5] = (float)sensors_data->values[5] / mDataDiv[data->sensor];
+ break;
+ }
+ return;
+}
+
+int BatchSensor::TypeToSensor(int type)
+{
+ int sensor;
+ switch(type){
+ case SENSOR_TYPE_ACCELEROMETER:
+ sensor = ID_ACCELEROMETER;
+ break;
+ case SENSOR_TYPE_MAGNETIC_FIELD:
+ sensor = ID_MAGNETIC;
+ break;
+ case SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED:
+ sensor = ID_MAGNETIC_UNCALIBRATED;
+ break;
+ case SENSOR_TYPE_ORIENTATION:
+ sensor = ID_ORIENTATION;
+ break;
+ case SENSOR_TYPE_GYROSCOPE:
+ sensor = ID_GYROSCOPE;
+ break;
+ case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
+ sensor = ID_GYROSCOPE_UNCALIBRATED;
+ break;
+ case SENSOR_TYPE_LIGHT:
+ sensor = ID_LIGHT;
+ break;
+ case SENSOR_TYPE_PROXIMITY:
+ sensor = ID_PROXIMITY;
+ break;
+ case SENSOR_TYPE_PRESSURE:
+ sensor = ID_PRESSURE;
+ break;
+ case SENSOR_TYPE_TEMPERATURE:
+ sensor = ID_TEMPERATURE;
+ break;
+ case SENSOR_TYPE_GRAVITY:
+ sensor = ID_GRAVITY;
+ break;
+ case SENSOR_TYPE_LINEAR_ACCELERATION:
+ sensor = ID_LINEAR_ACCELERATION;
+ break;
+ case SENSOR_TYPE_ROTATION_VECTOR:
+ sensor = ID_ROTATION_VECTOR;
+ break;
+ case SENSOR_TYPE_GAME_ROTATION_VECTOR:
+ sensor = ID_GAME_ROTATION_VECTOR;
+ break;
+ case SENSOR_TYPE_SIGNIFICANT_MOTION:
+ sensor = ID_SIGNIFICANT_MOTION;
+ break;
+ case SENSOR_TYPE_STEP_DETECTOR:
+ sensor = ID_STEP_DETECTOR;
+ break;
+ case SENSOR_TYPE_STEP_COUNTER:
+ sensor = ID_STEP_COUNTER;
+ break;
+ case SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR:
+ sensor = ID_GEOMAGNETIC_ROTATION_VECTOR;
+ break;
+ case SENSOR_TYPE_PEDOMETER:
+ sensor = ID_PEDOMETER;
+ break;
+ case SENSOR_TYPE_IN_POCKET:
+ sensor = ID_IN_POCKET;
+ break;
+ case SENSOR_TYPE_ACTIVITY:
+ sensor = ID_ACTIVITY;
+ break;
+ case SENSOR_TYPE_PICK_UP_GESTURE:
+ sensor = ID_PICK_UP_GESTURE;
+ break;
+ case SENSOR_TYPE_WAKE_GESTURE:
+ sensor = ID_WAKE_GESTURE;
+ break;
+ case SENSOR_TYPE_GLANCE_GESTURE:
+ sensor = ID_GLANCE_GESTURE;
+ break;
+ case SENSOR_TYPE_FACE_DOWN:
+ sensor = ID_FACE_DOWN;
+ break;
+ case SENSOR_TYPE_SHAKE:
+ sensor = ID_SHAKE;
+ break;
+ case SENSOR_TYPE_HEART_RATE:
+ sensor = ID_HEART_RATE;
+ break;
+ case SENSOR_TYPE_BRINGTOSEE:
+ sensor = ID_BRINGTOSEE;
+ break;
+ case SENSOR_TYPE_HUMIDITY:
+ sensor = ID_HUMIDITY;
+ break;
+ case SENSOR_TYPE_TILT_DETECTOR:
+ sensor = ID_TILT_DETECTOR;
+ break;
+ default:
+ sensor = -1;
+ }
+
+ return sensor;
+}
+
diff --git a/src/navigation/sensor/sensor_hal/src/Bringtosee.cpp b/src/navigation/sensor/sensor_hal/src/Bringtosee.cpp
new file mode 100644
index 0000000..18f38fa
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Bringtosee.cpp
@@ -0,0 +1,294 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include "Bringtosee.h"
+#include <string.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "BRINGTOSEE"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+/*****************************************************************************/
+BringtoseeSensor::BringtoseeSensor()
+ : SensorBase(NULL, "m_bts_input"),//_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_BRINGTOSEE;
+ mPendingEvent.type = SENSOR_TYPE_BRINGTOSEE;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+ m_bts_last_ts = 0;
+ m_bts_delay= 0;
+ batchMode=0;
+ firstData = 1;
+ char datapath[64]={"/sys/class/misc/m_bts_misc/btsactive"};
+ int fd = -1;
+ char buf[64]={0};
+ int len;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_bts_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ else
+ {
+ ALOGE("couldn't find input device bringtosee");
+ return;
+ }
+ ALOGD("Bringtosee misc path =%s", input_sysfs_path);
+
+ fd = open(datapath, O_RDWR);
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if (len <= 0)
+ {
+ ALOGE("read dev err, len = %d", len);
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s), mdiv %d", datapath, mDataDiv);
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open bts misc path %s fail ", datapath);
+ }
+}
+
+BringtoseeSensor::~BringtoseeSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int BringtoseeSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_bts_misc/btsdevnum";
+
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ ALOGE("len = %d, buf = %s",len, buf);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int BringtoseeSensor::enable(int32_t handle, int en)
+{
+ int fd=-1;
+ int flags = en ? 1 : 0;
+ char buf[2] = {0};
+
+ ALOGD("bts enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "btsactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no bts enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ m_bts_last_ts = 0;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+ ALOGD("bts enable(%d) done", mEnabled );
+ return 0;
+}
+int BringtoseeSensor::setDelay(int32_t handle, int64_t ns)
+{
+ //int fd;
+
+ ALOGD("setDelay: regardless of the setDelay() value (handle=%d, ns=%lld)", handle, ns);
+
+ return 0;
+}
+int BringtoseeSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int flag;
+ int fd;
+ char buf[2];
+
+ ALOGE("bts batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+
+ //Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ //From batch mode to normal mode.
+ if (1 == batchMode && 0 == flag)
+ {
+ firstData = 1;
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ batchMode = flag;
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "btsbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no bts batch control attr\r\n" );
+ return -1;
+ }
+
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("bts batch(%d) done", flag );
+ return 0;
+
+}
+
+int BringtoseeSensor::flush(int handle)
+{
+ ALOGD("handle=%d\n",handle);
+ return -errno;
+}
+
+int BringtoseeSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+ }
+ }
+ else
+ {
+ ALOGE("bts: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void BringtoseeSensor::processEvent(int code, int value)
+{
+ ALOGD("BringtoseeSensor::processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_BTS_VALUE:
+ mPendingEvent.data[0] = (float) value;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/FaceDown.cpp b/src/navigation/sensor/sensor_hal/src/FaceDown.cpp
new file mode 100644
index 0000000..7419861
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/FaceDown.cpp
@@ -0,0 +1,272 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "FaceDown.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "FACE_DOWN"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+FaceDownSensor::FaceDownSensor()
+ : SensorBase(NULL, "m_fdn_input"),//_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_FACE_DOWN;
+ mPendingEvent.type = SENSOR_TYPE_FACE_DOWN;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_fdn_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ ALOGD("FaceDown misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_fdn_misc/fdnactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if (len <= 0)
+ {
+ ALOGD("read div err buf(%s)",buf );
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d",mDataDiv );
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open fdn misc path %s fail ", datapath);
+ }
+}
+
+FaceDownSensor::~FaceDownSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int FaceDownSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_fdn_misc/fdndevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err buf(%s)", buf);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ ALOGE("len = %d, buf = %s",len, buf);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int FaceDownSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ ALOGD("fdn enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "fdnactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no fdn enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+ ALOGD("fdn enable(%d) done", mEnabled );
+ return 0;
+}
+int FaceDownSensor::setDelay(int32_t handle, int64_t ns)
+{
+ //int fd;
+
+ ALOGD("setDelay: regardless of the setDelay() value (handle=%d, ns=%lld)", handle, ns);
+
+ return 0;
+
+}
+int FaceDownSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int flag;
+ int fd;
+
+ ALOGE("fdn batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "fdnbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no fdn batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("fdn batch(%d) done", flag );
+ return 0;
+
+}
+
+int FaceDownSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int FaceDownSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = timevalToNano(event->time);
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+
+ }
+ }
+ else
+ {
+ ALOGE("fdn: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void FaceDownSensor::processEvent(int code, int value)
+{
+ ALOGD("FaceDownSensor::processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_FDN_VALUE:
+ mPendingEvent.data[0] = (float) value;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/GameRotationVector.cpp b/src/navigation/sensor/sensor_hal/src/GameRotationVector.cpp
new file mode 100644
index 0000000..f492dcd
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/GameRotationVector.cpp
@@ -0,0 +1,280 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "GameRotationVector.h"
+#undef LOG_TAG
+#define LOG_TAG "GRV"
+
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+GameRotationVectorSensor::GameRotationVectorSensor()
+ : SensorBase(NULL, "m_grv_input"),//GRV_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_GAME_ROTATION_VECTOR;
+ mPendingEvent.type = SENSOR_TYPE_GAME_ROTATION_VECTOR;
+ mPendingEvent.acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_grv_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ //ALOGD("grv misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_grv_misc/grvactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf)-1);
+ if (len <= 0) {
+ ALOGD("read div err buf(%s)", buf);
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ }
+ close(fd);
+ } else {
+ ALOGE("open grv misc path %s fail ", datapath);
+ }
+}
+
+GameRotationVectorSensor::~GameRotationVectorSensor() {
+if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+int GameRotationVectorSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ char devnum_dir[] = "/sys/class/misc/m_grv_misc/grvdevnum";
+ char buf_s[64] = {0};
+ int len;
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read devnum err buf(%s)", buf);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ //if (fd < 0)
+ // ALOGE( "couldn't find input device");
+ return fd;
+}
+
+int GameRotationVectorSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ //ALOGD("GRV enable: handle:%d, en:%d \r\n",handle, en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "grvactive");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ //ALOGD("no GRV enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ //ALOGD("GRV enable(%d) done", mEnabled );
+ return 0;
+
+}
+
+int GameRotationVectorSensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd;
+ //ALOGD("setDelay: (handle=%d, ns=%d)",handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "grvdelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ //ALOGD("no GRV setDelay control attr \r\n" );
+ return -1;
+ }
+ char buf[80];
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+
+int GameRotationVectorSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd;
+ int flag;
+
+ //ALOGE("GRV batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "grvbatch");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ //ALOGD("no grv batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ //ALOGD("GRV batch(%d) done", flag );
+ return 0;
+}
+
+int GameRotationVectorSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int GameRotationVectorSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ ////ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = timevalToNano(event->time);
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+
+ }
+ }
+ else// if (type != EV_ABS)
+ {
+ //ALOGE("GameRotationVectorSensor: unknown event (type=%d, code=%d)", type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void GameRotationVectorSensor::processEvent(int code, int value)
+{
+ ////ALOGD("processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_GRV_STATUS:
+ mPendingEvent.orientation.status = value;
+ break;
+ case EVENT_TYPE_GRV_X:
+ mPendingEvent.data[0] = (float)value / mDataDiv ;
+ break;
+ case EVENT_TYPE_GRV_Y:
+ mPendingEvent.data[1] = (float)value / mDataDiv;
+ break;
+ case EVENT_TYPE_GRV_Z:
+ mPendingEvent.data[2] = (float)value / mDataDiv;
+ ////ALOGE("GRVSensor: mDataDiv = %d", mDataDiv);
+ break;
+ case EVENT_TYPE_GRV_SCALAR:
+ mPendingEvent.data[3] = (float)value / mDataDiv;
+ ////ALOGE("GRVSensor: mDataDiv = %d", mDataDiv);
+ break;
+ }
+
+}
diff --git a/src/navigation/sensor/sensor_hal/src/GeomagneticRotationVector.cpp b/src/navigation/sensor/sensor_hal/src/GeomagneticRotationVector.cpp
new file mode 100644
index 0000000..3e30449
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/GeomagneticRotationVector.cpp
@@ -0,0 +1,280 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "GeomagneticRotationVector.h"
+#undef LOG_TAG
+#define LOG_TAG "GMRV"
+
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+GeomagneticRotationVectorSensor::GeomagneticRotationVectorSensor()
+ : SensorBase(NULL, "m_gmrv_input"),//GMRV_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_GEOMAGNETIC_ROTATION_VECTOR;
+ mPendingEvent.type = SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR;
+ mPendingEvent.acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_gmrv_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ //ALOGD("gmrv misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_gmrv_misc/gmrvactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf)-1);
+ if (len <= 0) {
+ ALOGD("read div err buf(%s)", buf);
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ }
+ close(fd);
+ } else {
+ ALOGE("open grv misc path %s fail ", datapath);
+ }
+}
+
+GeomagneticRotationVectorSensor::~GeomagneticRotationVectorSensor() {
+if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+int GeomagneticRotationVectorSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ char devnum_dir[] = "/sys/class/misc/m_gmrv_misc/gmrvdevnum";
+ char buf_s[64] = {0};
+ int len;
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read devnum err buf(%s)", buf);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ //if (fd < 0)
+ // ALOGE("couldn't find input device");
+ return fd;
+}
+
+int GeomagneticRotationVectorSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ //ALOGD("GMRV enable: handle:%d, en:%d \r\n",handle, en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "gmrvactive");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ //ALOGD("no GMRV enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ //ALOGD("GMRV enable(%d) done", mEnabled );
+ return 0;
+
+}
+
+int GeomagneticRotationVectorSensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd;
+ //ALOGD("setDelay: (handle=%d, ns=%d)",handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "gmrvdelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ //ALOGD("no GMRV setDelay control attr \r\n" );
+ return -1;
+ }
+ char buf[80];
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+
+int GeomagneticRotationVectorSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd;
+ int flag;
+
+ //ALOGE("GMRV batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "gmrvbatch");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ //ALOGD("no gmrv batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ //ALOGD("GMRV batch(%d) done", flag );
+ return 0;
+}
+
+int GeomagneticRotationVectorSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int GeomagneticRotationVectorSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ ////ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = timevalToNano(event->time);
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+
+ }
+ }
+ else// if (type != EV_ABS)
+ {
+ //ALOGE("GeomagneticRotationVectorSensor: unknown event (type=%d, code=%d)", type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void GeomagneticRotationVectorSensor::processEvent(int code, int value)
+{
+ ////ALOGD("processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_GMRV_STATUS:
+ mPendingEvent.orientation.status = value;
+ break;
+ case EVENT_TYPE_GMRV_X:
+ mPendingEvent.data[0] = (float)value / mDataDiv ;
+ break;
+ case EVENT_TYPE_GMRV_Y:
+ mPendingEvent.data[1] = (float)value / mDataDiv;
+ break;
+ case EVENT_TYPE_GMRV_Z:
+ mPendingEvent.data[2] = (float)value / mDataDiv;
+ ////ALOGE("GMRVSensor: mDataDiv = %d", mDataDiv);
+ break;
+ case EVENT_TYPE_GMRV_SCALAR:
+ mPendingEvent.data[3] = (float)value / mDataDiv;
+ ////ALOGE("GMRVSensor: mDataDiv = %d", mDataDiv);
+ break;
+ }
+
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Gesture.cpp b/src/navigation/sensor/sensor_hal/src/Gesture.cpp
new file mode 100644
index 0000000..0d421f3
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Gesture.cpp
@@ -0,0 +1,284 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include <inttypes.h>
+#include "Gesture.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "[Gesture Sensor]"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+
+GestureSensor::GestureSensor()
+ : SensorBase(NULL, "GES_INPUTDEV_NAME"),
+ mEnabled(0),
+ mInputReader(32),
+ mEnabledTime(0),
+ input_sysfs_path_len(0),
+ mPendingMask(0) {
+ memset(mPendingEvents, 0, sizeof(mPendingEvents));
+ mPendingEvents[inpocket].version = sizeof(sensors_event_t);
+ mPendingEvents[inpocket].sensor = ID_IN_POCKET;
+ mPendingEvents[inpocket].type = SENSOR_TYPE_IN_POCKET;
+
+ mPendingEvents[stationary].version = sizeof(sensors_event_t);
+ mPendingEvents[stationary].sensor = ID_STATIONARY;
+ mPendingEvents[stationary].type = SENSOR_TYPE_STATIONARY;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strncpy(input_sysfs_path, "/sys/class/misc/m_ges_misc/", sizeof(input_sysfs_path));
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ ALOGD("misc path =%s", input_sysfs_path);
+}
+
+GestureSensor::~GestureSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int GestureSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+
+ devnum_dir = "/sys/class/misc/m_ges_misc/gesdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0) {
+ int ret = read(fd, buf, sizeof(buf));
+ if (ret <= 0) {
+ close(fd);
+ return -1;
+ }
+ sscanf(buf, "%d\n", &num);
+ close(fd);
+ } else {
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ //if (fd < 0)
+ // ALOGE( "couldn't find input device");
+ return fd;
+}
+
+int GestureSensor::HandleToIndex(int handle) {
+ switch (handle) {
+ case ID_IN_POCKET:
+ return inpocket;
+ case ID_STATIONARY:
+ return stationary;
+ default:
+ ALOGE("HandleToIndex(%d)\n", handle);
+ }
+
+ return -1;
+}
+
+int GestureSensor::IndexToHandle(int index) {
+ switch (index) {
+ case inpocket:
+ return ID_IN_POCKET;
+ case stationary:
+ return ID_STATIONARY;
+ default:
+ ALOGE("IndexToHandle(%d)\n", index);
+ }
+
+ return -1;
+}
+
+int GestureSensor::enable(int32_t handle, int en) {
+ int fd;
+ int index;
+ unsigned int shift;
+ char buf[8];
+ int flags = en ? 1 : 0;
+
+ ALOGD("enable: handle:%d, en:%d \r\n", handle, en);
+ strncpy(&input_sysfs_path[input_sysfs_path_len], "gesactive", sizeof(input_sysfs_path) - input_sysfs_path_len);
+ ALOGD("path:%s \r\n", input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if (fd < 0) {
+ ALOGD("no gesture enable control attr\r\n");
+ return -1;
+ }
+
+ index = HandleToIndex(handle);
+ if (index < 0) {
+ close(fd);
+ ALOGD("enable fail: index:%d, handle:%d, en:%d \r\n", index, handle, en);
+ return -1;
+ }
+ shift = index;
+ sprintf(buf, "%d : %d", handle, flags);
+ if (flags) {
+ mEnabled |= (1ULL << shift);
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ } else {
+ mEnabled &= ~(1ULL << shift);
+ }
+
+ write(fd, buf, sizeof(buf));
+ close(fd);
+ ALOGD("enable:%" PRIu64 " done\n", mEnabled);
+ return 0;
+}
+
+int GestureSensor::setDelay(int32_t handle, int64_t ns) {
+ ALOGD("setDelay: regardless of the setDelay() value (handle=%d, ns=%lld)", handle, ns);
+ return 0;
+}
+
+int GestureSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs) {
+ int flag;
+ int fd;
+
+ ALOGE("batch: handle:%d, en:%d, samplingPeriodNs:%lld, maxBatchReportLatencyNs:%lld \r\n",
+ handle, flags, samplingPeriodNs, maxBatchReportLatencyNs);
+ if (maxBatchReportLatencyNs == 0) {
+ flag = 0;
+ } else {
+ flag = 1;
+ }
+
+ strncpy(&input_sysfs_path[input_sysfs_path_len], "gesbatch", sizeof(input_sysfs_path) - input_sysfs_path_len);
+ ALOGD("path:%s \r\n", input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if (fd < 0) {
+ ALOGD("no gesture batch control attr\r\n");
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag) {
+ buf[0] = '1';
+ } else {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("ges batch(%d) done", flag);
+ return 0;
+}
+
+int GestureSensor::flush(int handle) {
+ ALOGD("flush, handle:%d\r\n", handle);
+ return -errno;
+}
+
+int GestureSensor::readEvents(sensors_event_t* data, int count) {
+ int i;
+ int handle;
+
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ if (type == EV_REL) {
+ processEvent(event->code, event->value);
+ SelectGestureEvent(event->code);
+ } else if (type == EV_SYN) {
+ int64_t time = getTimestamp();
+
+ for (i = 0; i < numSensors; i++) {
+ if (((mEnabled & (1ULL << i)) != 0) && ((mPendingMask & (1ULL << i)) != 0)) {
+ if (time >= mEnabledTime) {
+ mPendingEvents[i].timestamp = time;
+ *data++ = mPendingEvents[i];
+ numEventReceived++;
+ mPendingMask &= ~(1 << i);
+ handle = IndexToHandle(i);
+ enable(handle, false);
+ }
+ count--;
+ }
+ }
+ } else {
+ ALOGE("unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+
+ return numEventReceived;
+}
+
+void GestureSensor::SelectGestureEvent(int code) {
+ ALOGD("SelectGestureEvent code=%d\r\n", code);
+ switch (code) {
+ case EVENT_TYPE_INPK_VALUE:
+ mPendingMask |= (1 << inpocket);
+ break;
+ case EVENT_TYPE_STATIONARY_VALUE:
+ mPendingMask |= (1 << stationary);
+ break;
+ }
+}
+void GestureSensor::processEvent(int code, int value) {
+ ALOGD("processEvent code=%d,value=%d\r\n", code, value);
+ switch (code) {
+ case EVENT_TYPE_INPK_VALUE:
+ mPendingEvents[inpocket].data[0] = (float) value;
+ break;
+ case EVENT_TYPE_STATIONARY_VALUE:
+ mPendingEvents[stationary].data[0] = (float) value;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/GlanceGesture.cpp b/src/navigation/sensor/sensor_hal/src/GlanceGesture.cpp
new file mode 100644
index 0000000..a78bb71
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/GlanceGesture.cpp
@@ -0,0 +1,273 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "GlanceGesture.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "GLANCE_GESTURE"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+GlanceGestureSensor::GlanceGestureSensor()
+ : SensorBase(NULL, "m_glg_input"),//_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_GLANCE_GESTURE;
+ mPendingEvent.type = SENSOR_TYPE_GLANCE_GESTURE;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ //input_sysfs_path[PATH_MAX] = {0};
+ memset(input_sysfs_path, 0, sizeof(char)*PATH_MAX);
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_glg_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ ALOGD("GlanceGesture misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_glg_misc/glgactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if(len<=0)
+ {
+ ALOGD("read div err buf(%s)",buf );
+ }
+ else
+ {
+ buf[len] = '\0';
+ ALOGE("len = %d, buf = %s",len, buf);
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d",mDataDiv );
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open glance misc path %s fail ", datapath);
+ }
+}
+
+GlanceGestureSensor::~GlanceGestureSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int GlanceGestureSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_glg_misc/glgdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int GlanceGestureSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ ALOGD("glg enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "glgactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no glg enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+ ALOGD("glg enable(%d) done", mEnabled );
+ return 0;
+}
+int GlanceGestureSensor::setDelay(int32_t handle, int64_t ns)
+{
+ //int fd;
+
+ ALOGD("setDelay: regardless of the setDelay() value (handle=%d, ns=%lld)", handle, ns);
+
+ return 0;
+
+}
+int GlanceGestureSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int flag;
+ int fd;
+
+ ALOGE("glg batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "glgbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no glg batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("glg batch(%d) done", flag );
+ return 0;
+
+}
+
+int GlanceGestureSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int GlanceGestureSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ if(mPendingEvent.sensor == ID_GLANCE_GESTURE)
+ enable(ID_GLANCE_GESTURE, false);
+ }
+ count--;
+
+ }
+ }
+ else
+ {
+ ALOGE("glg: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void GlanceGestureSensor::processEvent(int code, int value)
+{
+ ALOGD("GlanceGestureSensor::processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_GLG_VALUE:
+ mPendingEvent.data[0] = (float) value;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Gravity.cpp b/src/navigation/sensor/sensor_hal/src/Gravity.cpp
new file mode 100644
index 0000000..378f7fc
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Gravity.cpp
@@ -0,0 +1,319 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "Gravity.h"
+#undef LOG_TAG
+#define LOG_TAG "Grav"
+
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+GravitySensor::GravitySensor()
+ : SensorBase(NULL, "m_grav_input"),//GRAV_INPUTDEV_NAME
+ mEnabled(0),
+ mOrientationEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_GRAVITY;
+ mPendingEvent.type = SENSOR_TYPE_GRAVITY;
+ mPendingEvent.acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_grav_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ //ALOGD("grav misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_grav_misc/gravactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf)-1);
+ if (len <= 0) {
+ ALOGD("read div err buf(%s)", buf);
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d", mDataDiv);
+ }
+ close(fd);
+ } else {
+ ALOGE("open gravity misc path %s fail ", datapath);
+ }
+}
+
+GravitySensor::~GravitySensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int GravitySensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ char devnum_dir[] = "/sys/class/misc/m_grav_misc/gravdevnum";
+ char buf_s[64] = {0};
+ int len;
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read devnum err buf(%s)", buf);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ //if (fd < 0)
+ // ALOGE("couldn't find input device");
+ return fd;
+}
+int GravitySensor::enableNoHALDataAcc(int en)
+{
+ int fd;
+ //ALOGD("GRAV enable nodata en(%d) \r\n",en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "gravenablenodata");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ //ALOGD("no GRAV enable nodata control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if(1==en)
+ {
+ buf[0] = '1';
+ }
+ if(0==en)
+ {
+ buf[0] = '0';
+ }
+
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ //ALOGD("GRAV enable nodata done");
+ return 0;
+}
+
+int GravitySensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ //ALOGD("GRAV enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "gravactive");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ //ALOGD("no GRAV enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ //ALOGD("GRAV enable(%d) done", mEnabled );
+ return 0;
+}
+int GravitySensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd;
+ //uint32_t ms=0;
+ //ALOGD("setDelay: (handle=%d, ns=%d)",handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "gravdelay");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ //ALOGD("no GRAV setDelay control attr \r\n" );
+ return -1;
+ }
+ //ms = ns/1000000;
+
+ char buf[80];
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+
+int GravitySensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd;
+ int flag;
+
+ ////ALOGE("GRAV batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ //Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "gravbatch");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ //ALOGD("no GRAV batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ //ALOGD("GRAV batch(%d) done", flag );
+ return 0;
+
+}
+
+int GravitySensor::flush(int handle)
+{
+ return -errno;
+}
+
+int GravitySensor::readEvents(sensors_event_t* data, int count)
+{
+
+ // ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (numEventReceived < count && 0 < mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ // ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ // ALOGE("fwq3....\r\n");
+ int64_t time = timevalToNano(event->time);
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+
+ }
+ }
+ else// if (type != EV_ABS)
+ {
+ //ALOGE("GravitySensor: unknown event (type=%d, code=%d)", type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void GravitySensor::processEvent(int code, int value)
+{
+ //ALOGD("gravel, processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_GRAV_STATUS:
+ mPendingEvent.acceleration.status = value;
+ //ALOGE("GravitySensor: EVENT_TYPE_GRAV_STATUS");
+ break;
+ case EVENT_TYPE_GRAV_X:
+ mPendingEvent.acceleration.x = (float)value / mDataDiv ;
+ //ALOGE("GravitySensor: EVENT_TYPE_GRAV_X");
+ break;
+ case EVENT_TYPE_GRAV_Y:
+ mPendingEvent.acceleration.y = (float)value / mDataDiv;
+ //ALOGE("GravitySensor: EVENT_TYPE_GRAV_Y");
+ break;
+ case EVENT_TYPE_GRAV_Z:
+ mPendingEvent.acceleration.z = (float)value / mDataDiv;
+ //ALOGE("GravitySensor: EVENT_TYPE_GRAV_Z");
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Gyroscope.cpp b/src/navigation/sensor/sensor_hal/src/Gyroscope.cpp
new file mode 100644
index 0000000..f337bad
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Gyroscope.cpp
@@ -0,0 +1,420 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include "Gyroscope.h"
+#include <string.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "GYRO"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+GyroscopeSensor::GyroscopeSensor()
+ : SensorBase(NULL, "m_gyro_input"),//GYRO_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_GYROSCOPE;
+ mPendingEvent.type = SENSOR_TYPE_GYROSCOPE;
+ mPendingEvent.acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime = 0;
+ mDataDiv = 1;
+ mTempDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ mAllInputDataCompleteFlag = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+
+ char datapath[64]={"/sys/class/misc/m_gyro_misc/gyroactive"};
+ int fd = -1;
+ char buf[64]={0};
+ int len;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_gyro_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ else
+ {
+ ALOGE("couldn't find input device gyroscope");
+ return;
+ }
+ ALOGD("gyro misc path =%s", input_sysfs_path);
+
+ fd = open(datapath, O_RDWR);
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if (len <= 0)
+ {
+ ALOGD("read div err, len = %d", len);
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d %d", &mDataDiv, &mTempDiv);
+ ALOGD("read div buf(%s), mdiv %d, tdiv %d", datapath, mDataDiv, mTempDiv);
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open gyro misc path %s fail ", datapath);
+ }
+}
+
+GyroscopeSensor::~GyroscopeSensor() {
+if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+int GyroscopeSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_gyro_misc/gyrodevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find gyro input device: %s \n", buf_s);
+ return fd;
+}
+
+int GyroscopeSensor::enableNoHALData(int en) {
+ int fd = 0;
+ char buf[2] = {0};
+ ALOGD("GYRO enable nodata en(%d) \r\n", en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "gyroenablenodata");
+ ALOGD("path:%s \r\n", input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if (fd < 0) {
+ ALOGD("no GYRO enable nodata control attr\r\n");
+ return -1;
+ }
+
+ buf[1] = 0;
+ if (1 == en) {
+ buf[0] = '1';
+ }
+ if (0 == en) {
+ buf[0] = '0';
+ }
+
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("GYRO enable nodata done");
+ return 0;
+}
+int GyroscopeSensor::enable(int32_t handle, int en)
+{
+ int fd=-1;
+ int flags = en ? 1 : 0;
+
+ ALOGD("Gyro enable: handle:%d, en:%d \r\n",handle, en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "gyroactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no Gyro enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("Gyro enable(%d) done", mEnabled );
+ return 0;
+
+}
+
+int GyroscopeSensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd=-1;
+ ALOGD("setDelay: (handle=%d, ns=%lld)",handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "gyrodelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no GYRO setDelay control attr \r\n" );
+ return -1;
+ }
+ char buf[80]={0};
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+
+int GyroscopeSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd;
+ int flag;
+ ALOGE("GYRO batch: handle:%d, en:%d,samplingPeriodNs:%lld, maxBatchReportLatencyNs:%lld \r\n",handle, flags,samplingPeriodNs, maxBatchReportLatencyNs);
+
+ //Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "gyrobatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no gyro batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("GYRO batch(%d) done", flag );
+ return 0;
+}
+
+int GyroscopeSensor::flush(int handle)
+{
+ ALOGD("handle=%d\n",handle);
+ return -errno;
+}
+
+int GyroscopeSensor::getODR(int32_t handle, int *odr)
+{
+ int fd = -1;
+ int len;
+ char buf[64] = {0};
+ const char *odr_dir = NULL;
+
+ odr_dir = "/sys/class/misc/m_gyro_misc/gyrogetodr";
+ ALOGD("gyro getODR path: %s\n", odr_dir);
+ fd = open(odr_dir, O_RDONLY);
+ if(fd < 0) {
+ ALOGE("no GYRO getODR control attr \r\n" );
+ return -1;
+ }
+
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read gyrogetodr err, len = %d", len);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%x %x %x %x %x %x %x %x\n",
+ &odr[0], &odr[1], &odr[2], &odr[3],
+ &odr[4], &odr[5], &odr[6], &odr[7]);
+ }
+
+ ALOGD("GYRO getODR ok [%d, %d, %d, %d, %d, %d, %d, %d]\n",
+ odr[0], odr[1], odr[2], odr[3],
+ odr[4], odr[5], odr[6], odr[7]);
+ return 0;
+}
+
+int GyroscopeSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(type, event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+ if (mEnabled) {
+ //ALOGE("fwq4....\r\n");
+ if (time >= mEnabledTime) {
+ if (mAllInputDataCompleteFlag == all_complete) {
+ //Assign timestamp if kernel is not assigned.
+ if (0 == mPendingEvent.timestamp)
+ mPendingEvent.timestamp = time;
+ if (mPendingEvent.timestamp > mEnabledTime) {
+ //ALOGD("gyro[%6f, %6f, %6f, %6f][%lld]\n",
+ // mPendingEvent.acceleration.x, mPendingEvent.acceleration.y, mPendingEvent.acceleration.z,
+ // mPendingEvent.acceleration.t, mPendingEvent.timestamp);
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ mPendingEvent.timestamp = 0;
+ count--;
+ }
+ } else {
+ ALOGE("gyroscope dropped data due to mAllInputDataCompleteFlag(%d) is not all_complete\n",
+ mAllInputDataCompleteFlag);
+ }
+ }
+ mAllInputDataCompleteFlag = restart;
+ }
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void GyroscopeSensor::processEvent(int type, int code, int value)
+{
+ //ALOGD("processEvent code=%d,value=%d\r\n",code, value);
+ if (EV_ABS == type) {
+ switch (code) {
+ case EVENT_TYPE_GYRO_STATUS:
+ mPendingEvent.gyro.status = value;
+ mAllInputDataCompleteFlag = status;
+ break;
+ case EVENT_TYPE_GYRO_X:
+ mPendingEvent.gyro.x = (float)value / mDataDiv;
+ mAllInputDataCompleteFlag = x;
+ break;
+ case EVENT_TYPE_GYRO_Y:
+ mPendingEvent.gyro.y = (float)value / mDataDiv;
+ mAllInputDataCompleteFlag = y;
+ break;
+ case EVENT_TYPE_GYRO_Z:
+ mPendingEvent.gyro.z = (float)value / mDataDiv;
+ mAllInputDataCompleteFlag = z;
+ //ALOGD("gy_xyz=%f, %f, %f", mPendingEvent.gyro.x, mPendingEvent.gyro.y, mPendingEvent.gyro.z);
+ break;
+ case EVENT_TYPE_GYRO_T:
+ mPendingEvent.gyro.t = (float)value / mTempDiv;
+ break;
+ default:
+ ALOGE("GyroscopeSensor: unknown event (type=%d, code=%d)", type, code);
+ break;
+ }
+ } else if (EV_REL == type) {
+ switch (code) {
+ case EVENT_TYPE_GYRO_TIMESTAMP_HI:
+ mPendingEvent.timestamp = (mPendingEvent.timestamp & 0xFFFFFFFFLL) | ((int64_t)value << 32);
+ mAllInputDataCompleteFlag = hi;
+ break;
+ case EVENT_TYPE_GYRO_TIMESTAMP_LO:
+ mPendingEvent.timestamp =
+ (mPendingEvent.timestamp & 0xFFFFFFFF00000000LL) | ((int64_t)value & 0xFFFFFFFFLL);
+ //ALOGD("gy_t=%lld", mPendingEvent.timestamp);
+ if (mAllInputDataCompleteFlag == hi)
+ mAllInputDataCompleteFlag = lo;
+ break;
+ case EVENT_TYPE_GYRO_UPDATE:
+ break;
+ default:
+ ALOGE("GyroscopeSensor: unknown event (type=%d, code=%d)", type, code);
+ break;
+ }
+ }
+}
+
diff --git a/src/navigation/sensor/sensor_hal/src/HeartRate.cpp b/src/navigation/sensor/sensor_hal/src/HeartRate.cpp
new file mode 100644
index 0000000..48a65b2
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/HeartRate.cpp
@@ -0,0 +1,277 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "HeartRate.h"
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "HRM"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+HeartRateSensor::HeartRateSensor()
+ : SensorBase(NULL, "m_hrm_input"),//HRM_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_HEART_RATE;
+ mPendingEvent.type = SENSOR_TYPE_HEART_RATE;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ //input_sysfs_path[PATH_MAX] = {0};
+ memset(input_sysfs_path, 0, sizeof(char)*PATH_MAX);
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_hrm_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ ALOGD("hrm misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_hrm_misc/hrmactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf)-1);
+ if(len<=0) {
+ ALOGD("read div err buf(%s)",buf );
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d",mDataDiv );
+ }
+ close(fd);
+ } else {
+ ALOGE("open heartRate misc path %s fail ", datapath);
+ }
+}
+
+HeartRateSensor::~HeartRateSensor() {
+if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+int HeartRateSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_hrm_misc/hrmdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int HeartRateSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ ALOGD("Hrm enable: handle:%d, en:%d \r\n",handle, en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "hrmactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no Hrm enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("Hrm enable(%d) done", mEnabled );
+ return 0;
+
+}
+
+int HeartRateSensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd;
+ ALOGD("setDelay: (handle=%d, ns=%lld)", handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "hrmdelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no HRM setDelay control attr \r\n" );
+ return -1;
+ }
+ char buf[80];
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+
+int HeartRateSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd;
+ int flag;
+
+ ALOGE("HRM batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "hrmbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no hrm batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("HRM batch(%d) done", flag );
+ return 0;
+}
+
+int HeartRateSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int HeartRateSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+
+ }
+ }
+ else if (type != EV_ABS)
+ {
+ ALOGE("HeartRateSensor: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void HeartRateSensor::processEvent(int code, int value)
+{
+ ALOGD("processEvent::processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_HRM_BPM:
+ mPendingEvent.data[0] = value / mDataDiv;
+ break;
+ case EVENT_TYPE_HRM_STATUS:
+ mPendingEvent.data[1] = value;
+ break;
+ }
+
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Humidity.cpp b/src/navigation/sensor/sensor_hal/src/Humidity.cpp
new file mode 100644
index 0000000..17436b4
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Humidity.cpp
@@ -0,0 +1,300 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "Humidity.h"
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "HUMIDITY"
+#endif
+
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+HumiditySensor::HumiditySensor()
+ : SensorBase(NULL, "m_hmdy_input"), // HUMIDITY_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32) {
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_HUMIDITY;
+ mPendingEvent.type = SENSOR_TYPE_HUMIDITY;
+ mPendingEvent.acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime = 0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp = 0;
+ input_sysfs_path_len = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+ m_hmdy_last_ts = 0;
+ m_hmdy_delay = 0;
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_hmdy_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ } else {
+ ALOGE("couldn't find input device humidity");
+ return;
+ }
+ ALOGD("humidity misc path =%s", input_sysfs_path);
+
+ char datapath[64] = {"/sys/class/misc/m_hmdy_misc/hmdyactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64] = {0};
+ int len;
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf)-1);
+ if (len <= 0) {
+ ALOGD("read div err, len = %d", len);
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s), mdiv %d", datapath, mDataDiv);
+ }
+ close(fd);
+ } else {
+ ALOGE("open hmdy misc path %s fail ", datapath);
+ }
+}
+
+HumiditySensor::~HumiditySensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int HumiditySensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64] = {0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_hmdy_misc/hmdydevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ } else {
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int HumiditySensor::enable(int32_t handle, int en) {
+ int fd = -1;
+ int flags = en ? 1 : 0;
+
+ ALOGD("humidity enable: handle:%d, en:%d\r\n", handle, en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "hmdyactive");
+ ALOGD("path:%s \r\n", input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if (fd < 0) {
+ ALOGD("no humidity enable control attr\r\n");
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flags) {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ m_hmdy_last_ts = 0;
+ } else {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("humidity enable(%d) done", mEnabled);
+ return 0;
+}
+int HumiditySensor::setDelay(int32_t handle, int64_t ns) {
+ int fd = -1;
+
+ ALOGD("setDelay: (handle=%d, ns=%lld)", handle, ns);
+ m_hmdy_delay = ns;
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "hmdydelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if (fd < 0) {
+ ALOGD("no humidity setDelay control attr\r\n");
+ return -1;
+ }
+
+ char buf[80]={0};
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+int HumiditySensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs) {
+ int flag = 0;
+ int fd = -1;
+
+ ALOGE("humidity batch: handle:%d, en:%d,samplingPeriodNs:%lld, maxBatchReportLatencyNs:%lld\r\n",
+ handle, flags,samplingPeriodNs, maxBatchReportLatencyNs);
+
+ // Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+
+ if (maxBatchReportLatencyNs == 0) {
+ flag = 0;
+ } else {
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "hmdybatch");
+ ALOGD("path:%s \r\n", input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if (fd < 0) {
+ ALOGD("no humidity batch control attr\r\n");
+ return -1;
+ }
+
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flag) {
+ buf[0] = '1';
+ } else {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("humidity batch(%d) done", flag);
+ return 0;
+}
+
+int HumiditySensor::flush(int handle) {
+ ALOGD("handle=%d\n", handle);
+ return -errno;
+}
+
+int HumiditySensor::readEvents(sensors_event_t* data, int count) {
+ // ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ // ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL) {
+ processEvent(event->code, event->value);
+ // ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN) {
+ // ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+ mPendingEvent.timestamp = time;
+ if (mEnabled) {
+ if (mPendingEvent.timestamp >= mEnabledTime) {
+ float delta_mod = (float)(mPendingEvent.timestamp - m_hmdy_last_ts) / (float)(m_hmdy_delay);
+ int loopcout = delta_mod;
+
+ if (loopcout >= 1 && loopcout < 100) {
+ for (int i = 0; i < loopcout; i++) {
+ mPendingEvent.timestamp = time- (loopcout-i)*m_hmdy_delay;
+ if ((time - mPendingEvent.timestamp) < 450000000) {
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ count--;
+ if (0 == count) {
+ break;
+ }
+ }
+ }
+ }
+
+ if (count != 0) {
+ mPendingEvent.timestamp = time;
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ }
+ if (count != 0)
+ count--;
+ }
+ m_hmdy_last_ts = mPendingEvent.timestamp;
+ }
+ else if (type != EV_ABS) {
+ ALOGE("HumiditySensor: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ // ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void HumiditySensor::processEvent(int code, int value) {
+ // ALOGD("processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_HMDY_VALUE:
+ mPendingEvent.relative_humidity = (float) value / mDataDiv;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Hwmsen.cpp b/src/navigation/sensor/sensor_hal/src/Hwmsen.cpp
new file mode 100644
index 0000000..99fe33c
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Hwmsen.cpp
@@ -0,0 +1,665 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include "Hwmsen.h"
+#include <string.h>
+
+//#include <hwmsen_chip_info.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "Hwmsen_sensors"
+#endif
+
+typedef enum SENSOR_NUM_DEF
+{
+ SONSER_UNSUPPORTED = -1,
+
+ #if defined(CONFIG_CUSTOM_KERNEL_ACCGYRO) || defined(CUSTOM_KERNEL_ACCELEROMETER)
+ ACCELEROMETER_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_MAGNETOMETER
+ MAGNETOMETER_NUM,
+ ORIENTATION_NUM ,
+ #endif
+
+ #if defined(CUSTOM_KERNEL_ALSPS) || defined(CUSTOM_KERNEL_ALS)
+ ALS_NUM,
+ #endif
+ #if defined(CUSTOM_KERNEL_ALSPS) || defined(CUSTOM_KERNEL_PS)
+ PS_NUM,
+ #endif
+
+ #if defined(CONFIG_CUSTOM_KERNEL_ACCGYRO) || defined(CUSTOM_KERNEL_GYROSCOPE)
+ GYROSCOPE_NUM,
+ #endif
+
+ #if defined(CUSTOM_KERNEL_BARO_TEMP) || defined(CUSTOM_KERNEL_BAROMETER)
+ PRESSURE_NUM,
+ #endif
+
+ #if defined(CUSTOM_KERNEL_BARO_TEMP) || defined(CUSTOM_KERNEL_TEMPERATURE)
+ TEMPERATURE_NUM,
+ #endif
+ #ifdef CUSTOM_KERNEL_HUMIDITY
+ HUMIDITY_NUM,
+ #endif
+ #ifdef CUSTOM_KERNEL_STEP_COUNTER
+ STEP_COUNTER_NUM,
+ STEP_DETECTOR_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_SIGNIFICANT_MOTION
+ STEP_SIGNIFICANT_MOTION_NUM,
+ #endif
+
+ SENSORS_NUM
+
+}SENSOR_NUM_DEF;
+
+Hwmsen::Hwmsen()
+ : SensorBase(LS_DEVICE_NAME, "hwmdata"),
+ mActiveSensors(0),
+ mEnabled(0),
+ mInputReader(4),
+ mHasPendingEvent(false),
+ mPendingMask(0)
+{
+ memset(mDelays, 0, numSensors);
+ memset(m_hwm_last_ts,0,numSensors);
+ data_type = 0;
+ ALOGD("Hwmsen mPendingEvents len(%d)\r\n",sizeof(mPendingEvents)/sizeof(sensors_event_t));
+ memset(mPendingEvents, 0, sizeof(mPendingEvents));
+ mPendingEvents[Accelerometer].version = sizeof(sensors_event_t);
+ mPendingEvents[Accelerometer].sensor = ID_ACCELEROMETER;
+ mPendingEvents[Accelerometer].type = SENSOR_TYPE_ACCELEROMETER;
+ mPendingEvents[Accelerometer].acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
+
+ mPendingEvents[MagneticField].version = sizeof(sensors_event_t);
+ mPendingEvents[MagneticField].sensor = ID_MAGNETIC;
+ mPendingEvents[MagneticField].type = SENSOR_TYPE_MAGNETIC_FIELD;
+ mPendingEvents[MagneticField].magnetic.status = SENSOR_STATUS_ACCURACY_HIGH;
+
+ mPendingEvents[Orientation ].version = sizeof(sensors_event_t);
+ mPendingEvents[Orientation ].sensor = ID_ORIENTATION;
+ mPendingEvents[Orientation ].type = SENSOR_TYPE_ORIENTATION;
+ mPendingEvents[Orientation ].orientation.status = SENSOR_STATUS_ACCURACY_HIGH;
+
+ mPendingEvents[Gyro].version = sizeof(sensors_event_t);
+ mPendingEvents[Gyro].sensor = ID_GYROSCOPE;
+ mPendingEvents[Gyro].type = SENSOR_TYPE_GYROSCOPE;
+ mPendingEvents[Gyro].orientation.status = SENSOR_STATUS_ACCURACY_HIGH;
+
+ mPendingEvents[light].version = sizeof(sensors_event_t);
+ mPendingEvents[light].sensor = ID_LIGHT;
+ mPendingEvents[light].type = SENSOR_TYPE_LIGHT;
+
+ mPendingEvents[proximity].version = sizeof(sensors_event_t);
+ mPendingEvents[proximity].sensor = ID_PROXIMITY;
+ mPendingEvents[proximity].type = SENSOR_TYPE_PROXIMITY;
+ mdata_fd = FindDataFd();
+ mHwmSensorDebug = NULL;
+
+ for (int i=0 ; i<numSensors ; i++)
+ {
+ mDelays[i] = 200000000; // 200 ms by default
+ }
+ open_device();
+ ALOGD("Hwmsen Construct ok\r\n");
+
+ //{@input value 0 stands for old hwmsen sensor,please refer to nusensor.cpp
+ //enmu in sensors_poll_context_t to see other sensors,this is for sensor debug log
+ //mHwmSensorDebug = new SensorDebugObject((Hwmsen*)this, 0);
+ //@}
+}
+
+Hwmsen::~Hwmsen() {
+ close_device();
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int Hwmsen::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+
+
+ devnum_dir = "/sys/class/misc/hwmsensor/hwmsensordevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ int ret = read(fd, buf, sizeof(buf));
+ if(ret <= 0) {
+ close(fd);
+ return -1;
+ }
+ //num = atoi(buf);
+ sscanf(buf, "%d\n", &num);
+ close(fd);
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int Hwmsen::enableNoHALDataAcc(int en)
+{
+ int io_value = 0;
+ if(1==en)
+ {
+ io_value = ID_ACCELEROMETER;
+ if(ioctl(dev_fd, HWM_IO_ENABLE_SENSOR_NODATA, &io_value))
+ {
+ ALOGE("%s: Enable nodata old acc error!",__func__);
+ return -1;
+ }
+ }
+ if(0==en)
+ {
+ io_value = ID_ACCELEROMETER;
+ if(ioctl(dev_fd, HWM_IO_DISABLE_SENSOR_NODATA, &io_value))
+ {
+ ALOGE("%s: disable nodata old acc error!",__func__);
+ return -1;
+ }
+ }
+ return 0;
+}
+
+int Hwmsen::enable(int32_t handle, int en) {
+ //int sensor_type =0;
+ int io_value = 0;
+ int i=0;
+ int flags = en ? 1 : 0;
+ int err = 0;
+ //uint32_t sensor = 0;
+ uint32_t sensor = (1 << handle); // new active/inactive sensor
+ ALOGD("Hwmsen_Enable: handle:%d, en:%d \r\n",handle,en);
+ if( handle != ID_ACCELEROMETER && handle != ID_MAGNETIC &&
+ handle != ID_ORIENTATION && handle != ID_GYROSCOPE &&
+ handle != ID_PROXIMITY && handle != ID_LIGHT)
+ {
+ ALOGD("enable: (handle=%d) is not hwmsen driver command", handle);
+ return 0;
+ }
+
+ ALOGD("%s: handle %d, enable or disable %d!", __func__, handle, en);
+
+ if(en == 1)
+ {
+ switch(handle)
+ {
+ case ID_ACCELEROMETER:
+ m_hwm_last_ts[Accelerometer] = 0;
+ break;
+ case ID_MAGNETIC:
+ m_hwm_last_ts[MagneticField] = 0;
+ break;
+ case ID_ORIENTATION:
+ m_hwm_last_ts[Orientation] = 0;
+ break;
+ case ID_GYROSCOPE:
+ m_hwm_last_ts[Gyro] = 0;
+ break;
+ case ID_LIGHT:
+ m_hwm_last_ts[light] = 0;
+ break;
+ case ID_PROXIMITY:
+ m_hwm_last_ts[proximity] = 0;
+ break;
+ }
+
+ // TODO: Device IO control to enable sensor
+ //memset(m_hwm_last_ts,0,numSensors);
+ if(ioctl(dev_fd, HWM_IO_ENABLE_SENSOR, &handle))
+ {
+ ALOGE("%s: Enable sensor %d error!",__func__, handle);
+ return -1;
+ }
+
+ // When start orientation sensor, should start the G and M first.
+ if(((mActiveSensors & SENSOR_ORIENTATION) == 0) // hvae no orientation sensor
+ && (sensor & SENSOR_ORIENTATION)) // new orientation sensor start
+ {
+
+ io_value = ID_ACCELEROMETER;
+ if(ioctl(dev_fd, HWM_IO_ENABLE_SENSOR_NODATA, &io_value))
+ {
+ ALOGE("%s: Enable ACCELEROMETR sensor error!",__func__);
+ return -1;
+ }
+
+
+ io_value = ID_MAGNETIC;
+ if(ioctl(dev_fd, HWM_IO_ENABLE_SENSOR_NODATA, &io_value))
+ {
+ ALOGE("%s: Enable MAGNETIC sensor error!",__func__);
+ return -1;
+ }
+ }
+ mEnabled = 1;
+ mActiveSensors |= sensor;
+ }
+ else
+ {
+ mActiveSensors &= ~sensor;
+
+
+ if(0==mActiveSensors)
+ {
+ mEnabled = 0;
+ }
+
+ // When stop Orientation, should stop G and M sensor if they are inactive
+ if(((mActiveSensors & SENSOR_ORIENTATION) == 0)
+ && (sensor & SENSOR_ORIENTATION))
+ {
+
+
+ io_value = ID_ACCELEROMETER;
+ if(ioctl(dev_fd, HWM_IO_DISABLE_SENSOR_NODATA, &io_value))
+ {
+ ALOGE("%s: Disable ACCELEROMETR sensor error!",__func__);
+ return -1;
+ }
+
+
+ io_value = ID_MAGNETIC;
+ if(ioctl(dev_fd, HWM_IO_DISABLE_SENSOR_NODATA, &io_value))
+ {
+ ALOGE("%s: Disable MAGNETIC sensor error!",__func__);
+ return -1;
+ }
+
+ }
+
+ // TODO: Device IO control disable sensor
+ if(ioctl(dev_fd, HWM_IO_DISABLE_SENSOR, &handle))
+ {
+ ALOGE("%s: Disable sensor %d error!",__func__, handle);
+ return -1;
+ }
+ }
+
+ ALOGD("active_sensors =%x\r\n", mActiveSensors);
+
+ return err;
+}
+
+bool Hwmsen::hasPendingEvents() const {
+ return mHasPendingEvent;
+}
+
+
+int Hwmsen::readEvents(sensors_event_t* data, int count)
+{
+ int err=0;
+ int i=0;
+
+
+ if (count < 1)
+ {
+ //ALOGE("hwmsen: read event count:%d",count);
+ return -EINVAL;
+ }
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ {
+ //ALOGE("hwmsen: read event n:%d", n);
+ return n;
+ }
+
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("hwmsen: read event (type=%d, code=%d value=%d)",type, event->code,event->value);
+ if (type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ }
+ else if (type == EV_SYN)
+ {
+ readSensorData();
+ //ALOGE("hwmsen: EV_SYN event (type=%d, code=%d)",
+ // type, event->code);
+ int64_t time = getTimestamp();
+
+ //ALOGE("hwmsen: ++mPendingMask:0x%x",mPendingMask);
+
+ for (i=0 ; count && i<numSensors ; i++)
+ {
+ // ALOGE("hwmsen: ++mActiveSensors:0x%x",mActiveSensors);
+ if(mActiveSensors && (1<<i))
+ {
+ if (mPendingMask & (1<<i))
+ {
+ mPendingMask &= ~(1<<i);
+ mPendingEvents[i].timestamp = time;
+
+ if(i<=Gyro)
+ {
+ if (mPendingEvents[i].timestamp-m_hwm_last_ts[i] > mDelays[i]*18/10)
+ {
+ float delta_mod =
+ (float)(mPendingEvents[i].timestamp-m_hwm_last_ts[i])/(float)(mDelays[i]);
+ if (mDelays[i] == 1000000000 || m_hwm_last_ts[i] == 0)
+ delta_mod = 0;
+ /*ALOGE("fwq m-delta_mod=%f ,delta_mod_int=%lld,delta_mod_dec=%f\r\n",
+ delta_mod,delta_mod_int,delta_mod_dec);*/
+ int loopcout=delta_mod;
+ //ALOGE("fwq hwm-loopcout=%d \r\n",loopcout);
+
+ if(loopcout>=1 && loopcout<100) {
+ for(int j=0; j<loopcout; j++) {
+ mPendingEvents[i].timestamp = time- (loopcout-j)*mDelays[i];
+ //ALOGE("fwq_n hwm[%d]fack event [%lld ] \r\n",i,mPendingEvents[i].timestamp);
+ *data++ = mPendingEvents[i];
+ numEventReceived++;
+
+ count--;
+ if(0==count)
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ if(count != 0)
+ {
+ mPendingEvents[i].timestamp=time;
+ *data++ = mPendingEvents[i];
+ count--;
+ numEventReceived++;
+ }
+ m_hwm_last_ts[i] = mPendingEvents[i].timestamp;
+ }else
+ {
+ if(count !=0)
+ {
+ //ALOGE("fwq i=%d\r\n",i);
+ mPendingEvents[i].timestamp=time;
+ *data++ = mPendingEvents[i];
+ count--;
+ numEventReceived++;
+ }
+ }
+ //ALOGE("hwmsen: count:%d, numEventReceived:%d",count,numEventReceived);
+ }//if (mPendingMask & (1<<i))
+ }//if(mActiveSensors && (1<<i))
+ }//for (i=0 ; count && i<numSensors ; i++)
+
+ } else {
+ ALOGE("hwmsen: unknown event (type=%d, code=%d)",
+ type, event->code);
+ mInputReader.next();
+ }
+ mInputReader.next();
+ }
+
+ return numEventReceived;
+}
+
+void Hwmsen::processEvent(int code, int value) {
+ switch(code)
+ {
+ case EVENT_TYPE_SENSOR:
+ data_type &= 0xFFFFFFFF00000000LL;
+ data_type |= (uint64_t)value&0x00000000FFFFFFFFLL;
+ // ALOGE("hwmsen: processEvent, EVENT_TYPE_SENSOR = 0x%x, data_type = 0x%llx", value, data_type);
+ break;
+ case EVENT_TYPE_SENSOR_EXT:
+ data_type &= 0x00000000FFFFFFFFLL;
+ data_type |= (uint64_t)value<<32;
+ // ALOGE("hwmsen: processEvent, EVENT_TYPE_SENSOR_EXT = 0x%x, data_type = 0x%llx", value, data_type);
+ break;
+ default:
+ ALOGE("hwmsen: processEvent code =%d",code);
+ ALOGE("hwmsen: processEvent error!!!");
+ break;
+ } // switch(code)
+}
+
+void Hwmsen::readSensorData(void) {
+ hwm_trans_data sensors_data;
+ int err =0;
+ int i=0;
+
+ memset(&sensors_data, 0 , sizeof(hwm_trans_data));
+ sensors_data.data_type = data_type; // set flag to read specified sensor
+ err = ioctl(dev_fd, HWM_IO_GET_SENSORS_DATA, &sensors_data);
+
+ for (i = 0; i < MAX_SENSOR_DATA_UPDATE_ONCE; i++)
+ {
+ if (sensors_data.data[i].update == 0) {
+ break;
+ }
+
+ // ALOGE("hwmsen: processEvent, sensors_data.data[%d].sensor = %d",i, sensors_data.data[i].sensor);
+
+ switch (sensors_data.data[i].sensor) {
+ case ID_ORIENTATION:
+ mPendingMask |= 1 << Orientation;
+ mPendingEvents[Orientation].type = SENSOR_TYPE_ORIENTATION;
+ mPendingEvents[Orientation].sensor = sensors_data.data[i].sensor;
+ mPendingEvents[Orientation].orientation.status = sensors_data.data[i].status;
+ mPendingEvents[Orientation].orientation.v[0] = (float)sensors_data.data[i].values[0];
+ mPendingEvents[Orientation].orientation.v[1] = (float)sensors_data.data[i].values[1];
+ mPendingEvents[Orientation].orientation.v[2] = (float)sensors_data.data[i].values[2];
+
+ mPendingEvents[Orientation].orientation.v[0]/=sensors_data.data[i].value_divide;
+ mPendingEvents[Orientation].orientation.v[1]/=sensors_data.data[i].value_divide;
+ mPendingEvents[Orientation].orientation.v[2]/=sensors_data.data[i].value_divide;
+ mPendingEvents[Orientation].timestamp = sensors_data.data[i].time;
+ break;
+
+ case ID_MAGNETIC:
+ mPendingMask |= 1 << MagneticField;
+ mPendingEvents[MagneticField].type = SENSOR_TYPE_MAGNETIC_FIELD;
+ mPendingEvents[MagneticField].sensor = sensors_data.data[i].sensor;
+ mPendingEvents[MagneticField].magnetic.status = sensors_data.data[i].status;
+ mPendingEvents[MagneticField].magnetic.v[0] = (float)sensors_data.data[i].values[0];
+ mPendingEvents[MagneticField].magnetic.v[1] = (float)sensors_data.data[i].values[1];
+ mPendingEvents[MagneticField].magnetic.v[2] = (float)sensors_data.data[i].values[2];
+
+ mPendingEvents[MagneticField].magnetic.v[0]/=sensors_data.data[i].value_divide;
+ mPendingEvents[MagneticField].magnetic.v[1]/=sensors_data.data[i].value_divide;
+ mPendingEvents[MagneticField].magnetic.v[2]/=sensors_data.data[i].value_divide;
+ mPendingEvents[MagneticField].timestamp = sensors_data.data[i].time;
+ /*ALOGE("[ID_MAGNETIC](%f,%f,%f) \r\n",mPendingEvents[MagneticField].magnetic.v[0],
+ mPendingEvents[MagneticField].magnetic.v[1],
+ mPendingEvents[MagneticField].magnetic.v[2]);*/
+ // {@input value 0 stands for old hwmsen sensor,please refer to nusensor.cpp enmu
+ // in sensors_poll_context_t to see other sensors
+ // mHwmSensorDebug->send_singnal(0);
+ // @}
+ break;
+
+ case ID_ACCELEROMETER:
+
+ mPendingMask |= 1 << Accelerometer;
+ mPendingEvents[Accelerometer].type = SENSOR_TYPE_ACCELEROMETER;
+ mPendingEvents[Accelerometer].sensor = sensors_data.data[i].sensor;
+ mPendingEvents[Accelerometer].acceleration.status = sensors_data.data[i].status;
+ mPendingEvents[Accelerometer].acceleration.v[0] = (float)sensors_data.data[i].values[0];
+ mPendingEvents[Accelerometer].acceleration.v[1] = (float)sensors_data.data[i].values[1];
+ mPendingEvents[Accelerometer].acceleration.v[2] = (float)sensors_data.data[i].values[2];
+
+ mPendingEvents[Accelerometer].acceleration.v[0]/=sensors_data.data[i].value_divide;
+ mPendingEvents[Accelerometer].acceleration.v[1]/=sensors_data.data[i].value_divide;
+ mPendingEvents[Accelerometer].acceleration.v[2]/=sensors_data.data[i].value_divide;
+ mPendingEvents[Accelerometer].timestamp = sensors_data.data[i].time;
+ /*ALOGE("[ID_ACCELEROMETER](%f,%f,%f) \r\n",
+ mPendingEvents[Accelerometer].acceleration.v[0],
+ mPendingEvents[Accelerometer].acceleration.v[1],
+ mPendingEvents[Accelerometer].acceleration.v[2]);*/
+ break;
+ case ID_GYROSCOPE:
+
+ mPendingMask |= 1 << Gyro;
+ mPendingEvents[Gyro].type = SENSOR_TYPE_GYROSCOPE;
+ mPendingEvents[Gyro].sensor = sensors_data.data[i].sensor;
+ mPendingEvents[Gyro].gyro.status = sensors_data.data[i].status;
+ mPendingEvents[Gyro].gyro.v[0] = (float)sensors_data.data[i].values[0];
+ mPendingEvents[Gyro].gyro.v[1] = (float)sensors_data.data[i].values[1];
+ mPendingEvents[Gyro].gyro.v[2] = (float)sensors_data.data[i].values[2];
+
+ mPendingEvents[Gyro].gyro.v[0]/=sensors_data.data[i].value_divide;
+ mPendingEvents[Gyro].gyro.v[1]/=sensors_data.data[i].value_divide;
+ mPendingEvents[Gyro].gyro.v[2]/=sensors_data.data[i].value_divide;
+ mPendingEvents[Gyro].timestamp = sensors_data.data[i].time;
+ /*ALOGE("[ID_GYROSCOPE](%f,%f,%f) \r\n",mPendingEvents[Gyro].gyro.v[0],
+ mPendingEvents[Gyro].gyro.v[1],mPendingEvents[Gyro].gyro.v[2]);*/
+ break;
+
+ case ID_PROXIMITY:
+ mPendingMask |= 1 << proximity;
+ mPendingEvents[proximity].type = SENSOR_TYPE_PROXIMITY;
+ mPendingEvents[proximity].sensor = sensors_data.data[i].sensor;
+ mPendingEvents[proximity].distance = (float)sensors_data.data[i].values[0];
+ mPendingEvents[proximity].timestamp = sensors_data.data[i].time;
+ break;
+
+ case ID_LIGHT:
+ mPendingMask |= 1 << light;
+ mPendingEvents[light].type = SENSOR_TYPE_LIGHT;
+ mPendingEvents[light].sensor = sensors_data.data[i].sensor;
+ mPendingEvents[light].light = (float)sensors_data.data[i].values[0];
+ mPendingEvents[light].timestamp = sensors_data.data[i].time;
+ break;
+ default:
+ ALOGE("hwmsen: unknown sensor type =%d", sensors_data.data[i].sensor);
+ }
+ }
+
+ data_type = 0;
+}
+
+float Hwmsen::indexToValue(size_t index) const
+{
+ static const float luxValues[8] = {
+ 10.0, 160.0, 225.0, 320.0,
+ 640.0, 1280.0, 2600.0, 10240.0
+ };
+
+ const size_t maxIndex = sizeof(luxValues)/sizeof(*luxValues) - 1;
+ if (index > maxIndex)
+ index = maxIndex;
+ return luxValues[index];
+}
+
+int Hwmsen::setDelay(int32_t handle, int64_t ns)
+{
+ int what = -1;
+ ALOGD("setDelay: (handle=%d, ns=%lld)",
+ handle, ns);
+
+ if( handle != ID_ACCELEROMETER && handle != ID_MAGNETIC &&
+ handle != ID_ORIENTATION && handle != ID_GYROSCOPE &&
+ handle != ID_LIGHT)
+ {
+ ALOGD("setDelay: (handle=%d, ns=%lld) is not hwmsen driver command", handle, ns);
+ return 0;
+ }
+
+ what = handle;
+ /* if (uint32_t(what) >= numSensors)
+ return -EINVAL; */
+
+ if (ns < 0)
+ return -EINVAL;
+ mDelays[what] = ns;
+ return update_delay(what);
+
+}
+
+int Hwmsen::update_delay(int what)
+{
+
+ struct sensor_delay delayPara;
+
+ //if (mEnabled) //always update delay even sensor is not enabled.
+ {
+ delayPara.delay = mDelays[what]/1000000;
+ delayPara.handle = what;
+ ALOGD("setDelay: (what=%d, ms=%d)",
+ delayPara.handle , delayPara.delay);
+ if(delayPara.delay < 10) //set max sampling rate = 100Hz
+ {
+ ALOGD("Control set delay %d ms is too small \n",delayPara.delay );
+ delayPara.delay = 10;
+
+ }
+ ALOGD("really setDelay: (what=%d, ms=%d)",
+ delayPara.handle , delayPara.delay);
+ if(ioctl(dev_fd, HWM_IO_SET_DELAY, &delayPara))
+ {
+ ALOGE("%s: Set delay %d ms error ", __func__, delayPara.delay);
+ return -errno;
+ }
+ }
+ return 0;
+}
+int Hwmsen::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ ALOGD("handle=%d,flags=%d,samplingPeriodNs=%lld,maxBatchReportLatencyNs=%lld\n",handle,flags,samplingPeriodNs,maxBatchReportLatencyNs);
+ return -errno;
+}
+
+int Hwmsen::flush(int handle)
+{
+ ALOGD("handle=%d\n",handle);
+ return -errno;
+}
diff --git a/src/navigation/sensor/sensor_hal/src/InPocket.cpp b/src/navigation/sensor/sensor_hal/src/InPocket.cpp
new file mode 100644
index 0000000..7ff586b
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/InPocket.cpp
@@ -0,0 +1,284 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "InPocket.h"
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "IN_POCKET"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+InPocketSensor::InPocketSensor()
+ : SensorBase(NULL, "m_inpk_input"),//IN_POCKET_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_IN_POCKET;
+ mPendingEvent.type = SENSOR_TYPE_IN_POCKET;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp = 0;
+ mPendingEvent.distance = 1;
+ input_sysfs_path_len = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_inpk_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ ALOGD("inpk misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_inpk_misc/inpkactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+ if (fd>=0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if(len<=0)
+ {
+ ALOGD("read div err buf(%s)",buf );
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d",mDataDiv );
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open fdn misc path %s fail ", datapath);
+ }
+}
+
+InPocketSensor::~InPocketSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+
+}
+int InPocketSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_inpk_misc/inpkdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err buf(%s)", buf);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ ALOGE("len = %d, buf = %s",len, buf);
+ }
+ }
+ else
+ {
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int InPocketSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ ALOGD("INPK enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "inpkactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no INPK enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("INPK enable(%d) done", mEnabled );
+ return 0;
+
+}
+int InPocketSensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd;
+ ALOGD("setDelay: (handle=%d, ns=%lld)", handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "inpkdelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no INPK setDelay control attr \r\n" );
+ return -1;
+ }
+
+ char buf[80];
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+int InPocketSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd;
+ int flag;
+
+ ALOGE("INPK batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "inpkbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no INPK batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("INPK batch(%d) done", flag );
+ return 0;
+}
+
+int InPocketSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int InPocketSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+
+ }
+ }
+ else if (type != EV_REL)
+ {
+ ALOGE("InPocketSensor: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void InPocketSensor::processEvent(int code, int value)
+{
+ ALOGD("InPocketSensor::processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_INPK_VALUE:
+ mPendingEvent.data[0]= (float)value;
+ break;
+ }
+
+}
diff --git a/src/navigation/sensor/sensor_hal/src/InputEventReader.cpp b/src/navigation/sensor/sensor_hal/src/InputEventReader.cpp
new file mode 100644
index 0000000..0ccc890
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/InputEventReader.cpp
@@ -0,0 +1,105 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <stdint.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <poll.h>
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <linux/input.h>
+#include "InputEventReader.h"
+
+/*****************************************************************************/
+
+struct input_event;
+
+InputEventCircularReader::InputEventCircularReader(size_t numEvents)
+ : mBuffer(new input_event[numEvents * 2]),
+ mBufferEnd(mBuffer + numEvents),
+ mHead(mBuffer),
+ mCurr(mBuffer),
+ mFreeSpace(numEvents)
+{
+}
+
+InputEventCircularReader::~InputEventCircularReader()
+{
+ delete [] mBuffer;
+}
+
+ssize_t InputEventCircularReader::fill(int fd)
+{
+ size_t numEventsRead = 0;
+ if (mFreeSpace) {
+ const ssize_t nread = read(fd, mHead, mFreeSpace * sizeof(input_event));
+ 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) {
+ size_t s = mHead - mBufferEnd;
+ memcpy(mBuffer, mBufferEnd, s * sizeof(input_event));
+ mHead = mBuffer + s;
+ }
+ }
+ }
+
+ return numEventsRead;
+}
+
+ssize_t InputEventCircularReader::readEvent(input_event const** events)
+{
+ *events = mCurr;
+ ssize_t available = (mBufferEnd - mBuffer) - mFreeSpace;
+ return available ? 1 : 0;
+}
+
+void InputEventCircularReader::next()
+{
+ mCurr++;
+ mFreeSpace++;
+ if (mCurr >= mBufferEnd) {
+ mCurr = mBuffer;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Linearacceleration.cpp b/src/navigation/sensor/sensor_hal/src/Linearacceleration.cpp
new file mode 100644
index 0000000..e9f4c51
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Linearacceleration.cpp
@@ -0,0 +1,318 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "Linearacceleration.h"
+#undef LOG_TAG
+#define LOG_TAG "La"
+
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+LinearaccelSensor::LinearaccelSensor()
+ : SensorBase(NULL, "m_la_input"),//LA_INPUTDEV_NAME
+ mEnabled(0),
+ mOrientationEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_LINEAR_ACCELERATION;
+ mPendingEvent.type = SENSOR_TYPE_LINEAR_ACCELERATION;
+ mPendingEvent.acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_la_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ //ALOGD("la misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_la_misc/laactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf)-1);
+ if(len <= 0) {
+ ALOGD("read div err buf(%s)", buf);
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d", mDataDiv);
+ }
+ close(fd);
+ } else {
+ ALOGE("open linearacceleration misc path %s fail ", datapath);
+ }
+}
+
+LinearaccelSensor::~LinearaccelSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int LinearaccelSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ char devnum_dir[] = "/sys/class/misc/m_la_misc/ladevnum";
+ char buf_s[64] = {0};
+ int len;
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read devnum err buf(%s)", buf);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ //if (fd < 0)
+ // ALOGE( "couldn't find input device");
+ return fd;
+}
+int LinearaccelSensor::enableNoHALDataAcc(int en)
+{
+ int fd;
+ //ALOGD("LA enable nodata en(%d) \r\n",en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "laenablenodata");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ //ALOGD("no LA enable nodata control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if(1==en)
+ {
+ buf[0] = '1';
+ }
+ if(0==en)
+ {
+ buf[0] = '0';
+ }
+
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ //ALOGD("LA enable nodata done");
+ return 0;
+}
+
+int LinearaccelSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ //ALOGD("LA enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "laactive");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ //ALOGD("no LA enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ //ALOGD("LA enable(%d) done", mEnabled );
+ return 0;
+}
+int LinearaccelSensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd;
+ //uint32_t ms=0;
+ //ALOGD("setDelay: (handle=%d, ns=%d)",handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "ladelay");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ //ALOGD("no LA setDelay control attr \r\n" );
+ return -1;
+ }
+ //ms = ns/1000000;
+
+ char buf[80];
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+
+int LinearaccelSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd;
+ int flag;
+
+ ////ALOGE("LA batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ //Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "labatch");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ //ALOGD("no LA batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ //ALOGD("LA batch(%d) done", flag );
+ return 0;
+
+}
+
+int LinearaccelSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int LinearaccelSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ // ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (numEventReceived < count && 0 < mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ // ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ // ALOGE("fwq3....\r\n");
+ int64_t time = timevalToNano(event->time);
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+
+ }
+ }
+ else// if (type != EV_ABS)
+ {
+ //ALOGE("LinearaccelSensor: unknown event (type=%d, code=%d)", type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void LinearaccelSensor::processEvent(int code, int value)
+{
+ //ALOGD("lael, processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_LA_STATUS:
+ mPendingEvent.acceleration.status = value;
+ //ALOGE("LinearaccelSensor: EVENT_TYPE_LA_STATUS");
+ break;
+ case EVENT_TYPE_LA_X:
+ mPendingEvent.acceleration.x = (float)value / mDataDiv ;
+ //ALOGE("LinearaccelSensor: EVENT_TYPE_LA_X");
+ break;
+ case EVENT_TYPE_LA_Y:
+ mPendingEvent.acceleration.y = (float)value / mDataDiv;
+ //ALOGE("LinearaccelSensor: EVENT_TYPE_LA_Y");
+ break;
+ case EVENT_TYPE_LA_Z:
+ mPendingEvent.acceleration.z = (float)value / mDataDiv;
+ //ALOGE("LinearaccelSensor: EVENT_TYPE_LA_Z");
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Magnetic.cpp b/src/navigation/sensor/sensor_hal/src/Magnetic.cpp
new file mode 100644
index 0000000..9310a62
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Magnetic.cpp
@@ -0,0 +1,495 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "Magnetic.h"
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "Magnetic"
+#endif
+
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+MagneticSensor::MagneticSensor()
+ : SensorBase(NULL, "m_mag_input"),
+ mEnabled(0),
+ mOrientationEnabled(0),
+ mInputReader(32),
+ mPendingMask(0)
+{
+ input_sysfs_path_len = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+ mPendingEvent[0].version = sizeof(sensors_event_t);
+ mPendingEvent[0].sensor = ID_MAGNETIC;
+ mPendingEvent[0].type = SENSOR_TYPE_MAGNETIC_FIELD;
+ mPendingEvent[0].magnetic.status = SENSOR_STATUS_ACCURACY_HIGH;
+ memset(mPendingEvent[0].data, 0x00, sizeof(mPendingEvent[0].data));
+
+ mPendingEvent[1].version = sizeof(sensors_event_t);
+ mPendingEvent[1].sensor = ID_ORIENTATION;
+ mPendingEvent[1].type = SENSOR_TYPE_ORIENTATION;
+ mPendingEvent[1].magnetic.status = SENSOR_STATUS_ACCURACY_HIGH;
+ memset(mPendingEvent[1].data, 0x00, sizeof(mPendingEvent[1].data));
+
+ mDataDiv_M = 1;
+ mDataDiv_O = 1;
+ mAllInputDataCompleteFlag[MagneticField] = 0;
+ mAllInputDataCompleteFlag[Orientation] = 0;
+ mEnabledTime[MagneticField] = 0;
+ mEnabledTime[Orientation] = 0;
+ mMagSensorDebug = NULL;
+ char datapath1[64]={"/sys/class/misc/m_mag_misc/magactive"};
+ int fd_m = -1;
+ char buf_m[64]={0};
+ int len_m;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_mag_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ else
+ {
+ ALOGE("couldn't find input device magnetic");
+ return;
+ }
+ ALOGD("mag misc path =%s", input_sysfs_path);
+
+ fd_m = open(datapath1, O_RDWR);
+ if (fd_m >= 0)
+ {
+ len_m = read(fd_m,buf_m,sizeof(buf_m)-1);
+ if (len_m <= 0)
+ {
+ ALOGD("read div err, len_m = %d", len_m);
+ }
+ else
+ {
+ buf_m[len_m] = '\0';
+ sscanf(buf_m, "%d", &mDataDiv_M);
+ ALOGD("read div buf(%s), mdiv_M %d",datapath1,mDataDiv_M);
+ }
+ close(fd_m);
+ }
+ else
+ {
+ ALOGE("open mag misc path %s fail ", datapath1);
+ }
+
+ char datapath2[64]={"/sys/class/misc/m_mag_misc/magoactive"};
+ int fd_o = open(datapath2, O_RDWR);
+ char buf_o[64]={0};
+ int len_o=0;
+ if (fd_o >= 0)
+ {
+ len_o = read(fd_o,buf_o,sizeof(buf_o)-1);
+ if (len_o <= 0)
+ {
+ ALOGD("read div err, len_o = %d", len_o);
+ }
+ else
+ {
+ buf_o[len_o] = '\0';
+ sscanf(buf_o, "%d", &mDataDiv_O);
+ ALOGD("read div buf(%s), mdiv_O %d",datapath2,mDataDiv_O);
+ }
+ close(fd_o);
+ }
+ else
+ {
+ ALOGE("open mag_o misc path %s fail ", datapath2);
+ }
+
+ //{@input value 2 stands for MagneticField sensor,please refer to nusensor.cpp
+ //enmu in sensors_poll_context_t to see other sensors,this is for sensor debug log
+ //mMagSensorDebug = new SensorDebugObject((SensorBase*)this, 2);
+ //@}
+
+}
+
+MagneticSensor::~MagneticSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int MagneticSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_mag_misc/magdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int MagneticSensor::write_attr(char* path, char* buf,int len)
+{
+ int fd=0;
+ int err=0;
+ ALOGD("fwq write attr path %s \n",path );
+ fd = open(path, O_RDWR);
+ if (fd >= 0)
+ {
+ write(fd, buf, len);
+ close(fd);
+ }
+ else
+ {
+ err =-1;
+ ALOGD("fwq write attr %s fail \n",path );
+ }
+
+ return err;
+
+}
+int MagneticSensor::enable(int32_t handle, int en)
+{
+ int fd=-1;
+ int flags = en ? 1 : 0;
+ int err=0;
+ char buf[2]={0};
+ int index=0;
+ ALOGD("fwq enable: handle:%d, en:%d \r\n",handle,en);
+ if(ID_ORIENTATION == handle)
+ {
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "magoactive");
+ index = Orientation;
+ }
+ if(ID_MAGNETIC== handle)
+ {
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "magactive");
+ index = MagneticField;
+ }
+ ALOGD("handle(%d),path:%s \r\n",handle,input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no magntic enable attr \r\n");
+ return -1;
+ }
+
+ if(0== en )
+ {
+ mEnabled &= ~(1<<index);
+ buf[1] = 0;
+ buf[0] = '0';
+ }
+
+ if(1== en)
+ {
+ mEnabledTime[index] = getTimestamp() + IGNORE_EVENT_TIME;
+ mEnabled |= (1<<index);
+ buf[1] = 0;
+ buf[0] = '1';
+ }
+
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("mag(%d) mEnabled(0x%x) ----\r\n",handle,mEnabled);
+ return 0;
+}
+int MagneticSensor::setDelay(int32_t handle, int64_t ns)
+{
+ //uint32_t ms=0;
+ //ms = ns/1000000;
+ int err;
+ int fd;
+ if(ID_ORIENTATION == handle)
+ {
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "magodelay");
+ }
+ if(ID_MAGNETIC == handle)
+ {
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "magdelay");
+ }
+
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no MAG setDelay control attr\r\n" );
+ return -1;
+ }
+
+ ALOGD("setDelay: (handle=%d, ms=%lld)",handle , ns);
+ char buf[80]={0};
+ sprintf(buf, "%lld", (long long int)ns);
+ write(fd, buf, strlen(buf)+1);
+
+ close(fd);
+
+ ALOGD("really setDelay: (handle=%d, ns=%lld)",handle , ns);
+ return 0;
+
+}
+int MagneticSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd=-1;
+ int flag=0;
+ int err=0;
+ char buf[2]={0};
+ int index=0;
+
+ ALOGE("Mag batch: handle:%d, en:%d, samplingPeriodNs:%lld,maxBatchReportLatencyNs:%lld \r\n",handle, flags, samplingPeriodNs,maxBatchReportLatencyNs);
+
+ //Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ if(ID_ORIENTATION == handle)
+ {
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "magobatch");
+ index = Orientation;
+ }
+ if(ID_MAGNETIC== handle)
+ {
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "magbatch");
+ index = MagneticField;
+ }
+ ALOGD("handle(%d),path:%s \r\n",handle,input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no magntic enable attr \r\n");
+ return -1;
+ }
+
+ if(0 == flag )
+ {
+ buf[1] = 0;
+ buf[0] = '0';
+ }
+
+ if(1 == flag)
+ {
+ buf[1] = 0;
+ buf[0] = '1';
+ }
+
+ write(fd, buf, sizeof(buf));
+ close(fd);
+ return 0;
+
+}
+
+int MagneticSensor::flush(int handle)
+{
+ ALOGD("handle=%d\n",handle);
+ return -errno;
+}
+int MagneticSensor::readEvents(sensors_event_t* data, int count)
+{
+ if (count < 1)
+ {
+ return -EINVAL;
+ }
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ {
+ return n;
+ }
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ if (type == EV_ABS || type == EV_REL) {
+ processEvent(type, event->code, event->value);
+ mInputReader.next();
+ } else if (type == EV_SYN) {
+
+ int64_t time = getTimestamp();
+ //ALOGE("fwqM1....\r\n");
+ for (int j=0 ; count && mPendingMask && j<numSensors ; j++)
+ {
+ //ALOGE("fwqM2....\r\n");
+ if (mPendingMask & (1<<j))
+ {
+ if (mAllInputDataCompleteFlag[j] == all_complete) {
+ mAllInputDataCompleteFlag[j] = restart;
+ if (mPendingEvent[j].timestamp > mEnabledTime[j]) {
+ *data++ = mPendingEvent[j];
+ numEventReceived++;
+ mPendingEvent[j].timestamp = 0;
+ count--;
+ }
+ } else {
+ ALOGE("magnetic dropped data due to mAllInputDataCompleteFlag(%d) is not all_complete\n",
+ mAllInputDataCompleteFlag);
+ }
+ }
+ }
+ if (!mPendingMask) {
+ mInputReader.next();
+ }
+ } else {
+ ALOGE("unknown event (type=%d, code=%d)", type, event->code);
+ mInputReader.next();
+ }
+ }
+
+ //{@input value 2 stands for MagneticField sensor,please refer to nusensor.cpp enmu in sensors_poll_context_t to see other sensors
+ //mMagSensorDebug->send_singnal(2);
+ //@}
+ return numEventReceived;
+}
+
+void MagneticSensor::processEvent(int type, int code, int value)
+{
+ //ALOGD("processEvent code=%d,value=%d\r\n",code, value);a
+ if (EV_ABS == type)
+ {
+ switch (code) {
+ case EVENT_TYPE_MAG_STATUS:
+ mPendingMask |= 1<<MagneticField;
+ mPendingEvent[MagneticField].magnetic.status = value;
+ mAllInputDataCompleteFlag[MagneticField] = status;
+ break;
+ case EVENT_TYPE_MAG_X:
+ mPendingMask |= 1<<MagneticField;
+ mPendingEvent[MagneticField].magnetic.x = (float)value / (float)mDataDiv_M;
+ mAllInputDataCompleteFlag[MagneticField] = x;
+ break;
+ case EVENT_TYPE_MAG_Y:
+ mPendingMask |= 1<<MagneticField;
+ mPendingEvent[MagneticField].magnetic.y = (float)value / (float)mDataDiv_M;
+ mAllInputDataCompleteFlag[MagneticField] = y;
+ break;
+ case EVENT_TYPE_MAG_Z:
+ mPendingMask |= 1<<MagneticField;
+ mPendingEvent[MagneticField].magnetic.z = (float)value / (float)mDataDiv_M;
+ mAllInputDataCompleteFlag[MagneticField] = z;
+ break;
+ //for osensor
+ case EVENT_TYPE_ORIENT_STATUS:
+ mPendingMask |= 1<<Orientation;
+ mPendingEvent[Orientation].orientation.status = value;
+ mAllInputDataCompleteFlag[Orientation] = status;
+ break;
+ case EVENT_TYPE_ORIENT_X:
+ mPendingMask |= 1<<Orientation;
+ mPendingEvent[Orientation].orientation.x = (float)value / (float)mDataDiv_O;
+ mAllInputDataCompleteFlag[Orientation] = x;
+ break;
+ case EVENT_TYPE_ORIENT_Y:
+ mPendingMask |= 1<<Orientation;
+ mPendingEvent[Orientation].orientation.y = (float)value / (float)mDataDiv_O;
+ mAllInputDataCompleteFlag[Orientation] = y;
+ break;
+ case EVENT_TYPE_ORIENT_Z:
+ mPendingMask |= 1<<Orientation;
+ mPendingEvent[Orientation].orientation.z = (float)value / (float)mDataDiv_O;
+ mAllInputDataCompleteFlag[Orientation] = z;
+ break;
+ }
+ }
+ else if (EV_REL == type)
+ {
+ switch (code) {
+ case EVENT_TYPE_MAG_UPDATE:
+ mPendingMask |= 1<<MagneticField;
+ break;
+ case EVENT_TYPE_MAG_TIMESTAMP_HI:
+ mPendingEvent[MagneticField].timestamp =
+ (mPendingEvent[MagneticField].timestamp & 0xFFFFFFFFLL) | ((int64_t)value << 32);
+ mAllInputDataCompleteFlag[MagneticField] = hi;
+ break;
+ case EVENT_TYPE_MAG_TIMESTAMP_LO:
+ mPendingEvent[MagneticField].timestamp =
+ (mPendingEvent[MagneticField].timestamp & 0xFFFFFFFF00000000LL) | ((int64_t)value & 0xFFFFFFFFLL);
+ mAllInputDataCompleteFlag[MagneticField] = lo;
+ break;
+ case EVENT_TYPE_ORIENT_UPDATE:
+ mPendingMask |= 1<<Orientation;
+ break;
+ case EVENT_TYPE_ORIENT_TIMESTAMP_HI:
+ mPendingEvent[Orientation].timestamp =
+ (mPendingEvent[Orientation].timestamp & 0xFFFFFFFFLL) | ((int64_t)value << 32);
+ mAllInputDataCompleteFlag[Orientation] = hi;
+ break;
+ case EVENT_TYPE_ORIENT_TIMESTAMP_LO:
+ mPendingEvent[Orientation].timestamp =
+ (mPendingEvent[Orientation].timestamp & 0xFFFFFFFF00000000LL) | ((int64_t)value & 0xFFFFFFFFLL);
+ mAllInputDataCompleteFlag[Orientation] = lo;
+ break;
+ default:
+ ALOGE("AccelerationSensor: unknown event (type=%d, code=%d)", type, code);
+ break;
+ }
+ }
+}
+
diff --git a/src/navigation/sensor/sensor_hal/src/Pdr.cpp b/src/navigation/sensor/sensor_hal/src/Pdr.cpp
new file mode 100644
index 0000000..52884d0
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Pdr.cpp
@@ -0,0 +1,273 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "Pdr.h"
+
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "PDR"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+PdrSensor::PdrSensor()
+ : SensorBase(NULL, "m_pdr_input"), // PDR_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_PDR;
+ mPendingEvent.type = SENSOR_TYPE_PDR;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_pdr_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ else
+ {
+ ALOGE(">> pdr couldn't find input device pdr");
+ return;
+ }
+
+ char datapath[64]={"/sys/class/misc/m_pdr_misc/pdractive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if(len<=0)
+ {
+ ALOGD("read div err buf(%s)",buf );
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ // ALOGD("read div buf(%s)", datapath);
+ // ALOGD("mdiv %d",mDataDiv );
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open pdr misc path %s fail ", datapath);
+ }
+}
+
+PdrSensor::~PdrSensor() {
+if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+int PdrSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_pdr_misc/pdrdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0){
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0){
+ ALOGD("read devnum err buf(%s)", buf);
+ return -1;
+ }
+ else{
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ ALOGD("len = %d, buf = %s",len, buf);
+ }
+ }
+ else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int PdrSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "pdractive");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0){
+ ALOGD("no Pdr enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags){
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else{
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("Pdr enable(%d) done", mEnabled );
+ return 0;
+}
+
+int PdrSensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd;
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "pdrdelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0){
+ ALOGD("no PDR setDelay control attr \r\n" );
+ return -1;
+ }
+ char buf[80];
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+
+int PdrSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd;
+ int flag;
+
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }
+ else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "pdrbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0){
+ ALOGD("no pdr batch control attr\r\n");
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag) {
+ buf[0] = '1';
+ }
+ else{
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("PDR batch(%d) done", flag);
+ return 0;
+}
+
+int PdrSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int PdrSensor::readEvents(sensors_event_t* data, int count)
+{
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ if ((type == EV_ABS) || (type == EV_REL)){
+ processEvent(event->code, event->value);
+ }
+ else if (type == EV_SYN){
+ int64_t time = getTimestamp();
+ mPendingEvent.timestamp = time;
+ if (mEnabled){
+ if (mPendingEvent.timestamp >= mEnabledTime){
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+ }
+ }
+ else if (type != EV_REL){
+ ALOGD("PdrSensor: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ return numEventReceived;
+}
+
+void PdrSensor::processEvent(int code, int value)
+{
+ switch (code) {
+ case EVENT_TYPE_PDR_X:
+ mPendingEvent.data[0] = (float) value;//axis x
+ break;
+ case EVENT_TYPE_PDR_Y:
+ mPendingEvent.data[1] = (float) value;//axis y
+ break;
+ case EVENT_TYPE_PDR_Z:
+ mPendingEvent.data[2] = (float) value;//axis z
+ break;
+ case EVENT_TYPE_PDR_SCALAR:
+ mPendingEvent.data[3] = (float) value;//scalar
+ break;
+ case EVENT_TYPE_PDR_STATUS:
+ mPendingEvent.data[4] = (float) value;//status
+ break;
+ default:
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Pedometer.cpp b/src/navigation/sensor/sensor_hal/src/Pedometer.cpp
new file mode 100644
index 0000000..5630626
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Pedometer.cpp
@@ -0,0 +1,291 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "Pedometer.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "PEDO"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+PedometerSensor::PedometerSensor()
+ : SensorBase(NULL, "m_pedo_input"), // PEDO_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_PEDOMETER;
+ mPendingEvent.type = SENSOR_TYPE_PEDOMETER;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_pedo_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ ALOGD("pedo misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_pedo_misc/pedoactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if(len<=0)
+ {
+ ALOGD("read div err buf(%s)",buf );
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d",mDataDiv );
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open pedo misc path %s fail ", datapath);
+ }
+}
+
+PedometerSensor::~PedometerSensor() {
+if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+int PedometerSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_pedo_misc/pedodevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err buf(%s)", buf);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ ALOGE("len = %d, buf = %s",len, buf);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int PedometerSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ ALOGD("Pdr enable: handle:%d, en:%d \r\n",handle, en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "pedoactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no Pdr enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("Pdr enable(%d) done", mEnabled );
+ return 0;
+
+}
+
+int PedometerSensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd;
+ ALOGD("setDelay: (handle=%d, ns=%lld)", handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "pedodelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no PDR setDelay control attr \r\n" );
+ return -1;
+ }
+ char buf[80];
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+
+int PedometerSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd;
+ int flag;
+
+ ALOGE("PDR batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "pedobatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no pedo batch control attr\r\n");
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("PDR batch(%d) done", flag );
+ return 0;
+}
+
+int PedometerSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int PedometerSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+
+ }
+ }
+ else if (type != EV_REL)
+ {
+ ALOGE("PedometerSensor: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void PedometerSensor::processEvent(int code, int value)
+{
+ ALOGD("PedometerSensor::processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_PEDO_LENGTH:
+ mPendingEvent.data[0] = (float) value/1000; //change from milli-meter to meter
+ break;
+ case EVENT_TYPE_PEDO_FREQUENCY:
+ mPendingEvent.data[1] = (float) value/1024; //frequency div SHIFT_VALUE (define in SCP)
+ break;
+ case EVENT_TYPE_PEDO_COUNT:
+ mPendingEvent.data[2] = value;
+ break;
+ case EVENT_TYPE_PEDO_DISTANCE:
+ mPendingEvent.data[3] = (float) value/1000; //change from milli-meter to meter
+ break;
+ }
+
+}
diff --git a/src/navigation/sensor/sensor_hal/src/PickUp.cpp b/src/navigation/sensor/sensor_hal/src/PickUp.cpp
new file mode 100644
index 0000000..10a52ae
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/PickUp.cpp
@@ -0,0 +1,275 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include "PickUp.h"
+#include <string.h>
+
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "PICK_UP"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+PickUpSensor::PickUpSensor()
+ : SensorBase(NULL, "m_pkup_input"),//_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ memset(input_sysfs_path, 0, PATH_MAX);
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_PICK_UP_GESTURE;
+ mPendingEvent.type = SENSOR_TYPE_PICK_UP_GESTURE;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_pkup_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ ALOGD("PickUp misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_pkup_misc/pkupactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if(len<=0)
+ {
+ ALOGD("read div err buf(%s)",buf );
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d",mDataDiv );
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open pkup misc path %s fail ", datapath);
+ }
+}
+
+PickUpSensor::~PickUpSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int PickUpSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_pkup_misc/pkupdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err buf(%s)", buf);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ ALOGE("len = %d, buf = %s",len, buf);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int PickUpSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ ALOGD("pkup enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "pkupactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no pkup enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+ ALOGD("pkup enable(%d) done", mEnabled );
+ return 0;
+}
+int PickUpSensor::setDelay(int32_t handle, int64_t ns)
+{
+ //int fd;
+
+ ALOGD("setDelay: regardless of the setDelay() value (handle=%d, ns=%lld)", handle, ns);
+
+ return 0;
+
+}
+int PickUpSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int flag;
+ int fd;
+
+ ALOGE("pkup batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "pkupbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no pkup batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("pkup batch(%d) done", flag );
+ return 0;
+
+}
+
+int PickUpSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int PickUpSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ if(mPendingEvent.sensor == ID_PICK_UP_GESTURE)
+ enable(ID_PICK_UP_GESTURE, false);
+ }
+ count--;
+
+ }
+ }
+ else
+ {
+ ALOGE("pkup: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void PickUpSensor::processEvent(int code, int value)
+{
+ ALOGD("PickUpSensor::processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_PKUP_VALUE:
+ mPendingEvent.data[0] = (float) value;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Pressure.cpp b/src/navigation/sensor/sensor_hal/src/Pressure.cpp
new file mode 100644
index 0000000..f2865df
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Pressure.cpp
@@ -0,0 +1,347 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "Pressure.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "PRESSURE"
+#endif
+
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+PressureSensor::PressureSensor()
+ : SensorBase(NULL, "m_baro_input"),//PRESSURE_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_PRESSURE;
+ mPendingEvent.type = SENSOR_TYPE_PRESSURE;
+ mPendingEvent.acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime = 0;
+ mDataDiv = 1;
+ mTempDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ mAllInputDataCompleteFlag = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_baro_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ else
+ {
+ ALOGE("couldn't find input device pressure");
+ return;
+ }
+ ALOGD("pressure misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_baro_misc/baroactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64]={0};
+ int len;
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if (len <= 0)
+ {
+ ALOGD("read div err, len = %d", len);
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d %d", &mDataDiv, &mTempDiv);
+ ALOGD("read div buf(%s), mdiv %d, tdiv %d", datapath, mDataDiv, mTempDiv);
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open baro misc path %s fail ", datapath);
+ }
+}
+
+PressureSensor::~PressureSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int PressureSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_baro_misc/barodevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find pressure input device: %s \n", buf_s);
+ return fd;
+}
+
+int PressureSensor::enable(int32_t handle, int en)
+{
+ int fd= -1;
+ int flags = en ? 1 : 0;
+
+ ALOGD("PRESS enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "baroactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no PRESS enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("PRESS enable(%d) done", mEnabled );
+ return 0;
+}
+int PressureSensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd=-1;
+
+ ALOGD("setDelay: (handle=%d, ns=%lld)",handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "barodelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no PRESS setDelay control attr \r\n" );
+ return -1;
+ }
+
+ char buf[80]={0};
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+int PressureSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int flag=0;
+ int fd=-1;
+
+ ALOGE("PRESS batch: handle:%d, en:%d,samplingPeriodNs:%lld, maxBatchReportLatencyNs:%lld \r\n",handle, flags,samplingPeriodNs, maxBatchReportLatencyNs);
+
+ //Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "barobatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no PRESS batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("PRESS batch(%d) done", flag );
+ return 0;
+
+}
+
+int PressureSensor::flush(int handle)
+{
+ ALOGD("handle=%d\n",handle);
+ return -errno;
+}
+
+int PressureSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(type, event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+ if (mEnabled)
+ {
+ if (time >= mEnabledTime)
+ {
+ if (mAllInputDataCompleteFlag == all_complete) {
+ //Assign timestamp if kernel is not assigned.
+ if (0 == mPendingEvent.timestamp)
+ mPendingEvent.timestamp = time;
+ if (mPendingEvent.timestamp > mEnabledTime) {
+ //ALOGD("pres[%6f, %6f][%lld]\n",
+ // mPendingEvent.pressure.data, mPendingEvent.pressure.temperature,
+ // mPendingEvent.timestamp);
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ mPendingEvent.timestamp = 0;
+ count--;
+ }
+ }
+ }
+ mAllInputDataCompleteFlag = restart;
+ }
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void PressureSensor::processEvent(int type, int code, int value)
+{
+ //ALOGD("PprocessEvent code=%d,value=%d\r\n",code, value);
+ if (EV_ABS == type) {
+ switch (code) {
+ case EVENT_TYPE_BARO_VALUE:
+ mPendingEvent.pressure.data = (float) value / mDataDiv;
+ mAllInputDataCompleteFlag = val;
+ break;
+ case EVENT_TYPE_BARO_VALUE_T:
+ mPendingEvent.pressure.temperature = (float) value / mTempDiv;
+ break;
+ case EVENT_TYPE_BARO_STATUS:
+ mPendingEvent.pressure.status = value;
+ mAllInputDataCompleteFlag = status;
+ //ALOGE("PressureSensor: no need (type=%d, code=%d)", type, code);
+ break;
+ default:
+ //ALOGE("PressureSensor: unknown event (type=%d, code=%d)", type, code);
+ break;
+ }
+ } else if (EV_REL == type) {
+ switch (code) {
+ case EVENT_TYPE_BARO_TIMESTAMP_HI:
+ mPendingEvent.timestamp = (mPendingEvent.timestamp & 0xFFFFFFFFLL) | ((int64_t)value << 32);
+ mAllInputDataCompleteFlag = hi;
+ break;
+ case EVENT_TYPE_BARO_TIMESTAMP_LO:
+ mPendingEvent.timestamp = (mPendingEvent.timestamp & 0xFFFFFFFF00000000LL) |
+ ((int64_t)value & 0xFFFFFFFFLL);
+ if (mAllInputDataCompleteFlag = hi)
+ mAllInputDataCompleteFlag = lo;
+ break;
+ default:
+ //ALOGE("PressureSensor: unknown event (type=%d, code=%d)", type, code);
+ break;
+ }
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Proximity.cpp b/src/navigation/sensor/sensor_hal/src/Proximity.cpp
new file mode 100644
index 0000000..53bc7bd
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Proximity.cpp
@@ -0,0 +1,311 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include "Proximity.h"
+
+#include <string.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "PROXIMITY"
+#endif
+
+
+#define IGNORE_EVENT_TIME 0//350000000
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+ProximitySensor::ProximitySensor()
+ : SensorBase(NULL, "m_alsps_input"),//PRO_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_PROXIMITY;
+ mPendingEvent.type = SENSOR_TYPE_PROXIMITY;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp = 0;
+ mPendingEvent.distance = -1; //initialize p sensor value to invalid.
+ input_sysfs_path_len = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+ char datapath[64]={"/sys/class/misc/m_alsps_misc/psactive"};
+ int fd = -1;
+ char buf[64]={0};
+ int len;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_alsps_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ else
+ {
+ ALOGE("couldn't find input device proximity");
+ return;
+ }
+ ALOGD("prox misc path =%s", input_sysfs_path);
+
+ fd = open(datapath, O_RDWR);
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if (len <= 0)
+ {
+ ALOGD("read div err, len = %d", len);
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s), mdiv %d", datapath,mDataDiv);
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open Proximity misc path %s fail ", datapath);
+ }
+}
+
+ProximitySensor::~ProximitySensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+
+}
+int ProximitySensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_alsps_misc/psdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int ProximitySensor::enable(int32_t handle, int en)
+{
+ int fd=-1;
+ int flags = en ? 1 : 0;
+
+ ALOGD("PS enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "psactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no PS enable control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ mPendingEvent.distance = -1; //reset p sensor value to invalid.
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ mEnabled = flags; //assign enable after reset p sensor value.
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("PS enable(%d) done", mEnabled );
+ return 0;
+
+}
+int ProximitySensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd=-1;
+ ALOGD("setDelay: (handle=%d, ns=%lld)",handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "psdelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no PS setDelay control attr \r\n" );
+ return -1;
+ }
+
+ char buf[80]={0};
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+int ProximitySensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd=-1;
+ int flag=0;
+
+ ALOGE("PS batch: handle:%d, en:%d,samplingPeriodNs:%lld, maxBatchReportLatencyNs:%lld \r\n",handle, flags,samplingPeriodNs, maxBatchReportLatencyNs);
+
+ //Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "psbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no PS batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("PS batch(%d) done", flag );
+ return 0;
+}
+
+int ProximitySensor::flush(int handle)
+{
+ ALOGD("handle=%d\n",handle);
+ return -errno;
+}
+
+int ProximitySensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+ mPendingEvent.timestamp = time;
+ if (mEnabled && mPendingEvent.distance >= 0)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+ mPendingEvent.distance = -1;
+ }
+ }else if (type != EV_REL) {
+ ALOGE("ProximitySensor: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void ProximitySensor::processEvent(int code, int value)
+{
+ //ALOGD("processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_PS_VALUE:
+ mPendingEvent.distance= value-1;
+ break;
+ }
+
+}
diff --git a/src/navigation/sensor/sensor_hal/src/RotationVector.cpp b/src/navigation/sensor/sensor_hal/src/RotationVector.cpp
new file mode 100644
index 0000000..9f733cd
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/RotationVector.cpp
@@ -0,0 +1,284 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+
+#include "RotationVector.h"
+#undef LOG_TAG
+#define LOG_TAG "RV"
+
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+RotationVectorSensor::RotationVectorSensor()
+ : SensorBase(NULL, "m_rv_input"),//RV_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_ROTATION_VECTOR;
+ mPendingEvent.type = SENSOR_TYPE_ROTATION_VECTOR;
+ mPendingEvent.acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_rv_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ //ALOGD("rv misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_rv_misc/rvactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf)-1);
+ if (len <= 0) {
+ ALOGD("read div err buf(%s)", buf);
+ } else {
+ buf[len] = '\0';
+ ALOGE("len = %d, buf = %s", len, buf);
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d", mDataDiv);
+ }
+ close(fd);
+ } else {
+ ALOGE("open RotationV misc path %s fail", datapath);
+ }
+}
+
+RotationVectorSensor::~RotationVectorSensor() {
+if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+int RotationVectorSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ char devnum_dir[] = "/sys/class/misc/m_rv_misc/rvdevnum";
+ char buf_s[64] = {0};
+ int len;
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len < 0) {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ //if (fd < 0)
+ // ALOGE("couldn't find input device");
+ return fd;
+}
+
+int RotationVectorSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ //ALOGD("RV enable: handle:%d, en:%d \r\n",handle, en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "rvactive");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ //ALOGD("no RV enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ //ALOGD("RV enable(%d) done", mEnabled );
+ return 0;
+
+}
+
+int RotationVectorSensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd;
+ //ALOGD("setDelay: (handle=%d, ns=%d)",handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "rvdelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ //ALOGD("no RV setDelay control attr \r\n" );
+ return -1;
+ }
+ char buf[80];
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+
+int RotationVectorSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd;
+ int flag;
+
+ //ALOGE("RV batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "rvbatch");
+ //ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ //ALOGD("no rv batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ //ALOGD("RV batch(%d) done", flag );
+ return 0;
+}
+
+int RotationVectorSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int RotationVectorSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ ////ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = timevalToNano(event->time);
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+
+ }
+ }
+ else// if (type != EV_ABS)
+ {
+ //ALOGE("RotationVectorSensor: unknown event (type=%d, code=%d)", type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void RotationVectorSensor::processEvent(int code, int value)
+{
+ ////ALOGD("processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_RV_STATUS:
+ mPendingEvent.orientation.status = value;
+ break;
+ case EVENT_TYPE_RV_X:
+ mPendingEvent.data[0] = (float)value / mDataDiv ;
+ break;
+ case EVENT_TYPE_RV_Y:
+ mPendingEvent.data[1] = (float)value / mDataDiv;
+ break;
+ case EVENT_TYPE_RV_Z:
+ mPendingEvent.data[2] = (float)value / mDataDiv;
+ ////ALOGE("RVSensor: mDataDiv = %d", mDataDiv);
+ break;
+ case EVENT_TYPE_RV_SCALAR:
+ mPendingEvent.data[3] = (float)value / mDataDiv;
+ ////ALOGE("RVSensor: mDataDiv = %d", mDataDiv);
+ break;
+ }
+
+}
diff --git a/src/navigation/sensor/sensor_hal/src/SensorBase.cpp b/src/navigation/sensor/sensor_hal/src/SensorBase.cpp
new file mode 100644
index 0000000..692291c
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/SensorBase.cpp
@@ -0,0 +1,159 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+
+#include <sys/select.h>
+#include <linux/input.h>
+
+#include "SensorBase.h"
+#include <string.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "SensorBase"
+#endif
+
+
+/*****************************************************************************/
+
+SensorBase::SensorBase(
+ const char* dev_name,
+ const char* data_name)
+ : dev_name(dev_name), data_name(data_name),
+ dev_fd(-1), data_fd(-1)
+{
+ //data_fd = openInput(data_name);
+}
+
+SensorBase::~SensorBase() {
+ if (data_fd >= 0) {
+ close(data_fd);
+ }
+ if (dev_fd >= 0) {
+ close(dev_fd);
+ }
+}
+
+int SensorBase::open_device() {
+ if (dev_fd<0 && dev_name) {
+ dev_fd = open(dev_name, O_RDONLY);
+ if(dev_fd < 0)
+ ALOGE("Couldn't open %s (%s)", dev_name, strerror(errno));
+ }
+ return 0;
+}
+
+int SensorBase::close_device() {
+ if (dev_fd >= 0) {
+ close(dev_fd);
+ dev_fd = -1;
+ }
+ return 0;
+}
+
+int SensorBase::getFd() const {
+ return data_fd;
+}
+
+int SensorBase::setDelay(int32_t handle, int64_t ns) {
+ ALOGD("handle=%d,ns=%lld\n",handle,ns);
+ return 0;
+}
+
+int SensorBase::getODR(int32_t handle, int *odr) {
+ ALOGD("getODR handle=%d\n",handle);
+ return 0;
+}
+
+bool SensorBase::hasPendingEvents() const {
+ return false;
+}
+
+int64_t SensorBase::getTimestamp() {
+ int64_t time_ns;
+ struct timespec tp;
+ int res;
+
+ res = clock_gettime(CLOCK_BOOTTIME, &tp);
+ time_ns = tp.tv_sec * 1000000000LL + tp.tv_nsec;
+
+ return time_ns;
+}
+/*
+int SensorBase::openInput(const char* inputName) {
+ int fd = -1;
+ const char *dirname = "/dev/input";
+ char devname[PATH_MAX];
+ char *filename;
+ DIR *dir;
+ struct dirent *de;
+ dir = opendir(dirname);
+ if(dir == NULL)
+ return -1;
+ strcpy(devname, dirname);
+ filename = devname + strlen(devname);
+ *filename++ = '/';
+ while((de = readdir(dir))) {
+ if(de->d_name[0] == '.' &&
+ (de->d_name[1] == '\0' ||
+ (de->d_name[1] == '.' && de->d_name[2] == '\0')))
+ continue;
+ strcpy(filename, de->d_name);
+ fd = open(devname, O_RDONLY);
+ if (fd>=0) {
+ char name[80];
+ if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
+ name[0] = '\0';
+ }
+ if (!strcmp(name, inputName)) {
+ break;
+ } else {
+ close(fd);
+ fd = -1;
+ }
+ }
+ }
+ closedir(dir);
+ if (fd < 0)
+ ALOGE( "couldn't find '%s' input device", inputName);
+ return fd;
+}
+*/
diff --git a/src/navigation/sensor/sensor_hal/src/Shake.cpp b/src/navigation/sensor/sensor_hal/src/Shake.cpp
new file mode 100644
index 0000000..ef9ed87
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Shake.cpp
@@ -0,0 +1,273 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "Shake.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "SHAKE"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+ShakeSensor::ShakeSensor()
+ : SensorBase(NULL, "m_shk_input"),//_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_SHAKE;
+ mPendingEvent.type = SENSOR_TYPE_SHAKE;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ //input_sysfs_path[PATH_MAX] = {0};
+ memset(input_sysfs_path, 0, sizeof(char)*PATH_MAX);
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_shk_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ ALOGD("Shake misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_shk_misc/shkactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if(len<=0)
+ {
+ ALOGD("read div err buf(%s)",buf );
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d",mDataDiv );
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open shk misc path %s fail ", datapath);
+ }
+}
+
+ShakeSensor::~ShakeSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int ShakeSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_shk_misc/shkdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err buf(%s)", buf);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ ALOGE("len = %d, buf = %s",len, buf);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int ShakeSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ ALOGD("shk enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "shkactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no shk enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+ ALOGD("shk enable(%d) done", mEnabled );
+ return 0;
+}
+int ShakeSensor::setDelay(int32_t handle, int64_t ns)
+{
+ //int fd;
+
+ ALOGD("setDelay: regardless of the setDelay() value (handle=%d, ns=%lld)", handle, ns);
+
+ return 0;
+
+}
+int ShakeSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int flag;
+ int fd;
+
+ ALOGE("shk batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "shkbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no shk batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("shk batch(%d) done", flag );
+ return 0;
+
+}
+
+int ShakeSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int ShakeSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+
+ }
+ }
+ else
+ {
+ ALOGE("shk: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void ShakeSensor::processEvent(int code, int value)
+{
+ ALOGD("ShakeSensor::processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_SHK_VALUE:
+ mPendingEvent.data[0] = (float) value;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/StepCounter.cpp b/src/navigation/sensor/sensor_hal/src/StepCounter.cpp
new file mode 100644
index 0000000..1b7f5f6
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/StepCounter.cpp
@@ -0,0 +1,308 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "StepCounter.h"
+#include <pthread.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "STEP_COUNTER"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+StepCounterSensor::StepCounterSensor()
+ : SensorBase(NULL, "m_step_c_input"),//_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_STEP_COUNTER;
+ mPendingEvent.type = SENSOR_TYPE_STEP_COUNTER;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.reserved0 =0;
+ mPendingEvent.timestamp =0;
+ mPendingEvent.flags =0;
+ input_sysfs_path_len = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+ pthread_mutex_init(&mSensorMutex, NULL);
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_step_c_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ ALOGD("StepCounter misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_step_c_misc/step_cactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if(len<=0)
+ {
+ ALOGD("read div err, len = %d", len);
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d",mDataDiv );
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open step_c misc path %s fail ", datapath);
+ }
+}
+
+StepCounterSensor::~StepCounterSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int StepCounterSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_step_c_misc/step_cdevnum";
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0)
+ {
+ ALOGD("read devnum err, len:%d\r\n", len);
+ return -1;
+ }
+ else
+ {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int StepCounterSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ ALOGD("step counter enable: handle:%d, en:%d \r\n",handle,en);
+ strncpy(&input_sysfs_path[input_sysfs_path_len], "step_cactive", input_sysfs_path_len);
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ pthread_mutex_lock(&mSensorMutex);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no step counter enable control attr\r\n" );
+ pthread_mutex_unlock(&mSensorMutex);
+ return -1;
+ }
+
+ //mEnabled = flags;
+ mEnabled = en ? mEnabled|(1<<handle) : mEnabled&(~(1<<handle)); //there are three sensors, separate the mEnabled bit.
+ char buf[120] = {0};
+ sprintf(buf, "%d,%d", handle, en);
+ ALOGD("step value:%s ,size: %d \r\n",buf, strlen(buf)+1);
+ write(fd, buf, strlen(buf)+1);
+ ALOGD("step write path:%s \r\n",input_sysfs_path);
+ close(fd);
+ pthread_mutex_unlock(&mSensorMutex);
+ /*
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+ */
+ ALOGD("step counter enable(%d) done", mEnabled );
+ return 0;
+}
+int StepCounterSensor::setDelay(int32_t handle, int64_t ns)
+{
+ //int fd;
+
+ ALOGD("setDelay: regardless of the setDelay() value (handle=%d, ns=%lld)",handle, ns);
+
+ return 0;
+
+}
+int StepCounterSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int flag;
+ int fd;
+ int en;
+
+ ALOGE("step counter batch: handle:%d, en:%d, samplingPeriodNs:%lld, maxBatchReportLatencyNs:%lld \r\n",handle, flags,samplingPeriodNs, maxBatchReportLatencyNs);
+
+ //Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "step_cbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no step counter batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[20];
+ if (flag)
+ {
+ en = 1;
+ }
+ else
+ {
+ en = 0;
+ }
+ sprintf(buf, "%d,%d", handle, en);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+
+ ALOGD("step counter batch(%d) done", flag );
+ return 0;
+
+}
+
+
+int StepCounterSensor::flush(int handle)
+{
+ ALOGD("handle=%d\n",handle);
+ return -errno;
+}
+
+
+int StepCounterSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ if(mPendingEvent.sensor == ID_SIGNIFICANT_MOTION)
+ enable(ID_SIGNIFICANT_MOTION, false); //one shot sensor need auto disable
+ }
+ count--;
+ }
+ }
+ else /*if (type != EV_ABS || type !=EV_REL)*/
+ {
+ ALOGE("step: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void StepCounterSensor::processEvent(int code, int value)
+{
+ //ALOGD("processEvent code=%d,value=%d\r\n",code, value);
+ //uint64_t stepcount=0;
+ switch (code) {
+ case EVENT_TYPE_STEP_COUNTER_VALUE:
+ mPendingEvent.sensor = ID_STEP_COUNTER;
+ mPendingEvent.type = SENSOR_TYPE_STEP_COUNTER;
+ mPendingEvent.u64.step_counter= value;
+ break;
+ case EVENT_TYPE_STEP_DETECTOR_VALUE:
+ mPendingEvent.sensor = ID_STEP_DETECTOR;
+ mPendingEvent.type = SENSOR_TYPE_STEP_DETECTOR;
+ mPendingEvent.data[0] = (float) value;
+ break;
+ case EVENT_TYPE_SIGNIFICANT_VALUE:
+ mPendingEvent.sensor = ID_SIGNIFICANT_MOTION;
+ mPendingEvent.type = SENSOR_TYPE_SIGNIFICANT_MOTION;
+ mPendingEvent.data[0] = (float) value;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Temperature.cpp b/src/navigation/sensor/sensor_hal/src/Temperature.cpp
new file mode 100644
index 0000000..e437297
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Temperature.cpp
@@ -0,0 +1,345 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "Temperature.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "TEMPERATURE"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+TemperatureSensor::TemperatureSensor()
+ : SensorBase(NULL, "m_temp_input"),
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_TEMPERATURE;
+ mPendingEvent.type = SENSOR_TYPE_TEMPERATURE;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ mAllInputDataCompleteFlag = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+
+ //char datapath[64]={"/sys/class/misc/m_temp_misc/tempactive"};
+ char datapath[64]={"/sys/class/misc/m_baro_misc/tempactive"};
+ int fd = -1;
+ char buf[64]={0};
+ int len;
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ //strcpy(input_sysfs_path, "/sys/class/misc/m_temp_misc/");
+ strcpy(input_sysfs_path, "/sys/class/misc/m_baro_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ else
+ {
+ ALOGE("couldn't find input device temperature");
+ return;
+ }
+ ALOGD("temp misc path =%s", input_sysfs_path);
+
+ fd = open(datapath, O_RDWR);
+ if (fd>=0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ if (len <= 0) {
+ ALOGD("read div err buf(%s)", buf);
+ } else {
+ buf[len] = '\0';
+ ALOGE("len = %d, buf = %s", len, buf);
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d", mDataDiv);
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open temp misc path %s fail ", datapath);
+ }
+}
+
+TemperatureSensor::~TemperatureSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int TemperatureSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ //devnum_dir = "/sys/class/misc/m_temp_misc/tempdevnum";
+ devnum_dir = "/sys/class/misc/m_baro_misc/tempdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if(fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+int TemperatureSensor::enable(int32_t handle, int en)
+{
+ int fd =-1;
+ int flags = en ? 1 : 0;
+
+ ALOGD("TEMP enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "tempactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no TEMP enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("TEMP enable(%d) done", mEnabled );
+ return 0;
+
+}
+int TemperatureSensor::setDelay(int32_t handle, int64_t ns)
+{
+ int fd=-1;
+
+ ALOGD("setDelay: (handle=%d, ns=%lld)",handle, ns);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "tempdelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no TEMP setDelay control attr \r\n" );
+ return -1;
+ }
+
+ char buf[80]={0};
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+
+}
+int TemperatureSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int fd=-1;
+ int flag=0;
+
+ ALOGE("TEMP batch: handle:%d, en:%d, samplingPeriodNs:%lld,maxBatchReportLatencyNs:%lld \r\n",handle, flags, samplingPeriodNs,maxBatchReportLatencyNs);
+
+ //Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "tempbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no TEMP batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("TEMP batch(%d) done", flag );
+ return 0;
+
+}
+
+int TemperatureSensor::flush(int handle)
+{
+ ALOGD("handle=%d\n",handle);
+ return -errno;
+}
+
+int TemperatureSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(type, event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (time >= mEnabledTime)
+ {
+ if (mAllInputDataCompleteFlag == all_complete) {
+ //Assign timestamp if kernel is not assigned.
+ if (0 == mPendingEvent.timestamp)
+ mPendingEvent.timestamp = time;
+ if (mPendingEvent.timestamp > mEnabledTime) {
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ mPendingEvent.timestamp = 0;
+ count--;
+ }
+ }
+ }
+ mAllInputDataCompleteFlag = restart;
+ }
+ }
+ else
+ {
+ ALOGD("Temperature Sensor: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void TemperatureSensor::processEvent(int type, int code, int value)
+{
+ //ALOGD("TprocessEvent code=%d,value=%d\r\n",code, value);
+ if (EV_ABS == type) {
+ switch (code) {
+ case EVENT_TYPE_TEMPERATURE_VALUE:
+ mPendingEvent.temperature = (float) value / mDataDiv;
+ mAllInputDataCompleteFlag= val;
+ break;
+ case EVENT_TYPE_TEMPERATURE_STATUS:
+ mAllInputDataCompleteFlag= status;
+ //ALOGE("Temperature: no need (type=%d, code=%d)", type, code);
+ break;
+ default:
+ //ALOGE("Temperature: unknown event (type=%d, code=%d)", type, code);
+ break;
+ }
+ } else if (EV_REL == type) {
+ switch (code) {
+ case EVENT_TYPE_TEMPERATURE_TIMESTAMP_HI:
+ mPendingEvent.timestamp = (mPendingEvent.timestamp & 0xFFFFFFFFLL) | ((int64_t)value << 32);
+ mAllInputDataCompleteFlag= hi;
+ break;
+ case EVENT_TYPE_TEMPERATURE_TIMESTAMP_LO:
+ mPendingEvent.timestamp = (mPendingEvent.timestamp & 0xFFFFFFFF00000000LL) |
+ ((int64_t)value & 0xFFFFFFFFLL);
+ if (mAllInputDataCompleteFlag == hi)
+ mAllInputDataCompleteFlag= lo;
+ //ALOGD("t_t=%lld", mPendingEvent.timestamp);
+ break;
+ default:
+ //ALOGE("Temperature: unknown event (type=%d, code=%d)", type, code);
+ break;
+ }
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Tilt.cpp b/src/navigation/sensor/sensor_hal/src/Tilt.cpp
new file mode 100644
index 0000000..ad85dee
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Tilt.cpp
@@ -0,0 +1,270 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+
+#include "Tilt.h"
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "TILT"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+TiltSensor::TiltSensor()
+ : SensorBase(NULL, "m_tilt_input"),//_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_TILT_DETECTOR;
+ mPendingEvent.type = SENSOR_TYPE_TILT_DETECTOR;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ //input_sysfs_path[PATH_MAX] = {0};
+ memset(input_sysfs_path, 0, sizeof(char)*PATH_MAX);
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_tilt_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ ALOGD("Tilt misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_tilt_misc/tiltactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if(len<=0)
+ {
+ ALOGD("read div err buf(%s)",buf );
+ }
+ else
+ {
+ buf[len] = '\0';
+ ALOGE("len = %d, buf = %s",len, buf);
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d",mDataDiv );
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open Tilt misc path %s fail ", datapath);
+ }
+}
+
+TiltSensor::~TiltSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int TiltSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_tilt_misc/tiltdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int TiltSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ ALOGD("tilt enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "tiltactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no tilt enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+ ALOGD("tilt enable(%d) done", mEnabled );
+ return 0;
+}
+int TiltSensor::setDelay(int32_t handle, int64_t ns)
+{
+ //int fd;
+
+ ALOGD("setDelay: regardless of the setDelay() value (handle=%d, ns=%lld)", handle, ns);
+
+ return 0;
+
+}
+int TiltSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int flag;
+ int fd;
+
+ ALOGE("tilt batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "tiltbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no tilt batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("tilt batch(%d) done", flag );
+ return 0;
+
+}
+
+int TiltSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int TiltSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = timevalToNano(event->time);
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ count--;
+
+ }
+ }
+ else
+ {
+ ALOGE("tilt: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void TiltSensor::processEvent(int code, int value)
+{
+ ALOGD("TiltSensor::processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_TILT_VALUE:
+ mPendingEvent.data[0] = (float) value;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Uncaligyro.cpp b/src/navigation/sensor/sensor_hal/src/Uncaligyro.cpp
new file mode 100644
index 0000000..39d6554
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Uncaligyro.cpp
@@ -0,0 +1,315 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "Uncaligyro.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "UNGYRO"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+UncaligyroSensor::UncaligyroSensor()
+ : SensorBase(NULL, "m_uncali_gyro_input"), // UNGYRO_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32) {
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_GYROSCOPE_UNCALIBRATED;
+ mPendingEvent.type = SENSOR_TYPE_GYROSCOPE_UNCALIBRATED;
+ mPendingEvent.acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mEnabledTime = 0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp = 0;
+ input_sysfs_path_len = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+ m_uncali_gyro_last_ts = 0;
+ m_uncali_gyro_delay = 0;
+
+ char datapath[64]={"/sys/class/misc/m_uncali_gyro_misc/ungyroactive"};
+ int fd = -1;
+ char buf[64]={0};
+ int len;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_uncali_gyro_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ } else {
+ ALOGE("couldn't find input device uncaligyro");
+ return;
+ }
+ ALOGD("uncali_gyro misc path =%s", input_sysfs_path);
+
+ fd = open(datapath, O_RDWR);
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf)-1);
+ if (len <= 0) {
+ ALOGD("read div err, len = %d", len);
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s), mdiv %d", datapath, mDataDiv);
+ }
+ close(fd);
+ } else {
+ ALOGE("open ungyro misc path %s fail ", datapath);
+ }
+}
+
+UncaligyroSensor::~UncaligyroSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+int UncaligyroSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_uncali_gyro_misc/ungyrodevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ } else {
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int UncaligyroSensor::enable(int32_t handle, int en) {
+ int fd = -1;
+ int flags = en ? 1 : 0;
+
+ ALOGD("Gyro enable: handle:%d, en:%d\r\n", handle, en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "ungyroactive");
+ ALOGD("path:%s \r\n", input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if (fd < 0) {
+ ALOGD("no Gyro enable control attr\r\n");
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flags) {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ m_uncali_gyro_last_ts = 0;
+ } else {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("Gyro enable(%d) done", mEnabled);
+ return 0;
+}
+
+int UncaligyroSensor::setDelay(int32_t handle, int64_t ns) {
+ int fd = -1;
+ ALOGD("setDelay: (handle=%d, ns=%lld)", handle, ns);
+ m_uncali_gyro_delay = ns;
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "ungyrodelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if (fd < 0) {
+ ALOGD("no UNGYRO setDelay control attr\r\n");
+ return -1;
+ }
+ char buf[80]={0};
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+
+int UncaligyroSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs) {
+ int fd;
+ int flag;
+ ALOGE("UNGYRO batch: handle:%d, en:%d,samplingPeriodNs:%lld, maxBatchReportLatencyNs:%lld\r\n",
+ handle, flags, samplingPeriodNs, maxBatchReportLatencyNs);
+
+ // Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+ if (maxBatchReportLatencyNs == 0) {
+ flag = 0;
+ } else {
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "ungyrobatch");
+ ALOGD("path:%s \r\n", input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if (fd < 0) {
+ ALOGD("no uncali_gyro batch control attr\r\n");
+ return -1;
+ }
+
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flag) {
+ buf[0] = '1';
+ } else {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("UNGYRO batch(%d) done", flag);
+ return 0;
+}
+
+int UncaligyroSensor::flush(int handle) {
+ ALOGD("handle=%d\n", handle);
+ return -errno;
+}
+
+int UncaligyroSensor::readEvents(sensors_event_t* data, int count) {
+ // ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ // ALOGE("fwq1....\r\n");
+ if (type == EV_ABS) {
+ processEvent(event->code, event->value);
+ // ALOGE("fwq2....\r\n");
+ } else if (type == EV_SYN) {
+ // ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+ mPendingEvent.timestamp = time;
+ if (mEnabled) {
+ // ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime) {
+ // ALOGE("fwq5....\r\n");
+ float delta_mod =
+ (float)(mPendingEvent.timestamp - m_uncali_gyro_last_ts) / (float)(m_uncali_gyro_delay);
+ if (m_uncali_gyro_delay == 1000000000)
+ delta_mod = 0;
+ // ALOGE("fwq uncali_gyro-delta_mod=%f\r\n",delta_mod);
+ int loopcout = delta_mod;
+ // ALOGE("fwq uncali_gyro-loopcout=%d \r\n",loopcout);
+ if (loopcout >= 1 && loopcout < 100) {
+ for (int i = 0; i < loopcout; i++) {
+ mPendingEvent.timestamp = time - (loopcout-i) * m_uncali_gyro_delay;
+ // ALOGE("fwq_n uncali_gyro fack event [%lld ] \r\n",mPendingEvent.timestamp);
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ count--;
+ if (0 == count)
+ break;
+ }
+ }
+ if (count != 0) {
+ mPendingEvent.timestamp = time;
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ }
+ if (count != 0)
+ count--;
+ }
+ m_uncali_gyro_last_ts = mPendingEvent.timestamp;
+ } else if (type != EV_ABS) {
+ if (EVENT_TYPE_UNCALI_GYRO_UPDATE != event->code) {
+ ALOGE("UncaligyroSensor: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ }
+ mInputReader.next();
+ }
+ // ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void UncaligyroSensor::processEvent(int code, int value) {
+ /* ALOGD("processEvent code=%d,value=%d\r\n",code, value); */
+ switch (code) {
+ case EVENT_TYPE_UNCALI_GYRO_X:
+ mPendingEvent.uncalibrated_gyro.x_uncalib = (float)value / 7506;
+ break;
+ case EVENT_TYPE_UNCALI_GYRO_Y:
+ mPendingEvent.uncalibrated_gyro.y_uncalib = (float)value / 7506;
+ break;
+ case EVENT_TYPE_UNCALI_GYRO_Z:
+ mPendingEvent.uncalibrated_gyro.z_uncalib = (float)value / 7506;
+ break;
+ case EVENT_TYPE_UNCALI_GYRO_X_BIAS:
+ mPendingEvent.uncalibrated_gyro.x_bias = (float)value / 7506;
+ break;
+ case EVENT_TYPE_UNCALI_GYRO_Y_BIAS:
+ mPendingEvent.uncalibrated_gyro.y_bias = (float)value / 7506;
+ break;
+ case EVENT_TYPE_UNCALI_GYRO_Z_BIAS:
+ mPendingEvent.uncalibrated_gyro.z_bias = (float)value / 7506;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/Uncalimag.cpp b/src/navigation/sensor/sensor_hal/src/Uncalimag.cpp
new file mode 100644
index 0000000..706e82f
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/Uncalimag.cpp
@@ -0,0 +1,315 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+#include "Uncalimag.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "UNMAG"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+UncalimagSensor::UncalimagSensor()
+ : SensorBase(NULL, "m_uncali_mag_input"), // UNMAG_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32) {
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_MAGNETIC_UNCALIBRATED;
+ mPendingEvent.type = SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED;
+ mPendingEvent.acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mEnabledTime = 0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp = 0;
+ input_sysfs_path_len = 0;
+ memset(input_sysfs_path, 0, PATH_MAX);
+ m_uncali_mag_last_ts = 0;
+ m_uncali_mag_delay = 0;
+
+ char datapath[64]={"/sys/class/misc/m_uncali_mag_misc/unmagactive"};
+ int fd = -1;
+ char buf[64]={0};
+ int len;
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_uncali_mag_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ } else {
+ ALOGE("couldn't find input device unclimag");
+ return;
+ }
+ ALOGD("uncali_mag misc path =%s", input_sysfs_path);
+
+ fd = open(datapath, O_RDWR);
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf)-1);
+ if (len <= 0) {
+ ALOGD("read div err, len = %d", len);
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s), mdiv %d", datapath, mDataDiv);
+ }
+ close(fd);
+ } else {
+ ALOGE("open unmag misc path %s fail ", datapath);
+ }
+}
+
+UncalimagSensor::~UncalimagSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+int UncalimagSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_uncali_mag_misc/unmagdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf) - 1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ } else {
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int UncalimagSensor::enable(int32_t handle, int en) {
+ int fd = -1;
+ int flags = en ? 1 : 0;
+
+ ALOGD("Gyro enable: handle:%d, en:%d \r\n", handle, en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "unmagactive");
+ ALOGD("path:%s \r\n", input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if (fd < 0) {
+ ALOGD("no Gyro enable control attr\r\n");
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flags) {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ m_uncali_mag_last_ts = 0;
+ } else {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("Gyro enable(%d) done", mEnabled);
+ return 0;
+}
+
+int UncalimagSensor::setDelay(int32_t handle, int64_t ns) {
+ int fd = -1;
+ ALOGD("setDelay: (handle=%d, ns=%lld)", handle, ns);
+ m_uncali_mag_delay = ns;
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "unmagdelay");
+ fd = open(input_sysfs_path, O_RDWR);
+ if (fd < 0) {
+ ALOGD("no UNMAG setDelay control attr \r\n");
+ return -1;
+ }
+ char buf[80]={0};
+ sprintf(buf, "%lld", ns);
+ write(fd, buf, strlen(buf)+1);
+ close(fd);
+ return 0;
+}
+
+int UncalimagSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs) {
+ int fd;
+ int flag;
+ ALOGE("UNMAG batch: handle:%d, en:%d,samplingPeriodNs:%lld, maxBatchReportLatencyNs:%lld \r\n",
+ handle, flags, samplingPeriodNs, maxBatchReportLatencyNs);
+
+ // Don't change batch status if dry run.
+ if (flags & SENSORS_BATCH_DRY_RUN)
+ return 0;
+ if (maxBatchReportLatencyNs == 0) {
+ flag = 0;
+ } else {
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "unmagbatch");
+ ALOGD("path:%s \r\n", input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if (fd < 0) {
+ ALOGD("no uncali_mag batch control attr\r\n");
+ return -1;
+ }
+
+ char buf[2]={0};
+ buf[1] = 0;
+ if (flag) {
+ buf[0] = '1';
+ } else {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("UNMAG batch(%d) done", flag);
+ return 0;
+}
+
+int UncalimagSensor::flush(int handle) {
+ ALOGD("handle=%d\n", handle);
+ return -errno;
+}
+
+int UncalimagSensor::readEvents(sensors_event_t* data, int count) {
+ // ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ // ALOGE("fwq1....\r\n");
+ if (type == EV_ABS) {
+ processEvent(event->code, event->value);
+ // ALOGE("fwq2....\r\n");
+ } else if (type == EV_SYN) {
+ // ALOGE("fwq3....\r\n");
+ int64_t time = getTimestamp();
+ mPendingEvent.timestamp = time;
+ if (mEnabled) {
+ // ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime) {
+ // ALOGE("fwq5....\r\n");
+ float delta_mod =
+ (float)(mPendingEvent.timestamp - m_uncali_mag_last_ts) / (float)(m_uncali_mag_delay);
+ if (m_uncali_mag_delay == 1000000000)
+ delta_mod = 0;
+ // ALOGE("fwq uncali_mag-delta_mod=%f\r\n",delta_mod);
+ int loopcout = delta_mod;
+ // ALOGE("fwq uncali_mag-loopcout=%d \r\n",loopcout);
+ if (loopcout >= 1 && loopcout < 100) {
+ for (int i = 0; i < loopcout; i++) {
+ mPendingEvent.timestamp = time - (loopcout - i) * m_uncali_mag_delay;
+ // ALOGE("fwq_n uncali_mag fack event [%lld ] \r\n",mPendingEvent.timestamp);
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ count--;
+ if (0 == count)
+ break;
+ }
+ }
+ if (count != 0) {
+ mPendingEvent.timestamp = time;
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ }
+ }
+ if (count != 0)
+ count--;
+ }
+ m_uncali_mag_last_ts = mPendingEvent.timestamp;
+ } else if (type != EV_ABS) {
+ if (EVENT_TYPE_UNCALI_MAG_UPDATE != event->code) {
+ ALOGE("UncalimagSensor: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ }
+ mInputReader.next();
+ }
+ // ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void UncalimagSensor::processEvent(int code, int value) {
+ // ALOGD("processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_UNCALI_MAG_X:
+ mPendingEvent.uncalibrated_magnetic.x_uncalib = (float)value / 100;
+ break;
+ case EVENT_TYPE_UNCALI_MAG_Y:
+ mPendingEvent.uncalibrated_magnetic.y_uncalib = (float)value / 100;
+ break;
+ case EVENT_TYPE_UNCALI_MAG_Z:
+ mPendingEvent.uncalibrated_magnetic.z_uncalib = (float)value / 100;
+ break;
+ case EVENT_TYPE_UNCALI_MAG_X_BIAS:
+ mPendingEvent.uncalibrated_magnetic.x_bias = (float)value / 100;
+ break;
+ case EVENT_TYPE_UNCALI_MAG_Y_BIAS:
+ mPendingEvent.uncalibrated_magnetic.y_bias = (float)value / 100;
+ break;
+ case EVENT_TYPE_UNCALI_MAG_Z_BIAS:
+ mPendingEvent.uncalibrated_magnetic.z_bias = (float)value / 100;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/WakeGesture.cpp b/src/navigation/sensor/sensor_hal/src/WakeGesture.cpp
new file mode 100644
index 0000000..165d876
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/WakeGesture.cpp
@@ -0,0 +1,272 @@
+/*
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <math.h>
+#include <poll.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/select.h>
+#include <string.h>
+
+#include "WakeGesture.h"
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "WAKE_GESTURE"
+#endif
+
+#define IGNORE_EVENT_TIME 350000LL
+#define SYSFS_PATH "/sys/class/input"
+
+
+/*****************************************************************************/
+WakeGestureSensor::WakeGestureSensor()
+ : SensorBase(NULL, "m_wag_input"),//_INPUTDEV_NAME
+ mEnabled(0),
+ mInputReader(32)
+{
+ mPendingEvent.version = sizeof(sensors_event_t);
+ mPendingEvent.sensor = ID_WAKE_GESTURE;
+ mPendingEvent.type = SENSOR_TYPE_WAKE_GESTURE;
+ memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
+ mPendingEvent.flags = 0;
+ mPendingEvent.reserved0 = 0;
+ mEnabledTime =0;
+ mDataDiv = 1;
+ mPendingEvent.timestamp =0;
+ input_sysfs_path_len = 0;
+ //input_sysfs_path[PATH_MAX] = {0};
+ memset(input_sysfs_path, 0, sizeof(char)*PATH_MAX);
+
+ mdata_fd = FindDataFd();
+ if (mdata_fd >= 0) {
+ strcpy(input_sysfs_path, "/sys/class/misc/m_wag_misc/");
+ input_sysfs_path_len = strlen(input_sysfs_path);
+ }
+ ALOGD("WakeGesture misc path =%s", input_sysfs_path);
+
+ char datapath[64]={"/sys/class/misc/m_wag_misc/wagactive"};
+ int fd = open(datapath, O_RDWR);
+ char buf[64];
+ int len;
+ if (fd >= 0)
+ {
+ len = read(fd,buf,sizeof(buf)-1);
+ if(len<=0)
+ {
+ ALOGD("read div err buf(%s)",buf );
+ }
+ else
+ {
+ buf[len] = '\0';
+ ALOGE("len = %d, buf = %s",len, buf);
+ sscanf(buf, "%d", &mDataDiv);
+ ALOGD("read div buf(%s)", datapath);
+ ALOGD("mdiv %d",mDataDiv );
+ }
+ close(fd);
+ }
+ else
+ {
+ ALOGE("open WakeGesture misc path %s fail ", datapath);
+ }
+}
+
+WakeGestureSensor::~WakeGestureSensor() {
+ if (mdata_fd >= 0)
+ close(mdata_fd);
+}
+
+int WakeGestureSensor::FindDataFd() {
+ int fd = -1;
+ int num = -1;
+ char buf[64]={0};
+ const char *devnum_dir = NULL;
+ char buf_s[64] = {0};
+ int len;
+
+ devnum_dir = "/sys/class/misc/m_wag_misc/wagdevnum";
+
+ fd = open(devnum_dir, O_RDONLY);
+ if (fd >= 0)
+ {
+ len = read(fd, buf, sizeof(buf)-1);
+ close(fd);
+ if (len <= 0) {
+ ALOGD("read devnum err, len = %d", len);
+ return -1;
+ } else {
+ buf[len] = '\0';
+ sscanf(buf, "%d\n", &num);
+ }
+ }else{
+ return -1;
+ }
+ sprintf(buf_s, "/dev/input/event%d", num);
+
+ fd = open(buf_s, O_RDONLY);
+ if (fd < 0)
+ ALOGE("couldn't find input device: %s \n", buf_s);
+ return fd;
+}
+
+int WakeGestureSensor::enable(int32_t handle, int en)
+{
+ int fd;
+ int flags = en ? 1 : 0;
+
+ ALOGD("wag enable: handle:%d, en:%d \r\n",handle,en);
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "wagactive");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd<0)
+ {
+ ALOGD("no wag enable control attr\r\n" );
+ return -1;
+ }
+
+ mEnabled = flags;
+ char buf[2];
+ buf[1] = 0;
+ if (flags)
+ {
+ buf[0] = '1';
+ mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+ ALOGD("wag enable(%d) done", mEnabled );
+ return 0;
+}
+int WakeGestureSensor::setDelay(int32_t handle, int64_t ns)
+{
+ //int fd;
+
+ ALOGD("setDelay: regardless of the setDelay() value (handle=%d, ns=%lld)", handle, ns);
+
+ return 0;
+
+}
+int WakeGestureSensor::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ int flag;
+ int fd;
+
+ ALOGE("wag batch: handle:%d, en:%d, maxBatchReportLatencyNs:%lld \r\n",handle, flags, maxBatchReportLatencyNs);
+ if(maxBatchReportLatencyNs == 0){
+ flag = 0;
+ }else{
+ flag = 1;
+ }
+
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "wagbatch");
+ ALOGD("path:%s \r\n",input_sysfs_path);
+ fd = open(input_sysfs_path, O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("no wag batch control attr\r\n" );
+ return -1;
+ }
+
+ char buf[2];
+ buf[1] = 0;
+ if (flag)
+ {
+ buf[0] = '1';
+ }
+ else
+ {
+ buf[0] = '0';
+ }
+ write(fd, buf, sizeof(buf));
+ close(fd);
+
+ ALOGD("wag batch(%d) done", flag );
+ return 0;
+
+}
+
+int WakeGestureSensor::flush(int handle)
+{
+ return -errno;
+}
+
+int WakeGestureSensor::readEvents(sensors_event_t* data, int count)
+{
+
+ //ALOGE("fwq read Event 1\r\n");
+ if (count < 1)
+ return -EINVAL;
+
+ ssize_t n = mInputReader.fill(mdata_fd);
+ if (n < 0)
+ return n;
+ int numEventReceived = 0;
+ input_event const* event;
+
+ while (count && mInputReader.readEvent(&event)) {
+ int type = event->type;
+ //ALOGE("fwq1....\r\n");
+ if (type == EV_ABS || type == EV_REL)
+ {
+ processEvent(event->code, event->value);
+ //ALOGE("fwq2....\r\n");
+ }
+ else if (type == EV_SYN)
+ {
+ //ALOGE("fwq3....\r\n");
+ int64_t time = timevalToNano(event->time);
+ mPendingEvent.timestamp = time;
+ if (mEnabled)
+ {
+ //ALOGE("fwq4....\r\n");
+ if (mPendingEvent.timestamp >= mEnabledTime)
+ {
+ //ALOGE("fwq5....\r\n");
+ *data++ = mPendingEvent;
+ numEventReceived++;
+ if(mPendingEvent.sensor == ID_WAKE_GESTURE)
+ enable(ID_WAKE_GESTURE, false);
+ }
+ count--;
+
+ }
+ }
+ else
+ {
+ ALOGE("wag: unknown event (type=%d, code=%d)",
+ type, event->code);
+ }
+ mInputReader.next();
+ }
+ //ALOGE("fwq read Event 2\r\n");
+ return numEventReceived;
+}
+
+void WakeGestureSensor::processEvent(int code, int value)
+{
+ ALOGD("WakeGestureSensor::processEvent code=%d,value=%d\r\n",code, value);
+ switch (code) {
+ case EVENT_TYPE_WAG_VALUE:
+ mPendingEvent.data[0] = (float) value;
+ break;
+ }
+}
diff --git a/src/navigation/sensor/sensor_hal/src/hwmsen_chip_info.c b/src/navigation/sensor/sensor_hal/src/hwmsen_chip_info.c
new file mode 100644
index 0000000..18cf7bb
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/hwmsen_chip_info.c
@@ -0,0 +1,16 @@
+/*
+ * 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.
+ */
+
diff --git a/src/navigation/sensor/sensor_hal/src/hwmsen_custom.c b/src/navigation/sensor/sensor_hal/src/hwmsen_custom.c
new file mode 100644
index 0000000..f65ff87
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/hwmsen_custom.c
@@ -0,0 +1,35 @@
+/*
+ * 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 "sensors.h"
+#include "hwmsensor.h"
+#include "hwmsen_custom.h"
+
+struct sensor_t sSensorList_nouse[MAX_NUM_SENSORS] =
+{
+ /*MT6516 the spec follows ADXL345*/
+ {
+ .name = "MT6516 3-axis Accelerometer",
+ .vendor = "The Android Open Source Project",
+ .version = 1,
+ .handle = ID_ACCELEROMETER,
+ .type = SENSOR_TYPE_ACCELEROMETER,
+ .maxRange = 32.0f,
+ .resolution = 4.0f/1024.0f,
+ .power =130.0f/1000.0f,
+ .reserved = {}
+ },
+};
+
diff --git a/src/navigation/sensor/sensor_hal/src/nusensors.cpp b/src/navigation/sensor/sensor_hal/src/nusensors.cpp
new file mode 100644
index 0000000..79ad571
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/nusensors.cpp
@@ -0,0 +1,783 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+
+#include <fcntl.h>
+#include <errno.h>
+#include <dirent.h>
+#include <math.h>
+#include <string.h>
+
+#include <poll.h>
+#include <pthread.h>
+
+#include <linux/input.h>
+
+
+#include "nusensors.h"
+#include "Hwmsen.h"
+#include "Acceleration.h"
+#include "Magnetic.h"
+#include "Proximity.h"
+#include "Pressure.h"
+#include "Temperature.h"
+#include "Humidity.h"
+#include "Gyroscope.h"
+#include "AmbienteLight.h"
+#include "BatchSensor.h"
+#include "StepCounter.h"
+
+#include "Activity.h"
+#include "FaceDown.h"
+#include "InPocket.h"
+#include "Pedometer.h"
+#include "PickUp.h"
+#include "Shake.h"
+#include "HeartRate.h"
+#include "Tilt.h"
+#include "WakeGesture.h"
+#include "GlanceGesture.h"
+
+#include "Bringtosee.h"
+#include "GameRotationVector.h"
+#include "GeomagneticRotationVector.h"
+#include "RotationVector.h"
+#include "Linearacceleration.h"
+#include "Gravity.h"
+#include "Uncaligyro.h"
+#include "Uncalimag.h"
+#include "AnswerCall.h"
+#include "Gesture.h"
+#include "Pdr.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "Sensors"
+#endif
+/*****************************************************************************/
+
+struct sensors_poll_context_t {
+ struct sensors_poll_device_1 device;// must be first
+
+ sensors_poll_context_t();
+ ~sensors_poll_context_t();
+ int activate(int handle, int enabled);
+ int setDelay(int handle, int64_t ns);
+ int pollEvents(sensors_event_t* data, int count);
+ int batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs);
+ int flush(int handle);
+ int getODR(int handle, int *odr);
+
+private:
+ enum {
+ batchsensor = 0,
+ hwmsen,
+ accel,
+ gyro,
+ pressure,
+ temperature,
+ numSensorDrivers,
+ numFds,
+ };
+
+#if 0
+ enum {
+ batchsensor = 0,
+ hwmsen,
+ accel,
+ magnetic,
+ gyro,
+ light,
+ proximity,
+ pressure,
+ temperature,
+ humidity,
+ stepcounter,
+ pedometer,
+ activity,
+ pick_up,
+ face_down,
+ shake,
+ heartrate,
+ tilt,
+ wake_gesture,
+ glance_gesture,
+ linear_acceleration,
+ rotation_vector,
+ game_rotation_vector,
+ gravity,
+ geomagnetic_rotation_vector,
+ bringtosee,
+ uncaligyro,
+ uncalimag,
+ answercall,
+ gesture,
+ pdr,
+ numSensorDrivers,
+ numFds,
+ };
+#endif
+#if 0
+ int handleToDriver(int handle) const {
+ ALOGE("handleToDriver handle(%d)\n",handle);
+ switch (handle) {
+ case ID_ACCELEROMETER:
+ return accel;
+ case ID_MAGNETIC:
+ case ID_ORIENTATION:
+ return magnetic;
+ case ID_PROXIMITY:
+ return proximity;
+ case ID_LIGHT:
+ return light;
+ case ID_GYROSCOPE:
+ return gyro;
+ case ID_PRESSURE:
+ return pressure;
+ case ID_TEMPERATURE:
+ return temperature;
+ case ID_HUMIDITY:
+ return humidity;
+ case ID_STEP_COUNTER:
+ case ID_STEP_DETECTOR:
+ case ID_SIGNIFICANT_MOTION:
+ return stepcounter;
+ case ID_PEDOMETER:
+ return pedometer;
+ case ID_ACTIVITY:
+ return activity;
+ case ID_PICK_UP_GESTURE:
+ return pick_up;
+ case ID_FACE_DOWN:
+ return face_down;
+ case ID_SHAKE:
+ return shake;
+ case ID_HEART_RATE:
+ return heartrate;
+ case ID_TILT_DETECTOR:
+ return tilt;
+ case ID_WAKE_GESTURE:
+ return wake_gesture;
+ case ID_GLANCE_GESTURE:
+ return glance_gesture;
+ case ID_LINEAR_ACCELERATION:
+ return linear_acceleration;
+ case ID_ROTATION_VECTOR:
+ return rotation_vector;
+ case ID_GAME_ROTATION_VECTOR:
+ return game_rotation_vector;
+ case ID_GRAVITY:
+ return gravity;
+ case ID_GEOMAGNETIC_ROTATION_VECTOR:
+ return geomagnetic_rotation_vector;
+ case ID_BRINGTOSEE:
+ return bringtosee;
+ case ID_GYROSCOPE_UNCALIBRATED:
+ return uncaligyro;
+ case ID_MAGNETIC_UNCALIBRATED:
+ return uncalimag;
+ case ID_ANSWER_CALL:
+ return answercall;
+ case ID_IN_POCKET:
+ return gesture;
+ case ID_STATIONARY:
+ return gesture;
+ case ID_PDR:
+ return pdr;
+ default:
+ break;
+ //return pressure;
+ }
+ return -EINVAL;
+ }
+#endif
+ int handleToDriver(int handle) const {
+ ALOGD("handleToDriver handle(%d)\n",handle);
+ switch (handle) {
+ case ID_ACCELEROMETER:
+ return accel;
+ case ID_GYROSCOPE:
+ return gyro;
+ case ID_PRESSURE:
+ return pressure;
+ case ID_TEMPERATURE:
+ return temperature;
+ default:
+ break;
+ }
+ return -EINVAL;
+ }
+
+ static const size_t wake = numFds - 1;
+ static const char WAKE_MESSAGE = 'W';
+ struct pollfd mPollFds[numFds];
+ int mWritePipeFd;
+ SensorBase* mSensors[numSensorDrivers];
+};
+static sensors_poll_context_t *dev;
+
+/*****************************************************************************/
+
+#if 0
+sensors_poll_context_t::sensors_poll_context_t()
+{
+ memset(&device, 0, sizeof(device));
+
+ mSensors[hwmsen] = new Hwmsen();
+ mPollFds[hwmsen].fd = ((Hwmsen *)mSensors[hwmsen])->mdata_fd;
+ mPollFds[hwmsen].events = POLLIN;
+ mPollFds[hwmsen].revents = 0;
+
+ mSensors[accel] = new AccelerationSensor();
+ mPollFds[accel].fd = ((AccelerationSensor*)mSensors[accel])->mdata_fd;
+ mPollFds[accel].events = POLLIN;
+ mPollFds[accel].revents = 0;
+
+ mSensors[magnetic] = new MagneticSensor();
+ mPollFds[magnetic].fd = ((MagneticSensor*)mSensors[magnetic])->mdata_fd;
+ mPollFds[magnetic].events = POLLIN;
+ mPollFds[magnetic].revents = 0;
+
+ mSensors[proximity] = new ProximitySensor();
+ mPollFds[proximity].fd = ((ProximitySensor*)mSensors[proximity])->mdata_fd;
+ mPollFds[proximity].events = POLLIN;
+ mPollFds[proximity].revents = 0;
+
+ mSensors[light] = new AmbiLightSensor();
+ mPollFds[light].fd = ((AmbiLightSensor*)mSensors[light])->mdata_fd;
+ mPollFds[light].events = POLLIN;
+ mPollFds[light].revents = 0;
+
+ mSensors[gyro] = new GyroscopeSensor();
+ mPollFds[gyro].fd = ((GyroscopeSensor*)mSensors[gyro])->mdata_fd;
+ mPollFds[gyro].events = POLLIN;
+ mPollFds[gyro].revents = 0;
+
+ mSensors[pressure] = new PressureSensor();
+ mPollFds[pressure].fd = ((PressureSensor*)mSensors[pressure])->mdata_fd;
+ mPollFds[pressure].events = POLLIN;
+ mPollFds[pressure].revents = 0;
+
+ mSensors[temperature] = new TemperatureSensor();
+ mPollFds[temperature].fd = ((TemperatureSensor*)mSensors[temperature])->mdata_fd;
+ mPollFds[temperature].events = POLLIN;
+ mPollFds[temperature].revents = 0;
+
+ mSensors[humidity] = new HumiditySensor();
+ mPollFds[humidity].fd = ((HumiditySensor*)mSensors[humidity])->mdata_fd;
+ mPollFds[humidity].events = POLLIN;
+ mPollFds[humidity].revents = 0;
+
+ mSensors[stepcounter] = new StepCounterSensor();
+ mPollFds[stepcounter].fd = ((StepCounterSensor*)mSensors[stepcounter])->mdata_fd;
+ mPollFds[stepcounter].events = POLLIN;
+ mPollFds[stepcounter].revents = 0;
+
+ mSensors[batchsensor] = new BatchSensor();
+ mPollFds[batchsensor].fd = ((BatchSensor*)mSensors[batchsensor])->mdata_fd;
+ mPollFds[batchsensor].events = POLLIN;
+ mPollFds[batchsensor].revents = 0;
+
+ mSensors[pedometer] = new PedometerSensor();
+ mPollFds[pedometer].fd = ((PedometerSensor*)mSensors[pedometer])->mdata_fd;
+ mPollFds[pedometer].events = POLLIN;
+ mPollFds[pedometer].revents = 0;
+
+ mSensors[activity] = new ActivitySensor();
+ mPollFds[activity].fd = ((ActivitySensor*)mSensors[activity])->mdata_fd;
+ mPollFds[activity].events = POLLIN;
+ mPollFds[activity].revents = 0;
+
+ mSensors[pick_up] = new PickUpSensor();
+ mPollFds[pick_up].fd = ((PickUpSensor*)mSensors[pick_up])->mdata_fd;
+ mPollFds[pick_up].events = POLLIN;
+ mPollFds[pick_up].revents = 0;
+
+ mSensors[face_down] = new FaceDownSensor();
+ mPollFds[face_down].fd = ((FaceDownSensor*)mSensors[face_down])->mdata_fd;
+ mPollFds[face_down].events = POLLIN;
+ mPollFds[face_down].revents = 0;
+
+ mSensors[shake] = new ShakeSensor();
+ mPollFds[shake].fd = ((ShakeSensor*)mSensors[shake])->mdata_fd;
+ mPollFds[shake].events = POLLIN;
+ mPollFds[shake].revents = 0;
+
+ mSensors[heartrate] = new HeartRateSensor();
+ mPollFds[heartrate].fd = ((HeartRateSensor*)mSensors[heartrate])->mdata_fd;
+ mPollFds[heartrate].events = POLLIN;
+ mPollFds[heartrate].revents = 0;
+
+ mSensors[tilt] = new TiltSensor();
+ mPollFds[tilt].fd = ((TiltSensor*)mSensors[tilt])->mdata_fd;
+ mPollFds[tilt].events = POLLIN;
+ mPollFds[tilt].revents = 0;
+
+ mSensors[wake_gesture] = new WakeGestureSensor();
+ mPollFds[wake_gesture].fd = ((WakeGestureSensor*)mSensors[wake_gesture])->mdata_fd;
+ mPollFds[wake_gesture].events = POLLIN;
+ mPollFds[wake_gesture].revents = 0;
+
+ mSensors[glance_gesture] = new GlanceGestureSensor();
+ mPollFds[glance_gesture].fd = ((GlanceGestureSensor*)mSensors[glance_gesture])->mdata_fd;
+ mPollFds[glance_gesture].events = POLLIN;
+ mPollFds[glance_gesture].revents = 0;
+
+ mSensors[linear_acceleration] = new LinearaccelSensor();
+ mPollFds[linear_acceleration].fd = ((LinearaccelSensor*)mSensors[linear_acceleration])->mdata_fd;
+ mPollFds[linear_acceleration].events = POLLIN;
+ mPollFds[linear_acceleration].revents = 0;
+
+ mSensors[rotation_vector] = new RotationVectorSensor();
+ mPollFds[rotation_vector].fd = ((RotationVectorSensor*)mSensors[rotation_vector])->mdata_fd;
+ mPollFds[rotation_vector].events = POLLIN;
+ mPollFds[rotation_vector].revents = 0;
+
+ mSensors[game_rotation_vector] = new GameRotationVectorSensor();
+ mPollFds[game_rotation_vector].fd = ((GameRotationVectorSensor*)mSensors[game_rotation_vector])->mdata_fd;
+ mPollFds[game_rotation_vector].events = POLLIN;
+ mPollFds[game_rotation_vector].revents = 0;
+
+ mSensors[gravity] = new GravitySensor();
+ mPollFds[gravity].fd = ((GravitySensor*)mSensors[gravity])->mdata_fd;
+ mPollFds[gravity].events = POLLIN;
+ mPollFds[gravity].revents = 0;
+
+ mSensors[geomagnetic_rotation_vector] = new GeomagneticRotationVectorSensor();
+ mPollFds[geomagnetic_rotation_vector].fd = ((GeomagneticRotationVectorSensor*)mSensors[geomagnetic_rotation_vector])->mdata_fd;
+ mPollFds[geomagnetic_rotation_vector].events = POLLIN;
+ mPollFds[geomagnetic_rotation_vector].revents = 0;
+
+ mSensors[bringtosee] = new BringtoseeSensor();
+ mPollFds[bringtosee].fd = ((BringtoseeSensor*)mSensors[bringtosee])->mdata_fd;
+ mPollFds[bringtosee].events = POLLIN;
+ mPollFds[bringtosee].revents = 0;
+
+ mSensors[uncaligyro] = new UncaligyroSensor();
+ mPollFds[uncaligyro].fd = ((UncaligyroSensor*)mSensors[uncaligyro])->mdata_fd;
+ mPollFds[uncaligyro].events = POLLIN;
+ mPollFds[uncaligyro].revents = 0;
+
+ mSensors[uncalimag] = new UncalimagSensor();
+ mPollFds[uncalimag].fd = ((UncalimagSensor*)mSensors[uncalimag])->mdata_fd;
+ mPollFds[uncalimag].events = POLLIN;
+ mPollFds[uncalimag].revents = 0;
+
+ mSensors[answercall] = new AnswerCallSensor();
+ mPollFds[answercall].fd = ((AnswerCallSensor*)mSensors[answercall])->mdata_fd;
+ mPollFds[answercall].events = POLLIN;
+ mPollFds[answercall].revents = 0;
+
+ mSensors[gesture] = new GestureSensor();
+ mPollFds[gesture].fd = ((GestureSensor*)mSensors[gesture])->mdata_fd;
+ mPollFds[gesture].events = POLLIN;
+ mPollFds[gesture].revents = 0;
+
+ mSensors[pdr] = new PdrSensor();
+ mPollFds[pdr].fd = ((PdrSensor*)mSensors[pdr])->mdata_fd;
+ mPollFds[pdr].events = POLLIN;
+ mPollFds[pdr].revents = 0;
+
+ int wakeFds[2];
+ int result = pipe(wakeFds);
+ if (result < 0) {
+ ALOGE("error creating wake pipe (%s)", strerror(errno));
+ mWritePipeFd = -1;
+ } else {
+ result = fcntl(wakeFds[0], F_SETFL, O_NONBLOCK);
+ if (result < 0)
+ ALOGE( "fcntl(wakeFds[0] fail (%s)", strerror(errno));
+ result = fcntl(wakeFds[1], F_SETFL, O_NONBLOCK);
+ if (result < 0)
+ ALOGE( "fcntl(wakeFds[1] fail (%s)", strerror(errno));
+ mWritePipeFd = wakeFds[1];
+ }
+
+ mPollFds[wake].fd = wakeFds[0];
+ mPollFds[wake].events = POLLIN;
+ mPollFds[wake].revents = 0;
+}
+#endif
+
+sensors_poll_context_t::sensors_poll_context_t()
+{
+ memset(&device, 0, sizeof(device));
+
+ mSensors[hwmsen] = new Hwmsen();
+ mPollFds[hwmsen].fd = ((Hwmsen *)mSensors[hwmsen])->mdata_fd;
+ mPollFds[hwmsen].events = POLLIN;
+ mPollFds[hwmsen].revents = 0;
+
+ mSensors[accel] = new AccelerationSensor();
+ mPollFds[accel].fd = ((AccelerationSensor*)mSensors[accel])->mdata_fd;
+ mPollFds[accel].events = POLLIN;
+ mPollFds[accel].revents = 0;
+
+ mSensors[gyro] = new GyroscopeSensor();
+ mPollFds[gyro].fd = ((GyroscopeSensor*)mSensors[gyro])->mdata_fd;
+ mPollFds[gyro].events = POLLIN;
+ mPollFds[gyro].revents = 0;
+
+ mSensors[pressure] = new PressureSensor();
+ mPollFds[pressure].fd = ((PressureSensor*)mSensors[pressure])->mdata_fd;
+ mPollFds[pressure].events = POLLIN;
+ mPollFds[pressure].revents = 0;
+
+ mSensors[temperature] = new TemperatureSensor();
+ mPollFds[temperature].fd = ((TemperatureSensor*)mSensors[temperature])->mdata_fd;
+ mPollFds[temperature].events = POLLIN;
+ mPollFds[temperature].revents = 0;
+
+ mSensors[batchsensor] = new BatchSensor();
+ mPollFds[batchsensor].fd = ((BatchSensor*)mSensors[batchsensor])->mdata_fd;
+ mPollFds[batchsensor].events = POLLIN;
+ mPollFds[batchsensor].revents = 0;
+
+ int wakeFds[2];
+ int result = pipe(wakeFds);
+ if (result < 0) {
+ ALOGE("error creating wake pipe (%s)", strerror(errno));
+ mWritePipeFd = -1;
+ } else {
+ result = fcntl(wakeFds[0], F_SETFL, O_NONBLOCK);
+ if (result < 0)
+ ALOGE( "fcntl(wakeFds[0] fail (%s)", strerror(errno));
+ result = fcntl(wakeFds[1], F_SETFL, O_NONBLOCK);
+ if (result < 0)
+ ALOGE( "fcntl(wakeFds[1] fail (%s)", strerror(errno));
+ mWritePipeFd = wakeFds[1];
+ }
+
+ mPollFds[wake].fd = wakeFds[0];
+ mPollFds[wake].events = POLLIN;
+ mPollFds[wake].revents = 0;
+}
+
+sensors_poll_context_t::~sensors_poll_context_t() {
+ for (int i=0 ; i<numSensorDrivers ; i++) {
+ delete mSensors[i];
+ }
+ close(mPollFds[wake].fd);
+ close(mWritePipeFd);
+}
+
+int sensors_poll_context_t::activate(int handle, int enabled)
+{
+ ALOGD( "activate handle =%d, enable = %d",handle, enabled );
+ int err=0;
+
+ int index = handleToDriver(handle);
+
+ if(ID_ORIENTATION == handle)
+ {
+ //ALOGD( "fwq1111" );
+ /* ((GyroscopeSensor*)(mSensors[gyro]))->enableNoHALData(enabled); */
+ ((AccelerationSensor*)(mSensors[accel]))->enableNoHALDataAcc(enabled);
+ ((Hwmsen*)(mSensors[hwmsen]))->enableNoHALDataAcc(enabled);
+ }
+ /* if (ID_MAGNETIC == handle) {
+ ((GyroscopeSensor*)(mSensors[gyro]))->enableNoHALData(enabled);
+ } */
+ if( (index >= numSensorDrivers) || (index < 0) )
+ {
+ ALOGD("activate error index=%d\n", index);
+ return 0;
+ }
+ if(NULL != mSensors[index])
+ {
+ ALOGD( "use new sensor index=%d, mSensors[index](%x)", index, mSensors[index]);
+ /* remove hw version part for test
+ if(this->device.common.version >= SENSORS_DEVICE_API_VERSION_1_1)
+ {
+ ALOGD("support batch active \n" );
+ mSensors[batchsensor]->enable(handle, enabled);
+ }
+ */
+ err = mSensors[index]->enable(handle, enabled);
+ }
+
+ if(err || index<0 )
+ {
+ ALOGD("use old sensor err(%d),index(%d) go to old hwmsen\n",err,index);
+ // notify to hwmsen sensor to support old architecture
+ err = mSensors[hwmsen]->enable(handle, enabled);
+ }
+
+ if (enabled && !err) {
+ const char wakeMessage(WAKE_MESSAGE);
+ int result = write(mWritePipeFd, &wakeMessage, 1);
+ if (result < 0)
+ ALOGE( "error sending wake message (%s)", strerror(errno));
+ }
+ return err;
+}
+
+int sensors_poll_context_t::setDelay(int handle, int64_t ns)
+{
+ int err =0;
+
+ int index = handleToDriver(handle);
+
+ if( (index >= numSensorDrivers) || (index < 0) ) {
+ ALOGE("new setDelay handle error(%d)\n",index);
+ return 0;
+ }
+ if(ns < 1000000LL)//mkt70620
+ ns = 1000000LL;
+ if(NULL != mSensors[index]) {
+ err = mSensors[index]->setDelay(handle, ns);
+ ALOGD("new setDelay handle(%d),ns(%lld)m, error(%d), index(%d)\n",handle,ns,err,index);
+ }
+ if(err || index < 0) {
+ ALOGE("old setDelay handle(%d),ns(%lld) err! go to hwmsen\n",handle,ns);
+ // notify to hwmsen sensor to support old architecture
+ err = mSensors[hwmsen]->setDelay(handle, ns);
+ }
+ return err;
+}
+
+int sensors_poll_context_t::batch(int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs)
+{
+ ALOGD( "batch handle =%d, flag=%d, sampling=%lld, batchtimeout=%lld",handle, flags, samplingPeriodNs, maxBatchReportLatencyNs);
+ int err=0;
+ int index = handleToDriver(handle);
+
+ if( (index >= numSensorDrivers) || (index < 0) ) {
+ ALOGE("new batch handle error(%d)\n",index);
+ return 0;
+ }
+ if(maxBatchReportLatencyNs == 0) {
+ if ((flags & SENSORS_BATCH_DRY_RUN) == 0)//Don't set delay if dry run.
+ setDelay(handle, samplingPeriodNs);
+
+ err = mSensors[index]->batch(handle, flags, samplingPeriodNs, maxBatchReportLatencyNs);//tell single sensors to disable there own polling and use
+
+ } else
+ err = mSensors[index]->batch(handle, flags, samplingPeriodNs, maxBatchReportLatencyNs);//tell single sensors to disable there own polling and use
+
+ if(err) {
+ ALOGE("sensor %d use old arch\n", handle);
+ return 0;
+ }
+ else {
+ // notify to batch sensor to support new architecture
+ ALOGE("sensor %d go to common batch\n", handle);
+ err = mSensors[batchsensor]->batch(handle, flags, samplingPeriodNs, maxBatchReportLatencyNs);
+ return err;
+ }
+
+ return err;
+}
+int sensors_poll_context_t::flush(int handle)
+{
+ ALOGD( "flush handle =%d",handle);
+ int err=0;
+
+ int index = handleToDriver(handle);
+ if( (index >= numSensorDrivers) || (index < 0) )
+ {
+ ALOGE("new flush handle error(%d)\n",index);
+ return 0;
+ }
+ err = mSensors[index]->flush(handle);
+ ALOGE("go to batchsensor(%d)\n", handle);
+ // notify to hwmsen sensor to support old architecture
+ err = mSensors[batchsensor]->flush(handle);
+
+ const char wakeMessage(WAKE_MESSAGE);
+ int result = write(mWritePipeFd, &wakeMessage, 1);
+ if (result < 0)
+ ALOGE( "error sending wake message (%s)", strerror(errno));
+
+ return err;
+}
+
+int sensors_poll_context_t::getODR(int handle, int *odr)
+{
+ int err = -1;
+ int index = handleToDriver(handle);
+
+ ALOGD( "getODR handle =%d, index =%d\n", handle, index);
+ if (handle == ID_ACCELEROMETER || handle == ID_GYROSCOPE) {
+ if(NULL != mSensors[index])
+ err = mSensors[index]->getODR(handle, odr);
+ } else {
+ ALOGE("Only support ACC & GYRO.\n");
+ return -1;
+ }
+ return err;
+}
+
+int sensors_poll_context_t::pollEvents(sensors_event_t* data, int count)
+{
+ int nbEvents = 0;
+ int n = 0;
+
+ do {
+ // see if we have some leftover from the last poll()
+ for (int i=0 ; count && i<numSensorDrivers ; i++) {
+ SensorBase* const sensor(mSensors[i]);
+ if ((mPollFds[i].revents & POLLIN) || (sensor->hasPendingEvents())) {
+ int nb = sensor->readEvents(data, count);
+
+ if (data->type == SENSOR_TYPE_PEDOMETER) {
+ /* ALOGD("pollEvents pedometer buffer data[0]:%f data[1]:%f data[2]:%f data[3]:%f ",
+ data->data[0], data->data[1], data->data[2], data->data[3]); */
+ }
+ if (data->type == SENSOR_TYPE_SIGNIFICANT_MOTION) {
+ /* ALOGD("pollEvents significant buffer data[0]:%f ",
+ data->data[0]); */
+ }
+
+ if (nb < count) {
+ // no more data for this sensor
+ mPollFds[i].revents = 0;
+ }
+
+ for (int j=0;j<nb;j++)
+ {
+ if (data[j].type == SENSOR_TYPE_META_DATA)
+ data[j].meta_data.sensor += ID_OFFSET;
+ else
+ data[j].sensor += ID_OFFSET;
+ }
+
+ //if(nb < 0||nb > count)
+ // ALOGE("pollEvents count error nb:%d, count:%d, nbEvents:%d", nb, count, nbEvents);//for sensor NE debug
+ count -= nb;
+ nbEvents += nb;
+ data += nb;
+ //if(nb < 0||nb > count)
+ // ALOGE("pollEvents count error nb:%d, count:%d, nbEvents:%d", nb, count, nbEvents);//for sensor NE debug
+ }
+ }
+
+ if (count)
+ {
+ // we still have some room, so try to see if we can get
+ // some events immediately or just wait if we don't have
+ // anything to return
+ //ALOGE("poll() count %d\n", count);
+
+ n = poll(mPollFds, numFds, nbEvents ? 0 : -1);
+ if (n<0) {
+ int err;
+ err = errno;
+ ALOGE("poll() failed (%s)", strerror(errno));
+ return -err;
+ }
+ if (mPollFds[wake].revents & POLLIN) {
+ char msg;
+ int result = read(mPollFds[wake].fd, &msg, 1);
+ if (result < 0)
+ ALOGE("error reading from wake pipe (%s)", strerror(errno));
+ if(msg != WAKE_MESSAGE)
+ ALOGE("unknown message on wake queue (0x%02x)", int(msg));
+ mPollFds[wake].revents = 0;
+ }
+ }
+
+ // if we have events and space, go read them
+ } while (n && count);
+
+ return nbEvents;
+}
+
+/*****************************************************************************/
+
+static int poll__close(struct hw_device_t *dev)
+{
+ sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev;
+ if (ctx) {
+ delete ctx;
+ }
+ return 0;
+}
+
+static int poll__activate(struct sensors_poll_device_t *dev,
+ int handle, int enabled) {
+ sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev;
+ return ctx->activate(handle-ID_OFFSET, enabled);
+}
+
+static int poll__setDelay(struct sensors_poll_device_t *dev,
+ int handle, int64_t ns) {
+ sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev;
+ return ctx->setDelay(handle-ID_OFFSET, ns);
+}
+
+static int poll__poll(struct sensors_poll_device_t *dev,
+ sensors_event_t* data, int count) {
+ sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev;
+ return ctx->pollEvents(data, count);
+}
+
+static int poll__batch(struct sensors_poll_device_1 *dev,
+ int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs) {
+ sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev;
+ return ctx->batch(handle-ID_OFFSET, flags, samplingPeriodNs, maxBatchReportLatencyNs);
+}
+
+static int poll__flush(struct sensors_poll_device_1 *dev,
+ int handle) {
+ sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev;
+ return ctx->flush(handle-ID_OFFSET);
+}
+
+static int poll__getODR(struct sensors_poll_device_t *dev,
+ int handle, int *odr) {
+ sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev;
+ return ctx->getODR(handle-ID_OFFSET, odr);
+}
+
+/*****************************************************************************/
+
+int init_nusensors(sensors_poll_device_1_t** device)
+{
+ int status = -EINVAL;
+
+ dev = new sensors_poll_context_t();
+ memset(&dev->device, 0, sizeof(sensors_poll_device_1_t));
+
+ dev->device.activate = poll__activate;
+ dev->device.setDelay = poll__setDelay;
+ dev->device.poll = poll__poll;
+ dev->device.batch = poll__batch;
+ dev->device.flush = poll__flush;
+ dev->device.getODR = poll__getODR;
+ *device = &dev->device;
+ status = 0;
+ return status;
+}
diff --git a/src/navigation/sensor/sensor_hal/src/sensor_list_readme.txt b/src/navigation/sensor/sensor_hal/src/sensor_list_readme.txt
new file mode 100644
index 0000000..dc185be
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/sensor_list_readme.txt
@@ -0,0 +1,208 @@
+This document descript sensor attribute. It define the detail informations of sensor, as
+sensor_t struct define. You can use this information to compele your sensor hal customizaton file.
+alps/mtk/src/custom/&(project)/hal/sensors/sensor/hwmsen_custom.c file. You can add your project
+support sensor information to this file.
+struct sensor_t {
+ /* name of this sensors */
+ const char* name;
+ /* vendor of the hardware part */
+ const char* vendor;
+ /* version of the hardware part + driver. The value of this field is
+ * left to the implementation and doesn't have to be monotonicaly
+ * increasing.
+ */
+ int version;
+ /* handle that identifies this sensors. This handle is used to activate
+ * and deactivate this sensor. The value of the handle must be 8 bits
+ * in this version of the API.
+ */
+ int handle;
+ /* this sensor's type. */
+ int type;
+ /* maximaum range of this sensor's value in SI units */
+ float maxRange;
+ /* smallest difference between two values reported by this sensor */
+ float resolution;
+ /* rough estimate of this sensor's power consumption in mA */
+ float power;
+ /* reserved fields, must be zero */
+ void* reserved[9];
+};
+
+
+Now we support sensor type as follow (M-sensor will caluate the orientation sensor with G-sensor data):
+G-sensor: ADXL345,
+M-sensor: AMI304, Yamaha529
+ALS: CM3623
+PS: CM3623
+
+struct sensor_t AMI304_M
+ {
+ .name = "AMI304 3-axis Magnetic Field sensor",
+ .vendor = "Aichi Steel",
+ .version = 1,
+ .handle = ID_MAGNETIC,
+ .type = SENSOR_TYPE_MAGNETIC_FIELD,
+ .maxRange = 600.0f,
+ .resolution = 0.16667f,
+ .power = 0.25f,
+ .reserved = {}
+ };
+
+struct sensor_t AMI304_O
+{
+ .name = "AMI304 Orientation sensor",
+ .vendor = "Aichi Steel",
+ .version = 1,
+ .handle = ID_ORIENTATION,
+ .type = SENSOR_TYPE_ORIENTATION,
+ .maxRange = 360.0f,
+ .resolution = 0.9f,
+ .power = 0,
+ .reserved = {}
+ };
+
+struct sensor_t YAMAHA529_M
+ {
+ .name = "YAMAHA529 3-axis Magnetic Field sensor",
+ .vendor = "Yamaha",
+ .version = 1,
+ .handle = ID_MAGNETIC,
+ .type = SENSOR_TYPE_MAGNETIC_FIELD,
+ .maxRange = 300.0f,
+ .resolution = 0.6f,
+ .power = 4f,
+ .reserved = {}
+ };
+
+struct sensor_t YAMAHA529_O
+{
+ .name = "YAMAHA529 Orientation sensor",
+ .vendor = "Yamaha",
+ .version = 1,
+ .handle = ID_ORIENTATION,
+ .type = SENSOR_TYPE_ORIENTATION,
+ .maxRange = 360.0f,
+ .resolution = 1.0f,
+ .power = 0,
+ .reserved = {}
+ };
+
+struct sensor_t AKM8975_M
+ {
+ .name = "AKM8975 3-axis Magnetic Field sensor",
+ .vendor = "AKM",
+ .version = 1,
+ .handle = ID_MAGNETIC,
+ .type = SENSOR_TYPE_MAGNETIC_FIELD,
+ .maxRange = 1200.0f,
+ .resolution = 0.3f,
+ .power = 2f,
+ .reserved = {}
+ };
+
+struct sensor_t AKM8975_O
+{
+ .name = "AKM8975 Orientation sensor",
+ .vendor = "AKM",
+ .version = 1,
+ .handle = ID_ORIENTATION,
+ .type = SENSOR_TYPE_ORIENTATION,
+ .maxRange = 360.0f,
+ .resolution = 1.0f,
+ .power = 0,
+ .reserved = {}
+ };
+
+struct sensor_t MMC314X_M
+ {
+ .name = "MMC314X 3-axis Magnetic Field sensor",
+ .vendor = "Memsic",
+ .version = 1,
+ .handle = ID_MAGNETIC,
+ .type = SENSOR_TYPE_MAGNETIC_FIELD,
+ .maxRange = 400.0f,
+ .resolution = 0.195f,
+ .power = 0.55f,
+ .reserved = {}
+ };
+
+struct sensor_t MMC314X_O
+{
+ .name = "MMC314X Orientation sensor",
+ .vendor = "Memsic",
+ .version = 1,
+ .handle = ID_ORIENTATION,
+ .type = SENSOR_TYPE_ORIENTATION,
+ .maxRange = 360.0f,
+ .resolution = 1.0f,
+ .power = 0,
+ .reserved = {}
+ };
+
+
+
+struct sensor_t ADXL345_G
+ {
+ .name = "ADXL345 3-axis Accelerometer",
+ .vendor = "ADI",
+ .version = 1,
+ .handle = ID_ACCELEROMETER,
+ .type = SENSOR_TYPE_ACCELEROMETER,
+ .maxRange = 32.0f,
+ .resolution = 4.0f/1024.0f,
+ .power =130.0f/1000.0f,
+ .reserved = {}
+ };
+
+struct sensor_t BMA150_G
+ {
+ .name = "BMA150 3-axis Accelerometer",
+ .vendor = "BOSCH",
+ .version = 1,
+ .handle = ID_ACCELEROMETER,
+ .type = SENSOR_TYPE_ACCELEROMETER,
+ .maxRange = 39.22f,
+ .resolution = 4.0f/1024.0f,
+ .power =200.0f/1000.0f,
+ .reserved = {}
+ };
+
+struct sensor_t KXTF9_G
+ {
+ .name = "KXTF9 3-axis Accelerometer",
+ .vendor = "KIONIX",
+ .version = 1,
+ .handle = ID_ACCELEROMETER,
+ .type = SENSOR_TYPE_ACCELEROMETER,
+ .maxRange = 39.22f,
+ .resolution = 4.0f/4096.0f,
+ .power =750.0f/1000.0f,
+ .reserved = {}
+ };
+
+struct sensor_t CM3623_PS
+ {
+ .name = "CM3623 Proximity Sensor",
+ .vendor = "Capella",
+ .version = 1,
+ .handle = ID_PROXIMITY,
+ .type = SENSOR_TYPE_PROXIMITY,
+ .maxRange = 1.00f,
+ .resolution = 1.0f,
+ .power = 0.13f,
+ .reserved = {}
+ };
+
+struct sensor_t CM3623_ALS
+ {
+ .name = "CM3623 Light Sensor",
+ .vendor = "Capella",
+ .version = 1,
+ .handle = ID_LIGHT,
+ .type = SENSOR_TYPE_LIGHT,
+ .maxRange = 10240.0f,
+ .resolution = 1.0f,
+ .power = 0.13f,
+ .reserved = {}
+ },
\ No newline at end of file
diff --git a/src/navigation/sensor/sensor_hal/src/sensordebug.cpp b/src/navigation/sensor/sensor_hal/src/sensordebug.cpp
new file mode 100644
index 0000000..479f272
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/sensordebug.cpp
@@ -0,0 +1,286 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include "Hwmsen.h"
+#include "Acceleration.h"
+#include "Magnetic.h"
+#include "sensordebug.h"
+#include <string.h>
+
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "sensordebug"
+#endif
+
+/*****************************************************************************/
+unsigned int SensorDebugObject::SensorDebugBit=0;
+
+SensorBase* SensorDebugObject::mDebugsensorlist[3]={0,0,0};
+
+SensorDebugObject::SensorDebugObject(SensorBase* sensorbaseList, int sensor)
+ : m_G_active_log_path_id(0), m_MSENSOR_ACCURANCY(0), m_Mode_value(0),
+ m_Data_len(0), m_Is_old_m_driver(false), m_Is_old_g_driver(false), m_MAG_DATA(0)
+{
+ mDebugsensorlist[sensor] = sensorbaseList;
+ m_Is_old_m_driver = is_old_structure(2);//check where sensor data from
+ //m_Sensor_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+ pthread_mutex_init(&m_Sensor_mutex, NULL);
+
+ int ret = pthread_create(&mThread, NULL, sensors_debug, (void*)this);
+ if (ret) {
+ ALOGD( "Could not create thread for debug");
+ }
+ else
+ {
+ ALOGD("debug Thread is running and listening on ");
+ }
+ if (pthread_cond_init(&m_Sensor_event_cond, NULL))
+ {
+ ALOGD("debug Thread pthread_cond_init error ");
+ }
+
+
+ //{@init sensor log path
+ char p[20] ={SENSOR_LOG};
+ char q[20] ={SENSOR_LOG2};
+ strcpy(&m_Record_path[0][0],p);
+ strcpy(&m_Record_path[1][0],q);
+ //@}
+}
+
+
+SensorDebugObject::~SensorDebugObject() {
+
+}
+
+
+void SensorDebugObject::g_sensor_debug_func(){
+ //do gsensor debug operations
+}
+
+
+
+
+void SensorDebugObject::m_sensor_debug_func(){
+ sensors_event_t *tempdata;
+ sensors_event_t data;
+ int i=1;
+
+ if(m_Is_old_m_driver){
+ if(mDebugsensorlist[0] == 0){
+ ALOGE("mDebugsensorlist[0] 0 pointer");
+ return;
+ }
+ tempdata = ((Hwmsen*)mDebugsensorlist[0])->mPendingEvents;
+ data = *(tempdata+1);
+ }else{
+ if(mDebugsensorlist[2] == 0){
+ ALOGE("mDebugsensorlist[2] 0 pointer");
+ return;
+ }
+ tempdata = ((MagneticSensor*)mDebugsensorlist[2])->mPendingEvent;
+ data = *tempdata;
+ }
+
+ if(m_MSENSOR_ACCURANCY != data.magnetic.status)
+ {
+ float time = (float)((float)(data.timestamp)/(float)1000000000);
+ //ALOGD("M_ACC: %d, %.3f",data.magnetic.status,time);
+ //{@ write data to file
+ char buf[50];
+ int len = 0;
+ len = sprintf(buf,"M_ACC:%d,%.3f\n",data.magnetic.status,time);
+ //ALOGD("M_ACC len: %d",len);
+ write_sensor_log(buf,len);
+ //write data to file @}
+ m_MSENSOR_ACCURANCY = data.magnetic.status;
+ }
+
+ double x = 0,y = 0,z = 0, result = 0;
+ int mode_temp = 0;
+ x = (double)(data.magnetic.x);
+ y = (double)(data.magnetic.y);
+ z = (double)(data.magnetic.z);
+
+ x = pow(x,2);
+ y = pow(y,2);
+ z = pow(z,2);
+
+ result = x+y+z;
+ result = sqrt(result);
+ mode_temp =result;
+ if(abs(m_Mode_value-mode_temp)> 25)
+ {
+ float time = (float)((float)(data.timestamp)/(float)1000000000);
+ //ALOGD("M_DA: %.3f, %.3f",result,time);
+ //{@ write data to file
+ char buf[50];
+ int len = 0;
+ len = sprintf(buf,"M_DA:%.3f,%.3f\n",result,time);
+ //ALOGD("M_DA len: %d",len);
+ write_sensor_log(buf,len);
+ //write data to file @}
+ m_Mode_value = mode_temp;
+ }
+}
+
+void SensorDebugObject::write_sensor_log(char *buf,int len){
+ struct stat buffer = {0};
+ int fd = 0;
+ FILE* f1;
+
+ if(m_Data_len < TEMP_BUFFER_SIZE){
+ strcpy(&m_Data_buffer[m_Data_len], buf);
+ m_Data_len += len;
+ //ALOGD("%s: yucong data lenth:%d", __func__, m_Data_len);
+ }else{
+ //ALOGD("%s: begin data saving!", __func__);
+ //ALOGD("debug %s:!", m_Record_path[m_G_active_log_path_id]);
+ if((f1 = fopen(m_Record_path[m_G_active_log_path_id], "at+")) == NULL)
+ {
+ ALOGD("%s: open file: %s err!", __func__, SENSOR_LOG);
+ }
+ else
+ {
+ fwrite(&m_Data_buffer[0], sizeof(char), m_Data_len, f1);
+ fclose(f1);
+ }
+ m_Data_len = 0;
+
+ if((fd = open(m_Record_path[m_G_active_log_path_id], O_RDWR))<0){
+ ALOGD("%s: open file: %s err!", __func__, SENSOR_LOG);
+ return;
+ }
+ else
+ {
+ if(fstat(fd, &buffer)<0){
+ ALOGD("get file size error!");
+ }
+ ALOGD("file size: %lld", buffer.st_size);
+ close(fd);
+ }
+
+ if(buffer.st_size > MAX_RECORD_LEN)
+ {
+
+ ALOGD("size > MAX_RECORD_LEN!");
+ //recored in other file
+ m_G_active_log_path_id++;
+ if(2 == m_G_active_log_path_id)
+ {
+ m_G_active_log_path_id = 0;
+ }
+ ALOGD("m_G_active_log_path_id=%d",m_G_active_log_path_id);
+ ALOGD("going to record to %s ",m_Record_path[m_G_active_log_path_id]);
+ //clear the file we going to recored log
+ if((f1 = fopen(m_Record_path[m_G_active_log_path_id], "w+")) == NULL)
+ {
+ ALOGD("%s: open file: %s err!", __func__, SENSOR_LOG);
+ } else {
+ fclose(f1);
+ }
+
+ }
+ }
+}
+
+bool SensorDebugObject::is_old_structure(int sensor){
+ if(sensor == 1){
+ char input_sysfs_path[4096];
+ strcpy(input_sysfs_path, "/sys/class/misc/m_acc_misc/accactive");
+ int fd = 0;
+ fd = open(&input_sysfs_path[0], O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("old msensor driver will be used\r\n");
+ return true;
+ }
+ //ALOGD("new msensor driver will be used \r\n");
+ close(fd);
+ }
+
+ if(sensor == 2){
+ char input_sysfs_path[4096];
+ strcpy(input_sysfs_path, "/sys/class/misc/m_mag_misc/magactive");
+ int fd = 0;
+ fd = open(&input_sysfs_path[0], O_RDWR);
+ if(fd < 0)
+ {
+ ALOGD("old msensor driver will be used\r\n");
+ return true;
+ }
+ //ALOGD("new msensor driver will be used \r\n");
+ close(fd);
+ }
+
+ return false;
+}
+
+void SensorDebugObject::send_singnal(int i){
+ if((2 == i)||(0 == i))
+ {
+ pthread_mutex_lock(&m_Sensor_mutex);
+ if (pthread_cond_signal(&m_Sensor_event_cond))
+ {
+ ALOGE("%s: set signal error",__func__);
+ }
+ pthread_mutex_unlock(&m_Sensor_mutex);
+ //ALOGD("%s: set signal \r\n",__func__);
+ }
+}
+
+
+void * SensorDebugObject::sensors_debug(void *para){
+ SensorDebugObject *dev = (SensorDebugObject *) para;
+ while(1){
+ pthread_mutex_lock(&dev->m_Sensor_mutex);
+ if(pthread_cond_wait(&dev->m_Sensor_event_cond, &dev->m_Sensor_mutex))
+ {
+ ALOGD("%s: wait error\r\n",__func__);
+ }
+ pthread_mutex_unlock(&dev->m_Sensor_mutex);
+ //ALOGD("%s: begin debug \r\n",__func__);
+ dev->m_sensor_debug_func();
+ dev->g_sensor_debug_func();
+ }
+ return 0;
+}
+
diff --git a/src/navigation/sensor/sensor_hal/src/sensors.c b/src/navigation/sensor/sensor_hal/src/sensors.c
new file mode 100644
index 0000000..0e6a4b7
--- /dev/null
+++ b/src/navigation/sensor/sensor_hal/src/sensors.c
@@ -0,0 +1,1365 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2012. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include "sensors.h"
+#include "hwmsensor.h"
+//#include <hwmsen_chip_info.h>
+#include "nusensors.h"
+#include <string.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "Sensors_Init"
+#endif
+
+#include "hwmsen_custom.h"
+
+typedef enum SENSOR_NUM_DEF
+{
+ SONSER_UNSUPPORTED = -1,
+
+ #if defined(CONFIG_CUSTOM_KERNEL_ACCGYRO) || defined(CUSTOM_KERNEL_ACCELEROMETER)
+ ACCELEROMETER_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_MAGNETOMETER
+ MAGNETOMETER_NUM,
+ ORIENTATION_NUM ,
+ #endif
+
+ #if defined(CUSTOM_KERNEL_ALSPS) || defined(CUSTOM_KERNEL_ALS)
+ ALS_NUM,
+ #endif
+ #if defined(CUSTOM_KERNEL_ALSPS) || defined(CUSTOM_KERNEL_PS)
+ PS_NUM,
+ #endif
+
+ #if defined(CONFIG_CUSTOM_KERNEL_ACCGYRO) || defined(CUSTOM_KERNEL_GYROSCOPE)
+ GYROSCOPE_NUM,
+ #endif
+
+ #if defined(CONFIG_CUSTOM_KERNEL_ACCGYRO) || defined(CUSTOM_KERNEL_GYROSCOPE)
+ PRESSURE_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_TEMPERATURE
+ TEMPERATURE_NUM,
+ #endif
+ #ifdef CUSTOM_KERNEL_HUMIDITY
+ HUMIDITY_NUM,
+ #endif
+ #ifdef CUSTOM_KERNEL_STEP_COUNTER
+ STEP_COUNTER_NUM,
+ STEP_DETECTOR_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_SIGNIFICANT_MOTION_SENSOR
+ STEP_SIGNIFICANT_MOTION_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_PEDOMETER
+ PEDOMETER_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_IN_POCKET_SENSOR
+ IN_POCKET_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_ACTIVITY_SENSOR
+ ACTIVITY_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_PICK_UP_SENSOR
+ PICK_UP_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_FACE_DOWN_SENSOR
+ FACE_DOWN_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_SHAKE_SENSOR
+ SHAKE_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_HEART
+ HEART_RATE_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_TILT_DETECTOR_SENSOR
+ TILT_DETECTOR_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_WAKE_GESTURE_SENSOR
+ WAKE_GESTURE_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_GLANCE_GESTURE_SENSOR
+ GLANCE_GESTURE_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_GRV_SENSOR
+ GAME_ROTATION_VECTOR_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_GMRV_SENSOR
+ GEOMAGNETIC_ROTATION_VECTOR_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_RV_SENSOR
+ ROTATION_VECTOR_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_GRAVITY_SENSOR
+ GRAVITY_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_LINEARACCEL_SENSOR
+ LINEARACCEL_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_BRINGTOSEE_SENSOR
+ BRINGTOSEE_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_UNCALI_GYRO_SENSOR
+ UNCALI_GYRO_NUM,
+ #endif
+
+ #ifdef CUSTOM_KERNEL_UNCALI_MAG_SENSOR
+ UNCALI_MAG_NUM,
+ #endif
+#ifdef CUSTOM_KERNEL_ANSWER_CALL_SENSOR
+ ANSWER_CALL_NUM,
+#endif
+#ifdef CUSTOM_KERNEL_STATIONARY_SENSOR
+ STATIONARY_NUM,
+#endif
+ #ifdef CUSTOM_KERNEL_PDR_SENSOR
+ PDR_NUM,
+ #endif
+
+ SENSORS_NUM
+
+}SENSOR_NUM_DEF;
+
+#define MAX_NUM_SENSOR (SENSORS_NUM)
+
+
+/*--------------------------------------------------------*/
+#if defined(CONFIG_CUSTOM_KERNEL_ACCGYRO) || defined(CUSTOM_KERNEL_ACCELEROMETER)
+ #ifndef ACCELEROMETER
+ #define ACCELEROMETER "ACCELEROMETER"
+ #define ACCELEROMETER_VENDER "MTK"
+ #endif
+ #ifndef ACCELEROMETER_RANGE
+ #define ACCELEROMETER_RANGE 32.0f
+ #endif
+ #ifndef ACCELEROMETER_RESOLUTION
+ #define ACCELEROMETER_RESOLUTION 4.0f/1024.0f
+ #endif
+ #ifndef ACCELEROMETER_POWER
+ #define ACCELEROMETER_POWER 130.0f/1000.0f
+ #endif
+ #ifndef ACCELEROMETER_MINDELAY
+ #define ACCELEROMETER_MINDELAY 10000
+ #endif
+#endif
+
+#if defined(CUSTOM_KERNEL_ALSPS) || defined(CUSTOM_KERNEL_PS)
+ #ifndef PROXIMITY
+ #define PROXIMITY "PROXIMITY"
+ #define PROXIMITY_VENDER "MTK"
+ #endif
+ #ifndef PROXIMITY_RANGE
+ #define PROXIMITY_RANGE 1.00f
+ #endif
+ #ifndef PROXIMITY_RESOLUTION
+ #define PROXIMITY_RESOLUTION 1.0f
+ #endif
+ #ifndef PROXIMITY_POWER
+ #define PROXIMITY_POWER 0.13f
+ #endif
+ #ifndef PROXIMITY_MINDELAY
+ #define PROXIMITY_MINDELAY 0
+ #endif
+#endif
+#if defined(CUSTOM_KERNEL_ALSPS) || defined(CUSTOM_KERNEL_ALS)
+ #ifndef LIGHT
+ #define LIGHT "LIGHT"
+ #define LIGHT_VENDER "MTK"
+ #endif
+ #ifndef LIGHT_RANGE
+ #define LIGHT_RANGE 10240.0f
+ #endif
+ #ifndef LIGHT_RESOLUTION
+ #define LIGHT_RESOLUTION 1.0f
+ #endif
+ #ifndef LIGHT_POWER
+ #define LIGHT_POWER 0.13f
+ #endif
+ #ifndef LIGHT_MINDELAY
+ #define LIGHT_MINDELAY 0
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_MAGNETOMETER
+ #ifndef MAGNETOMETER
+ #define MAGNETOMETER "MAGNETOMETER"
+ #define MAGNETOMETER_VENDER "MTK"
+ #endif
+ #ifndef MAGNETOMETER_RANGE
+ #define MAGNETOMETER_RANGE 600.0f
+ #endif
+ #ifndef MAGNETOMETER_RESOLUTION
+ #define MAGNETOMETER_RESOLUTION 0.0016667f
+ #endif
+ #ifndef MAGNETOMETER_POWER
+ #define MAGNETOMETER_POWER 0.25f
+ #endif
+ #ifndef MAGNETOMETER_MINDELAY
+ #define MAGNETOMETER_MINDELAY 100000
+ #endif
+
+ #ifndef ORIENTATION
+ #define ORIENTATION "ORIENTATION"
+ #define ORIENTATION_VENDER "MTK"
+ #endif
+ #ifndef ORIENTATION_RANGE
+ #define ORIENTATION_RANGE 360.0f
+ #endif
+ #ifndef ORIENTATION_RESOLUTION
+ #define ORIENTATION_RESOLUTION 1.0f
+ #endif
+ #ifndef ORIENTATION_POWER
+ #define ORIENTATION_POWER 0.25f
+ #endif
+ #ifndef ORIENTATION_MINDELAY
+ #define ORIENTATION_MINDELAY 100000
+ #endif
+
+#endif
+#ifdef CUSTOM_KERNEL_UNCALI_MAG_SENSOR
+ #ifndef UNCALI_MAG
+ #define UNCALI_MAG "UNCALI_MAG"
+ #define UNCALI_MAG_VENDER "MTK"
+ #endif
+ #ifndef UNCALI_MAG_RANGE
+ #define UNCALI_MAG_RANGE 600.0f
+ #endif
+ #ifndef UNCALI_MAG_RESOLUTION
+ #define UNCALI_MAG_RESOLUTION 0.0016667f
+ #endif
+ #ifndef UNCALI_MAG_POWER
+ #define UNCALI_MAG_POWER 0.25f
+ #endif
+ #ifndef UNCALI_MAG_MINDELAY
+ #define UNCALI_MAG_MINDELAY 20000
+ #endif
+#endif
+
+#if defined(CONFIG_CUSTOM_KERNEL_ACCGYRO) || defined(CUSTOM_KERNEL_GYROSCOPE)
+ #ifndef GYROSCOPE
+ #define GYROSCOPE "GYROSCOPE"
+ #define GYROSCOPE_VENDER "MTK"
+ #endif
+ #ifndef GYROSCOPE_RANGE
+ #define GYROSCOPE_RANGE 34.91f
+ #endif
+ #ifndef GYROSCOPE_RESOLUTION
+ #define GYROSCOPE_RESOLUTION 0.0107f
+ #endif
+ #ifndef GYROSCOPE_POWER
+ #define GYROSCOPE_POWER 6.1f
+ #endif
+ #ifndef GYROSCOPE_MINDELAY
+ #define GYROSCOPE_MINDELAY 10000
+ #endif
+
+#endif
+
+#ifdef CUSTOM_KERNEL_UNCALI_GYRO_SENSOR
+ #ifndef UNCALI_GYRO
+ #define UNCALI_GYRO "UNCALI_GYRO"
+ #define UNCALI_GYRO_VENDER "MTK"
+ #endif
+ #ifndef UNCALI_GYRO_RANGE
+ #define UNCALI_GYRO_RANGE 34.91f
+ #endif
+ #ifndef UNCALI_GYRO_RESOLUTION
+ #define UNCALI_GYRO_RESOLUTION 0.0107f
+ #endif
+ #ifndef UNCALI_GYRO_POWER
+ #define UNCALI_GYRO_POWER 6.1f
+ #endif
+ #ifndef UNCALI_GYRO_MINDELAY
+ #define UNCALI_GYRO_MINDELAY 10000
+ #endif
+#endif
+
+#if defined(CUSTOM_KERNEL_BARO_TEMP) || defined(CUSTOM_KERNEL_BAROMETER)
+ #ifndef PRESSURE
+ #define PRESSURE "PRESSURE"
+ #define PRESSURE_VENDER "MTK"
+ #endif
+ #ifndef PRESSURE_RANGE
+ #define PRESSURE_RANGE 1100.0f
+ #endif
+ #ifndef PRESSURE_RESOLUTION
+ #define PRESSURE_RESOLUTION 100.0f
+ #endif
+ #ifndef PRESSURE_POWER
+ #define PRESSURE_POWER 0.5f
+ #endif
+ #ifndef PRESSURE_MINDELAY
+ #define PRESSURE_MINDELAY 200000
+ #endif
+#endif
+
+#if defined(CUSTOM_KERNEL_BARO_TEMP) || defined(CUSTOM_KERNEL_TEMPERATURE)
+ #ifndef TEMPERATURE
+ #define TEMPERATURE "TEMPERATURE"
+ #define TEMPERATURE_VENDER "MTK"
+ #endif
+ #ifndef TEMPERATURE_RANGE
+ #define TEMPERATURE_RANGE 85.0f
+ #endif
+ #ifndef TEMPERATURE_RESOLUTION
+ #define TEMPERATURE_RESOLUTION 0.1f
+ #endif
+ #ifndef TEMPERATURE_POWER
+ #define TEMPERATURE_POWER 0.5f
+ #endif
+#endif
+#ifdef CUSTOM_KERNEL_HUMIDITY
+ #ifndef HUMIDITY
+ #define HUMIDITY "HUMIDITY"
+ #define HUMIDITY_VENDER "MTK"
+ #endif
+ #ifndef HUMIDITY_RANGE
+ #define HUMIDITY_RANGE 85.0f
+ #endif
+ #ifndef HUMIDITY_RESOLUTION
+ #define HUMIDITY_RESOLUTION 0.1f
+ #endif
+ #ifndef HUMIDITY_POWER
+ #define HUMIDITY_POWER 0.5f
+ #endif
+ #ifndef HUMIDITY_MINDELAY
+ #define HUMIDITY_MINDELAY 200000
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_STEP_COUNTER
+ #ifndef STEP_COUNTER
+ #define STEP_COUNTER "STEP_COUNTER"
+ #define STEP_COUNTER_VENDER "MTK"
+
+ #define STEP_DETECTOR "STEP_DETECTOR"
+ #define STEP_DETECTOR_VENDER "MTK"
+ #endif
+ #ifndef STEP_COUNTER_RANGE
+ #define STEP_COUNTER_RANGE 85.0f
+ #define STEP_DETECTOR_RANGE 85.0f
+ #endif
+ #ifndef STEP_COUNTER_RESOLUTION
+ #define STEP_COUNTER_RESOLUTION 0.1f
+ #define STEP_DETECTOR_RESOLUTION 0.1f
+ #endif
+ #ifndef STEP_COUNTER_POWER
+ #define STEP_COUNTER_POWER 0.5f
+ #define STEP_DETECTOR_POWER 0.5f
+ #endif
+ #ifndef STEP_COUNTER_MINDELAY
+ #define STEP_COUNTER_MINDELAY 20000
+ #define STEP_DETECTOR_MINDELAY 20000
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_SIGNIFICANT_MOTION_SENSOR
+ #ifndef SIGNIFICANT_MOTION
+ #define SIGNIFICANT_MOTION "SIGNIFICANT_MOTION"
+ #define SIGNIFICANT_MOTION_VENDER "MTK"
+ #endif
+ #ifndef SIGNIFICANT_MOTION_RANGE
+ #define SIGNIFICANT_MOTION_RANGE 85.0f
+ #endif
+ #ifndef SIGNIFICANT_MOTION_RESOLUTION
+ #define SIGNIFICANT_MOTION_RESOLUTION 0.1f
+ #endif
+ #ifndef SIGNIFICANT_MOTION_POWER
+ #define SIGNIFICANT_MOTION_POWER 0.5f
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_IN_POCKET_SENSOR
+ #ifndef IN_POCKET
+ #define IN_POCKET "IN_POCKET"
+ #define IN_POCKET_VENDER "MTK"
+ #endif
+ #ifndef IN_POCKET_RANGE
+ #define IN_POCKET_RANGE 85.0f
+ #endif
+ #ifndef IN_POCKET_RESOLUTION
+ #define IN_POCKET_RESOLUTION 0.1f
+ #endif
+ #ifndef IN_POCKET_POWER
+ #define IN_POCKET_POWER 0.5f
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_PEDOMETER
+ #ifndef PEDOMETER
+ #define PEDOMETER "PEDOMETER"
+ #define PEDOMETER_VENDER "MTK"
+ #endif
+ #ifndef PEDOMETER_RANGE
+ #define PEDOMETER_RANGE 85.0f
+ #endif
+ #ifndef PEDOMETER_RESOLUTION
+ #define PEDOMETER_RESOLUTION 0.1f
+ #endif
+ #ifndef PEDOMETER_POWER
+ #define PEDOMETER_POWER 0.5f
+ #endif
+ #ifndef PEDOMETER_MINDELAY
+ #define PEDOMETER_MINDELAY 20000
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_ACTIVITY_SENSOR
+ #ifndef ACTIVITY
+ #define ACTIVITY "ACTIVITY"
+ #define ACTIVITY_VENDER "MTK"
+ #endif
+ #ifndef ACTIVITY_RANGE
+ #define ACTIVITY_RANGE 85.0f
+ #endif
+ #ifndef ACTIVITY_RESOLUTION
+ #define ACTIVITY_RESOLUTION 0.1f
+ #endif
+ #ifndef ACTIVITY_POWER
+ #define ACTIVITY_POWER 0.5f
+ #endif
+ #ifndef ACTIVITY_MINDELAY
+ #define ACTIVITY_MINDELAY 20000
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_SHAKE_SENSOR
+ #ifndef SHAKE
+ #define SHAKE "SHAKE"
+ #define SHAKE_VENDER "MTK"
+ #endif
+ #ifndef SHAKE_RANGE
+ #define SHAKE_RANGE 85.0f
+ #endif
+ #ifndef SHAKE_RESOLUTION
+ #define SHAKE_RESOLUTION 0.1f
+ #endif
+ #ifndef SHAKE_POWER
+ #define SHAKE_POWER 0.5f
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_PICK_UP_SENSOR
+ #ifndef PICK_UP
+ #define PICK_UP "PICK_UP"
+ #define PICK_UP_VENDER "MTK"
+ #endif
+ #ifndef PICK_UP_RANGE
+ #define PICK_UP_RANGE 85.0f
+ #endif
+ #ifndef PICK_UP_RESOLUTION
+ #define PICK_UP_RESOLUTION 0.1f
+ #endif
+ #ifndef PICK_UP_POWER
+ #define PICK_UP_POWER 0.5f
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_FACE_DOWN_SENSOR
+ #ifndef FACE_DOWN
+ #define FACE_DOWN "FACE_DOWN"
+ #define FACE_DOWN_VENDER "MTK"
+ #endif
+ #ifndef FACE_DOWN_RANGE
+ #define FACE_DOWN_RANGE 85.0f
+ #endif
+ #ifndef FACE_DOWN_RESOLUTION
+ #define FACE_DOWN_RESOLUTION 0.1f
+ #endif
+ #ifndef FACE_DOWN_POWER
+ #define FACE_DOWN_POWER 0.5f
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_HEART
+ #ifndef HEART_RATE
+ #define HEART_RATE "HEART_RATE"
+ #define HEART_RATE_VENDER "MTK"
+ #endif
+ #ifndef HEART_RATE_RANGE
+ #define HEART_RATE_RANGE 500.0f
+ #endif
+ #ifndef HEART_RATE_RESOLUTION
+ #define HEART_RATE_RESOLUTION 0.1f
+ #endif
+ #ifndef HEART_RATE_POWER
+ #define HEART_RATE_POWER 0.5f
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_TILT_DETECTOR_SENSOR
+ #ifndef TILT_DETECTOR
+ #define TILT_DETECTOR "TILT_DETECTOR"
+ #define TILT_DETECTOR_VENDER "MTK"
+ #endif
+ #ifndef TILT_DETECTOR_RANGE
+ #define TILT_DETECTOR_RANGE 100.0f
+ #endif
+ #ifndef TILT_DETECTOR_RESOLUTION
+ #define TILT_DETECTOR_RESOLUTION 0.1f
+ #endif
+ #ifndef TILT_DETECTOR_POWER
+ #define TILT_DETECTOR_POWER 0.5f
+ #endif
+ #ifndef TILT_DETECTOR_MINDELAY
+ #define TILT_DETECTOR_MINDELAY 20000
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_WAKE_GESTURE_SENSOR
+ #ifndef WAKE_GESTURE
+ #define WAKE_GESTURE "WAKE_GESTURE"
+ #define WAKE_GESTURE_VENDER "MTK"
+ #endif
+ #ifndef WAKE_GESTURE_RANGE
+ #define WAKE_GESTURE_RANGE 85.0f
+ #endif
+ #ifndef WAKE_GESTURE_RESOLUTION
+ #define WAKE_GESTURE_RESOLUTION 0.1f
+ #endif
+ #ifndef WAKE_GESTURE_POWER
+ #define WAKE_GESTURE_POWER 0.5f
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_GLANCE_GESTURE_SENSOR
+ #ifndef GLANCE_GESTURE
+ #define GLANCE_GESTURE "GLANCE_GESTURE"
+ #define GLANCE_GESTURE_VENDER "MTK"
+ #endif
+ #ifndef GLANCE_GESTURE_RANGE
+ #define GLANCE_GESTURE_RANGE 85.0f
+ #endif
+ #ifndef GLANCE_GESTURE_RESOLUTION
+ #define GLANCE_GESTURE_RESOLUTION 0.1f
+ #endif
+ #ifndef GLANCE_GESTURE_POWER
+ #define GLANCE_GESTURE_POWER 0.5f
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_GRV_SENSOR
+ #ifndef GAME_ROTATION_VECTOR
+ #define GAME_ROTATION_VECTOR "GAME ROTATION VECTOR"
+ #define GAME_ROTATION_VECTOR_VENDER "MTK"
+ #endif
+ #ifndef GAME_ROTATION_VECTOR_RANGE
+ #define GAME_ROTATION_VECTOR_RANGE 10240.0f
+ #endif
+ #ifndef GAME_ROTATION_VECTOR_RESOLUTION
+ #define GAME_ROTATION_VECTOR_RESOLUTION 1.0f
+ #endif
+ #ifndef GAME_ROTATION_VECTOR_POWER
+ #define GAME_ROTATION_VECTOR_POWER 0.5f
+ #endif
+ #ifndef GRV_MINDELAY
+ #define GRV_MINDELAY 20000
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_GMRV_SENSOR
+ #ifndef GEOMAGNETIC_ROTATION_VECTOR
+ #define GEOMAGNETIC_ROTATION_VECTOR "GEOMAGNETIC ROTATION VECTOR"
+ #define GEOMAGNETIC_ROTATION_VECTOR_VENDER "MTK"
+ #endif
+ #ifndef GEOMAGNETIC_ROTATION_VECTOR_RANGE
+ #define GEOMAGNETIC_ROTATION_VECTOR_RANGE 10240.0f
+ #endif
+ #ifndef GEOMAGNETIC_ROTATION_VECTOR_RESOLUTION
+ #define GEOMAGNETIC_ROTATION_VECTOR_RESOLUTION 1.0f
+ #endif
+ #ifndef GEOMAGNETIC_ROTATION_VECTOR_POWER
+ #define GEOMAGNETIC_ROTATION_VECTOR_POWER 0.5f
+ #endif
+ #ifndef GMRV_MINDELAY
+ #define GMRV_MINDELAY 20000
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_RV_SENSOR
+ #ifndef ROTATION_VECTOR
+ #define ROTATION_VECTOR "ROTATION VECTOR"
+ #define ROTATION_VECTOR_VENDER "MTK"
+ #endif
+ #ifndef ROTATION_VECTOR_RANGE
+ #define ROTATION_VECTOR_RANGE 10240.0f
+ #endif
+ #ifndef ROTATION_VECTOR_RESOLUTION
+ #define ROTATION_VECTOR_RESOLUTION 1.0f
+ #endif
+ #ifndef ROTATION_VECTOR_POWER
+ #define ROTATION_VECTOR_POWER 0.5f
+ #endif
+ #ifndef RV_MINDELAY
+ #define RV_MINDELAY 20000
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_GRAVITY_SENSOR
+ #ifndef GRAVITY
+ #define GRAVITY "GRAVITY"
+ #define GRAVITY_VENDER "MTK"
+ #endif
+ #ifndef GRAVITY_RANGE
+ #define GRAVITY_RANGE 10240.0f
+ #endif
+ #ifndef GRAVITY_RESOLUTION
+ #define GRAVITY_RESOLUTION 1.0f
+ #endif
+ #ifndef GRAVITY_POWER
+ #define GRAVITY_POWER 0.5f
+ #endif
+ #ifndef GRAVITY_MINDELAY
+ #define GRAVITY_MINDELAY 20000
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_LINEARACCEL_SENSOR
+ #ifndef LINEARACCEL
+ #define LINEARACCEL "LINEARACCEL"
+ #define LINEARACCEL_VENDER "MTK"
+ #endif
+ #ifndef LINEARACCEL_RANGE
+ #define LINEARACCEL_RANGE 10240.0f
+ #endif
+ #ifndef LINEARACCEL_RESOLUTION
+ #define LINEARACCEL_RESOLUTION 1.0f
+ #endif
+ #ifndef LINEARACCEL_POWER
+ #define LINEARACCEL_POWER 0.5f
+ #endif
+ #ifndef LINEARACCEL_MINDELAY
+ #define LINEARACCEL_MINDELAY 20000
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_BRINGTOSEE_SENSOR
+ #ifndef BRINGTOSEE
+ #define BRINGTOSEE "BRING TO SEE DETECTOR"
+ #define BRINGTOSEE_VENDER "MTK"
+ #endif
+ #ifndef BRINGTOSEE_RANGE
+ #define BRINGTOSEE_RANGE 10240.0f
+ #endif
+ #ifndef BRINGTOSEE_RESOLUTION
+ #define BRINGTOSEE_RESOLUTION 1.0f
+ #endif
+ #ifndef BRINGTOSEE_POWER
+ #define BRINGTOSEE_POWER 0.5f
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_ANSWER_CALL_SENSOR
+ #ifndef ANSWER_CALL
+ #define ANSWER_CALL "Answer Call Detector"
+ #define ANSWER_CALL_VENDER "MTK"
+ #endif
+ #ifndef ANSWER_CALL_RANGE
+ #define ANSWER_CALL_RANGE 10240.0f
+ #endif
+ #ifndef ANSWER_CALL_RESOLUTION
+ #define ANSWER_CALL_RESOLUTION 1.0f
+ #endif
+ #ifndef ANSWER_CALL_POWER
+ #define ANSWER_CALL_POWER 0.5f
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_STATIONARY_SENSOR
+ #ifndef STATIONARY_SENSOR
+ #define STATIONARY "STATIONARY"
+ #define STATIONARY_VENDER "MTK"
+ #endif
+ #ifndef STATIONARY_RANGE
+ #define STATIONARY_RANGE 85.0f
+ #endif
+ #ifndef STATIONARY_RESOLUTION
+ #define STATIONARY_RESOLUTION 0.1f
+ #endif
+ #ifndef STATIONARY_POWER
+ #define STATIONARY_POWER 0.5f
+ #endif
+#endif
+
+#ifdef CUSTOM_KERNEL_PDR_SENSOR
+ #ifndef PDR
+ #define PDR "PDR"
+ #define PDR_VENDER "MTK"
+ #endif
+ #ifndef PDR_RANGE
+ #define PDR_RANGE 10240.0f
+ #endif
+ #ifndef PDR_RESOLUTION
+ #define PDR_RESOLUTION 1.0f
+ #endif
+ #ifndef PDR_POWER
+ #define PDR_POWER 0.5f
+ #endif
+#endif
+/*--------------------------------------------------------*/
+
+struct sensor_t sSensorList[] =
+{
+#if defined(CONFIG_CUSTOM_KERNEL_ACCGYRO) || defined(CUSTOM_KERNEL_ACCELEROMETER)
+ {
+ .name = ACCELEROMETER,
+ .vendor = ACCELEROMETER_VENDER,
+ .version = 3,
+ .handle = ID_ACCELEROMETER+ID_OFFSET,
+ .type = SENSOR_TYPE_ACCELEROMETER,
+ .maxRange = ACCELEROMETER_RANGE,//32.0f,
+ .resolution = ACCELEROMETER_RESOLUTION,//4.0f/1024.0f,
+ .power = ACCELEROMETER_POWER,//130.0f/1000.0f,
+ .minDelay = ACCELEROMETER_MINDELAY,
+ .maxDelay = 1000000,
+ .reserved = {}
+ },
+#endif
+
+#if defined(CUSTOM_KERNEL_ALSPS) || defined(CUSTOM_KERNEL_PS)
+ {
+ .name = PROXIMITY,
+ .vendor = PROXIMITY_VENDER,
+ .version = 1,
+ .handle = ID_PROXIMITY+ID_OFFSET,
+ .type = SENSOR_TYPE_PROXIMITY,
+ .maxRange = PROXIMITY_RANGE,//1.00f,
+ .resolution = PROXIMITY_RESOLUTION,//1.0f,
+ .power = PROXIMITY_POWER,//0.13f,
+ .minDelay = PROXIMITY_MINDELAY,
+ .reserved = {}
+ },
+#endif
+#if defined(CUSTOM_KERNEL_ALSPS) || defined(CUSTOM_KERNEL_ALS)
+ {
+ .name = LIGHT,
+ .vendor = LIGHT_VENDER,
+ .version = 1,
+ .handle = ID_LIGHT+ID_OFFSET,
+ .type = SENSOR_TYPE_LIGHT,
+ .maxRange = LIGHT_RANGE,//10240.0f,
+ .resolution = LIGHT_RESOLUTION,//1.0f,
+ .power = LIGHT_POWER,//0.13f,
+ .minDelay = LIGHT_MINDELAY,
+ .reserved = {}
+ },
+#endif
+
+#if defined(CONFIG_CUSTOM_KERNEL_ACCGYRO) || defined(CUSTOM_KERNEL_GYROSCOPE)
+ {
+ .name = GYROSCOPE,
+ .vendor = GYROSCOPE_VENDER,
+ .version = 3,
+ .handle = ID_GYROSCOPE+ID_OFFSET,
+ .type = SENSOR_TYPE_GYROSCOPE,
+ .maxRange = GYROSCOPE_RANGE,//34.91f,
+ .resolution = GYROSCOPE_RESOLUTION,//0.0107f,
+ .power = GYROSCOPE_POWER,//6.1f,
+ .minDelay = GYROSCOPE_MINDELAY,
+ .maxDelay = 1000000,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_MAGNETOMETER
+ {
+ .name = ORIENTATION,
+ .vendor = ORIENTATION_VENDER,
+ .version = 3,
+ .handle = ID_ORIENTATION+ID_OFFSET,
+ .type = SENSOR_TYPE_ORIENTATION,
+ .maxRange = ORIENTATION_RANGE,//360.0f,
+ .resolution = ORIENTATION_RESOLUTION,//1.0f,
+ .power = ORIENTATION_POWER,//0.25f,
+ .minDelay = ORIENTATION_MINDELAY,
+ .maxDelay = 1000000,
+ .reserved = {}
+ },
+
+ {
+ .name = MAGNETOMETER,
+ .vendor = MAGNETOMETER_VENDER,
+ .version = 3,
+ .handle = ID_MAGNETIC+ID_OFFSET,
+ .type = SENSOR_TYPE_MAGNETIC_FIELD,
+ .maxRange = MAGNETOMETER_RANGE,//600.0f,
+ .resolution = MAGNETOMETER_RESOLUTION,//0.0016667f,
+ .power = MAGNETOMETER_POWER,//0.25f,
+ .minDelay = MAGNETOMETER_MINDELAY,
+ .maxDelay = 1000000,
+ .reserved = {}
+ },
+#endif
+
+#if defined(CUSTOM_KERNEL_BARO_TEMP) || defined(CUSTOM_KERNEL_BAROMETER)
+ {
+ .name = PRESSURE,
+ .vendor = PRESSURE_VENDER,
+ .version = 3,
+ .handle = ID_PRESSURE+ID_OFFSET,
+ .type = SENSOR_TYPE_PRESSURE,
+ .maxRange = PRESSURE_RANGE,//360.0f,
+ .resolution = PRESSURE_RESOLUTION,//1.0f,
+ .power = PRESSURE_POWER,//0.25f,
+ .minDelay = PRESSURE_MINDELAY,
+ .maxDelay = 1000000,
+ .reserved = {}
+ },
+#endif
+
+#if defined(CUSTOM_KERNEL_TEMPERATURE)
+ {
+ .name = TEMPERATURE,
+ .vendor = TEMPERATURE_VENDER,
+ .version = 1,
+ .handle = ID_TEMPERATURE+ID_OFFSET,
+ .type = SENSOR_TYPE_TEMPERATURE,
+ .maxRange = TEMPERATURE_RANGE,//600.0f,
+ .resolution = TEMPERATURE_RESOLUTION,//0.0016667f,
+ .power = TEMPERATURE_POWER,//0.25f,
+ .reserved = {}
+ },
+#endif
+#ifdef CUSTOM_KERNEL_HUMIDITY
+ {
+ .name = HUMIDITY,
+ .vendor = HUMIDITY_VENDER,
+ .version = 1,
+ .handle = ID_HUMIDITY+ID_OFFSET,
+ .type = SENSOR_TYPE_HUMIDITY,
+ .maxRange = HUMIDITY_RANGE, // 600.0f,
+ .resolution = HUMIDITY_RESOLUTION, // 0.0016667f,
+ .power = HUMIDITY_POWER, // 0.25f,
+ .minDelay = HUMIDITY_MINDELAY,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_STEP_COUNTER
+ {
+ .name = STEP_COUNTER,
+ .vendor = STEP_COUNTER_VENDER,
+ .version = 1,
+ .handle = ID_STEP_COUNTER+ID_OFFSET,
+ .type = SENSOR_TYPE_STEP_COUNTER,
+ .maxRange = STEP_COUNTER_RANGE,//600.0f,
+ .resolution = STEP_COUNTER_RESOLUTION,//0.0016667f,
+ .power = STEP_COUNTER_POWER,//0.25f,
+ .minDelay = STEP_COUNTER_MINDELAY,
+ .reserved = {}
+ },
+ {
+ .name = STEP_DETECTOR,
+ .vendor = STEP_DETECTOR_VENDER,
+ .version = 1,
+ .handle = ID_STEP_DETECTOR+ID_OFFSET,
+ .type = SENSOR_TYPE_STEP_DETECTOR,
+ .maxRange = STEP_DETECTOR_RANGE,//600.0f,
+ .resolution = STEP_DETECTOR_RESOLUTION,//0.0016667f,
+ .power = STEP_DETECTOR_POWER,//0.25f,
+ .minDelay = STEP_DETECTOR_MINDELAY,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_SIGNIFICANT_MOTION_SENSOR
+ {
+ .name = SIGNIFICANT_MOTION,
+ .vendor = SIGNIFICANT_MOTION_VENDER,
+ .version = 1,
+ .handle = ID_SIGNIFICANT_MOTION+ID_OFFSET,
+ .type = SENSOR_TYPE_SIGNIFICANT_MOTION,
+ .maxRange = SIGNIFICANT_MOTION_RANGE,//600.0f,
+ .resolution = SIGNIFICANT_MOTION_RESOLUTION,//0.0016667f,
+ .power = SIGNIFICANT_MOTION_POWER,//0.25f,
+ .minDelay = -1, //SENSOR_FLAG_ONE_SHOT_MODE
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_GRV_SENSOR
+ {
+ .name = GAME_ROTATION_VECTOR,
+ .vendor = GAME_ROTATION_VECTOR_VENDER,
+ .version = 1,
+ .handle = ID_GAME_ROTATION_VECTOR+ID_OFFSET,
+ .type = SENSOR_TYPE_GAME_ROTATION_VECTOR,
+ .maxRange = GAME_ROTATION_VECTOR_RANGE,
+ .resolution = GAME_ROTATION_VECTOR_RESOLUTION,
+ .power = GAME_ROTATION_VECTOR_POWER,
+ .minDelay = GRV_MINDELAY,
+
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_GMRV_SENSOR
+ {
+ .name = GEOMAGNETIC_ROTATION_VECTOR,
+ .vendor = GEOMAGNETIC_ROTATION_VECTOR_VENDER,
+ .version = 1,
+ .handle = ID_GEOMAGNETIC_ROTATION_VECTOR+ID_OFFSET,
+ .type = SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR,
+ .maxRange = GEOMAGNETIC_ROTATION_VECTOR_RANGE,
+ .resolution = GEOMAGNETIC_ROTATION_VECTOR_RESOLUTION,
+ .power = GEOMAGNETIC_ROTATION_VECTOR_POWER,
+ .minDelay = GMRV_MINDELAY,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_RV_SENSOR
+ {
+ .name = ROTATION_VECTOR,
+ .vendor = ROTATION_VECTOR_VENDER,
+ .version = 1,
+ .handle = ID_ROTATION_VECTOR+ID_OFFSET,
+ .type = SENSOR_TYPE_ROTATION_VECTOR,
+ .maxRange = ROTATION_VECTOR_RANGE,
+ .resolution = ROTATION_VECTOR_RESOLUTION,
+ .power = ROTATION_VECTOR_POWER,
+ .minDelay = RV_MINDELAY,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_GRAVITY_SENSOR
+ {
+ .name = GRAVITY,
+ .vendor = GRAVITY_VENDER,
+ .version = 1,
+ .handle = ID_GRAVITY+ID_OFFSET,
+ .type = SENSOR_TYPE_GRAVITY,
+ .maxRange = GRAVITY_RANGE,
+ .resolution = GRAVITY_RESOLUTION,
+ .power = GRAVITY_POWER,
+ .minDelay = GRAVITY_MINDELAY,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_LINEARACCEL_SENSOR
+ {
+ .name = LINEARACCEL,
+ .vendor = LINEARACCEL_VENDER,
+ .version = 1,
+ .handle = ID_LINEAR_ACCELERATION+ID_OFFSET,
+ .type = SENSOR_TYPE_LINEAR_ACCELERATION,
+ .maxRange = LINEARACCEL_RANGE,
+ .resolution = LINEARACCEL_RESOLUTION,
+ .power = LINEARACCEL_POWER,
+ .minDelay = LINEARACCEL_MINDELAY,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_HEART
+ {
+ .name = HEART_RATE,
+ .vendor = HEART_RATE_VENDER,
+ .version = 1,
+ .handle = ID_HEART_RATE+ID_OFFSET,
+ .type = SENSOR_TYPE_HEART_RATE,
+ .maxRange = HEART_RATE_RANGE,//600.0f,
+ .resolution = HEART_RATE_RESOLUTION,//0.0016667f,
+ .power = HEART_RATE_POWER,//0.25f,
+ .minDelay = 0,
+ .fifoReservedEventCount = 0,
+ .fifoMaxEventCount = 0,
+ .stringType = SENSOR_STRING_TYPE_HEART_RATE,
+ .requiredPermission = SENSOR_PERMISSION_BODY_SENSORS,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_BRINGTOSEE_SENSOR
+ {
+ .name = BRINGTOSEE,
+ .vendor = BRINGTOSEE_VENDER,
+ .version = 1,
+ .handle = ID_BRINGTOSEE+ID_OFFSET,
+ .type = SENSOR_TYPE_BRINGTOSEE,
+ .maxRange = BRINGTOSEE_RANGE,
+ .resolution = BRINGTOSEE_RESOLUTION,
+ .power = BRINGTOSEE_POWER,
+ .minDelay = 10000,
+ .fifoReservedEventCount = 0,
+ .fifoMaxEventCount = 64,
+ .stringType = SENSOR_STRING_TYPE_BRINGTOSEE,
+ //.requiredPermission = SENSOR_PERMISSION_BODY_SENSORS,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_IN_POCKET_SENSOR
+ {
+ .name = IN_POCKET,
+ .vendor = IN_POCKET_VENDER,
+ .version = 1,
+ .handle = ID_IN_POCKET+ID_OFFSET,
+ .type = SENSOR_TYPE_IN_POCKET,
+ .maxRange = IN_POCKET_RANGE,//600.0f,
+ .resolution = IN_POCKET_RESOLUTION,//0.0016667f,
+ .power = IN_POCKET_POWER,//0.25f,
+ .minDelay = -1, //SENSOR_FLAG_ONE_SHOT_MODE
+ .stringType = SENSOR_STRING_TYPE_IN_POCKET,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_PEDOMETER
+ {
+ .name = PEDOMETER,
+ .vendor = PEDOMETER_VENDER,
+ .version = 1,
+ .handle = ID_PEDOMETER+ID_OFFSET,
+ .type = SENSOR_TYPE_PEDOMETER,
+ .maxRange = PEDOMETER_RANGE,//600.0f,
+ .resolution = PEDOMETER_RESOLUTION,//0.0016667f,
+ .power = PEDOMETER_POWER,//0.25f,
+ .stringType = SENSOR_STRING_TYPE_PEDOMETER,
+ .minDelay = PEDOMETER_MINDELAY,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_ACTIVITY_SENSOR
+ {
+ .name = ACTIVITY,
+ .vendor = ACTIVITY_VENDER,
+ .version = 1,
+ .handle = ID_ACTIVITY+ID_OFFSET,
+ .type = SENSOR_TYPE_ACTIVITY,
+ .maxRange = ACTIVITY_RANGE,//600.0f,
+ .resolution = ACTIVITY_RESOLUTION,//0.0016667f,
+ .power = ACTIVITY_POWER,//0.25f,
+ .stringType = SENSOR_STRING_TYPE_ACTIVITY,
+ .minDelay = ACTIVITY_MINDELAY,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_SHAKE_SENSOR
+ {
+ .name = SHAKE,
+ .vendor = SHAKE_VENDER,
+ .version = 1,
+ .handle = ID_SHAKE+ID_OFFSET,
+ .type = SENSOR_TYPE_SHAKE,
+ .maxRange = SHAKE_RANGE,//600.0f,
+ .resolution = SHAKE_RESOLUTION,//0.0016667f,
+ .power = SHAKE_POWER,//0.25f,
+ .minDelay = -1, //SENSOR_FLAG_ONE_SHOT_MODE
+ .stringType = SENSOR_STRING_TYPE_SHAKE,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_PICK_UP_SENSOR
+ {
+ .name = PICK_UP,
+ .vendor = PICK_UP_VENDER,
+ .version = 1,
+ .handle = ID_PICK_UP_GESTURE+ID_OFFSET,
+ .type = SENSOR_TYPE_PICK_UP_GESTURE,
+ .maxRange = PICK_UP_RANGE,//600.0f,
+ .resolution = PICK_UP_RESOLUTION,//0.0016667f,
+ .power = PICK_UP_POWER,//0.25f,
+ .minDelay = -1, //SENSOR_FLAG_ONE_SHOT_MODE
+ .stringType = SENSOR_STRING_TYPE_PICK_UP_GESTURE,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_FACE_DOWN_SENSOR
+ {
+ .name = FACE_DOWN,
+ .vendor = FACE_DOWN_VENDER,
+ .version = 1,
+ .handle = ID_FACE_DOWN+ID_OFFSET,
+ .type = SENSOR_TYPE_FACE_DOWN,
+ .maxRange = FACE_DOWN_RANGE,//600.0f,
+ .resolution = FACE_DOWN_RESOLUTION,//0.0016667f,
+ .power = FACE_DOWN_POWER,//0.25f,
+ .minDelay = -1, //SENSOR_FLAG_ONE_SHOT_MODE
+ .stringType = SENSOR_STRING_TYPE_FACE_DOWN,
+ .reserved = {}
+ },
+#endif
+
+//#ifdef CUSTOM_KERNEL_HEART
+// {
+// .name = HEART_RATE,
+// .vendor = HEART_RATE_VENDER,
+// .version = 1,
+// .handle = ID_HEART_RATE+ID_OFFSET,
+// .type = SENSOR_TYPE_HEART_RATE,
+// .maxRange = HEART_RATE_RANGE,//600.0f,
+// .resolution = HEART_RATE_RESOLUTION,//0.0016667f,
+// .power = HEART_RATE_POWER,//0.25f,
+// .reserved = {}
+// },
+//#endif
+
+#ifdef CUSTOM_KERNEL_TILT_DETECTOR_SENSOR
+ {
+ .name = TILT_DETECTOR,
+ .vendor = TILT_DETECTOR_VENDER,
+ .version = 1,
+ .handle = ID_TILT_DETECTOR+ID_OFFSET,
+ .type = SENSOR_TYPE_TILT_DETECTOR,
+ .maxRange = TILT_DETECTOR_RANGE,//600.0f,
+ .resolution = TILT_DETECTOR_RESOLUTION,//0.0016667f,
+ .power = TILT_DETECTOR_POWER,//0.25f,
+ .minDelay = TILT_DETECTOR_MINDELAY,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_WAKE_GESTURE_SENSOR
+ {
+ .name = WAKE_GESTURE,
+ .vendor = WAKE_GESTURE_VENDER,
+ .version = 1,
+ .handle = ID_WAKE_GESTURE+ID_OFFSET,
+ .type = SENSOR_TYPE_WAKE_GESTURE,
+ .maxRange = WAKE_GESTURE_RANGE,//600.0f,
+ .resolution = WAKE_GESTURE_RESOLUTION,//0.0016667f,
+ .power = WAKE_GESTURE_POWER,//0.25f,
+ .minDelay = -1,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_GLANCE_GESTURE_SENSOR
+ {
+ .name = GLANCE_GESTURE,
+ .vendor = GLANCE_GESTURE_VENDER,
+ .version = 1,
+ .handle = ID_GLANCE_GESTURE+ID_OFFSET,
+ .type = SENSOR_TYPE_GLANCE_GESTURE,
+ .maxRange = GLANCE_GESTURE_RANGE, // 600.0f,
+ .resolution = GLANCE_GESTURE_RESOLUTION, // 0.0016667f,
+ .power = GLANCE_GESTURE_POWER, // 0.25f,
+ .minDelay = -1,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_PDR_SENSOR //??need commit
+ {
+ .name = PDR,
+ .vendor = PDR_VENDER,
+ .version = 3,
+ .handle = ID_PDR+ID_OFFSET,
+ .type = SENSOR_TYPE_PDR,
+ .maxRange = PDR_RANGE, // 600.0f,
+ .resolution = PDR_RESOLUTION, // 0.0016667f,
+ .power = PDR_POWER, // 0.25f,
+ .minDelay = 20000, //20ms
+ .stringType = SENSOR_STRING_TYPE_PDR,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_ANSWER_CALL_SENSOR
+ {
+ .name = ANSWER_CALL,
+ .vendor = ANSWER_CALL_VENDER,
+ .version = 3,
+ .handle = ID_ANSWER_CALL+ID_OFFSET,
+ .type = SENSOR_TYPE_ANSWER_CALL,
+ .maxRange = ANSWER_CALL_RANGE, // 600.0f,
+ .resolution = ANSWER_CALL_RESOLUTION, // 0.0016667f,
+ .power = ANSWER_CALL_POWER, // 0.25f,
+ .minDelay = -1, // SENSOR_FLAG_ONE_SHOT_MODE
+ .stringType = SENSOR_STRING_TYPE_ANSWERCALL,
+ .reserved = {}
+ },
+#endif
+
+
+#ifdef CUSTOM_KERNEL_UNCALI_GYRO_SENSOR
+ {
+ .name = UNCALI_GYRO,
+ .vendor = UNCALI_GYRO_VENDER,
+ .version = 3,
+ .handle = ID_GYROSCOPE_UNCALIBRATED+ID_OFFSET,
+ .type = SENSOR_TYPE_GYROSCOPE_UNCALIBRATED,
+ .maxRange = UNCALI_GYRO_RANGE, // 34.91f,
+ .resolution = UNCALI_GYRO_RESOLUTION, // 0.0107f,
+ .power = UNCALI_GYRO_POWER, // 6.1f,
+ .minDelay = UNCALI_GYRO_MINDELAY,
+ .maxDelay = 1000000,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_UNCALI_MAG_SENSOR
+ {
+ .name = UNCALI_MAG,
+ .vendor = UNCALI_MAG_VENDER,
+ .version = 3,
+ .handle = ID_MAGNETIC_UNCALIBRATED+ID_OFFSET,
+ .type = SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED,
+ .maxRange = UNCALI_MAG_RANGE, // 600.0f,
+ .resolution = UNCALI_MAG_RESOLUTION, // 0.0016667f,
+ .power = UNCALI_MAG_POWER, // 0.25f,
+ .minDelay = UNCALI_MAG_MINDELAY,
+ .maxDelay = 1000000,
+ .reserved = {}
+ },
+#endif
+
+#ifdef CUSTOM_KERNEL_STATIONARY_SENSOR
+ {
+ .name = STATIONARY,
+ .vendor = "MTK",
+ .version = 3,
+ .handle = ID_STATIONARY+ID_OFFSET,
+ .type = SENSOR_TYPE_STATIONARY,
+ .maxRange = STATIONARY_RANGE,
+ .resolution = STATIONARY_RESOLUTION,
+ .power = STATIONARY_POWER,
+ .minDelay = -1,
+ .stringType = SENSOR_STRING_TYPE_STATIONARY,
+ .reserved = {}
+ },
+#endif
+
+};
+
+/*****************************************************************************/
+
+/*
+ * The SENSORS Module
+ */
+
+/*
+ * the AK8973 has a 8-bit ADC but the firmware seems to average 16 samples,
+ * or at least makes its calibration on 12-bits values. This increases the
+ * resolution by 4 bits.
+ */
+
+//extern struct sensor_t sSensorList[MAX_NUM_SENSOR];
+
+
+int sensors__get_sensors_list(struct sensor_t const** list)
+{
+ // ALOGD(" sSensorList addr =%p, module addr =%p\r\n",sSensorList,module);
+ // ALOGD(" ARRAY_SIZE(sSensorList) =%d SENSORS_NUM=%d MAX_NUM_SENSOR=%d \r\n",ARRAY_SIZE(sSensorList), SENSORS_NUM, MAX_NUM_SENSOR);
+ *list = sSensorList;
+ return ARRAY_SIZE(sSensorList);
+
+}
+
+
+
+int sensor_open(sensors_poll_device_1_t** device)
+{
+ return init_nusensors(device);
+}
+
+void tag_log(int type, const char* tag, const char *fmt, ...)
+{
+ char out_buf[1100] = {0};
+ char buf[1024] = {0};
+ va_list ap;
+ int prio = 0;
+
+ va_start(ap, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+
+ sprintf(out_buf, "%s %s", tag, buf);
+
+ //char time_buf[64] = {0};
+ UNUSED(type);
+ UNUSED(prio);
+ //get_time_str(time_buf, sizeof(time_buf));
+ printf("%s\n", out_buf);
+ // printf("%s 0x%08x %s\n", time_buf, pthread_self(), out_buf);
+}
+#if 0
+int64_t get_time_stamp(char* time_str1, char* time_str2)
+{
+ struct tm *tm_pt;
+ time_t time_st;
+ struct timeval tv;
+ int64_t time_ns;
+
+ tm_pt = NULL;
+ time(&time_st);
+ gettimeofday(&tv, NULL);
+ tm_pt = gmtime(&time_st);
+ tm_pt = localtime((time_t *)&tv.tv_sec);
+ memset(time_str1, 0, sizeof(char) * 30);
+ memset(time_str2, 0, sizeof(char) * 30);
+ time_ns = tv.tv_sec * 1000000000LL + tv.tv_usec*1000LL;
+ if (tm_pt) {
+ sprintf(time_str1, "%d%02d%02d%02d%02d%02d.%01ld",
+ tm_pt->tm_year + 1900, tm_pt->tm_mon + 1, tm_pt->tm_mday,
+ tm_pt->tm_hour, tm_pt->tm_min, tm_pt->tm_sec, tv.tv_usec / 100000);
+ sprintf(time_str2, "%d%02d%02d%02d%02d%02d.%06ld",
+ tm_pt->tm_year+1900, tm_pt->tm_mon+1, tm_pt->tm_mday,
+ tm_pt->tm_hour, tm_pt->tm_min, tm_pt->tm_sec, tv.tv_usec);
+ }
+ ALOGD("time_str1=%s, time_str2=%s\n", time_str1, time_str2);
+ ALOGD("timeStamp: %lld, sec=%lld, usec=%lld\n", time_ns, tv.tv_sec, tv.tv_usec);
+ return time_ns;
+}
+#endif