OSDN Git Service

libsensors: Added support for Pressure sensor
authorArchana <archana.patni@linux.intel.com>
Tue, 11 Feb 2014 10:25:27 +0000 (05:25 -0500)
committerLilja, Ola <ola.lilja@intel.com>
Thu, 20 Feb 2014 12:04:08 +0000 (04:04 -0800)
This patch adds the HAL specific changes for Pressure Sensor.
This uses IIO model to communicate to kernel driver.
This exposes pressure data in hPa format.

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

diff --git a/HidSensor_Pressure.cpp b/HidSensor_Pressure.cpp
new file mode 100644 (file)
index 0000000..d0ef12c
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * 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_Pressure.h"
+
+#define CHANNEL_PR 0
+
+/* TODO: POWERCONSUMP_PRESS, PRESS_MINDELAY replace or fill that macros */
+#define POWERCONSUMP_PRESS      0.11f
+#define PRESS_MINDELAY         0
+#define RANGE_PRESS                 1260
+#define RESOLUTION_PRESS        0.0f
+
+struct pressure_sample{
+    unsigned int pressure_s; /* TODO: check type: too short? */
+} __packed;
+
+const struct sensor_t PressureSensor::sSensorInfo_pressure = {
+    "HID_SENSOR Barometer Sensor", "Intel", 1, SENSORS_PRESSURE_HANDLE,
+        SENSOR_TYPE_PRESSURE, RANGE_PRESS, RESOLUTION_PRESS, POWERCONSUMP_PRESS, PRESS_MINDELAY,0,0,{}
+};
+
+const long HID_USAGE_SENSOR_UNITS_PASCAL = 0xF1E1;
+const long UNIT_EXPO_DEC_BASE = 0x0F;
+const int retry_cnt = 5;
+
+
+PressureSensor::PressureSensor(): SensorIIODev("press", "in_pressure_scale", "in_pressure_offset", "in_pressure_", retry_cnt){
+    ALOGV(">>PressureSensor 3D: constructor!");
+    mPendingEvent.version = sizeof(sensors_event_t);
+    mPendingEvent.sensor = ID_PR;
+    mPendingEvent.type = SENSOR_TYPE_PRESSURE;
+    memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
+    sample_delay_min_ms = 500;
+    ALOGV("<<PressureSensor 3D: constructor!");
+}
+
+int PressureSensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
+    struct pressure_sample *sample;
+
+    ALOGV(">>%s", __func__);
+    if (IsDeviceInitialized() == false){
+        ALOGE("Device was not initialized \n");
+        return  - 1;
+    } if (raw_data_len < sizeof(struct pressure_sample)){
+        ALOGE("Insufficient length \n");
+        return  - 1;
+    }
+    sample = (struct pressure_sample*)raw_data;
+    ALOGV("Pressure:%2x",  sample->pressure_s);
+
+    mPendingEvent.data[0] = mPendingEvent.pressure =
+               CONVERT_PR_HPA_VTF16E14(GetChannelBytesUsedSize(CHANNEL_PR), GetExponentValue(), sample->pressure_s);
+
+    ALOGV("PRESSURE Sample %f(hPa=Pa/100)\n", mPendingEvent.pressure);
+    ALOGV("<<%s", __func__);
+    return 0;
+}
diff --git a/HidSensor_Pressure.h b/HidSensor_Pressure.h
new file mode 100644 (file)
index 0000000..79080f3
--- /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_PRESSURE_H
+#define HIDSENSOR_PRESSURE_H
+
+#include <stdint.h>
+#include <errno.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include "SensorIIODev.h"
+#include "Helpers.h"
+
+class PressureSensor : public SensorIIODev {
+
+public:
+    PressureSensor();
+    virtual int processEvent(unsigned char *raw_data, size_t raw_data_len);
+    static const struct sensor_t sSensorInfo_pressure;
+};
+
+#endif