Merge "Adding pressure sensor plugin code modified for compatibility with IIO driver...
authorKibak Yoon <kibak.yoon@samsung.com>
Mon, 22 Sep 2014 04:55:27 +0000 (21:55 -0700)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Mon, 22 Sep 2014 04:55:27 +0000 (21:55 -0700)
sensor_plugins.xml.in
sensors.xml.in
src/libsensord/CMakeLists.txt
src/libsensord/sensor.h
src/libsensord/sensor_pressure.h [new file with mode: 0755]
src/pressure/CMakeLists.txt [new file with mode: 0755]
src/pressure/pressure_sensor.cpp [new file with mode: 0755]
src/pressure/pressure_sensor.h [new file with mode: 0755]
src/pressure/pressure_sensor_hal.cpp [new file with mode: 0755]
src/pressure/pressure_sensor_hal.h [new file with mode: 0755]

index fcaef6a..c00b2c0 100755 (executable)
@@ -5,6 +5,7 @@
                <MODULE path = "/usr/lib/sensord/libgeo_sensor_hal.so"/>
                <MODULE path = "/usr/lib/sensord/libproxi_sensor_hal.so"/>
                <MODULE path = "/usr/lib/sensord/liblight_sensor_hal.so"/>
+               <MODULE path = "/usr/lib/sensord/libpressure_sensor_hal.so"/>
        </HAL>
 
        <SENSOR>
@@ -13,6 +14,7 @@
                <MODULE path = "/usr/lib/sensord/libgeo_sensor.so"/>
                <MODULE path = "/usr/lib/sensord/libproxi_sensor.so"/>
                <MODULE path = "/usr/lib/sensord/liblight_sensor.so"/>
+               <MODULE path = "/usr/lib/sensord/libpressure_sensor.so"/>
                <MODULE path = "/usr/lib/sensord/libmotion_sensor.so"/>
                <MODULE path = "/usr/lib/sensord/liborientation_sensor.so"/>
                <MODULE path = "/usr/lib/sensord/libgravity_sensor.so"/>
index 6408101..c610e41 100755 (executable)
                        <TEMPERATURE_RESOLUTION value="0.002083"/>
                        <TEMPERATURE_OFFSET value="42.5"/>
                </MODEL>
+
+               <MODEL id="LPS331">
+                       <NAME value="LPS331"/>
+                       <VENDOR value="ST Microelectronics"/>
+                       <RAW_DATA_UNIT value="0.000244"/>
+                       <MIN_RANGE value="260"/>
+                       <MAX_RANGE value="1260"/>
+                       <RESOLUTION value="1"/>
+                       <TEMPERATURE_RESOLUTION value="0.002083"/>
+                       <TEMPERATURE_OFFSET value="42.5"/>
+               </MODEL>
        </PRESSURE>
 </SENSOR>
index a9534c9..5de0c38 100755 (executable)
@@ -62,6 +62,7 @@ install(FILES sensor_geomag.h DESTINATION include/sensor/)
 install(FILES sensor_light.h DESTINATION include/sensor/)
 install(FILES sensor_proxi.h DESTINATION include/sensor/)
 install(FILES sensor_gyro.h DESTINATION include/sensor/)
+install(FILES sensor_pressure.h DESTINATION include/sensor/)
 install(FILES sensor_gravity.h DESTINATION include/sensor/)
 install(FILES sensor_linear_accel.h DESTINATION include/sensor/)
 install(FILES sensor_orientation.h DESTINATION include/sensor/)
index 794a497..533a462 100755 (executable)
@@ -41,6 +41,7 @@ extern "C"
 #include <sensor_proxi.h>
 #include <sensor_motion.h>
 #include <sensor_gyro.h>
+#include <sensor_pressure.h>
 #include <sensor_gravity.h>
 #include <sensor_linear_accel.h>
 #include <sensor_orientation.h>
