OSDN Git Service

libsensors: Add orientation sensor
authorAndy Ross <andrew.j.ross@intel.com>
Mon, 4 Nov 2013 18:07:20 +0000 (10:07 -0800)
committerMattias Pettersson <mattias.pettersson@intel.com>
Wed, 4 Dec 2013 14:13:12 +0000 (15:13 +0100)
The sensor hub emits an euler-representation orientation which
correspond's closely to Google's SENSOR_ORIENTATION sensor type.  Use
this in lieu of the SensorFusion auto-generated one.  The API is
deprecated, but old apps might still use it and we want to provide
optimal data.

Issue: AXIA-4758
Change-Id: I7e0c2486ec8e49f1a6e42658295b7f265541022e
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Reviewed-on: https://otc-android.intel.com/gerrit/22522
Reviewed-by: Daniel Leung <daniel.leung@intel.com>
Tested-by: jenkins autobuilder
Works-for-me: jenkins autobuilder
Reviewed-by: Brian E Woodruff <brian.e.woodruff@intel.com>
Reviewed-by: Sridhar Uyyala <sridhar.uyyala@intel.com>
Reviewed-by: Robert Chiras <robert.chiras@intel.com>
bigcore/libsensors/Android.mk
bigcore/libsensors/BoardConfig.cpp
bigcore/libsensors/SensorConfig.h
common/libsensors/OrientationSensor.cpp [new file with mode: 0644]
common/libsensors/OrientationSensor.h [new file with mode: 0644]

index f1b8979..9ce8a58 100644 (file)
@@ -38,6 +38,7 @@ sensor_src_files := $(common_src_path)/HidSensor_Accel3D.cpp \
                    $(common_src_path)/HidSensor_ALS.cpp \
                    $(common_src_path)/RotVecSensor.cpp \
                    $(common_src_path)/SynthCompassSensor.cpp \
+                   $(common_src_path)/OrientationSensor.cpp \
 
 include external/stlport/libstlport.mk
 LOCAL_C_INCLUDES += $(LOCAL_PATH) device/intel/common/libsensors
index 31db853..881f19c 100644 (file)
@@ -28,6 +28,7 @@
 #include "HidSensor_Gyro3D.h"
 #include "HidSensor_Compass3D.h"
 #include "HidSensor_ALS.h"
+#include "OrientationSensor.h"
 #include "RotVecSensor.h"
 #include "SynthCompassSensor.h"
 
@@ -37,6 +38,7 @@ static const struct sensor_t sSensorList[] = {
     SynthCompassSensor::sSensorInfo_compass,
     ALSSensor::sSensorInfo_als,
     RotVecSensor::sSensorInfo_rotvec,
+    OrientationSensor::sSensorInfo_orientation,
 };
 
 const struct sensor_t* BoardConfig::sensorList()
@@ -99,6 +101,7 @@ void BoardConfig::initSensors(SensorBase* sensors[])
     sensors[light] = new ALSSensor();
     sensors[rotvec] = new RotVecSensor();
     sensors[syncompass] = new SynthCompassSensor();
+    sensors[orientation] = new OrientationSensor();
 }
 
 int BoardConfig::handleToDriver(int handle)
@@ -119,6 +122,8 @@ int BoardConfig::handleToDriver(int handle)
         return rotvec;
     case ID_SC:
         return syncompass;
+    case ID_O:
+        return orientation;
   default:
         return -EINVAL;
     }
index 6ff565e..ebf185a 100644 (file)
@@ -29,6 +29,7 @@ enum {
     light,
     rotvec,
     syncompass,
+    orientation,
     numSensorDrivers,
     numFds,
 };
diff --git a/common/libsensors/OrientationSensor.cpp b/common/libsensors/OrientationSensor.cpp
new file mode 100644 (file)
index 0000000..7ec83b2
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2013 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 <cutils/log.h>
+#include "common.h"
+#include "SensorConfig.h"
+#include "SynthCompassSensor.h"
+#include "OrientationSensor.h"
+
+const struct sensor_t OrientationSensor::sSensorInfo_orientation = {
+    .name       = "HID_SENSOR Orientation",
+    .vendor     = "Intel",
+    .version    = 1,
+    .handle     = SENSORS_ORIENTATION_HANDLE,
+    .type       = SENSOR_TYPE_ORIENTATION,
+    .maxRange   = 360.0,
+    .resolution = 1./512, // Advertise as 9 bits, no idea about reality
+    .power      = 0.1f,
+    .minDelay   = 0,
+    .reserved   = {},
+};
+
+OrientationSensor::OrientationSensor()
+    : SensorIIODev("incli_3d",  // name
+                   "in_incli_scale",  // units sysfs node
+                   "in_incli_offset", // exponent sysfs node
+                   "in_incli_",       // channel_prefix
+                   10)                // retry count
+{
+    mPendingEvent.version = sizeof(sensors_event_t);
+    mPendingEvent.sensor = ID_O;
+    mPendingEvent.type = SENSOR_TYPE_ORIENTATION;
+    memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
+
+    sample_delay_min_ms = 50; // 20Hz default
+}
+
+int OrientationSensor::processEvent(unsigned char *data, size_t len)
+{
+    if (IsDeviceInitialized() == false) {
+        ALOGE("Device was not initialized \n");
+        return -1;
+    }
+
+    if (len < 3*sizeof(unsigned int)) {
+        ALOGE("Insufficient length \n");
+        return -1;
+    }
+
+    float vals[3];
+    unsigned int *sample = (unsigned int*)data;
+    long ex = GetExponentValue();
+    for (int i=0; i<3; i++) {
+        int sz = GetChannelBytesUsedSize(i);
+        vals[i] = convert_from_vtf_format(sz, ex, sample[i]);
+    }
+
+    // When held in the Android convention frame (X to the right, Y
+    // toward "screen up", Z out from the screen toward the user) a
+    // windows sensor hub reports pitch/roll/yaw where Android wants
+    // hdg/pitch/roll.  And the sense of the rotations is reversed
+    // from what is observed on Nexus devices (which themselves seem
+    // to disagree with documentation on the sign of the output, see:
+    // http://developer.android.com/reference/android/hardware/SensorEvent.html#values).
+    //
+    // These conversions produce behavior identical to the Nexus 7,
+    // Galaxy Nexus and Google Edition GS4:
+    mPendingEvent.data[0] = 360.0 - vals[2];
+    mPendingEvent.data[1] = -vals[0];
+    mPendingEvent.data[2] = -vals[1];
+
+    ALOGV("orient %f %f %f\n", mPendingEvent.data[0], mPendingEvent.data[1], mPendingEvent.data[2]);
+
+    return 0;
+}
diff --git a/common/libsensors/OrientationSensor.h b/common/libsensors/OrientationSensor.h
new file mode 100644 (file)
index 0000000..67c9146
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2013 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 HIDSENSOR_ORIENTATION_H
+#define HIDSENSOR_ORIENTATION_H
+
+#include "SensorIIODev.h"
+
+class OrientationSensor : public SensorIIODev {
+
+public:
+    OrientationSensor();
+    virtual int processEvent(unsigned char *data, size_t len);
+
+    static const struct sensor_t sSensorInfo_orientation;
+};
+#endif