OSDN Git Service

libsensors: Added support for Proximity sensor
authorArchana <archana.patni@linux.intel.com>
Tue, 11 Feb 2014 13:40:28 +0000 (08:40 -0500)
committerLilja, Ola <ola.lilja@intel.com>
Thu, 20 Feb 2014 12:04:36 +0000 (04:04 -0800)
This patch adds the HAL specific changes for Proximity Sensor.
This uses IIO model to communicate to kernel driver.

Change-Id: I1f34f1530b3182dc78d22bf486aa3600b0c7ec23
Signed-off-by: Archana Patni <archana.patni@intel.com>
Reviewed-on: https://android.intel.com/162360
Tested-by: sys_abtbuild <sys_abtbuild@intel.com>
Reviewed-by: Persson, Per <per.persson@intel.com>
Reviewed-by: Sesha, Subramony <subramony.sesha@intel.com>
Reviewed-by: Lilja, Ola <ola.lilja@intel.com>
HidSensor_Proximity.cpp [new file with mode: 0644]
HidSensor_Proximity.h [new file with mode: 0644]

diff --git a/HidSensor_Proximity.cpp b/HidSensor_Proximity.cpp
new file mode 100644 (file)
index 0000000..889059e
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2014 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 <cutils/log.h>
+
+#include "common.h"
+#include "SensorConfig.h"
+#include "HidSensor_Proximity.h"
+
+
+struct prox_sample{
+    unsigned short presence;
+} __packed;
+
+const struct sensor_t ProximitySensor::sSensorInfo_proximity = {
+    "HID_SENSOR Proximity", "Intel", 1, SENSORS_PROXIMITY_HANDLE, SENSOR_TYPE_PROXIMITY,
+        5.0f, 1.0f, 0.75f, 0, 0, 0, {}
+    ,
+};
+const int retry_cnt = 10;
+
+ProximitySensor::ProximitySensor(): SensorIIODev("prox", "in_proximity_scale", "in_proximity_offset", "in_proximity_", retry_cnt){
+    ALOGV(">>ProximitySensor 3D: constructor!");
+    mPendingEvent.version = sizeof(sensors_event_t);
+    mPendingEvent.sensor = ID_P;
+    mPendingEvent.type = SENSOR_TYPE_PROXIMITY;
+    memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
+
+    // CDD is silent on Proximity requirements.  Fix default at 2Hz pending
+    // better numbers from somewhere.
+     sample_delay_min_ms = 500;
+
+    ALOGV("<<ProximitySensor 3D: constructor!");
+}
+
+int ProximitySensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
+    struct prox_sample *sample;
+
+    ALOGV(">>%s", __func__);
+    if (IsDeviceInitialized() == false){
+        ALOGE("Device was not initialized \n");
+        return  - 1;
+    } if (raw_data_len < sizeof(struct prox_sample)){
+        ALOGE("Insufficient length \n");
+        return  - 1;
+    }
+    sample = (struct prox_sample*)raw_data;
+    if (sample->presence == 1)
+            mPendingEvent.distance = (float)0;
+    else
+            mPendingEvent.distance = (float)5;
+
+
+    ALOGE("Proximity %fm\n", mPendingEvent.distance);
+    ALOGV("<<%s", __func__);
+    return 0;
+}
diff --git a/HidSensor_Proximity.h b/HidSensor_Proximity.h
new file mode 100644 (file)
index 0000000..d10d2cd
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2014 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_Proximity_H
+#define HIDSENSOR_Proximity_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include "SensorIIODev.h"
+#include "Helpers.h"
+
+class ProximitySensor : public SensorIIODev {
+
+public:
+    ProximitySensor();
+    virtual int processEvent(unsigned char *raw_data, size_t raw_data_len);
+    static const struct sensor_t sSensorInfo_proximity;
+};
+
+#endif