diff --git a/src/libsensord/sensor_pressure.h b/src/libsensord/sensor_pressure.h
new file mode 100755 (executable)
index 0000000..5a113ed
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * libsensord
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 __SENSOR_PRESSURE_H__
+#define __SENSOR_PRESSURE_H__
+
+//! Pre-defined events for the pressurescope sensor
+//! Sensor Plugin developer can add more event to their own headers
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * @defgroup SENSOR_PRESSURE pressure Sensor
+ * @ingroup SENSOR_FRAMEWORK
+ *
+ * These APIs are used to control the pressure sensor.
+ * @{
+ */
+
+enum pressure_data_id {
+       PRESSURE_BASE_DATA_SET          = (PRESSURE_SENSOR << 16) | 0x0001,
+};
+
+enum pressure_evet_type {
+       PRESSURE_EVENT_RAW_DATA_REPORT_ON_TIME          = (PRESSURE_SENSOR << 16) | 0x0001,
+};
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+//! End of a file
diff --git a/src/pressure/CMakeLists.txt b/src/pressure/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..b1984d0
--- /dev/null
@@ -0,0 +1,53 @@
+cmake_minimum_required(VERSION 2.6)
+project(pressure CXX)
+
+# to install pkgconfig setup file.
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(VERSION 1.0)
+
+SET(SENSOR_NAME pressure_sensor)
+SET(SENSOR_HAL_NAME pressure_sensor_hal)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
+
+include(FindPkgConfig)
+pkg_check_modules(rpkgs REQUIRED vconf)
+add_definitions(${rpkgs_CFLAGS} -DUSE_ONLY_ONE_MODULE)
+
+set(PROJECT_MAJOR_VERSION "0")
+set(PROJECT_MINOR_VERSION "0")
+set(PROJECT_RELEASE_VERSION "1")
+set(CMAKE_VERBOSE_MAKEFILE OFF)
+
+
+FIND_PROGRAM(UNAME NAMES uname)
+EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
+IF("${ARCH}" MATCHES "^arm.*")
+       ADD_DEFINITIONS("-DTARGET -DHWREV_CHECK")
+       MESSAGE("add -DTARGET -DHWREV_CHECK")
+ELSE("${ARCH}" MATCHES "^arm.*")
+       ADD_DEFINITIONS("-DSIMULATOR")
+       MESSAGE("add -DSIMULATOR")
+ENDIF("${ARCH}" MATCHES "^arm.*")
+
+add_definitions(-Wall -O3 -omit-frame-pointer)
+#add_definitions(-Wall -g -D_DEBUG)
+add_definitions(-DUSE_DLOG_LOG)
+add_definitions(-Iinclude)
+
+add_library(${SENSOR_NAME} SHARED
+               pressure_sensor.cpp
+               )
+
+add_library(${SENSOR_HAL_NAME} SHARED
+               pressure_sensor_hal.cpp
+               )
+
+target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm")
+target_link_libraries(${SENSOR_HAL_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS})
+
+install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord)
+install(TARGETS ${SENSOR_HAL_NAME} DESTINATION lib/sensord)
diff --git a/src/pressure/pressure_sensor.cpp b/src/pressure/pressure_sensor.cpp
new file mode 100755 (executable)
index 0000000..e13c3a4
--- /dev/null
@@ -0,0 +1,229 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 <common.h>
+#include <sf_common.h>
+
+#include <pressure_sensor.h>
+#include <sensor_plugin_loader.h>
+#include <algorithm>
+#include <cconfig.h>
+
+using config::CConfig;
+using std::bind1st;
+using std::mem_fun;
+
+#define SENSOR_NAME                            "PRESSURE_SENSOR"
+#define SENSOR_TYPE_PRESSURE   "PRESSURE"
+#define ELEMENT_NAME                   "NAME"
+#define ELEMENT_VENDOR                 "VENDOR"
+#define ELEMENT_TEMPERATURE_RESOLUTION "TEMPERATURE_RESOLUTION"
+#define ELEMENT_TEMPERATURE_OFFSET             "TEMPERATURE_OFFSET"
+#define ATTR_VALUE                             "value"
+
+#define SEA_LEVEL_RESOLUTION   0.01
+#define ALT_CONST1                             44330.0
+#define ALT_CONST2                             (1.0f/5.255f)
+
+pressure_sensor::pressure_sensor()
+: m_sensor_hal(NULL)
+, m_resolution(0.0f)
+{
+       m_name = string(SENSOR_NAME);
+
+       register_supported_event(PRESSURE_EVENT_RAW_DATA_REPORT_ON_TIME);
+
+       physical_sensor::set_poller(pressure_sensor::working, this);
+}
+
+pressure_sensor::~pressure_sensor()
+{
+       INFO("pressure_sensor is destroyed!");
+}
+
+bool pressure_sensor::init()
+{
+       m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(PRESSURE_SENSOR);
+
+       if (!m_sensor_hal)
+       {
+               ERR("cannot load sensor_hal[%s]", sensor_base::get_name());
+               return false;
+       }
+
+       sensor_properties_t properties;
+
+       if (m_sensor_hal->get_properties(properties) == false)
+       {
+               ERR("sensor->get_properties() is failed!\n");
+               return false;
+       }
+
+       m_resolution = properties.sensor_resolution;
+
+       string model_id = m_sensor_hal->get_model_id();
+
+       CConfig &config = CConfig::get_instance();
+
+       double temperature_resolution;
+
+       if (!config.get(SENSOR_TYPE_PRESSURE, model_id, ELEMENT_TEMPERATURE_RESOLUTION, temperature_resolution))
+       {
+               ERR("[TEMPERATURE_RESOLUTION] is empty\n");
+               throw ENXIO;
+       }
+
+       m_temperature_resolution = (float)temperature_resolution;
+       INFO("m_temperature_resolution = %f\n", m_temperature_resolution);
+
+       double temperature_offset;
+
+       if (!config.get(SENSOR_TYPE_PRESSURE, model_id, ELEMENT_TEMPERATURE_OFFSET, temperature_offset))
+       {
+               ERR("[TEMPERATURE_OFFSET] is empty\n");
+               throw ENXIO;
+       }
+
+       m_temperature_offset = (float)temperature_offset;
+       INFO("m_temperature_offset = %f\n", m_temperature_offset);
+
+       INFO("%s is created!", sensor_base::get_name());
+
+       return true;
+}
+
+sensor_type_t pressure_sensor::get_type(void)
+{
+       return PRESSURE_SENSOR;
+}
+
+bool pressure_sensor::working(void *inst)
+{
+       pressure_sensor *sensor = (pressure_sensor*)inst;
+       return sensor->process_event();
+}
+
+bool pressure_sensor::process_event(void)
+{
+       sensor_event_t event;
+       int pressure;
+
+       if (!m_sensor_hal->is_data_ready(true))
+               return true;
+
+       m_sensor_hal->get_sensor_data(event.data);
+
+       AUTOLOCK(m_client_info_mutex);
+
+       if (get_client_cnt(PRESSURE_EVENT_RAW_DATA_REPORT_ON_TIME))
+       {
+               event.event_type = PRESSURE_EVENT_RAW_DATA_REPORT_ON_TIME;
+               raw_to_base(event.data);
+               push(event);
+       }
+
+       return true;
+}
+
+bool pressure_sensor::on_start(void)
+{
+       if (!m_sensor_hal->enable())
+       {
+               ERR("m_sensor_hal start fail\n");
+               return false;
+       }
+
+       return start_poll();
+}
+
+bool pressure_sensor::on_stop(void)
+{
+       if (!m_sensor_hal->disable())
+       {
+               ERR("m_sensor_hal stop fail\n");
+               return false;
+       }
+
+       return stop_poll();
+}
+
+bool pressure_sensor::get_properties(const unsigned int type, sensor_properties_t &properties)
+{
+       return m_sensor_hal->get_properties(properties);
+}
+
+int pressure_sensor::get_sensor_data(const unsigned int type, sensor_data_t &data)
+{
+       int ret;
+
+       ret = m_sensor_hal->get_sensor_data(data);
+
+       if (ret < 0)
+               return -1;
+
+       if (type == PRESSURE_BASE_DATA_SET)
+       {
+               raw_to_base(data);
+               return 0;
+       }
+
+       return -1;
+}
+
+bool pressure_sensor::set_interval(unsigned long interval)
+{
+       AUTOLOCK(m_mutex);
+
+       INFO("Polling interval is set to %dms", interval);
+
+       return m_sensor_hal->set_interval(interval);
+}
+
+float pressure_sensor::pressure_to_altitude(float pressure)
+{
+       return ALT_CONST1 * (1.0f - pow(pressure/m_sea_level_pressure, ALT_CONST2));
+}
+
+void pressure_sensor::raw_to_base(sensor_data_t &data)
+{
+       m_sea_level_pressure = data.values[1] * SEA_LEVEL_RESOLUTION;
+       data.values[1] = pressure_to_altitude(data.values[0]);
+}
+
+extern "C" void *create(void)
+{
+       pressure_sensor *inst;
+
+       try
+       {
+               inst = new pressure_sensor();
+       }
+       catch (int err)
+       {
+               ERR("pressure_sensor class create fail , errno : %d , errstr : %s\n", err, strerror(err));
+               return NULL;
+       }
+
+       return (void*)inst;
+}
+
+extern "C" void destroy(void *inst)
+{
+       delete (pressure_sensor*)inst;;
+}
diff --git a/src/pressure/pressure_sensor.h b/src/pressure/pressure_sensor.h
new file mode 100755 (executable)
index 0000000..2124f6c
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 _PRESSURE_SENSOR_H_
+#define _PRESSURE_SENSOR_H_
+
+#include <sensor_common.h>
+
+#include <physical_sensor.h>
+#include <sensor_hal.h>
+
+class pressure_sensor : public physical_sensor
+{
+public:
+       pressure_sensor();
+       virtual ~pressure_sensor();
+
+       bool init();
+       sensor_type_t get_type(void);
+
+       static bool working(void *inst);
+
+       bool set_interval(unsigned long interval);
+       bool get_properties(const unsigned int type, sensor_properties_t &properties);
+       int get_sensor_data(const unsigned int type, sensor_data_t &data);
+
+private:
+       sensor_hal *m_sensor_hal;
+       float m_pressure;
+       float m_resolution;
+       float m_sea_level_pressure;
+       float m_temperature_offset;
+       float m_temperature_resolution;
+
+       virtual bool on_start(void);
+       virtual bool on_stop(void);
+       bool process_event(void);
+       float pressure_to_altitude(float pressure);
+       void raw_to_base(sensor_data_t &data);
+};
+
+#endif
diff --git a/src/pressure/pressure_sensor_hal.cpp b/src/pressure/pressure_sensor_hal.cpp
new file mode 100755 (executable)
index 0000000..37dc7ac
--- /dev/null
@@ -0,0 +1,392 @@
+/*
+ * pressure_sensor_hal
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 <sys/stat.h>
+#include <dirent.h>
+
+#include <linux/input.h>
+#include <cconfig.h>
+
+#include <pressure_sensor_hal.h>
+#include <sys/ioctl.h>
+#include <fstream>
+#include <cconfig.h>
+#include <iio_common.h>
+
+using std::ifstream;
+using config::CConfig;
+
+#define SENSOR_TYPE_PRESSURE   "PRESSURE"
+#define ELEMENT_NAME                   "NAME"
+#define ELEMENT_VENDOR                 "VENDOR"
+#define ELEMENT_RAW_DATA_UNIT  "RAW_DATA_UNIT"
+#define ELEMENT_MIN_RANGE              "MIN_RANGE"
+#define ELEMENT_MAX_RANGE              "MAX_RANGE"
+
+#define ENABLE_VAL                     true
+#define DISABLE_VAL                    false
+#define SEA_LEVEL_PRESSURE     101325.0
+#define NO_FLAG                                0
+#define TIMEOUT                                1
+
+pressure_sensor_hal::pressure_sensor_hal()
+: m_pressure(0)
+, m_temperature(0)
+, m_polling_interval(POLL_1HZ_MS)
+, m_fired_time(0)
+, m_sensorhub_supported(false)
+{
+       int fd, ret;
+       string file_name;
+
+       if (!check_hw_node())
+       {
+               ERR("check_hw_node() fail");
+               throw ENXIO;
+       }
+
+       CConfig &config = CConfig::get_instance();
+
+       if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_VENDOR, m_vendor))
+       {
+               ERR("[VENDOR] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_vendor = %s", m_vendor.c_str());
+
+       if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_NAME, m_chip_name))
+       {
+               ERR("[NAME] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_chip_name = %s", m_chip_name.c_str());
+
+       double min_range;
+
+       if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_MIN_RANGE, min_range))
+       {
+               ERR("[MIN_RANGE] is empty\n");
+               throw ENXIO;
+       }
+
+       m_min_range = (float)min_range;
+       INFO("m_min_range = %f\n",m_min_range);
+
+       double max_range;
+
+       if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_MAX_RANGE, max_range))
+       {
+               ERR("[MAX_RANGE] is empty\n");
+               throw ENXIO;
+       }
+
+       m_max_range = (float)max_range;
+       INFO("m_max_range = %f\n",m_max_range);
+
+       double raw_data_unit;
+
+       if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_RAW_DATA_UNIT, raw_data_unit))
+       {
+               ERR("[RAW_DATA_UNIT] is empty\n");
+               throw ENXIO;
+       }
+
+       m_raw_data_unit = (float)(raw_data_unit);
+       INFO("m_raw_data_unit = %f\n", m_raw_data_unit);
+
+       file_name = string(IIO_DIR) + m_pressure_dir + string(TEMP_SCALE);
+       if (!read_node_value<int>(file_name, m_temp_scale))
+               throw ENXIO;
+
+       file_name = string(IIO_DIR) + m_pressure_dir + string(TEMP_OFFSET);
+       if (!read_node_value<float>(file_name, m_temp_offset))
+               throw ENXIO;
+
+       file_name = string(IIO_DIR) + m_pressure_dir + string(PRESSURE_SCALE);
+       if (!read_node_value<int>(file_name, m_pressure_scale))
+               throw ENXIO;
+
+       INFO("Temperature scale:%d", m_temp_scale);
+       INFO("Temperature offset:%f", m_temp_offset);
+       INFO("Pressure scale:%d", m_pressure_scale);
+
+       fd = open(m_event_resource.c_str(), NO_FLAG);
+       if (fd == -1)
+       {
+               ERR("Could not open event resource");
+               throw ENXIO;
+       }
+
+       ret = ioctl(fd, IOCTL_IIO_EVENT_FD, &m_event_fd);
+
+       close(fd);
+
+       if ((ret == -1) || (m_event_fd == -1))
+       {
+               ERR("Failed to retrieve event fd");
+               throw ENXIO;
+       }
+
+       INFO("pressure_sensor_hal is created!\n");
+}
+
+pressure_sensor_hal::~pressure_sensor_hal()
+{
+       close(m_event_fd);
+       INFO("pressure_sensor_hal is destroyed!\n");
+}
+
+string pressure_sensor_hal::get_model_id(void)
+{
+       return m_model_id;
+}
+
+sensor_type_t pressure_sensor_hal::get_type(void)
+{
+       return PRESSURE_SENSOR;
+}
+
+bool pressure_sensor_hal::enable_resource(bool enable)
+{
+       update_sysfs_num(m_enable_resource.c_str(), enable);
+       return true;
+}
+
+bool pressure_sensor_hal::enable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       enable_resource(ENABLE_VAL);
+
+       m_fired_time = 0;
+       INFO("Pressure sensor real starting");
+       return true;
+}
+
+bool pressure_sensor_hal::disable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       enable_resource(DISABLE_VAL);
+
+       INFO("Pressure sensor real stopping");
+       return true;
+}
+
+bool pressure_sensor_hal::set_interval(unsigned long val)
+{
+       return true;
+}
+
+bool pressure_sensor_hal::update_value(bool wait)
+{
+       iio_event_t pressure_event;
+       fd_set readfds, exceptfds;
+       struct timeval tv;
+       int raw_pressure_count;
+       int raw_temp_count;
+       int ret;
+
+       FD_ZERO(&readfds);
+       FD_ZERO(&exceptfds);
+       FD_SET(m_event_fd, &readfds);
+       FD_SET(m_event_fd, &exceptfds);
+
+       if (wait)
+       {
+               tv.tv_sec = TIMEOUT;
+               tv.tv_usec = 0;
+       }
+       else
+       {
+               tv.tv_sec = 0;
+               tv.tv_usec = 0;
+       }
+
+       ret = select(m_event_fd + 1, &readfds, NULL, &exceptfds, &tv);
+
+       if (ret == -1)
+       {
+               ERR("select error:%s m_event_fd:d", strerror(errno), m_event_fd);
+               return false;
+       }
+       else if (!ret)
+       {
+               DBG("select timeout");
+               return false;
+       }
+
+       if (FD_ISSET(m_event_fd, &exceptfds))
+       {
+               ERR("select exception occurred!");
+               return false;
+       }
+
+       if (FD_ISSET(m_event_fd, &readfds))
+       {
+               INFO("pressure event detection!");
+               int len = read(m_event_fd, &pressure_event, sizeof(pressure_event));
+
+               if (len == -1)
+               {
+                       DBG("Error in read(m_event_fd):%s.", strerror(errno));
+                       return false;
+               }
+               m_fired_time = pressure_event.timestamp;
+               if (!read_node_value<int>(m_pressure_node, raw_pressure_count))
+                       return false;
+               if (!read_node_value<int>(m_temp_node, raw_temp_count))
+                       return false;
+               m_pressure = ((float)raw_pressure_count)/((float)m_pressure_scale);
+               m_temperature = m_temp_offset + ((float)raw_temp_count)/((float)m_temp_scale);
+       }
+       else
+       {
+               ERR("No pressure event data available to read");
+               return false;
+       }
+       return true;
+}
+
+bool pressure_sensor_hal::is_data_ready(bool wait)
+{
+       bool ret;
+       ret = update_value(wait);
+       return ret;
+}
+
+int pressure_sensor_hal::get_sensor_data(sensor_data_t &data)
+{
+       AUTOLOCK(m_value_mutex);
+       data.data_accuracy = SENSOR_ACCURACY_GOOD;
+       data.data_unit_idx = SENSOR_UNIT_HECTOPASCAL;
+       data.timestamp = m_fired_time ;
+       data.values_num = 3;
+       data.values[0] = m_pressure;
+       data.values[1] = SEA_LEVEL_PRESSURE;
+       data.values[2] = m_temperature;
+
+       return 0;
+}
+
+bool pressure_sensor_hal::get_properties(sensor_properties_t &properties)
+{
+       properties.sensor_unit_idx = SENSOR_UNIT_HECTOPASCAL;
+       properties.sensor_min_range = m_min_range;
+       properties.sensor_max_range = m_max_range;
+       snprintf(properties.sensor_name, sizeof(properties.sensor_name), "%s", m_chip_name.c_str());
+       snprintf(properties.sensor_vendor, sizeof(properties.sensor_vendor), "%s", m_vendor.c_str());
+       properties.sensor_resolution = m_raw_data_unit;
+       return true;
+}
+
+bool pressure_sensor_hal::is_sensorhub_supported(void)
+{
+       return false;
+}
+
+bool pressure_sensor_hal::check_hw_node(void)
+{
+       string name_node;
+       string hw_name;
+       string file_name;
+
+       DIR *main_dir = NULL;
+       struct dirent *dir_entry = NULL;
+       bool find_node = false;
+
+       INFO("======================start check_hw_node=============================\n");
+
+       m_sensorhub_supported = is_sensorhub_supported();
+
+       main_dir = opendir(IIO_DIR);
+
+       if (!main_dir)
+       {
+               ERR("Could not open IIO directory\n");
+               return false;
+       }
+
+       while (!find_node)
+       {
+               dir_entry = readdir(main_dir);
+               if(dir_entry == NULL)
+                       break;
+
+               if ((strncasecmp(dir_entry->d_name ,".",1 ) != 0) && (strncasecmp(dir_entry->d_name ,"..",2 ) != 0) && (dir_entry->d_ino != 0))
+               {
+                       file_name = string(IIO_DIR) + string(dir_entry->d_name) + string(NAME_NODE);
+
+                       ifstream infile(file_name.c_str());
+
+                       if (!infile)
+                               continue;
+
+                       infile >> hw_name;
+
+                       if (strncmp(dir_entry->d_name, IIO_DEV_BASE_NAME, IIO_DEV_STR_LEN) == 0)
+                       {
+                               if (CConfig::get_instance().is_supported(SENSOR_TYPE_PRESSURE, hw_name) == true)
+                               {
+                                       m_name = m_model_id = hw_name;
+                                       m_pressure_dir = string(dir_entry->d_name);
+                                       m_enable_resource = string(IIO_DIR) + m_pressure_dir + string(EVENT_DIR) + string(EVENT_EN_NODE);
+                                       m_event_resource = string(DEV_DIR) + m_pressure_dir;
+                                       m_pressure_node = string(IIO_DIR) + m_pressure_dir + string(PRESSURE_RAW);
+                                       m_temp_node = string(IIO_DIR) + m_pressure_dir + string(TEMP_RAW);
+
+                                       INFO("m_enable_resource = %s", m_enable_resource.c_str());
+                                       INFO("m_model_id = %s", m_model_id.c_str());
+                                       INFO("m_pressure_dir = %s", m_pressure_dir.c_str());
+                                       INFO("m_event_resource = %s", m_event_resource.c_str());
+
+                                       find_node = true;
+                                       break;
+                               }
+                       }
+               }
+       }
+
+       closedir(main_dir);
+       return find_node;
+}
+
+extern "C" void *create(void)
+{
+       pressure_sensor_hal *inst;
+
+       try
+       {
+               inst = new pressure_sensor_hal();
+       }
+       catch (int err)
+       {
+               ERR("pressure_sensor_hal class create fail , errno : %d , errstr : %s\n", err, strerror(err));
+               return NULL;
+       }
+
+       return (void*)inst;
+}
+
+extern "C" void destroy(void *inst)
+{
+       delete (pressure_sensor_hal*)inst;
+}
diff --git a/src/pressure/pressure_sensor_hal.h b/src/pressure/pressure_sensor_hal.h
new file mode 100755 (executable)
index 0000000..ca95085
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * pressure_sensor_hal
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 _PRESSURE_SENSOR_HAL_H_
+#define _PRESSURE_SENSOR_HAL_H_
+
+#include <sensor_hal.h>
+#include <string>
+#include <fstream>
+
+#define IIO_DIR                        "/sys/bus/iio/devices/"
+#define NAME_NODE              "/name"
+#define EVENT_DIR              "/events"
+#define EVENT_EN_NODE  "/in_pressure_mag_either_en"
+#define DEV_DIR                        "/dev/"
+#define PRESSURE_SCALE "/in_pressure_scale"
+#define PRESSURE_RAW   "/in_pressure_raw"
+#define TEMP_OFFSET            "/in_temp_offset"
+#define TEMP_SCALE             "/in_temp_scale"
+#define TEMP_RAW               "/in_temp_raw"
+
+#define IIO_DEV_BASE_NAME      "iio:device"
+#define IIO_DEV_STR_LEN                10
+
+using std::string;
+using std::ifstream;
+
+class pressure_sensor_hal : public sensor_hal
+{
+public:
+       pressure_sensor_hal();
+       virtual ~pressure_sensor_hal();
+       string get_model_id(void);
+       sensor_type_t get_type(void);
+
+       bool enable(void);
+       bool disable(void);
+       bool set_interval(unsigned long val);
+       bool is_data_ready(bool wait);
+       virtual int get_sensor_data(sensor_data_t &data);
+       bool get_properties(sensor_properties_t &properties);
+
+private:
+       string m_model_id;
+       string m_name;
+       string m_vendor;
+       string m_chip_name;
+
+       int m_pressure_scale;
+       float m_pressure;
+
+       int m_temp_scale;
+       float m_temp_offset;
+       float m_temperature;
+
+       float m_min_range;
+       float m_max_range;
+       float m_raw_data_unit;
+
+       unsigned long m_polling_interval;
+
+       unsigned long long m_fired_time;
+       int m_event_fd;
+
+       string m_pressure_dir;
+       string m_pressure_node;
+       string m_temp_node;
+       string m_event_resource;
+       string m_enable_resource;
+
+       cmutex m_value_mutex;
+
+       bool m_sensorhub_supported;
+
+       bool check_hw_node(void);
+       bool update_value(bool wait);
+       bool enable_resource(bool enable);
+       bool is_sensorhub_supported(void);
+
+       template <typename value_t>
+       bool read_node_value(string node_path, value_t &value)
+       {
+               ifstream handle;
+               handle.open(node_path.c_str());
+               if (!handle)
+               {
+                       ERR("Failed to open handle(%s)", node_path.c_str());
+                       return false;
+               }
+               handle >> value;
+               handle.close();
+
+               return true;
+       }
+};
+#endif /*_PRESSURE_SENSOR_HAL_CLASS_H_*/