sensor-hal: rename interface of HAL for managing it easily
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 3 Feb 2016 07:47:57 +0000 (16:47 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 3 Feb 2016 07:47:57 +0000 (16:47 +0900)
Change-Id: Icc2327a0c7a34e45560abb9b5ddf94eec9a2758c
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
17 files changed:
src/CMakeLists.txt
src/hal_module_create.cpp.in [deleted file]
src/interface/sensor_device_base.cpp [new file with mode: 0644]
src/interface/sensor_device_base.h [new file with mode: 0644]
src/interface/sensor_hal.h
src/interface/sensor_hal_base.cpp [deleted file]
src/interface/sensor_hal_base.h [deleted file]
src/lib/sensor_common.h
src/plugins/accel/accel_sensor_device.cpp [new file with mode: 0755]
src/plugins/accel/accel_sensor_device.h [new file with mode: 0755]
src/plugins/accel/accel_sensor_hal.cpp [deleted file]
src/plugins/accel/accel_sensor_hal.h [deleted file]
src/plugins/proxi/proxi_sensor_device.cpp [new file with mode: 0644]
src/plugins/proxi/proxi_sensor_device.h [new file with mode: 0755]
src/plugins/proxi/proxi_sensor_hal.cpp [deleted file]
src/plugins/proxi/proxi_sensor_hal.h [deleted file]
src/sensor_device_create.cpp.in [new file with mode: 0644]

index dfa75cf7d7f64bd5997b0ebcff59e24553c098cc..29eb9a6df53ed002287c0781e5ea21a0dcebe16c 100644 (file)
@@ -20,64 +20,64 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 
 IF("${ACCEL}" STREQUAL "ON")
 include_directories(${CMAKE_SOURCE_DIR}/src/plugins/accel)
-list (APPEND SRCS "plugins/accel/accel_sensor_hal.cpp")
+list (APPEND SRCS "plugins/accel/accel_sensor_device.cpp")
 add_definitions(-DENABLE_ACCEL)
 ENDIF()
 IF("${GYRO}" STREQUAL "ON")
 include_directories(${CMAKE_SOURCE_DIR}/src/plugins/gyro)
-list (APPEND SRCS "plugins/gyro/gyro_sensor_hal.cpp")
+list (APPEND SRCS "plugins/gyro/gyro_sensor_device.cpp")
 add_definitions(-DENABLE_GYRO)
 ENDIF()
 IF("${PROXI}" STREQUAL "ON")
 include_directories(${CMAKE_SOURCE_DIR}/src/plugins/proxi)
-list (APPEND SRCS "plugins/proxi/proxi_sensor_hal.cpp")
+list (APPEND SRCS "plugins/proxi/proxi_sensor_device.cpp")
 add_definitions(-DENABLE_PROXI)
 ENDIF()
 IF("${LIGHT}" STREQUAL "ON")
 include_directories(${CMAKE_SOURCE_DIR}/src/plugins/light)
-list (APPEND SRCS "plugins/light/light_sensor_hal.cpp")
+list (APPEND SRCS "plugins/light/light_sensor_device.cpp")
 add_definitions(-DENABLE_LIGHT)
 ENDIF()
 IF("${GEO}" STREQUAL "ON")
 include_directories(${CMAKE_SOURCE_DIR}/src/plugins/geo)
-list (APPEND SRCS "plugins/geo/geo_sensor_hal.cpp")
+list (APPEND SRCS "plugins/geo/geo_sensor_device.cpp")
 add_definitions(-DENABLE_GEO)
 ENDIF()
 IF("${PRESSURE}" STREQUAL "ON")
 include_directories(${CMAKE_SOURCE_DIR}/src/plugins/pressure)
-list (APPEND SRCS "plugins/pressure/pressure_sensor_hal.cpp")
+list (APPEND SRCS "plugins/pressure/pressure_sensor_device.cpp")
 add_definitions(-DENABLE_PRESSURE)
 ENDIF()
 IF("${TEMPERATURE}" STREQUAL "ON")
 include_directories(${CMAKE_SOURCE_DIR}/src/plugins/temperature)
-list (APPEND SRCS "plugins/temperature/temperature_sensor_hal.cpp")
+list (APPEND SRCS "plugins/temperature/temperature_sensor_device.cpp")
 add_definitions(-DENABLE_TEMPERATURE)
 ENDIF()
 IF("${ULTRAVIOLET}" STREQUAL "ON")
 include_directories(${CMAKE_SOURCE_DIR}/src/plugins/ultraviolet)
-list (APPEND SRCS "plugins/ultraviolet/ultraviolet_sensor_hal.cpp")
+list (APPEND SRCS "plugins/ultraviolet/ultraviolet_sensor_device.cpp")
 add_definitions(-DENABLE_ULTRAVIOLET)
 ENDIF()
 IF("${BIO_LED_RED}" STREQUAL "ON")
 include_directories(${CMAKE_SOURCE_DIR}/src/plugins/bio_led_red)
-list (APPEND SRCS "plugins/bio_led_red/bio_led_red_sensor_hal.cpp")
+list (APPEND SRCS "plugins/bio_led_red/bio_led_red_sensor_device.cpp")
 add_definitions(-DENABLE_BIO_LED_RED)
 ENDIF()
 IF("${RV}" STREQUAL "ON")
 include_directories(${CMAKE_SOURCE_DIR}/src/plugins/rotation_vector/rv_raw)
-list (APPEND SRCS "plugins/rotation_vector/rv_raw/rv_raw_sensor_hal.cpp")
+list (APPEND SRCS "plugins/rotation_vector/rv_raw/rv_raw_sensor_device.cpp")
 add_definitions(-DENABLE_RV_RAW)
 ENDIF()
 
-configure_file(hal_module_create.cpp.in hal_module_create.cpp)
+configure_file(sensor_device_create.cpp.in sensor_device_create.cpp)
 
 add_library(${PROJECT_NAME} SHARED
        ${SRCS}
        lib/cconfig.cpp
        lib/sensor_logs.cpp
-       interface/sensor_hal_base.cpp
+       interface/sensor_device_base.cpp
        interface/sensor_hal.h
-       hal_module_create.cpp
+       sensor_device_create.cpp
 )
 
 target_link_libraries(${PROJECT_NAME} ${plugin_pkgs_LDFLAGS})
diff --git a/src/hal_module_create.cpp.in b/src/hal_module_create.cpp.in
deleted file mode 100644 (file)
index 14a04b2..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-#ifdef ENABLE_ACCEL
-#include <accel_sensor_hal.h>
-#endif
-#ifdef ENABLE_BIO_LED_RED
-#include <bio_led_red_sensor_hal.h>
-#endif
-#ifdef ENABLE_GEO
-#include <geo_sensor_hal.h>
-#endif
-#ifdef ENABLE_GYRO
-#include <gyro_sensor_hal.h>
-#endif
-#ifdef ENABLE_LIGHT
-#include <light_sensor_hal.h>
-#endif
-#ifdef ENABLE_PRESSURE
-#include <pressure_sensor_hal.h>
-#endif
-#ifdef ENABLE_PROXI
-#include <proxi_sensor_hal.h>
-#endif
-#ifdef ENABLE_RV_RAW
-#include <rv_raw_sensor_hal.h>
-#endif
-#ifdef ENABLE_TEMPERATURE
-#include <temperature_sensor_hal.h>
-#endif
-#ifdef ENABLE_ULTRAVIOLET
-#include <ultraviolet_sensor_hal.h>
-#endif
-
-#include <sensor_common.h>
-
-extern "C" sensor_module* create(void)
-{
-       sensor_module *module = new(std::nothrow) sensor_module;
-       retvm_if(!module, NULL, "Failed to allocate memory");
-
-#ifdef ENABLE_ACCEL
-       accel_sensor_hal *accel_sensor = NULL;
-       try {
-               accel_sensor = new(std::nothrow) accel_sensor_hal;
-       } catch (int err) {
-               ERR("Failed to create accel_sensor_hal module, err: %d, cause: %s", err, strerror(err));
-       }
-
-       if (accel_sensor != NULL) {
-               module->sensors.push_back(accel_sensor);
-       }
-#endif
-
-#ifdef ENABLE_BIO_LED_RED
-       bio_led_red_sensor_hal *bio_led_red_sensor = NULL;
-       try {
-               bio_led_red_sensor = new(std::nothrow) bio_led_red_sensor_hal;
-       } catch (int err) {
-               ERR("Failed to create bio_led_red_sensor_hal module, err: %d, cause: %s", err, strerror(err));
-       }
-       if (bio_led_red_sensor != NULL)
-               module->sensors.push_back(bio_led_red_sensor);
-#endif
-
-#ifdef ENABLE_GEO
-       geo_sensor_hal *geo_sensor = NULL;
-       try {
-               geo_sensor = new(std::nothrow) geo_sensor_hal;
-       } catch (int err) {
-               ERR("Failed to create geo_sensor_hal module, err: %d, cause: %s", err, strerror(err));
-       }
-       if (geo_sensor != NULL)
-               module->sensors.push_back(geo_sensor);
-#endif
-
-#ifdef ENABLE_GYRO
-       gyro_sensor_hal *gyro_sensor = NULL;
-       try {
-               gyro_sensor = new(std::nothrow) gyro_sensor_hal;
-       } catch (int err) {
-               ERR("Failed to create gyro_sensor_hal module, err: %d, cause: %s", err, strerror(err));
-       }
-       if (gyro_sensor != NULL)
-               module->sensors.push_back(gyro_sensor);
-#endif
-
-#ifdef ENABLE_LIGHT
-       light_sensor_hal *light_sensor = NULL;
-       try {
-               light_sensor = new(std::nothrow) light_sensor_hal;
-       } catch (int err) {
-               ERR("Failed to create light_sensor_hal module, err: %d, cause: %s", err, strerror(err));
-       }
-       if (light_sensor != NULL)
-               module->sensors.push_back(light_sensor);
-#endif
-
-#ifdef ENABLE_PRESSURE
-       pressure_sensor_hal *pressure_sensor = NULL;
-       try {
-               pressure_sensor = new(std::nothrow) pressure_sensor_hal;
-       } catch (int err) {
-               ERR("Failed to create pressure_sensor_hal module, err: %d, cause: %s", err, strerror(err));
-       }
-       if (pressure_sensor != NULL)
-               module->sensors.push_back(pressure_sensor);
-#endif
-
-#ifdef ENABLE_PROXI
-       proxi_sensor_hal *proxi_sensor = NULL;
-       try {
-               proxi_sensor = new(std::nothrow) proxi_sensor_hal;
-       } catch (int err) {
-               ERR("Failed to create proxi_sensor_hal module, err: %d, cause: %s", err, strerror(err));
-       }
-       if (proxi_sensor != NULL)
-               module->sensors.push_back(proxi_sensor);
-#endif
-
-#ifdef ENABLE_RV_RAW
-       rv_raw_sensor_hal *rv_raw_sensor = NULL;
-       try {
-               rv_raw_sensor = new(std::nothrow) rv_raw_sensor_hal;
-       } catch (int err) {
-               ERR("Failed to create rv_raw_sensor_hal module, err: %d, cause: %s", err, strerror(err));
-       }
-       if (rv_raw_sensor != NULL)
-               module->sensors.push_back(rv_raw_sensor);
-#endif
-
-#ifdef ENABLE_TEMPERATURE
-       temperature_sensor_hal *temperature_sensor = NULL;
-       try {
-               temperature_sensor = new(std::nothrow) temperature_sensor_hal;
-       } catch (int err) {
-               ERR("Failed to create temperature_sensor_hal module, err: %d, cause: %s", err, strerror(err));
-       }
-       if (temperature_sensor != NULL)
-               module->sensors.push_back(temperature_sensor);
-#endif
-
-#ifdef ENABLE_ULTRAVIOLET
-       ultraviolet_sensor_hal *ultraviolet_sensor = NULL;
-       try {
-               ultraviolet_sensor = new(std::nothrow) ultraviolet_sensor_hal;
-       } catch (int err) {
-               ERR("Failed to create ultraviolet_sensor_hal module, err: %d, cause: %s", err, strerror(err));
-       }
-       if (ultraviolet_sensor != NULL)
-               module->sensors.push_back(ultraviolet_sensor);
-#endif
-
-       return module;
-}
diff --git a/src/interface/sensor_device_base.cpp b/src/interface/sensor_device_base.cpp
new file mode 100644 (file)
index 0000000..0c4f3fe
--- /dev/null
@@ -0,0 +1,317 @@
+/*
+ * libsensord-share
+ *
+ * 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 <sensor_device_base.h>
+#include <dirent.h>
+#include <string.h>
+#include <fstream>
+
+using std::ifstream;
+using std::ofstream;
+using std::fstream;
+using std::string;
+
+sensor_device_base::sensor_device_base()
+{
+}
+
+sensor_device_base::~sensor_device_base()
+{
+}
+
+unsigned long long sensor_device_base::get_timestamp(void)
+{
+       struct timespec t;
+       clock_gettime(CLOCK_MONOTONIC, &t);
+       return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000;
+}
+
+unsigned long long sensor_device_base::get_timestamp(timeval *t)
+{
+       if (!t) {
+               ERR("t is NULL");
+               return 0;
+       }
+
+       return ((unsigned long long)(t->tv_sec)*1000000LL +t->tv_usec);
+}
+
+bool sensor_device_base::is_sensorhub_controlled(const string &key)
+{
+       string key_node = string("/sys/class/sensors/ssp_sensor/") + key;
+
+       if (access(key_node.c_str(), F_OK) == 0)
+               return true;
+
+       return false;
+}
+
+bool sensor_device_base::get_node_info(const node_info_query &query, node_info &info)
+{
+       bool ret = false;
+       int method;
+       string device_num;
+
+       if (!get_input_method(query.key, method, device_num)) {
+               ERR("Failed to get input method for %s", query.key.c_str());
+               return false;
+       }
+
+       info.method = method;
+
+       if (method == IIO_METHOD) {
+               if (query.sensorhub_controlled)
+                       ret = get_sensorhub_iio_node_info(query.sensorhub_interval_node_name, device_num, info);
+               else
+                       ret = get_iio_node_info(query.iio_enable_node_name, device_num, info);
+       } else {
+               if (query.sensorhub_controlled)
+                       ret = get_sensorhub_input_event_node_info(query.sensorhub_interval_node_name, device_num, info);
+               else
+                       ret = get_input_event_node_info(device_num, info);
+       }
+
+       return ret;
+}
+
+
+void sensor_device_base::show_node_info(node_info &info)
+{
+       if (info.data_node_path.size())
+               INFO("Data node: %s", info.data_node_path.c_str());
+       if (info.enable_node_path.size())
+               INFO("Enable node: %s", info.enable_node_path.c_str());
+       if (info.interval_node_path.size())
+               INFO("Interval node: %s", info.interval_node_path.c_str());
+       if (info.buffer_enable_node_path.size())
+               INFO("Buffer enable node: %s", info.buffer_enable_node_path.c_str());
+       if (info.buffer_length_node_path.size())
+               INFO("Buffer length node: %s", info.buffer_length_node_path.c_str());
+       if (info.trigger_node_path.size())
+               INFO("Trigger node: %s", info.trigger_node_path.c_str());
+}
+
+bool sensor_device_base::get_iio_node_info(const string& enable_node_name, const string& device_num, node_info &info)
+{
+       const string base_dir = string("/sys/bus/iio/devices/iio:device") + device_num + string("/");
+
+       info.data_node_path = string("/dev/iio:device") + device_num;
+       info.enable_node_path = base_dir + enable_node_name;
+       info.interval_node_path = base_dir + string("sampling_frequency");
+       info.buffer_enable_node_path = base_dir + string("buffer/enable");
+       info.buffer_length_node_path = base_dir + string("buffer/length");
+       info.trigger_node_path = base_dir + string("trigger/current_trigger");
+
+       return true;
+}
+
+bool sensor_device_base::get_sensorhub_iio_node_info(const string &interval_node_name, const string& device_num, node_info &info)
+{
+       const string base_dir = string("/sys/bus/iio/devices/iio:device") + device_num + string("/");
+       const string hub_dir = "/sys/class/sensors/ssp_sensor/";
+
+       info.data_node_path = string("/dev/iio:device") + device_num;
+       info.enable_node_path = hub_dir + string("enable");
+       info.interval_node_path = hub_dir + interval_node_name;
+       info.buffer_enable_node_path = base_dir + string("buffer/enable");
+       info.buffer_length_node_path = base_dir + string("buffer/length");
+       return true;
+}
+
+bool sensor_device_base::get_input_event_node_info(const string& device_num, node_info &info)
+{
+       string base_dir;
+       string event_num;
+
+       base_dir = string("/sys/class/input/input") + device_num + string("/");
+
+       if (!get_event_num(base_dir, event_num))
+               return false;
+
+       info.data_node_path = string("/dev/input/event") + event_num;
+
+       info.enable_node_path = base_dir + string("enable");
+       info.interval_node_path = base_dir + string("poll_delay");
+       return true;
+}
+
+bool sensor_device_base::get_sensorhub_input_event_node_info(const string &interval_node_name, const string& device_num, node_info &info)
+{
+       const string base_dir = "/sys/class/sensors/ssp_sensor/";
+       string event_num;
+
+       string input_dir = string("/sys/class/input/input") + device_num + string("/");
+
+       if (!get_event_num(input_dir, event_num))
+               return false;
+
+       info.data_node_path = string("/dev/input/event") + event_num;
+       info.enable_node_path = base_dir + string("enable");
+       info.interval_node_path = base_dir + interval_node_name;
+       return true;
+}
+
+bool sensor_device_base::set_node_value(const string &node_path, int value)
+{
+       ofstream node(node_path, ofstream::binary);
+
+       if (!node)
+               return false;
+
+       node << value;
+
+       return true;
+}
+
+bool sensor_device_base::set_node_value(const string &node_path, unsigned long long value)
+{
+       ofstream node(node_path, ofstream::binary);
+
+       if (!node)
+               return false;
+
+       node << value;
+
+       return true;
+}
+
+
+bool sensor_device_base::get_node_value(const string &node_path, int &value)
+{
+       ifstream node(node_path, ifstream::binary);
+
+       if (!node)
+               return false;
+
+       node >> value;
+
+       return true;
+}
+
+bool sensor_device_base::set_enable_node(const string &node_path, bool sensorhub_controlled, bool enable, int enable_bit)
+{
+       int prev_status, status;
+
+       if (!get_node_value(node_path, prev_status)) {
+               ERR("Failed to get node: %s", node_path.c_str());
+               return false;
+       }
+
+       int _enable_bit = sensorhub_controlled ? enable_bit : 0;
+
+       if (enable)
+               status = prev_status | (1 << _enable_bit);
+       else
+               status = prev_status & (~(1 << _enable_bit));
+
+       if (!set_node_value(node_path, status)) {
+               ERR("Failed to set node: %s", node_path.c_str());
+               return false;
+       }
+
+       return true;
+}
+
+bool sensor_device_base::get_event_num(const string &input_path, string &event_num)
+{
+       const string event_prefix = "event";
+       DIR *dir = NULL;
+       struct dirent *dir_entry = NULL;
+       string node_name;
+       bool find = false;
+
+       dir = opendir(input_path.c_str());
+       if (!dir) {
+               ERR("Failed to open dir: %s", input_path.c_str());
+               return false;
+       }
+
+       int prefix_size = event_prefix.size();
+
+       while (!find && (dir_entry = readdir(dir))) {
+               node_name = dir_entry->d_name;
+
+               if (node_name.compare(0, prefix_size, event_prefix) == 0) {
+                       event_num = node_name.substr(prefix_size, node_name.size() - prefix_size);
+                       find = true;
+                       break;
+               }
+       }
+
+       closedir(dir);
+
+       return find;
+}
+
+bool sensor_device_base::get_input_method(const string &key, int &method, string &device_num)
+{
+       input_method_info input_info[2] = {
+               {INPUT_EVENT_METHOD, "/sys/class/input/", "input"},
+               {IIO_METHOD, "/sys/bus/iio/devices/", "iio:device"}
+       };
+
+       const int input_info_len = sizeof(input_info)/sizeof(input_info[0]);
+       size_t prefix_size;
+       string name_node, name;
+       string d_name;
+       DIR *dir = NULL;
+       struct dirent *dir_entry = NULL;
+       bool find = false;
+
+       for (int i = 0; i < input_info_len; ++i) {
+
+               prefix_size = input_info[i].prefix.size();
+
+               dir = opendir(input_info[i].dir_path.c_str());
+               if (!dir) {
+                       ERR("Failed to open dir: %s", input_info[i].dir_path.c_str());
+                       return false;
+               }
+
+               find = false;
+
+               while (!find && (dir_entry = readdir(dir))) {
+                       d_name = string(dir_entry->d_name);
+
+                       if (d_name.compare(0, prefix_size, input_info[i].prefix) == 0) {
+                               name_node = input_info[i].dir_path + d_name + string("/name");
+
+                               ifstream infile(name_node.c_str());
+                               if (!infile)
+                                       continue;
+
+                               infile >> name;
+
+                               if (name == key) {
+                                       device_num = d_name.substr(prefix_size, d_name.size() - prefix_size);
+                                       find = true;
+                                       method = input_info[i].method;
+                                       break;
+                               }
+                       }
+               }
+
+               closedir(dir);
+
+               if (find)
+                       break;
+       }
+
+       return find;
+}
diff --git a/src/interface/sensor_device_base.h b/src/interface/sensor_device_base.h
new file mode 100644 (file)
index 0000000..45c7d66
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * libsensord-share
+ *
+ * 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_DEVICE_BASE_H_
+#define _SENSOR_DEVICE_BASE_H_
+#include <sys/time.h>
+#include <sensor_logs.h>
+#include <string>
+#include <sensor_hal.h>
+
+/*
+* As of Linux 3.4, there is a new EVIOCSCLOCKID ioctl to set the desired clock
+* Current kernel-headers package doesn't have it so we should define it here.
+*/
+
+#ifndef EVIOCSCLOCKID
+/* Set clockid to be used for timestamps */
+#define EVIOCSCLOCKID          _IOW('E', 0xa0, int)
+#endif
+
+typedef struct {
+       int method;
+       std::string data_node_path;
+       std::string enable_node_path;
+       std::string interval_node_path;
+       std::string buffer_enable_node_path;
+       std::string buffer_length_node_path;
+       std::string trigger_node_path;
+} node_info;
+
+typedef struct {
+       bool sensorhub_controlled;
+       std::string sensor_type;
+       std::string key;
+       std::string iio_enable_node_name;
+       std::string sensorhub_interval_node_name;
+} node_info_query;
+
+enum input_method {
+       IIO_METHOD = 0,
+       INPUT_EVENT_METHOD = 1,
+};
+
+typedef struct {
+       int method;
+       std::string dir_path;
+       std::string prefix;
+} input_method_info;
+
+class sensor_device_base : public sensor_device
+{
+public:
+       sensor_device_base();
+       virtual ~sensor_device_base();
+
+protected:
+       bool set_enable_node(const std::string &node_path, bool sensorhub_controlled, bool enable, int enable_bit = 0);
+
+       static unsigned long long get_timestamp(void);
+       static unsigned long long get_timestamp(timeval *t);
+       static bool is_sensorhub_controlled(const std::string &key);
+       static bool get_node_info(const node_info_query &query, node_info &info);
+       static void show_node_info(node_info &info);
+       static bool set_node_value(const std::string &node_path, int value);
+       static bool set_node_value(const std::string &node_path, unsigned long long value);
+       static bool get_node_value(const std::string &node_path, int &value);
+private:
+       static bool get_event_num(const std::string &node_path, std::string &event_num);
+       static bool get_input_method(const std::string &key, int &method, std::string &device_num);
+
+       static bool get_iio_node_info(const std::string& enable_node_name, const std::string& device_num, node_info &info);
+       static bool get_sensorhub_iio_node_info(const std::string &interval_node_name, const std::string& device_num, node_info &info);
+       static bool get_input_event_node_info(const std::string& device_num, node_info &info);
+       static bool get_sensorhub_input_event_node_info(const std::string &interval_node_name, const std::string& device_num, node_info &info);
+};
+#endif /*_SENSOR_DEVICE_BASE_H_*/
index 279a869df6ed87038b624574ae427b81995721ce..660be013ce5606d625732bfb0d2b81ae010e82fd 100644 (file)
  *   humidity            : relative humidity (%)
  */
 typedef enum {
-       SENSOR_HAL_TYPE_UNKNOWN = -2,
-       SENSOR_HAL_TYPE_ALL = -1,
-       SENSOR_HAL_TYPE_ACCELEROMETER,
-       SENSOR_HAL_TYPE_GRAVITY,
-       SENSOR_HAL_TYPE_LINEAR_ACCELERATION,
-       SENSOR_HAL_TYPE_GEOMAGNETIC,
-       SENSOR_HAL_TYPE_ROTATION_VECTOR,
-       SENSOR_HAL_TYPE_ORIENTATION,
-       SENSOR_HAL_TYPE_GYROSCOPE,
-       SENSOR_HAL_TYPE_LIGHT,
-       SENSOR_HAL_TYPE_PROXIMITY,
-       SENSOR_HAL_TYPE_PRESSURE,
-       SENSOR_HAL_TYPE_ULTRAVIOLET,
-       SENSOR_HAL_TYPE_TEMPERATURE,
-       SENSOR_HAL_TYPE_HUMIDITY,
-       SENSOR_HAL_TYPE_HRM,
-       SENSOR_HAL_TYPE_HRM_LED_GREEN,
-       SENSOR_HAL_TYPE_HRM_LED_IR,
-       SENSOR_HAL_TYPE_HRM_LED_RED,
-       SENSOR_HAL_TYPE_GYROSCOPE_UNCAL,
-       SENSOR_HAL_TYPE_GEOMAGNETIC_UNCAL,
-       SENSOR_HAL_TYPE_GYROSCOPE_RV,
-       SENSOR_HAL_TYPE_GEOMAGNETIC_RV,
-
-       SENSOR_HAL_TYPE_ACTIVITY_STATIONARY = 0x100,
-       SENSOR_HAL_TYPE_ACTIVITY_WALK,
-       SENSOR_HAL_TYPE_ACTIVITY_RUN,
-       SENSOR_HAL_TYPE_ACTIVITY_IN_VEHICLE,
-       SENSOR_HAL_TYPE_ACTIVITY_ON_BICYCLE,
-
-       SENSOR_HAL_TYPE_GESTURE_MOVEMENT = 0x200,
-       SENSOR_HAL_TYPE_GESTURE_WRIST_UP,
-       SENSOR_HAL_TYPE_GESTURE_WRIST_DOWN,
-
-       SENSOR_HAL_TYPE_HUMAN_PEDOMETER = 0x300,
-       SENSOR_HAL_TYPE_HUMAN_SLEEP_MONITOR,
-
-       SENSOR_HAL_TYPE_FUSION = 0x900,
-       SENSOR_HAL_TYPE_AUTO_ROTATION,
-
-       SENSOR_HAL_TYPE_CONTEXT = 0x1000,
-       SENSOR_HAL_TYPE_MOTION,
-       SENSOR_HAL_TYPE_PIR,
-       SENSOR_HAL_TYPE_PIR_LONG,
-       SENSOR_HAL_TYPE_DUST,
-       SENSOR_HAL_TYPE_THERMOMETER,
-       SENSOR_HAL_TYPE_PEDOMETER,
-       SENSOR_HAL_TYPE_FLAT,
-       SENSOR_HAL_TYPE_HRM_RAW,
-       SENSOR_HAL_TYPE_TILT,
-       SENSOR_HAL_TYPE_ROTATION_VECTOR_RAW,
-} sensor_hal_type;
+       SENSOR_DEVICE_UNKNOWN = -2,
+       SENSOR_DEVICE_ALL = -1,
+       SENSOR_DEVICE_ACCELEROMETER,
+       SENSOR_DEVICE_GRAVITY,
+       SENSOR_DEVICE_LINEAR_ACCELERATION,
+       SENSOR_DEVICE_GEOMAGNETIC,
+       SENSOR_DEVICE_ROTATION_VECTOR,
+       SENSOR_DEVICE_ORIENTATION,
+       SENSOR_DEVICE_GYROSCOPE,
+       SENSOR_DEVICE_LIGHT,
+       SENSOR_DEVICE_PROXIMITY,
+       SENSOR_DEVICE_PRESSURE,
+       SENSOR_DEVICE_ULTRAVIOLET,
+       SENSOR_DEVICE_TEMPERATURE,
+       SENSOR_DEVICE_HUMIDITY,
+       SENSOR_DEVICE_HRM,
+       SENSOR_DEVICE_HRM_LED_GREEN,
+       SENSOR_DEVICE_HRM_LED_IR,
+       SENSOR_DEVICE_HRM_LED_RED,
+       SENSOR_DEVICE_GYROSCOPE_UNCAL,
+       SENSOR_DEVICE_GEOMAGNETIC_UNCAL,
+       SENSOR_DEVICE_GYROSCOPE_RV,
+       SENSOR_DEVICE_GEOMAGNETIC_RV,
+
+       SENSOR_DEVICE_ACTIVITY_STATIONARY = 0x100,
+       SENSOR_DEVICE_ACTIVITY_WALK,
+       SENSOR_DEVICE_ACTIVITY_RUN,
+       SENSOR_DEVICE_ACTIVITY_IN_VEHICLE,
+       SENSOR_DEVICE_ACTIVITY_ON_BICYCLE,
+
+       SENSOR_DEVICE_GESTURE_MOVEMENT = 0x200,
+       SENSOR_DEVICE_GESTURE_WRIST_UP,
+       SENSOR_DEVICE_GESTURE_WRIST_DOWN,
+
+       SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300,
+       SENSOR_DEVICE_HUMAN_SLEEP_MONITOR,
+
+       SENSOR_DEVICE_FUSION = 0x900,
+       SENSOR_DEVICE_AUTO_ROTATION,
+
+       SENSOR_DEVICE_CONTEXT = 0x1000,
+       SENSOR_DEVICE_MOTION,
+       SENSOR_DEVICE_PIR,
+       SENSOR_DEVICE_PIR_LONG,
+       SENSOR_DEVICE_DUST,
+       SENSOR_DEVICE_THERMOMETER,
+       SENSOR_DEVICE_PEDOMETER,
+       SENSOR_DEVICE_FLAT,
+       SENSOR_DEVICE_HRM_RAW,
+       SENSOR_DEVICE_TILT,
+       SENSOR_DEVICE_ROTATION_VECTOR_RAW,
+} sensor_device_type;
 
 /*
  * A platform sensor handler is generated based on this handle
@@ -104,19 +104,20 @@ typedef enum {
 typedef struct sensor_handle_t {
        uint32_t id;
        std::string name;
-       sensor_hal_type type;
+       sensor_device_type type;
        unsigned int event_type; // for Internal API
        sensor_properties_s properties;
 } sensor_handle_t;
 
 /*
- * Sensor HAL interface
+ * Sensor device interface
  * 1 HAL must be abstracted from 1 device event node
  */
-class sensor_hal
+class sensor_device
 {
 public:
-       uint32_t get_hal_version(void) {
+       uint32_t get_hal_version(void)
+       {
                return SENSOR_HAL_VERSION(1, 0);
        }
 
@@ -142,4 +143,4 @@ public:
        /* TODO: use get_sensors() instead of get_properties() */
        virtual bool get_properties(uint32_t id, sensor_properties_s &properties) = 0;
 };
-#endif /*_SENSOR_HAL_H_*/
+#endif /* _SENSOR_HAL_H_ */
diff --git a/src/interface/sensor_hal_base.cpp b/src/interface/sensor_hal_base.cpp
deleted file mode 100644 (file)
index 15c6443..0000000
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * libsensord-share
- *
- * 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 <sensor_hal_base.h>
-#include <dirent.h>
-#include <string.h>
-#include <fstream>
-
-using std::ifstream;
-using std::ofstream;
-using std::fstream;
-using std::string;
-
-sensor_hal_base::sensor_hal_base()
-{
-}
-
-sensor_hal_base::~sensor_hal_base()
-{
-}
-
-unsigned long long sensor_hal_base::get_timestamp(void)
-{
-       struct timespec t;
-       clock_gettime(CLOCK_MONOTONIC, &t);
-       return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000;
-}
-
-unsigned long long sensor_hal_base::get_timestamp(timeval *t)
-{
-       if (!t) {
-               ERR("t is NULL");
-               return 0;
-       }
-
-       return ((unsigned long long)(t->tv_sec)*1000000LL +t->tv_usec);
-}
-
-bool sensor_hal_base::is_sensorhub_controlled(const string &key)
-{
-       string key_node = string("/sys/class/sensors/ssp_sensor/") + key;
-
-       if (access(key_node.c_str(), F_OK) == 0)
-               return true;
-
-       return false;
-}
-
-bool sensor_hal_base::get_node_info(const node_info_query &query, node_info &info)
-{
-       bool ret = false;
-       int method;
-       string device_num;
-
-       if (!get_input_method(query.key, method, device_num)) {
-               ERR("Failed to get input method for %s", query.key.c_str());
-               return false;
-       }
-
-       info.method = method;
-
-       if (method == IIO_METHOD) {
-               if (query.sensorhub_controlled)
-                       ret = get_sensorhub_iio_node_info(query.sensorhub_interval_node_name, device_num, info);
-               else
-                       ret = get_iio_node_info(query.iio_enable_node_name, device_num, info);
-       } else {
-               if (query.sensorhub_controlled)
-                       ret = get_sensorhub_input_event_node_info(query.sensorhub_interval_node_name, device_num, info);
-               else
-                       ret = get_input_event_node_info(device_num, info);
-       }
-
-       return ret;
-}
-
-
-void sensor_hal_base::show_node_info(node_info &info)
-{
-       if (info.data_node_path.size())
-               INFO("Data node: %s", info.data_node_path.c_str());
-       if (info.enable_node_path.size())
-               INFO("Enable node: %s", info.enable_node_path.c_str());
-       if (info.interval_node_path.size())
-               INFO("Interval node: %s", info.interval_node_path.c_str());
-       if (info.buffer_enable_node_path.size())
-               INFO("Buffer enable node: %s", info.buffer_enable_node_path.c_str());
-       if (info.buffer_length_node_path.size())
-               INFO("Buffer length node: %s", info.buffer_length_node_path.c_str());
-       if (info.trigger_node_path.size())
-               INFO("Trigger node: %s", info.trigger_node_path.c_str());
-}
-
-bool sensor_hal_base::get_iio_node_info(const string& enable_node_name, const string& device_num, node_info &info)
-{
-       const string base_dir = string("/sys/bus/iio/devices/iio:device") + device_num + string("/");
-
-       info.data_node_path = string("/dev/iio:device") + device_num;
-       info.enable_node_path = base_dir + enable_node_name;
-       info.interval_node_path = base_dir + string("sampling_frequency");
-       info.buffer_enable_node_path = base_dir + string("buffer/enable");
-       info.buffer_length_node_path = base_dir + string("buffer/length");
-       info.trigger_node_path = base_dir + string("trigger/current_trigger");
-
-       return true;
-}
-
-bool sensor_hal_base::get_sensorhub_iio_node_info(const string &interval_node_name, const string& device_num, node_info &info)
-{
-       const string base_dir = string("/sys/bus/iio/devices/iio:device") + device_num + string("/");
-       const string hub_dir = "/sys/class/sensors/ssp_sensor/";
-
-       info.data_node_path = string("/dev/iio:device") + device_num;
-       info.enable_node_path = hub_dir + string("enable");
-       info.interval_node_path = hub_dir + interval_node_name;
-       info.buffer_enable_node_path = base_dir + string("buffer/enable");
-       info.buffer_length_node_path = base_dir + string("buffer/length");
-       return true;
-}
-
-bool sensor_hal_base::get_input_event_node_info(const string& device_num, node_info &info)
-{
-       string base_dir;
-       string event_num;
-
-       base_dir = string("/sys/class/input/input") + device_num + string("/");
-
-       if (!get_event_num(base_dir, event_num))
-               return false;
-
-       info.data_node_path = string("/dev/input/event") + event_num;
-
-       info.enable_node_path = base_dir + string("enable");
-       info.interval_node_path = base_dir + string("poll_delay");
-       return true;
-}
-
-bool sensor_hal_base::get_sensorhub_input_event_node_info(const string &interval_node_name, const string& device_num, node_info &info)
-{
-       const string base_dir = "/sys/class/sensors/ssp_sensor/";
-       string event_num;
-
-       string input_dir = string("/sys/class/input/input") + device_num + string("/");
-
-       if (!get_event_num(input_dir, event_num))
-               return false;
-
-       info.data_node_path = string("/dev/input/event") + event_num;
-       info.enable_node_path = base_dir + string("enable");
-       info.interval_node_path = base_dir + interval_node_name;
-       return true;
-}
-
-bool sensor_hal_base::set_node_value(const string &node_path, int value)
-{
-       ofstream node(node_path, ofstream::binary);
-
-       if (!node)
-               return false;
-
-       node << value;
-
-       return true;
-}
-
-bool sensor_hal_base::set_node_value(const string &node_path, unsigned long long value)
-{
-       ofstream node(node_path, ofstream::binary);
-
-       if (!node)
-               return false;
-
-       node << value;
-
-       return true;
-}
-
-
-bool sensor_hal_base::get_node_value(const string &node_path, int &value)
-{
-       ifstream node(node_path, ifstream::binary);
-
-       if (!node)
-               return false;
-
-       node >> value;
-
-       return true;
-}
-
-bool sensor_hal_base::set_enable_node(const string &node_path, bool sensorhub_controlled, bool enable, int enable_bit)
-{
-       int prev_status, status;
-
-       if (!get_node_value(node_path, prev_status)) {
-               ERR("Failed to get node: %s", node_path.c_str());
-               return false;
-       }
-
-       int _enable_bit = sensorhub_controlled ? enable_bit : 0;
-
-       if (enable)
-               status = prev_status | (1 << _enable_bit);
-       else
-               status = prev_status & (~(1 << _enable_bit));
-
-       if (!set_node_value(node_path, status)) {
-               ERR("Failed to set node: %s", node_path.c_str());
-               return false;
-       }
-
-       return true;
-}
-
-bool sensor_hal_base::get_event_num(const string &input_path, string &event_num)
-{
-       const string event_prefix = "event";
-       DIR *dir = NULL;
-       struct dirent *dir_entry = NULL;
-       string node_name;
-       bool find = false;
-
-       dir = opendir(input_path.c_str());
-       if (!dir) {
-               ERR("Failed to open dir: %s", input_path.c_str());
-               return false;
-       }
-
-       int prefix_size = event_prefix.size();
-
-       while (!find && (dir_entry = readdir(dir))) {
-               node_name = dir_entry->d_name;
-
-               if (node_name.compare(0, prefix_size, event_prefix) == 0) {
-                       event_num = node_name.substr(prefix_size, node_name.size() - prefix_size);
-                       find = true;
-                       break;
-               }
-       }
-
-       closedir(dir);
-
-       return find;
-}
-
-bool sensor_hal_base::get_input_method(const string &key, int &method, string &device_num)
-{
-       input_method_info input_info[2] = {
-               {INPUT_EVENT_METHOD, "/sys/class/input/", "input"},
-               {IIO_METHOD, "/sys/bus/iio/devices/", "iio:device"}
-       };
-
-       const int input_info_len = sizeof(input_info)/sizeof(input_info[0]);
-       size_t prefix_size;
-       string name_node, name;
-       string d_name;
-       DIR *dir = NULL;
-       struct dirent *dir_entry = NULL;
-       bool find = false;
-
-       for (int i = 0; i < input_info_len; ++i) {
-
-               prefix_size = input_info[i].prefix.size();
-
-               dir = opendir(input_info[i].dir_path.c_str());
-               if (!dir) {
-                       ERR("Failed to open dir: %s", input_info[i].dir_path.c_str());
-                       return false;
-               }
-
-               find = false;
-
-               while (!find && (dir_entry = readdir(dir))) {
-                       d_name = string(dir_entry->d_name);
-
-                       if (d_name.compare(0, prefix_size, input_info[i].prefix) == 0) {
-                               name_node = input_info[i].dir_path + d_name + string("/name");
-
-                               ifstream infile(name_node.c_str());
-                               if (!infile)
-                                       continue;
-
-                               infile >> name;
-
-                               if (name == key) {
-                                       device_num = d_name.substr(prefix_size, d_name.size() - prefix_size);
-                                       find = true;
-                                       method = input_info[i].method;
-                                       break;
-                               }
-                       }
-               }
-
-               closedir(dir);
-
-               if (find)
-                       break;
-       }
-
-       return find;
-}
diff --git a/src/interface/sensor_hal_base.h b/src/interface/sensor_hal_base.h
deleted file mode 100644 (file)
index 9b18c63..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * libsensord-share
- *
- * 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_HAL_BASE_H_
-#define _SENSOR_HAL_BASE_H_
-#include <sys/time.h>
-#include <sensor_logs.h>
-#include <string>
-#include <sensor_hal.h>
-
-/*
-* As of Linux 3.4, there is a new EVIOCSCLOCKID ioctl to set the desired clock
-* Current kernel-headers package doesn't have it so we should define it here.
-*/
-
-#ifndef EVIOCSCLOCKID
-/* Set clockid to be used for timestamps */
-#define EVIOCSCLOCKID          _IOW('E', 0xa0, int)
-#endif
-
-typedef struct {
-       int method;
-       std::string data_node_path;
-       std::string enable_node_path;
-       std::string interval_node_path;
-       std::string buffer_enable_node_path;
-       std::string buffer_length_node_path;
-       std::string trigger_node_path;
-} node_info;
-
-typedef struct {
-       bool sensorhub_controlled;
-       std::string sensor_type;
-       std::string key;
-       std::string iio_enable_node_name;
-       std::string sensorhub_interval_node_name;
-} node_info_query;
-
-enum input_method {
-       IIO_METHOD = 0,
-       INPUT_EVENT_METHOD = 1,
-};
-
-typedef struct {
-       int method;
-       std::string dir_path;
-       std::string prefix;
-} input_method_info;
-
-class sensor_hal_base : public sensor_hal
-{
-public:
-       sensor_hal_base();
-       virtual ~sensor_hal_base();
-
-protected:
-       bool set_enable_node(const std::string &node_path, bool sensorhub_controlled, bool enable, int enable_bit = 0);
-
-       static unsigned long long get_timestamp(void);
-       static unsigned long long get_timestamp(timeval *t);
-       static bool is_sensorhub_controlled(const std::string &key);
-       static bool get_node_info(const node_info_query &query, node_info &info);
-       static void show_node_info(node_info &info);
-       static bool set_node_value(const std::string &node_path, int value);
-       static bool set_node_value(const std::string &node_path, unsigned long long value);
-       static bool get_node_value(const std::string &node_path, int &value);
-private:
-       static bool get_event_num(const std::string &node_path, std::string &event_num);
-       static bool get_input_method(const std::string &key, int &method, std::string &device_num);
-
-       static bool get_iio_node_info(const std::string& enable_node_name, const std::string& device_num, node_info &info);
-       static bool get_sensorhub_iio_node_info(const std::string &interval_node_name, const std::string& device_num, node_info &info);
-       static bool get_input_event_node_info(const std::string& device_num, node_info &info);
-       static bool get_sensorhub_input_event_node_info(const std::string &interval_node_name, const std::string& device_num, node_info &info);
-};
-#endif /*_SENSOR_HAL_BASE_H_*/
index ee1778e41f103866678c7ba6c42e52abbdf30c0b..5b5834072c7682987d97667d51c3a6f79d22b9c3 100644 (file)
@@ -359,10 +359,10 @@ typedef struct sensorhub_event_t {
 } sensorhub_event_t;
 
 typedef struct {
-       std::vector<void*> sensors;
-} sensor_module;
+       std::vector<void*> devices;
+} sensor_devices;
 
-typedef sensor_module* (*create_t)(void);
+typedef sensor_devices* (*create_t)(void);
 
 typedef void *(*cmd_func_t)(void *data, void *cb_data);
 
diff --git a/src/plugins/accel/accel_sensor_device.cpp b/src/plugins/accel/accel_sensor_device.cpp
new file mode 100755 (executable)
index 0000000..129d454
--- /dev/null
@@ -0,0 +1,306 @@
+/*
+ * accel_sensor_device
+ *
+ * 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 <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <linux/input.h>
+#include <accel_sensor_device.h>
+#include <sys/poll.h>
+
+#define GRAVITY 9.80665
+#define G_TO_MG 1000
+#define RAW_DATA_TO_G_UNIT(X) (((float)(X))/((float)G_TO_MG))
+#define RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(X) (GRAVITY * (RAW_DATA_TO_G_UNIT(X)))
+
+#define MIN_RANGE(RES) (-((1 << (RES))/2))
+#define MAX_RANGE(RES) (((1 << (RES))/2)-1)
+
+#define MODEL_NAME "K2HH"
+#define VENDOR "ST Microelectronics"
+#define RESOLUTION 16
+#define RAW_DATA_UNIT 0.122
+#define MIN_INTERVAL 1
+#define FIFO_COUNT 0
+#define MAX_BATCH_COUNT 0
+
+static const sensor_properties_s accel_properties = {
+       name : MODEL_NAME,
+       vendor : VENDOR,
+       min_range : MIN_RANGE(RESOLUTION) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
+       max_range : MAX_RANGE(RESOLUTION) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
+       resolution : RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
+       min_interval : MIN_INTERVAL,
+       fifo_count : FIFO_COUNT,
+       max_batch_count : MAX_BATCH_COUNT,
+};
+
+static const sensor_handle_t handles[] = {
+       {
+               id: 0x1,
+               name: "Accelerometer",
+               type: SENSOR_DEVICE_ACCELEROMETER,
+               event_type: (SENSOR_DEVICE_ACCELEROMETER << 16) | 0x0001,
+               properties : accel_properties
+       },
+       {
+               id: 0x2,
+               name: "Accelerometer RAW",
+               type: SENSOR_DEVICE_ACCELEROMETER,
+               event_type: (SENSOR_DEVICE_ACCELEROMETER << 16) | 0x0002,
+               properties : accel_properties
+       }
+};
+
+accel_sensor_device::accel_sensor_device()
+: m_node_handle(-1)
+, m_x(-1)
+, m_y(-1)
+, m_z(-1)
+, m_polling_interval(0)
+, m_fired_time(0)
+, m_sensorhub_controlled(false)
+{
+       const std::string sensorhub_interval_node_name = "accel_poll_delay";
+
+       node_info_query query;
+       node_info info;
+
+       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
+       query.sensor_type = "ACCEL";
+       query.key = "accelerometer_sensor";
+       query.iio_enable_node_name = "accel_enable";
+       query.sensorhub_interval_node_name = sensorhub_interval_node_name;
+
+       if (!get_node_info(query, info)) {
+               ERR("Failed to get node info");
+               throw ENXIO;
+       }
+
+       show_node_info(info);
+
+       m_data_node = info.data_node_path;
+       m_enable_node = info.enable_node_path;
+       m_interval_node = info.interval_node_path;
+
+       if ((m_node_handle = open(m_data_node.c_str(), O_RDWR)) < 0) {
+               ERR("accel handle open fail for accel processor, error:%s\n", strerror(errno));
+               throw ENXIO;
+       }
+
+       INFO("accel_sensor_device is created!\n");
+}
+
+accel_sensor_device::~accel_sensor_device()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       INFO("accel_sensor_device is destroyed!\n");
+}
+
+bool accel_sensor_device::get_sensors(std::vector<sensor_handle_t> &sensors)
+{
+       int size = ARRAY_SIZE(handles);
+
+       for (int i = 0; i < size; ++i)
+               sensors.push_back(handles[i]);
+
+       return true;
+}
+
+bool accel_sensor_device::enable(uint32_t id)
+{
+       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
+       set_interval(id, m_polling_interval);
+
+       m_fired_time = 0;
+       INFO("Enable accelerometer sensor");
+       return true;
+}
+
+bool accel_sensor_device::disable(uint32_t id)
+{
+       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
+
+       INFO("Disable accelerometer sensor");
+       return true;
+}
+
+int accel_sensor_device::get_poll_fd()
+{
+       return m_node_handle;
+}
+
+bool accel_sensor_device::set_interval(uint32_t id, unsigned long val)
+{
+       unsigned long long polling_interval_ns;
+
+       polling_interval_ns = ((unsigned long long)(val) * 1000llu * 1000llu);
+
+       if (!set_node_value(m_interval_node, polling_interval_ns)) {
+               ERR("Failed to set polling resource: %s\n", m_interval_node.c_str());
+               return false;
+       }
+
+       INFO("Interval is changed from %dms to %dms]", m_polling_interval, val);
+       m_polling_interval = val;
+       return true;
+}
+
+bool accel_sensor_device::set_batch_latency(uint32_t id, unsigned long val)
+{
+       return false;
+}
+
+bool accel_sensor_device::set_command(uint32_t id, std::string command, std::string value)
+{
+       return false;
+}
+
+bool accel_sensor_device::is_data_ready(void)
+{
+       bool ret;
+       ret = update_value_input_event();
+       return ret;
+}
+
+bool accel_sensor_device::update_value_input_event(void)
+{
+       int accel_raw[3] = {0,};
+       bool x,y,z;
+       int read_input_cnt = 0;
+       const int INPUT_MAX_BEFORE_SYN = 10;
+       unsigned long long fired_time = 0;
+       bool syn = false;
+
+       x = y = z = false;
+
+       struct input_event accel_input;
+       DBG("accel event detection!");
+
+       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
+               int len = read(m_node_handle, &accel_input, sizeof(accel_input));
+               if (len != sizeof(accel_input)) {
+                       ERR("accel_file read fail, read_len = %d\n",len);
+                       return false;
+               }
+
+               ++read_input_cnt;
+
+               if (accel_input.type == EV_REL) {
+                       switch (accel_input.code) {
+                       case REL_X:
+                               accel_raw[0] = (int)accel_input.value;
+                               x = true;
+                               break;
+                       case REL_Y:
+                               accel_raw[1] = (int)accel_input.value;
+                               y = true;
+                               break;
+                       case REL_Z:
+                               accel_raw[2] = (int)accel_input.value;
+                               z = true;
+                               break;
+                       default:
+                               ERR("accel_input event[type = %d, code = %d] is unknown.", accel_input.type, accel_input.code);
+                               return false;
+                               break;
+                       }
+               } else if (accel_input.type == EV_SYN) {
+                       syn = true;
+                       fired_time = sensor_device_base::get_timestamp(&accel_input.time);
+               } else {
+                       ERR("accel_input event[type = %d, code = %d] is unknown.", accel_input.type, accel_input.code);
+                       return false;
+               }
+       }
+
+       if (syn == false) {
+               ERR("EV_SYN didn't come until %d inputs had come", read_input_cnt);
+               return false;
+       }
+
+       if (x)
+               m_x =  accel_raw[0];
+       if (y)
+               m_y =  accel_raw[1];
+       if (z)
+               m_z =  accel_raw[2];
+
+       m_fired_time = fired_time;
+
+       DBG("m_x = %d, m_y = %d, m_z = %d, time = %lluus", m_x, m_y, m_z, m_fired_time);
+
+       return true;
+}
+
+bool accel_sensor_device::get_sensor_data(uint32_t id, sensor_data_t &data)
+{
+       data.accuracy = SENSOR_ACCURACY_GOOD;
+       data.timestamp = m_fired_time;
+       data.value_count = 3;
+       data.values[0] = m_x;
+       data.values[1] = m_y;
+       data.values[2] = m_z;
+
+       raw_to_base(data);
+
+       return true;
+}
+
+int accel_sensor_device::get_sensor_event(uint32_t id, sensor_event_t **event)
+{
+       sensor_event_t *sensor_event;
+       sensor_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
+
+       sensor_event->data.accuracy = SENSOR_ACCURACY_GOOD;
+       sensor_event->data.timestamp = m_fired_time;
+       sensor_event->data.value_count = 3;
+       sensor_event->data.values[0] = m_x;
+       sensor_event->data.values[1] = m_y;
+       sensor_event->data.values[2] = m_z;
+
+       raw_to_base(sensor_event->data);
+
+       *event = sensor_event;
+
+       return sizeof(sensor_event_t);
+}
+
+void accel_sensor_device::raw_to_base(sensor_data_t &data)
+{
+       data.value_count = 3;
+       data.values[0] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data.values[0] * RAW_DATA_UNIT);
+       data.values[1] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data.values[1] * RAW_DATA_UNIT);
+       data.values[2] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data.values[2] * RAW_DATA_UNIT);
+}
+
+bool accel_sensor_device::get_properties(uint32_t id, sensor_properties_s &properties)
+{
+       properties.name = MODEL_NAME;
+       properties.vendor = VENDOR;
+       properties.min_range = accel_properties.min_range;
+       properties.max_range = accel_properties.max_range;
+       properties.min_interval = accel_properties.min_interval;
+       properties.resolution = accel_properties.resolution;
+       properties.fifo_count = accel_properties.fifo_count;
+       properties.max_batch_count = accel_properties.max_batch_count;
+       return true;
+}
diff --git a/src/plugins/accel/accel_sensor_device.h b/src/plugins/accel/accel_sensor_device.h
new file mode 100755 (executable)
index 0000000..8c34ae5
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * accel_sensor_device
+ *
+ * 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 _ACCEL_SENSOR_DEVICE_H_
+#define _ACCEL_SENSOR_DEVICE_H_
+
+#include <sensor_device_base.h>
+
+class accel_sensor_device : public sensor_device_base
+{
+public:
+       accel_sensor_device();
+       virtual ~accel_sensor_device();
+
+       int get_poll_fd(void);
+       bool get_sensors(std::vector<sensor_handle_t> &sensors);
+       bool enable(uint32_t id);
+       bool disable(uint32_t id);
+       bool set_interval(uint32_t id, unsigned long val);
+       bool set_batch_latency(uint32_t id, unsigned long val);
+       bool set_command(uint32_t id, std::string command, std::string value);
+       bool is_data_ready(void);
+       bool get_sensor_data(uint32_t id, sensor_data_t &data);
+       int get_sensor_event(uint32_t id, sensor_event_t **event);
+       bool get_properties(uint32_t id, sensor_properties_s &properties);
+
+private:
+       int m_node_handle;
+       int m_x;
+       int m_y;
+       int m_z;
+       unsigned long m_polling_interval;
+       unsigned long long m_fired_time;
+       bool m_sensorhub_controlled;
+
+       std::string m_data_node;
+       std::string m_enable_node;
+       std::string m_interval_node;
+
+       bool update_value_input_event(void);
+       void raw_to_base(sensor_data_t &data);
+};
+#endif /*_ACCEL_SENSOR_DEVICE_CLASS_H_*/
diff --git a/src/plugins/accel/accel_sensor_hal.cpp b/src/plugins/accel/accel_sensor_hal.cpp
deleted file mode 100755 (executable)
index 879e70d..0000000
+++ /dev/null
@@ -1,306 +0,0 @@
-/*
- * accel_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 <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <linux/input.h>
-#include <accel_sensor_hal.h>
-#include <sys/poll.h>
-
-#define GRAVITY 9.80665
-#define G_TO_MG 1000
-#define RAW_DATA_TO_G_UNIT(X) (((float)(X))/((float)G_TO_MG))
-#define RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(X) (GRAVITY * (RAW_DATA_TO_G_UNIT(X)))
-
-#define MIN_RANGE(RES) (-((1 << (RES))/2))
-#define MAX_RANGE(RES) (((1 << (RES))/2)-1)
-
-#define MODEL_NAME "K2HH"
-#define VENDOR "ST Microelectronics"
-#define RESOLUTION 16
-#define RAW_DATA_UNIT 0.122
-#define MIN_INTERVAL 1
-#define FIFO_COUNT 0
-#define MAX_BATCH_COUNT 0
-
-static const sensor_properties_s accel_properties = {
-       name : MODEL_NAME,
-       vendor : VENDOR,
-       min_range : MIN_RANGE(RESOLUTION) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
-       max_range : MAX_RANGE(RESOLUTION) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
-       resolution : RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
-       min_interval : MIN_INTERVAL,
-       fifo_count : FIFO_COUNT,
-       max_batch_count : MAX_BATCH_COUNT,
-};
-
-static const sensor_handle_t handles[] = {
-       {
-               id: 0x1,
-               name: "Accelerometer",
-               type: SENSOR_HAL_TYPE_ACCELEROMETER,
-               event_type: (SENSOR_HAL_TYPE_ACCELEROMETER << 16) | 0x0001,
-               properties : accel_properties
-       },
-       {
-               id: 0x2,
-               name: "Accelerometer RAW",
-               type: SENSOR_HAL_TYPE_ACCELEROMETER,
-               event_type: (SENSOR_HAL_TYPE_ACCELEROMETER << 16) | 0x0002,
-               properties : accel_properties
-       }
-};
-
-accel_sensor_hal::accel_sensor_hal()
-: m_node_handle(-1)
-, m_x(-1)
-, m_y(-1)
-, m_z(-1)
-, m_polling_interval(0)
-, m_fired_time(0)
-, m_sensorhub_controlled(false)
-{
-       const std::string sensorhub_interval_node_name = "accel_poll_delay";
-
-       node_info_query query;
-       node_info info;
-
-       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
-       query.sensor_type = "ACCEL";
-       query.key = "accelerometer_sensor";
-       query.iio_enable_node_name = "accel_enable";
-       query.sensorhub_interval_node_name = sensorhub_interval_node_name;
-
-       if (!get_node_info(query, info)) {
-               ERR("Failed to get node info");
-               throw ENXIO;
-       }
-
-       show_node_info(info);
-
-       m_data_node = info.data_node_path;
-       m_enable_node = info.enable_node_path;
-       m_interval_node = info.interval_node_path;
-
-       if ((m_node_handle = open(m_data_node.c_str(), O_RDWR)) < 0) {
-               ERR("accel handle open fail for accel processor, error:%s\n", strerror(errno));
-               throw ENXIO;
-       }
-
-       INFO("accel_sensor_hal is created!\n");
-}
-
-accel_sensor_hal::~accel_sensor_hal()
-{
-       close(m_node_handle);
-       m_node_handle = -1;
-
-       INFO("accel_sensor_hal is destroyed!\n");
-}
-
-bool accel_sensor_hal::get_sensors(std::vector<sensor_handle_t> &sensors)
-{
-       int size = ARRAY_SIZE(handles);
-
-       for (int i = 0; i < size; ++i)
-               sensors.push_back(handles[i]);
-
-       return true;
-}
-
-bool accel_sensor_hal::enable(uint32_t id)
-{
-       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
-       set_interval(id, m_polling_interval);
-
-       m_fired_time = 0;
-       INFO("Enable accelerometer sensor");
-       return true;
-}
-
-bool accel_sensor_hal::disable(uint32_t id)
-{
-       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
-
-       INFO("Disable accelerometer sensor");
-       return true;
-}
-
-int accel_sensor_hal::get_poll_fd()
-{
-       return m_node_handle;
-}
-
-bool accel_sensor_hal::set_interval(uint32_t id, unsigned long val)
-{
-       unsigned long long polling_interval_ns;
-
-       polling_interval_ns = ((unsigned long long)(val) * 1000llu * 1000llu);
-
-       if (!set_node_value(m_interval_node, polling_interval_ns)) {
-               ERR("Failed to set polling resource: %s\n", m_interval_node.c_str());
-               return false;
-       }
-
-       INFO("Interval is changed from %dms to %dms]", m_polling_interval, val);
-       m_polling_interval = val;
-       return true;
-}
-
-bool accel_sensor_hal::set_batch_latency(uint32_t id, unsigned long val)
-{
-       return false;
-}
-
-bool accel_sensor_hal::set_command(uint32_t id, std::string command, std::string value)
-{
-       return false;
-}
-
-bool accel_sensor_hal::is_data_ready(void)
-{
-       bool ret;
-       ret = update_value_input_event();
-       return ret;
-}
-
-bool accel_sensor_hal::update_value_input_event(void)
-{
-       int accel_raw[3] = {0,};
-       bool x,y,z;
-       int read_input_cnt = 0;
-       const int INPUT_MAX_BEFORE_SYN = 10;
-       unsigned long long fired_time = 0;
-       bool syn = false;
-
-       x = y = z = false;
-
-       struct input_event accel_input;
-       DBG("accel event detection!");
-
-       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
-               int len = read(m_node_handle, &accel_input, sizeof(accel_input));
-               if (len != sizeof(accel_input)) {
-                       ERR("accel_file read fail, read_len = %d\n",len);
-                       return false;
-               }
-
-               ++read_input_cnt;
-
-               if (accel_input.type == EV_REL) {
-                       switch (accel_input.code) {
-                       case REL_X:
-                               accel_raw[0] = (int)accel_input.value;
-                               x = true;
-                               break;
-                       case REL_Y:
-                               accel_raw[1] = (int)accel_input.value;
-                               y = true;
-                               break;
-                       case REL_Z:
-                               accel_raw[2] = (int)accel_input.value;
-                               z = true;
-                               break;
-                       default:
-                               ERR("accel_input event[type = %d, code = %d] is unknown.", accel_input.type, accel_input.code);
-                               return false;
-                               break;
-                       }
-               } else if (accel_input.type == EV_SYN) {
-                       syn = true;
-                       fired_time = sensor_hal_base::get_timestamp(&accel_input.time);
-               } else {
-                       ERR("accel_input event[type = %d, code = %d] is unknown.", accel_input.type, accel_input.code);
-                       return false;
-               }
-       }
-
-       if (syn == false) {
-               ERR("EV_SYN didn't come until %d inputs had come", read_input_cnt);
-               return false;
-       }
-
-       if (x)
-               m_x =  accel_raw[0];
-       if (y)
-               m_y =  accel_raw[1];
-       if (z)
-               m_z =  accel_raw[2];
-
-       m_fired_time = fired_time;
-
-       DBG("m_x = %d, m_y = %d, m_z = %d, time = %lluus", m_x, m_y, m_z, m_fired_time);
-
-       return true;
-}
-
-bool accel_sensor_hal::get_sensor_data(uint32_t id, sensor_data_t &data)
-{
-       data.accuracy = SENSOR_ACCURACY_GOOD;
-       data.timestamp = m_fired_time;
-       data.value_count = 3;
-       data.values[0] = m_x;
-       data.values[1] = m_y;
-       data.values[2] = m_z;
-
-       raw_to_base(data);
-
-       return true;
-}
-
-int accel_sensor_hal::get_sensor_event(uint32_t id, sensor_event_t **event)
-{
-       sensor_event_t *sensor_event;
-       sensor_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
-
-       sensor_event->data.accuracy = SENSOR_ACCURACY_GOOD;
-       sensor_event->data.timestamp = m_fired_time;
-       sensor_event->data.value_count = 3;
-       sensor_event->data.values[0] = m_x;
-       sensor_event->data.values[1] = m_y;
-       sensor_event->data.values[2] = m_z;
-
-       raw_to_base(sensor_event->data);
-
-       *event = sensor_event;
-
-       return sizeof(sensor_event_t);
-}
-
-void accel_sensor_hal::raw_to_base(sensor_data_t &data)
-{
-       data.value_count = 3;
-       data.values[0] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data.values[0] * RAW_DATA_UNIT);
-       data.values[1] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data.values[1] * RAW_DATA_UNIT);
-       data.values[2] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data.values[2] * RAW_DATA_UNIT);
-}
-
-bool accel_sensor_hal::get_properties(uint32_t id, sensor_properties_s &properties)
-{
-       properties.name = MODEL_NAME;
-       properties.vendor = VENDOR;
-       properties.min_range = accel_properties.min_range;
-       properties.max_range = accel_properties.max_range;
-       properties.min_interval = accel_properties.min_interval;
-       properties.resolution = accel_properties.resolution;
-       properties.fifo_count = accel_properties.fifo_count;
-       properties.max_batch_count = accel_properties.max_batch_count;
-       return true;
-}
diff --git a/src/plugins/accel/accel_sensor_hal.h b/src/plugins/accel/accel_sensor_hal.h
deleted file mode 100755 (executable)
index 923b29a..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * accel_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 _ACCEL_SENSOR_HAL_H_
-#define _ACCEL_SENSOR_HAL_H_
-
-#include <sensor_hal_base.h>
-
-class accel_sensor_hal : public sensor_hal_base
-{
-public:
-       accel_sensor_hal();
-       virtual ~accel_sensor_hal();
-
-       int get_poll_fd(void);
-       bool get_sensors(std::vector<sensor_handle_t> &sensors);
-       bool enable(uint32_t id);
-       bool disable(uint32_t id);
-       bool set_interval(uint32_t id, unsigned long val);
-       bool set_batch_latency(uint32_t id, unsigned long val);
-       bool set_command(uint32_t id, std::string command, std::string value);
-       bool is_data_ready(void);
-       bool get_sensor_data(uint32_t id, sensor_data_t &data);
-       int get_sensor_event(uint32_t id, sensor_event_t **event);
-       bool get_properties(uint32_t id, sensor_properties_s &properties);
-
-private:
-       int m_node_handle;
-       int m_x;
-       int m_y;
-       int m_z;
-       unsigned long m_polling_interval;
-       unsigned long long m_fired_time;
-       bool m_sensorhub_controlled;
-
-       std::string m_data_node;
-       std::string m_enable_node;
-       std::string m_interval_node;
-
-       bool update_value_input_event(void);
-       void raw_to_base(sensor_data_t &data);
-};
-#endif /*_ACCEL_SENSOR_HAL_CLASS_H_*/
diff --git a/src/plugins/proxi/proxi_sensor_device.cpp b/src/plugins/proxi/proxi_sensor_device.cpp
new file mode 100644 (file)
index 0000000..29410a6
--- /dev/null
@@ -0,0 +1,212 @@
+/*
+ * proxi_sensor_device
+ *
+ * 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 <proxi_sensor_device.h>
+
+#define MODEL_NAME "K2HH"
+#define VENDOR "ST Microelectronics"
+#define MIN_RANGE 0
+#define MAX_RANGE 5
+#define RESOLUTION 1
+#define MIN_INTERVAL 1
+#define FIFO_COUNT 0
+#define MAX_BATCH_COUNT 0
+
+static const sensor_properties_s proxi_properties = {
+       name : MODEL_NAME,
+       vendor : VENDOR,
+       min_range : MIN_RANGE,
+       max_range : MAX_RANGE,
+       resolution : RESOLUTION,
+       min_interval : MIN_INTERVAL,
+       fifo_count : FIFO_COUNT,
+       max_batch_count : MAX_BATCH_COUNT,
+};
+
+static const sensor_handle_t handles[] = {
+       {
+               id: 0x1,
+               name: "Proximity Sensor",
+               type: SENSOR_DEVICE_PROXIMITY,
+               event_type: (SENSOR_DEVICE_PROXIMITY << 16) | 0x0001,
+               properties : proxi_properties
+       }
+};
+
+proxi_sensor_device::proxi_sensor_device()
+: m_node_handle(-1)
+, m_state(-1)
+, m_fired_time(0)
+, m_sensorhub_controlled(false)
+{
+       const std::string sensorhub_interval_node_name = "prox_poll_delay";
+
+       node_info_query query;
+       node_info info;
+
+       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
+       query.sensor_type = "PROXI";
+       query.key = "proximity_sensor";
+       query.iio_enable_node_name = "proximity_enable";
+       query.sensorhub_interval_node_name = sensorhub_interval_node_name;
+
+       if (!get_node_info(query, info)) {
+               ERR("Failed to get node info");
+               throw ENXIO;
+       }
+
+       show_node_info(info);
+
+       m_data_node = info.data_node_path;
+       m_enable_node = info.enable_node_path;
+
+       if ((m_node_handle = open(m_data_node.c_str(), O_RDWR)) < 0) {
+               ERR("accel handle open fail for accel processor, error:%s\n", strerror(errno));
+               throw ENXIO;
+       }
+
+       INFO("Proxi_sensor_device is created!\n");
+}
+
+proxi_sensor_device::~proxi_sensor_device()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       INFO("Proxi_sensor_device is destroyed!\n");
+}
+
+bool proxi_sensor_device::get_sensors(std::vector<sensor_handle_t> &sensors)
+{
+       int size = ARRAY_SIZE(handles);
+
+       for (int i = 0; i < size; ++i)
+               sensors.push_back(handles[i]);
+
+       return true;
+}
+
+bool proxi_sensor_device::enable(uint32_t id)
+{
+       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_PROXIMITY_ENABLE_BIT);
+
+       m_fired_time = 0;
+       INFO("Enable proximity sensor");
+       return true;
+}
+
+bool proxi_sensor_device::disable(uint32_t id)
+{
+       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_PROXIMITY_ENABLE_BIT);
+
+       INFO("Disable proximity sensor");
+       return true;
+}
+
+int proxi_sensor_device::get_poll_fd()
+{
+       return m_node_handle;
+}
+
+bool proxi_sensor_device::set_interval(uint32_t id, unsigned long interval_ms)
+{
+       return true;
+}
+
+bool proxi_sensor_device::set_batch_latency(uint32_t id, unsigned long val)
+{
+       return false;
+}
+
+bool proxi_sensor_device::set_command(uint32_t id, std::string command, std::string value)
+{
+       return false;
+}
+
+bool proxi_sensor_device::is_data_ready(void)
+{
+       bool ret;
+       ret = update_value();
+       return ret;
+}
+
+bool proxi_sensor_device::update_value(void)
+{
+       struct input_event proxi_event;
+       DBG("proxi event detection!");
+
+       int len = read(m_node_handle, &proxi_event, sizeof(proxi_event));
+
+       if (len == -1) {
+               DBG("read(m_node_handle) is error:%s.\n", strerror(errno));
+               return false;
+       }
+
+       if ((proxi_event.type == EV_ABS) && (proxi_event.code == ABS_DISTANCE)) {
+               m_state = proxi_event.value;
+               m_fired_time = sensor_device_base::get_timestamp(&proxi_event.time);
+
+               DBG("m_state = %d, time = %lluus", m_state, m_fired_time);
+
+               return true;
+       }
+
+       return false;
+}
+
+bool proxi_sensor_device::get_sensor_data(uint32_t id, sensor_data_t &data)
+{
+       data.accuracy = SENSOR_ACCURACY_UNDEFINED;
+       data.timestamp = m_fired_time;
+       data.value_count = 1;
+       data.values[0] = m_state;
+
+       return true;
+}
+
+int proxi_sensor_device::get_sensor_event(uint32_t id, sensor_event_t **event)
+{
+       sensor_event_t *sensor_event;
+       sensor_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
+
+       sensor_event->data.accuracy = SENSOR_ACCURACY_GOOD;
+       sensor_event->data.timestamp = m_fired_time;
+       sensor_event->data.value_count = 1;
+       sensor_event->data.values[0] = m_state;
+
+       *event = sensor_event;
+
+       return sizeof(sensor_event_t);
+}
+
+bool proxi_sensor_device::get_properties(uint32_t id, sensor_properties_s &properties)
+{
+       properties.name = MODEL_NAME;
+       properties.vendor = VENDOR;
+       properties.min_range = proxi_properties.min_range;
+       properties.max_range = proxi_properties.max_range;
+       properties.min_interval = proxi_properties.min_interval;
+       properties.resolution = proxi_properties.resolution;
+       properties.fifo_count = proxi_properties.fifo_count;
+       properties.max_batch_count = proxi_properties.max_batch_count;
+       return true;
+}
diff --git a/src/plugins/proxi/proxi_sensor_device.h b/src/plugins/proxi/proxi_sensor_device.h
new file mode 100755 (executable)
index 0000000..368c0a2
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * proxi_sensor_device
+ *
+ * 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 _PROXI_SENSOR_DEVICE_H_
+#define _PROXI_SENSOR_DEVICE_H_
+
+#include <sensor_device_base.h>
+
+class proxi_sensor_device : public sensor_device_base
+{
+public:
+       proxi_sensor_device();
+       virtual ~proxi_sensor_device();
+
+       int get_poll_fd(void);
+       bool get_sensors(std::vector<sensor_handle_t> &sensors);
+       bool enable(uint32_t id);
+       bool disable(uint32_t id);
+       bool set_interval(uint32_t id, unsigned long ms_interval);
+       bool set_batch_latency(uint32_t id, unsigned long val);
+       bool set_command(uint32_t id, std::string command, std::string value);
+       bool is_data_ready(void);
+       bool get_sensor_data(uint32_t id, sensor_data_t &data);
+       int get_sensor_event(uint32_t id, sensor_event_t **event);
+       bool get_properties(uint32_t id, sensor_properties_s &properties);
+
+private:
+       int m_node_handle;
+       unsigned int m_state;
+       unsigned long long m_fired_time;
+       bool m_sensorhub_controlled;
+
+       std::string m_data_node;
+       std::string m_enable_node;
+
+       bool update_value(void);
+};
+#endif /*_PROXI_SENSOR_DEVICE_H_*/
diff --git a/src/plugins/proxi/proxi_sensor_hal.cpp b/src/plugins/proxi/proxi_sensor_hal.cpp
deleted file mode 100644 (file)
index ba307b8..0000000
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * proxi_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 <proxi_sensor_hal.h>
-
-#define MODEL_NAME "K2HH"
-#define VENDOR "ST Microelectronics"
-#define MIN_RANGE 0
-#define MAX_RANGE 5
-#define RESOLUTION 1
-#define MIN_INTERVAL 1
-#define FIFO_COUNT 0
-#define MAX_BATCH_COUNT 0
-
-static const sensor_properties_s proxi_properties = {
-       name : MODEL_NAME,
-       vendor : VENDOR,
-       min_range : MIN_RANGE,
-       max_range : MAX_RANGE,
-       resolution : RESOLUTION,
-       min_interval : MIN_INTERVAL,
-       fifo_count : FIFO_COUNT,
-       max_batch_count : MAX_BATCH_COUNT,
-};
-
-static const sensor_handle_t handles[] = {
-       {
-               id: 0x1,
-               name: "Proximity Sensor",
-               type: SENSOR_HAL_TYPE_PROXIMITY,
-               event_type: (SENSOR_HAL_TYPE_PROXIMITY << 16) | 0x0001,
-               properties : proxi_properties
-       }
-};
-
-proxi_sensor_hal::proxi_sensor_hal()
-: m_node_handle(-1)
-, m_state(-1)
-, m_fired_time(0)
-, m_sensorhub_controlled(false)
-{
-       const std::string sensorhub_interval_node_name = "prox_poll_delay";
-
-       node_info_query query;
-       node_info info;
-
-       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
-       query.sensor_type = "PROXI";
-       query.key = "proximity_sensor";
-       query.iio_enable_node_name = "proximity_enable";
-       query.sensorhub_interval_node_name = sensorhub_interval_node_name;
-
-       if (!get_node_info(query, info)) {
-               ERR("Failed to get node info");
-               throw ENXIO;
-       }
-
-       show_node_info(info);
-
-       m_data_node = info.data_node_path;
-       m_enable_node = info.enable_node_path;
-
-       if ((m_node_handle = open(m_data_node.c_str(), O_RDWR)) < 0) {
-               ERR("accel handle open fail for accel processor, error:%s\n", strerror(errno));
-               throw ENXIO;
-       }
-
-       INFO("Proxi_sensor_hal is created!\n");
-}
-
-proxi_sensor_hal::~proxi_sensor_hal()
-{
-       close(m_node_handle);
-       m_node_handle = -1;
-
-       INFO("Proxi_sensor_hal is destroyed!\n");
-}
-
-bool proxi_sensor_hal::get_sensors(std::vector<sensor_handle_t> &sensors)
-{
-       int size = ARRAY_SIZE(handles);
-
-       for (int i = 0; i < size; ++i)
-               sensors.push_back(handles[i]);
-
-       return true;
-}
-
-bool proxi_sensor_hal::enable(uint32_t id)
-{
-       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_PROXIMITY_ENABLE_BIT);
-
-       m_fired_time = 0;
-       INFO("Enable proximity sensor");
-       return true;
-}
-
-bool proxi_sensor_hal::disable(uint32_t id)
-{
-       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_PROXIMITY_ENABLE_BIT);
-
-       INFO("Disable proximity sensor");
-       return true;
-}
-
-int proxi_sensor_hal::get_poll_fd()
-{
-       return m_node_handle;
-}
-
-bool proxi_sensor_hal::set_interval(uint32_t id, unsigned long interval_ms)
-{
-       return true;
-}
-
-bool proxi_sensor_hal::set_batch_latency(uint32_t id, unsigned long val)
-{
-       return false;
-}
-
-bool proxi_sensor_hal::set_command(uint32_t id, std::string command, std::string value)
-{
-       return false;
-}
-
-bool proxi_sensor_hal::is_data_ready(void)
-{
-       bool ret;
-       ret = update_value();
-       return ret;
-}
-
-bool proxi_sensor_hal::update_value(void)
-{
-       struct input_event proxi_event;
-       DBG("proxi event detection!");
-
-       int len = read(m_node_handle, &proxi_event, sizeof(proxi_event));
-
-       if (len == -1) {
-               DBG("read(m_node_handle) is error:%s.\n", strerror(errno));
-               return false;
-       }
-
-       if ((proxi_event.type == EV_ABS) && (proxi_event.code == ABS_DISTANCE)) {
-               m_state = proxi_event.value;
-               m_fired_time = sensor_hal_base::get_timestamp(&proxi_event.time);
-
-               DBG("m_state = %d, time = %lluus", m_state, m_fired_time);
-
-               return true;
-       }
-
-       return false;
-}
-
-bool proxi_sensor_hal::get_sensor_data(uint32_t id, sensor_data_t &data)
-{
-       data.accuracy = SENSOR_ACCURACY_UNDEFINED;
-       data.timestamp = m_fired_time;
-       data.value_count = 1;
-       data.values[0] = m_state;
-
-       return true;
-}
-
-int proxi_sensor_hal::get_sensor_event(uint32_t id, sensor_event_t **event)
-{
-       sensor_event_t *sensor_event;
-       sensor_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
-
-       sensor_event->data.accuracy = SENSOR_ACCURACY_GOOD;
-       sensor_event->data.timestamp = m_fired_time;
-       sensor_event->data.value_count = 1;
-       sensor_event->data.values[0] = m_state;
-
-       *event = sensor_event;
-
-       return sizeof(sensor_event_t);
-}
-
-bool proxi_sensor_hal::get_properties(uint32_t id, sensor_properties_s &properties)
-{
-       properties.name = MODEL_NAME;
-       properties.vendor = VENDOR;
-       properties.min_range = proxi_properties.min_range;
-       properties.max_range = proxi_properties.max_range;
-       properties.min_interval = proxi_properties.min_interval;
-       properties.resolution = proxi_properties.resolution;
-       properties.fifo_count = proxi_properties.fifo_count;
-       properties.max_batch_count = proxi_properties.max_batch_count;
-       return true;
-}
diff --git a/src/plugins/proxi/proxi_sensor_hal.h b/src/plugins/proxi/proxi_sensor_hal.h
deleted file mode 100755 (executable)
index a804659..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * proxi_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 _PROXI_SENSOR_HAL_H_
-#define _PROXI_SENSOR_HAL_H_
-
-#include <sensor_hal_base.h>
-
-class proxi_sensor_hal : public sensor_hal_base
-{
-public:
-       proxi_sensor_hal();
-       virtual ~proxi_sensor_hal();
-
-       int get_poll_fd(void);
-       bool get_sensors(std::vector<sensor_handle_t> &sensors);
-       bool enable(uint32_t id);
-       bool disable(uint32_t id);
-       bool set_interval(uint32_t id, unsigned long ms_interval);
-       bool set_batch_latency(uint32_t id, unsigned long val);
-       bool set_command(uint32_t id, std::string command, std::string value);
-       bool is_data_ready(void);
-       bool get_sensor_data(uint32_t id, sensor_data_t &data);
-       int get_sensor_event(uint32_t id, sensor_event_t **event);
-       bool get_properties(uint32_t id, sensor_properties_s &properties);
-
-private:
-       int m_node_handle;
-       unsigned int m_state;
-       unsigned long long m_fired_time;
-       bool m_sensorhub_controlled;
-
-       std::string m_data_node;
-       std::string m_enable_node;
-
-       bool update_value(void);
-};
-#endif /*_PROXI_SENSOR_HAL_H_*/
diff --git a/src/sensor_device_create.cpp.in b/src/sensor_device_create.cpp.in
new file mode 100644 (file)
index 0000000..c840a42
--- /dev/null
@@ -0,0 +1,152 @@
+#ifdef ENABLE_ACCEL
+#include <accel_sensor_device.h>
+#endif
+#ifdef ENABLE_BIO_LED_RED
+#include <bio_led_red_sensor_device.h>
+#endif
+#ifdef ENABLE_GEO
+#include <geo_sensor_device.h>
+#endif
+#ifdef ENABLE_GYRO
+#include <gyro_sensor_device.h>
+#endif
+#ifdef ENABLE_LIGHT
+#include <light_sensor_device.h>
+#endif
+#ifdef ENABLE_PRESSURE
+#include <pressure_sensor_device.h>
+#endif
+#ifdef ENABLE_PROXI
+#include <proxi_sensor_device.h>
+#endif
+#ifdef ENABLE_RV_RAW
+#include <rv_raw_sensor_device.h>
+#endif
+#ifdef ENABLE_TEMPERATURE
+#include <temperature_sensor_device.h>
+#endif
+#ifdef ENABLE_ULTRAVIOLET
+#include <ultraviolet_sensor_device.h>
+#endif
+
+#include <sensor_common.h>
+
+extern "C" sensor_devices* create(void)
+{
+       sensor_devices *devices = new(std::nothrow) sensor_devices;
+       retvm_if(!devices, NULL, "Failed to allocate memory");
+
+#ifdef ENABLE_ACCEL
+       accel_sensor_device *accel_sensor = NULL;
+       try {
+               accel_sensor = new(std::nothrow) accel_sensor_device;
+       } catch (int err) {
+               ERR("Failed to create accel_sensor_device devices, err: %d, cause: %s", err, strerror(err));
+       }
+
+       if (accel_sensor != NULL) {
+               devices->devices.push_back(accel_sensor);
+       }
+#endif
+
+#ifdef ENABLE_BIO_LED_RED
+       bio_led_red_sensor_device *bio_led_red_sensor = NULL;
+       try {
+               bio_led_red_sensor = new(std::nothrow) bio_led_red_sensor_device;
+       } catch (int err) {
+               ERR("Failed to create bio_led_red_sensor_device devices, err: %d, cause: %s", err, strerror(err));
+       }
+       if (bio_led_red_sensor != NULL)
+               devices->devices.push_back(bio_led_red_sensor);
+#endif
+
+#ifdef ENABLE_GEO
+       geo_sensor_device *geo_sensor = NULL;
+       try {
+               geo_sensor = new(std::nothrow) geo_sensor_device;
+       } catch (int err) {
+               ERR("Failed to create geo_sensor_device devices, err: %d, cause: %s", err, strerror(err));
+       }
+       if (geo_sensor != NULL)
+               devices->devices.push_back(geo_sensor);
+#endif
+
+#ifdef ENABLE_GYRO
+       gyro_sensor_device *gyro_sensor = NULL;
+       try {
+               gyro_sensor = new(std::nothrow) gyro_sensor_device;
+       } catch (int err) {
+               ERR("Failed to create gyro_sensor_device devices, err: %d, cause: %s", err, strerror(err));
+       }
+       if (gyro_sensor != NULL)
+               devices->devices.push_back(gyro_sensor);
+#endif
+
+#ifdef ENABLE_LIGHT
+       light_sensor_device *light_sensor = NULL;
+       try {
+               light_sensor = new(std::nothrow) light_sensor_device;
+       } catch (int err) {
+               ERR("Failed to create light_sensor_device devices, err: %d, cause: %s", err, strerror(err));
+       }
+       if (light_sensor != NULL)
+               devices->devices.push_back(light_sensor);
+#endif
+
+#ifdef ENABLE_PRESSURE
+       pressure_sensor_device *pressure_sensor = NULL;
+       try {
+               pressure_sensor = new(std::nothrow) pressure_sensor_device;
+       } catch (int err) {
+               ERR("Failed to create pressure_sensor_device devices, err: %d, cause: %s", err, strerror(err));
+       }
+       if (pressure_sensor != NULL)
+               devices->devices.push_back(pressure_sensor);
+#endif
+
+#ifdef ENABLE_PROXI
+       proxi_sensor_device *proxi_sensor = NULL;
+       try {
+               proxi_sensor = new(std::nothrow) proxi_sensor_device;
+       } catch (int err) {
+               ERR("Failed to create proxi_sensor_device devices, err: %d, cause: %s", err, strerror(err));
+       }
+       if (proxi_sensor != NULL)
+               devices->devices.push_back(proxi_sensor);
+#endif
+
+#ifdef ENABLE_RV_RAW
+       rv_raw_sensor_device *rv_raw_sensor = NULL;
+       try {
+               rv_raw_sensor = new(std::nothrow) rv_raw_sensor_device;
+       } catch (int err) {
+               ERR("Failed to create rv_raw_sensor_device devices, err: %d, cause: %s", err, strerror(err));
+       }
+       if (rv_raw_sensor != NULL)
+               devices->devices.push_back(rv_raw_sensor);
+#endif
+
+#ifdef ENABLE_TEMPERATURE
+       temperature_sensor_device *temperature_sensor = NULL;
+       try {
+               temperature_sensor = new(std::nothrow) temperature_sensor_device;
+       } catch (int err) {
+               ERR("Failed to create temperature_sensor_device devices, err: %d, cause: %s", err, strerror(err));
+       }
+       if (temperature_sensor != NULL)
+               devices->devices.push_back(temperature_sensor);
+#endif
+
+#ifdef ENABLE_ULTRAVIOLET
+       ultraviolet_sensor_device *ultraviolet_sensor = NULL;
+       try {
+               ultraviolet_sensor = new(std::nothrow) ultraviolet_sensor_device;
+       } catch (int err) {
+               ERR("Failed to create ultraviolet_sensor_device devices, err: %d, cause: %s", err, strerror(err));
+       }
+       if (ultraviolet_sensor != NULL)
+               devices->devices.push_back(ultraviolet_sensor);
+#endif
+
+       return devices;
+}