sensor-hal: re-organize build procedure
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 3 Feb 2016 07:48:13 +0000 (16:48 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 3 Feb 2016 07:48:13 +0000 (16:48 +0900)
Change-Id: I7e34d8f61cc69c2c8a021fcb9969f48882aa048e
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
58 files changed:
CMakeLists.txt
packaging/sensor-plugins-tm1.spec
src/CMakeLists.txt [deleted file]
src/accel/accel_sensor_device.cpp [new file with mode: 0644]
src/accel/accel_sensor_device.h [new file with mode: 0644]
src/create.cpp [new file with mode: 0644]
src/gyro/gyro_sensor_hal.cpp [new file with mode: 0644]
src/gyro/gyro_sensor_hal.h [new file with mode: 0644]
src/hrm_led_red/bio_led_red_sensor_hal.cpp [new file with mode: 0644]
src/hrm_led_red/bio_led_red_sensor_hal.h [new file with mode: 0644]
src/interface/sensor_device_base.cpp [deleted file]
src/interface/sensor_device_base.h [deleted file]
src/interface/sensor_hal.h [deleted file]
src/lib/cconfig.cpp [deleted file]
src/lib/cconfig.h [deleted file]
src/lib/sensor_common.h [deleted file]
src/lib/sensor_logs.cpp [deleted file]
src/lib/sensor_logs.h [deleted file]
src/light/light_sensor_hal.cpp [new file with mode: 0644]
src/light/light_sensor_hal.h [new file with mode: 0644]
src/magnetic/geo_sensor_hal.cpp [new file with mode: 0644]
src/magnetic/geo_sensor_hal.h [new file with mode: 0644]
src/plugins/accel/accel_sensor_device.cpp [deleted file]
src/plugins/accel/accel_sensor_device.h [deleted file]
src/plugins/bio_led_red/bio_led_red_sensor_hal.cpp [deleted file]
src/plugins/bio_led_red/bio_led_red_sensor_hal.h [deleted file]
src/plugins/geo/geo_sensor_hal.cpp [deleted file]
src/plugins/geo/geo_sensor_hal.h [deleted file]
src/plugins/gyro/gyro_sensor_hal.cpp [deleted file]
src/plugins/gyro/gyro_sensor_hal.h [deleted file]
src/plugins/light/light_sensor_hal.cpp [deleted file]
src/plugins/light/light_sensor_hal.h [deleted file]
src/plugins/pressure/pressure_sensor_hal.cpp [deleted file]
src/plugins/pressure/pressure_sensor_hal.h [deleted file]
src/plugins/proxi/proxi_sensor_device.cpp [deleted file]
src/plugins/proxi/proxi_sensor_device.h [deleted file]
src/plugins/rotation_vector/rv_raw/rv_raw_sensor_hal.cpp [deleted file]
src/plugins/rotation_vector/rv_raw/rv_raw_sensor_hal.h [deleted file]
src/plugins/temperature/temperature_sensor_hal.cpp [deleted file]
src/plugins/temperature/temperature_sensor_hal.h [deleted file]
src/plugins/ultraviolet/ultraviolet_sensor_hal.cpp [deleted file]
src/plugins/ultraviolet/ultraviolet_sensor_hal.h [deleted file]
src/pressure/pressure_sensor_hal.cpp [new file with mode: 0644]
src/pressure/pressure_sensor_hal.h [new file with mode: 0644]
src/proximity/proxi_sensor_device.cpp [new file with mode: 0644]
src/proximity/proxi_sensor_device.h [new file with mode: 0644]
src/rotation_vector/rv_raw/rv_raw_sensor_hal.cpp [new file with mode: 0644]
src/rotation_vector/rv_raw/rv_raw_sensor_hal.h [new file with mode: 0644]
src/sensor_common.h [new file with mode: 0644]
src/sensor_device_base.cpp [new file with mode: 0644]
src/sensor_device_base.h [new file with mode: 0644]
src/sensor_device_create.cpp.in [deleted file]
src/sensor_hal.h [new file with mode: 0644]
src/sensor_logs.h [new file with mode: 0644]
src/temperature/temperature_sensor_hal.cpp [new file with mode: 0644]
src/temperature/temperature_sensor_hal.h [new file with mode: 0644]
src/ultraviolet/ultraviolet_sensor_hal.cpp [new file with mode: 0644]
src/ultraviolet/ultraviolet_sensor_hal.h [new file with mode: 0644]

index 3e511fe234b53e491cd278945359873ed803a88c..7d06cdb550ca8e29fba915a08425590db5a48bc1 100644 (file)
@@ -1,6 +1,19 @@
-cmake_minimum_required(VERSION 2.6)
-project(sensor-plugins CXX)
-include(GNUInstallDirs)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(sensor-plugins-tm1 CXX)
+INCLUDE(GNUInstallDirs)
+
+
+SET(ACCEL "ON")
+SET(GYRO "OFF")
+SET(PROXIMITY "ON")
+SET(LIGHT "OFF")
+SET(MAGNETIC "OFF")
+SET(PRESSURE "OFF")
+SET(TEMPERATURE "OFF")
+SET(ULTRAVIOLET "OFF")
+SET(ROTATION_VECTOR "OFF")
+SET(HRM_LED_RED "OFF")
+
 
 # Common Options
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -omit-frame-pointer -std=gnu++0x")
@@ -9,11 +22,77 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-section -Wl,--pri
 MESSAGE("FLAGS: ${CMAKE_CXX_FLAGS}")
 MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
 
-add_definitions(-DUSE_DLOG_LOG)
-add_definitions(-DLIBDIR="${CMAKE_INSTALL_LIBDIR}")
-
 # Internal Debugging Options
-#add_definitions(-Wall -g -D_DEBUG)
+#ADD_DEFINITIONS(-Wall -g -D_DEBUG)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(plugin_pkgs REQUIRED dlog)
+
+FOREACH(flag ${plugin_pkgs_LDFLAGS})
+       SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
+ENDFOREACH(flag)
+
+FOREACH(flag ${plugin_pkgs_CFLAGS})
+       SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
+FILE(GLOB SRCS src/*.cpp)
+
+IF("${ACCEL}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/accel/*.cpp)
+ADD_DEFINITIONS(-DENABLE_ACCEL)
+ENDIF()
+
+IF("${GYRO}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/gyro/*.cpp)
+ADD_DEFINITIONS(-DENABLE_GYRO)
+ENDIF()
+
+IF("${PROXIMITY}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/proximity/*.cpp)
+ADD_DEFINITIONS(-DENABLE_PROXIMITY)
+ENDIF()
+
+IF("${LIGHT}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/light/*.cpp)
+ADD_DEFINITIONS(-DENABLE_LIGHT)
+ENDIF()
+
+IF("${MAGNETIC}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/magnetic/*.cpp)
+ADD_DEFINITIONS(-DENABLE_MAGNETIC)
+ENDIF()
+
+IF("${PRESSURE}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/pressure/*.cpp)
+ADD_DEFINITIONS(-DENABLE_PRESSURE)
+ENDIF()
+
+IF("${TEMPERATURE}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/temperature/*.cpp)
+ADD_DEFINITIONS(-DENABLE_TEMPERATURE)
+ENDIF()
+
+IF("${ULTRAVIOLET}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/ultraviolet/*.cpp)
+ADD_DEFINITIONS(-DENABLE_ULTRAVIOLET)
+ENDIF()
+
+IF("${HRM_LED_RED}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/hrm_led_led/*.cpp)
+ADD_DEFINITIONS(-DENABLE_HRM_LED_RED)
+ENDIF()
+
+IF("${ROTATION_VECTOR}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/rotation_vector/*.cpp)
+ADD_DEFINITIONS(-DENABLE_ROTATION_VECTOR)
+ENDIF()
+
+MESSAGE("Sources: ${SRCS}")
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${plugin_pkgs_LDFLAGS})
 
-# Sub-directory
-add_subdirectory(src)
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor)
index 644c42fd706f46109d0309f5ce2c409ca45bf9f5..c91ca74f676a029e19fe18198ed75d36d015b535 100644 (file)
@@ -2,7 +2,7 @@ Name:       sensor-plugins-tm1
 Summary:    TM1 Sensor Plugins
 Version:    1.0.0
 Release:    0
-Group:      System/Sensor Framework
+Group:      Service/Sensor
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 
@@ -15,31 +15,18 @@ ExcludeArch: %{arm} aarch64 %ix86 x86_64
 BuildRequires:  cmake
 BuildRequires:  pkgconfig(dlog)
 
-%define accel_state ON
-%define gyro_state OFF
-%define proxi_state ON
-%define light_state OFF
-%define geo_state OFF
-%define pressure_state OFF
-%define temperature_state OFF
-%define ultraviolet_state OFF
-%define rv_state OFF
-%define bio_led_red_state OFF
-
 %description
 TM1 Sensor Plugins
 
 %prep
 %setup -q
 
-cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DACCEL=%{accel_state} \
--DGYRO=%{gyro_state} -DPROXI=%{proxi_state} -DLIGHT=%{light_state} \
--DGEO=%{geo_state} -DPRESSURE=%{pressure_state} -DTEMPERATURE=%{temperature_state} \
--DRV=%{rv_state} -DULTRAVIOLET=%{ultraviolet_state} \
--DBIO_LED_RED=%{bio_led_red_state} \
--DLIBDIR=%{_libdir} -DINCLUDEDIR=%{_includedir}
-
 %build
+export CXXFLAGS+=" -Wextra -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wswitch-default"
+export CXXFLAGS+=" -Wnon-virtual-dtor -Wno-c++0x-compat -Wno-unused-parameter -Wno-empty-body"
+export CXXFLAGS+=" -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-strict-aliasing"
+export CXXFLAGS+=" -fno-unroll-loops -fsigned-char -fstrict-overflow"
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
 make %{?jobs:-j%jobs}
 
 %install
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
deleted file mode 100644 (file)
index 29eb9a6..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-cmake_minimum_required(VERSION 2.6)
-project(sensor-plugins-tm1 CXX)
-
-INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(plugin_pkgs REQUIRED dlog)
-
-FOREACH(flag ${plugin_pkgs_LDFLAGS})
-       SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
-ENDFOREACH(flag)
-
-FOREACH(flag ${plugin_pkgs_CFLAGS})
-       SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
-ENDFOREACH(flag)
-
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
-
-include_directories(${CMAKE_SOURCE_DIR}/src/lib)
-include_directories(${CMAKE_SOURCE_DIR}/src/interface)
-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_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_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_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_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_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_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_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_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_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_device.cpp")
-add_definitions(-DENABLE_RV_RAW)
-ENDIF()
-
-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_device_base.cpp
-       interface/sensor_hal.h
-       sensor_device_create.cpp
-)
-
-target_link_libraries(${PROJECT_NAME} ${plugin_pkgs_LDFLAGS})
-
-install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor)
diff --git a/src/accel/accel_sensor_device.cpp b/src/accel/accel_sensor_device.cpp
new file mode 100644 (file)
index 0000000..412bd32
--- /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 <sys/poll.h>
+#include "accel_sensor_device.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/accel/accel_sensor_device.h b/src/accel/accel_sensor_device.h
new file mode 100644 (file)
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/create.cpp b/src/create.cpp
new file mode 100644 (file)
index 0000000..e7e6ab8
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * sensor-plugins-tm1
+ *
+ * Copyright (c) 2016 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_common.h>
+
+#include "accel/accel_sensor_device.h"
+//#include "gyro/gyro_sensor_device.h"
+//#include "magnetic/geo_sensor_device.h"
+#include "proximity/proxi_sensor_device.h"
+//#include "light/light_sensor_device.h"
+//#include "rotation_vector/rv_raw_sensor_device.h"
+//#include "pressure/pressure_sensor_device.h"
+//#include "temperature/temperature_sensor_device.h"
+//#include "ultraviolet/ultraviolet_sensor_device.h"
+//#include "hrm_led_red/bio_led_red_sensor_device.h"
+
+static sensor_devices *devices = NULL;
+
+template<typename _sensor>
+void create_sensor(const char *name)
+{
+       sensor_device *instance = NULL;
+       try {
+               instance = new _sensor;
+       } catch (std::exception &e) {
+               ERR("Failed to create %s sensor device, exception: %s", name, e.what());
+               return;
+       } catch (int err) {
+               ERR("Failed to create %s sensor device, err: %d, cause: %s", name, err, strerror(err));
+               return;
+       }
+
+       devices->devices.push_back(instance);
+}
+
+extern "C" sensor_devices* create(void)
+{
+       devices = new(std::nothrow) sensor_devices;
+       retvm_if(!devices, NULL, "Failed to allocate memory");
+
+#ifdef ENABLE_ACCEL
+       create_sensor<accel_sensor_device>("Accel");
+#endif
+
+#ifdef ENABLE_GYRO
+       create_sensor<gyro_sensor_device>("Gyro");
+#endif
+
+#ifdef ENABLE_MAGNETIC
+       create_sensor<geo_sensor_device>("Magnetic");
+#endif
+
+#ifdef ENABLE_PROXIMITY
+       create_sensor<proxi_sensor_device>("Proximity");
+#endif
+
+#ifdef ENABLE_LIGHT
+       create_sensor<light_sensor_device>("Light");
+#endif
+
+#ifdef ENABLE_ROTATION_VECTOR
+       create_sensor<rv_raw_sensor_device>("Rotation Vector");
+#endif
+
+#ifdef ENABLE_PRESSURE
+       create_sensor<pressure_sensor_device>("Pressure");
+#endif
+
+#ifdef ENABLE_TEMPERATURE
+       create_sensor<temperature_sensor_device>("Temperature");
+#endif
+
+#ifdef ENABLE_ULTRAVIOLET
+       create_sensor<ultraviolet_sensor_device>("Ultraviolet");
+#endif
+
+#ifdef ENABLE_HRM_LED_RED
+       create_sensor<bio_led_red_sensor_device>("HRM Led Red");
+#endif
+
+       return devices;
+}
diff --git a/src/gyro/gyro_sensor_hal.cpp b/src/gyro/gyro_sensor_hal.cpp
new file mode 100644 (file)
index 0000000..8dab83d
--- /dev/null
@@ -0,0 +1,286 @@
+/*
+ * gyro_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 <csensor_config.h>
+#include <gyro_sensor_hal.h>
+#include <sys/ioctl.h>
+#include <fstream>
+
+using std::ifstream;
+using std::string;
+
+#define DPS_TO_MDPS 1000
+#define MIN_RANGE(RES) (-((1 << (RES))/2))
+#define MAX_RANGE(RES) (((1 << (RES))/2)-1)
+#define RAW_DATA_TO_DPS_UNIT(X) ((float)(X)/((float)DPS_TO_MDPS))
+
+#define SENSOR_TYPE_GYRO               "GYRO"
+#define ELEMENT_NAME                   "NAME"
+#define ELEMENT_VENDOR                 "VENDOR"
+#define ELEMENT_RAW_DATA_UNIT  "RAW_DATA_UNIT"
+#define ELEMENT_RESOLUTION             "RESOLUTION"
+
+#define ATTR_VALUE                             "value"
+
+gyro_sensor_hal::gyro_sensor_hal()
+: m_x(-1)
+, m_y(-1)
+, m_z(-1)
+, m_node_handle(-1)
+, m_polling_interval(POLL_1HZ_MS)
+, m_fired_time(0)
+{
+       const string sensorhub_interval_node_name = "gyro_poll_delay";
+       csensor_config &config = csensor_config::get_instance();
+
+       node_info_query query;
+       node_info info;
+
+       if (!find_model_id(SENSOR_TYPE_GYRO, m_model_id)) {
+               ERR("Failed to find model id");
+               throw ENXIO;
+
+       }
+
+       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
+       query.sensor_type = SENSOR_TYPE_GYRO;
+       query.key = "gyro_sensor";
+       query.iio_enable_node_name = "gyro_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 (!config.get(SENSOR_TYPE_GYRO, 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_GYRO, m_model_id, ELEMENT_NAME, m_chip_name)) {
+               ERR("[NAME] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_chip_name = %s\n",m_chip_name.c_str());
+
+       long resolution;
+
+       if (!config.get(SENSOR_TYPE_GYRO, m_model_id, ELEMENT_RESOLUTION, resolution)) {
+               ERR("[RESOLUTION] is empty\n");
+               throw ENXIO;
+       }
+
+       m_resolution = (int)resolution;
+
+       double raw_data_unit;
+
+       if (!config.get(SENSOR_TYPE_GYRO, 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);
+
+       if ((m_node_handle = open(m_data_node.c_str(), O_RDWR)) < 0) {
+               ERR("gyro handle open fail for gyro processor, error:%s\n", strerror(errno));
+               throw ENXIO;
+       }
+
+       int clockId = CLOCK_MONOTONIC;
+       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
+               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
+
+       INFO("m_raw_data_unit = %f\n",m_raw_data_unit);
+       INFO("RAW_DATA_TO_DPS_UNIT(m_raw_data_unit) = [%f]",RAW_DATA_TO_DPS_UNIT(m_raw_data_unit));
+       INFO("gyro_sensor is created!\n");
+}
+
+gyro_sensor_hal::~gyro_sensor_hal()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       INFO("gyro_sensor is destroyed!\n");
+}
+
+string gyro_sensor_hal::get_model_id(void)
+{
+       return m_model_id;
+}
+
+sensor_hal_type_t gyro_sensor_hal::get_type(void)
+{
+       return SENSOR_HAL_TYPE_GYROSCOPE;
+}
+
+bool gyro_sensor_hal::enable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_GYROSCOPE_ENABLE_BIT);
+       set_interval(m_polling_interval);
+
+       m_fired_time = 0;
+       INFO("Gyro sensor real starting");
+       return true;
+}
+
+bool gyro_sensor_hal::disable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_GYROSCOPE_ENABLE_BIT);
+
+       INFO("Gyro sensor real stopping");
+       return true;
+
+}
+
+bool gyro_sensor_hal::set_interval(unsigned long val)
+{
+       unsigned long long polling_interval_ns;
+
+       AUTOLOCK(m_mutex);
+
+       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 gyro_sensor_hal::update_value(void)
+{
+       int gyro_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 gyro_input;
+       DBG("gyro event detection!");
+
+       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
+               int len = read(m_node_handle, &gyro_input, sizeof(gyro_input));
+               if (len != sizeof(gyro_input)) {
+                       ERR("gyro_file read fail, read_len = %d\n, %s",len, strerror(errno));
+                       return false;
+               }
+
+               ++read_input_cnt;
+
+               if (gyro_input.type == EV_REL) {
+                       switch (gyro_input.code) {
+                               case REL_RX:
+                                       gyro_raw[0] = (int)gyro_input.value;
+                                       x = true;
+                                       break;
+                               case REL_RY:
+                                       gyro_raw[1] = (int)gyro_input.value;
+                                       y = true;
+                                       break;
+                               case REL_RZ:
+                                       gyro_raw[2] = (int)gyro_input.value;
+                                       z = true;
+                                       break;
+                               default:
+                                       ERR("gyro_input event[type = %d, code = %d] is unknown.", gyro_input.type, gyro_input.code);
+                                       return false;
+                                       break;
+                       }
+               } else if (gyro_input.type == EV_SYN) {
+                       syn = true;
+                       fired_time = sensor_hal_base::get_timestamp(&gyro_input.time);
+               } else {
+                       ERR("gyro_input event[type = %d, code = %d] is unknown.", gyro_input.type, gyro_input.code);
+                       return false;
+               }
+       }
+
+       AUTOLOCK(m_value_mutex);
+
+       if (x)
+               m_x =  gyro_raw[0];
+       if (y)
+               m_y =  gyro_raw[1];
+       if (z)
+               m_z =  gyro_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 gyro_sensor_hal::is_data_ready(void)
+{
+       bool ret;
+       ret = update_value();
+       return ret;
+}
+
+int gyro_sensor_hal::get_sensor_data(sensor_data_t &data)
+{
+       AUTOLOCK(m_value_mutex);
+
+       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;
+
+       return 0;
+}
+
+bool gyro_sensor_hal::get_properties(sensor_properties_s &properties)
+{
+       properties.name = m_chip_name;
+       properties.vendor = m_vendor;
+       properties.min_range = MIN_RANGE(m_resolution)* RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
+       properties.max_range = MAX_RANGE(m_resolution)* RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
+       properties.min_interval = 1;
+       properties.resolution = RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
+       properties.fifo_count = 0;
+       properties.max_batch_count = 0;
+       return true;
+
+}
diff --git a/src/gyro/gyro_sensor_hal.h b/src/gyro/gyro_sensor_hal.h
new file mode 100644 (file)
index 0000000..aedd640
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * gyro_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 _GYRO_SENSOR_HAL_H_
+#define _GYRO_SENSOR_HAL_H_
+
+#include <sensor_hal_base.h>
+
+class gyro_sensor_hal : public sensor_hal_base
+{
+public:
+       gyro_sensor_hal();
+       virtual ~gyro_sensor_hal();
+       std::string get_model_id(void);
+       sensor_hal_type_t get_type(void);
+       bool enable(void);
+       bool disable(void);
+       bool set_interval(unsigned long ms_interval);
+       bool is_data_ready(void);
+       virtual int get_sensor_data(sensor_data_t &data);
+       virtual bool get_properties(sensor_properties_s &properties);
+
+private:
+       int m_x;
+       int m_y;
+       int m_z;
+       int m_node_handle;
+       unsigned long m_polling_interval;
+       unsigned long long m_fired_time;
+
+       std::string m_model_id;
+       std::string m_vendor;
+       std::string m_chip_name;
+
+       float m_min_range;
+       float m_max_range;
+       int m_resolution;
+       float m_raw_data_unit;
+
+       std::string m_data_node;
+       std::string m_enable_node;
+       std::string m_interval_node;
+
+       bool m_sensorhub_controlled;
+
+       cmutex m_value_mutex;
+
+       bool update_value(void);
+};
+#endif /*_GYRO_SENSOR_HAL_CLASS_H_*/
diff --git a/src/hrm_led_red/bio_led_red_sensor_hal.cpp b/src/hrm_led_red/bio_led_red_sensor_hal.cpp
new file mode 100644 (file)
index 0000000..ff4745e
--- /dev/null
@@ -0,0 +1,244 @@
+/*
+ * bio_led_red_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 <csensor_config.h>
+#include <bio_led_red_sensor_hal.h>
+#include <sys/ioctl.h>
+#include <fstream>
+
+using std::ifstream;
+using std::string;
+
+#define SENSOR_TYPE_BIO_LED_RED        "BIO_LED_RED"
+#define ELEMENT_NAME                   "NAME"
+#define ELEMENT_VENDOR                 "VENDOR"
+#define ATTR_VALUE                             "value"
+#define PATH_LED_RED_ENABLE            "/sys/class/sensors/hrm_sensor/led_current1";
+#define LED_RED_ENABLE_VALUE   255
+
+#define BIAS   1
+
+bio_led_red_sensor_hal::bio_led_red_sensor_hal()
+: m_polling_interval(POLL_1HZ_MS)
+, m_bio_led_red(0)
+, m_fired_time(0)
+, m_node_handle(-1)
+{
+       const string sensorhub_interval_node_name = "hrm_poll_delay";
+       csensor_config &config = csensor_config::get_instance();
+
+       node_info_query query;
+       node_info info;
+
+       if (!find_model_id(SENSOR_TYPE_BIO_LED_RED, m_model_id)) {
+               ERR("Failed to find model id");
+               throw ENXIO;
+
+       }
+
+       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
+       query.sensor_type = SENSOR_TYPE_BIO_LED_RED;
+       query.key = "hrm_sensor";
+       query.iio_enable_node_name = "hrm_raw_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 (!config.get(SENSOR_TYPE_BIO_LED_RED, 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_BIO_LED_RED, m_model_id, ELEMENT_NAME, m_chip_name)) {
+               ERR("[NAME] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_chip_name = %s\n",m_chip_name.c_str());
+
+       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
+               ERR("Failed to open handle(%d)", m_node_handle);
+               throw ENXIO;
+       }
+
+       int clockId = CLOCK_MONOTONIC;
+       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
+               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
+
+       INFO("bio_led_red_sensor_hal is created!\n");
+}
+
+bio_led_red_sensor_hal::~bio_led_red_sensor_hal()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       INFO("bio_led_red_sensor_hal is destroyed!\n");
+}
+
+string bio_led_red_sensor_hal::get_model_id(void)
+{
+       return m_model_id;
+}
+
+sensor_hal_type_t bio_led_red_sensor_hal::get_type(void)
+{
+       return SENSOR_HAL_TYPE_BIO_LED_RED;
+}
+
+bool bio_led_red_sensor_hal::enable(void)
+{
+       AUTOLOCK(m_mutex);
+       const string led_red_enable_path = PATH_LED_RED_ENABLE;
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_BIO_HRM_RAW_ENABLE_BIT);
+
+       if (!set_node_value(led_red_enable_path, LED_RED_ENABLE_VALUE)) {
+               ERR("Failed to set led red enable node: %s", led_red_enable_path.c_str());
+               return false;
+       }
+
+       set_interval(m_polling_interval);
+
+       m_fired_time = 0;
+       INFO("bio_led_red sensor starting");
+       return true;
+}
+
+bool bio_led_red_sensor_hal::disable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_BIO_HRM_RAW_ENABLE_BIT);
+
+       INFO("bio_led_red sensor real stopping");
+       return true;
+}
+
+bool bio_led_red_sensor_hal::set_interval(unsigned long val)
+{
+       unsigned long long polling_interval_ns;
+
+       AUTOLOCK(m_mutex);
+
+       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 bio_led_red_sensor_hal::update_value(void)
+{
+       int bio_led_red_raw = -1;
+       bool bio_led_red = false;
+       int read_input_cnt = 0;
+       const int INPUT_MAX_BEFORE_SYN = 10;
+       unsigned long long fired_time = 0;
+       bool syn = false;
+
+       struct input_event bio_led_red_event;
+       DBG("bio_led_red event detection!");
+
+       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
+               int len = read(m_node_handle, &bio_led_red_event, sizeof(bio_led_red_event));
+               if (len != sizeof(bio_led_red_event)) {
+                       ERR("bio_led_red file read fail, read_len = %d\n",len);
+                       return false;
+               }
+
+               ++read_input_cnt;
+
+               if (bio_led_red_event.type == EV_REL && bio_led_red_event.code == REL_X) {
+                       bio_led_red_raw = (int)bio_led_red_event.value;
+                       bio_led_red = true;
+               } else if (bio_led_red_event.type == EV_REL) {
+                       ERR("bio_led_red event[type = %d, code = %d] is skipped.", bio_led_red_event.type, bio_led_red_event.code);
+               } else if (bio_led_red_event.type == EV_SYN) {
+                       syn = true;
+                       fired_time = sensor_hal_base::get_timestamp(&bio_led_red_event.time);
+               } else {
+                       ERR("bio_led_red event[type = %d, code = %d] is unknown.", bio_led_red_event.type, bio_led_red_event.code);
+                       return false;
+               }
+       }
+
+       AUTOLOCK(m_value_mutex);
+
+       if (bio_led_red)
+               m_bio_led_red = bio_led_red_raw - BIAS;
+
+       m_fired_time = fired_time;
+
+       DBG("m_bio_led_red = %d, time = %lluus", m_bio_led_red, m_fired_time);
+
+       return true;
+}
+
+bool bio_led_red_sensor_hal::is_data_ready(void)
+{
+       bool ret;
+       ret = update_value();
+       return ret;
+}
+
+int bio_led_red_sensor_hal::get_sensor_data(sensor_data_t &data)
+{
+       AUTOLOCK(m_value_mutex);
+       data.accuracy = SENSOR_ACCURACY_GOOD;
+       data.timestamp = m_fired_time;
+       data.value_count = 1;
+       data.values[0] = (float) m_bio_led_red;
+
+       return 0;
+}
+
+bool bio_led_red_sensor_hal::get_properties(sensor_properties_s &properties)
+{
+       properties.name = m_chip_name;
+       properties.vendor = m_vendor;
+       properties.min_range = 0.0f;
+       properties.max_range = 1.0f;
+       properties.min_interval = 1;
+       properties.resolution = 1.0f;
+       properties.fifo_count = 0;
+       properties.max_batch_count = 0;
+
+       return true;
+}
diff --git a/src/hrm_led_red/bio_led_red_sensor_hal.h b/src/hrm_led_red/bio_led_red_sensor_hal.h
new file mode 100644 (file)
index 0000000..3a13682
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * hrm_red_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 _BIO_LED_RED_SENSOR_HAL_H_
+#define _BIO_LED_RED_SENSOR_HAL_H_
+
+#include <sensor_hal_base.h>
+
+class bio_led_red_sensor_hal : public sensor_hal_base
+{
+public:
+       bio_led_red_sensor_hal();
+       virtual ~bio_led_red_sensor_hal();
+       std::string get_model_id(void);
+       sensor_hal_type_t get_type(void);
+       bool enable(void);
+       bool disable(void);
+       bool set_interval(unsigned long val);
+       bool is_data_ready(void);
+       virtual int get_sensor_data(sensor_data_t &data);
+       bool get_properties(sensor_properties_s &properties);
+
+private:
+       std::string m_model_id;
+       std::string m_vendor;
+       std::string m_chip_name;
+
+       unsigned long m_polling_interval;
+
+       int m_bio_led_red;
+
+       unsigned long long m_fired_time;
+       int m_node_handle;
+
+       std::string m_enable_node;
+       std::string m_data_node;
+       std::string m_interval_node;
+
+       bool m_sensorhub_controlled;
+
+       cmutex m_value_mutex;
+
+       bool update_value(void);
+};
+#endif /*_BIO_LED_RED_SENSOR_HAL_CLASS_H_*/
+
diff --git a/src/interface/sensor_device_base.cpp b/src/interface/sensor_device_base.cpp
deleted file mode 100644 (file)
index 0c4f3fe..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_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
deleted file mode 100644 (file)
index 45c7d66..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_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_*/
diff --git a/src/interface/sensor_hal.h b/src/interface/sensor_hal.h
deleted file mode 100644 (file)
index 660be01..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * libsensord-share
- *
- * Copyright (c) 2015 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_H_
-#define _SENSOR_HAL_H_
-
-#include <stdint.h>
-#include <string>
-#include <vector>
-#include <sensor_common.h>
-
-#define SENSOR_HAL_VERSION(maj,min) \
-                       ((((maj) & 0xffff) << 24) | ((min) & 0xffff))
-
-/*
- * Sensor Types
- * These types are used to controll the sensors
- *
- * - base unit
- *   acceleration values : meter per second^2 (m/s^2)
- *   magnetic values     : micro-Tesla (uT)
- *   orientation values  : degrees
- *   gyroscope values    : degree/s
- *   temperature values  : degrees centigrade
- *   proximity valeus    : distance
- *   light values        : lux
- *   pressure values     : hectopascal (hPa)
- *   humidity            : relative humidity (%)
- */
-typedef enum {
-       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
- * ID can be assigned from HAL developer. so it has to be unique in HAL.
- */
-typedef struct sensor_handle_t {
-       uint32_t id;
-       std::string name;
-       sensor_device_type type;
-       unsigned int event_type; // for Internal API
-       sensor_properties_s properties;
-} sensor_handle_t;
-
-/*
- * Sensor device interface
- * 1 HAL must be abstracted from 1 device event node
- */
-class sensor_device
-{
-public:
-       uint32_t get_hal_version(void)
-       {
-               return SENSOR_HAL_VERSION(1, 0);
-       }
-
-       virtual int get_poll_fd(void) = 0;
-       virtual bool get_sensors(std::vector<sensor_handle_t> &sensors) = 0;
-
-       /* enable/disable sensor device */
-       virtual bool enable(uint32_t id) = 0;
-       virtual bool disable(uint32_t id) = 0;
-
-       /* set_command or set_option? */
-       virtual bool set_command(uint32_t id, std::string command, std::string value) = 0;
-
-       /* the belows can be merged to one */
-       virtual bool set_interval(uint32_t id, unsigned long val) = 0;
-       virtual bool set_batch_latency(uint32_t id, unsigned long val) = 0;
-
-       /* sensor fw read the data when is_data_ready() is true */
-       virtual bool is_data_ready() = 0;
-       virtual bool get_sensor_data(uint32_t id, sensor_data_t &data) = 0;
-       virtual int get_sensor_event(uint32_t id, sensor_event_t **event) = 0;
-
-       /* TODO: use get_sensors() instead of get_properties() */
-       virtual bool get_properties(uint32_t id, sensor_properties_s &properties) = 0;
-};
-#endif /* _SENSOR_HAL_H_ */
diff --git a/src/lib/cconfig.cpp b/src/lib/cconfig.cpp
deleted file mode 100755 (executable)
index 14c7f01..0000000
+++ /dev/null
@@ -1,72 +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 <cconfig.h>
-#include <fstream>
-#include <string>
-
-using std::ifstream;
-using std::string;
-using std::istringstream;
-
-cconfig::cconfig(void)
-{
-
-}
-
-cconfig::~cconfig(void)
-{
-
-}
-
-bool cconfig::get_device_id(void)
-{
-       const string INFO_INI_PATH = "/etc/info.ini";
-       const string START_DELIMETER = "Model=";
-       const string END_DELIMETER = ";";
-       string line;
-       ifstream in_file;
-       std::size_t start_pos, end_pos;
-       bool ret = false;
-
-       in_file.open(INFO_INI_PATH);
-
-       if (!in_file.is_open())
-               return false;
-
-       while (!in_file.eof()) {
-               getline(in_file, line);
-               start_pos = line.find(START_DELIMETER);
-
-               if (start_pos != std::string::npos) {
-                       start_pos = start_pos + START_DELIMETER.size();
-                       end_pos = line.find(END_DELIMETER, start_pos);
-
-                       if (end_pos != std::string::npos) {
-                               m_device_id = line.substr(start_pos, end_pos - start_pos);
-                               ret = true;
-                               break;
-                       }
-               }
-       }
-
-       in_file.close();
-
-       return ret;
-}
diff --git a/src/lib/cconfig.h b/src/lib/cconfig.h
deleted file mode 100755 (executable)
index ef2802f..0000000
+++ /dev/null
@@ -1,41 +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 _CCONFIG_H_
-#define _CCONFIG_H_
-
-#include <string>
-#include <unordered_map>
-#include <sensor_logs.h>
-
-class cconfig
-{
-protected:
-       virtual bool load_config(const std::string& config_path) = 0;
-
-       std::string m_device_id;
-public:
-       cconfig();
-       virtual ~cconfig();
-
-       bool get_device_id(void);
-
-};
-
-#endif /* _CCONFIG_H_ */
diff --git a/src/lib/sensor_common.h b/src/lib/sensor_common.h
deleted file mode 100644 (file)
index 5b58340..0000000
+++ /dev/null
@@ -1,413 +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_COMMON_H__
-#define __SENSOR_COMMON_H__
-
-#include <unistd.h>
-#include <sensor_logs.h>
-#include <string>
-#include <vector>
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
-#ifndef DEPRECATED
-#define DEPRECATED __attribute__((deprecated))
-#endif
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/**
- * @defgroup SENSOR_FRAMEWORK SensorFW
- * To support the unified API for the various sensors
- */
-
-/**
- * @defgroup SENSOR_FRAMEWORK_COMMON Sensor Framework Common API
- * @ingroup SENSOR_FRAMEWORK
- *
- * These APIs are used to control the sensors.
- * @{
- */
-
-typedef enum {
-       ALL_SENSOR = -1,
-       UNKNOWN_SENSOR = 0,
-       ACCELEROMETER_SENSOR,
-       GEOMAGNETIC_SENSOR,
-       LIGHT_SENSOR,
-       PROXIMITY_SENSOR,
-       THERMOMETER_SENSOR,
-       GYROSCOPE_SENSOR,
-       PRESSURE_SENSOR,
-       MOTION_SENSOR,
-       FUSION_SENSOR,
-       PEDOMETER_SENSOR,
-       CONTEXT_SENSOR,
-       FLAT_SENSOR,
-       BIO_SENSOR,
-       BIO_HRM_SENSOR,
-       AUTO_ROTATION_SENSOR,
-       GRAVITY_SENSOR,
-       LINEAR_ACCEL_SENSOR,
-       ROTATION_VECTOR_SENSOR,
-       GEOMAGNETIC_RV_SENSOR,
-       GAMING_RV_SENSOR,
-       ORIENTATION_SENSOR,
-       TILT_SENSOR,
-       PIR_SENSOR,
-       PIR_LONG_SENSOR,
-       TEMPERATURE_SENSOR,
-       HUMIDITY_SENSOR,
-       ULTRAVIOLET_SENSOR,
-       DUST_SENSOR,
-       BIO_LED_GREEN_SENSOR,
-       BIO_LED_IR_SENSOR,
-       BIO_LED_RED_SENSOR,
-       RV_RAW_SENSOR,
-       UNCAL_GYROSCOPE_SENSOR,
-       UNCAL_GEOMAGNETIC_SENSOR
-} sensor_type_t;
-
-typedef unsigned int sensor_id_t;
-
-typedef void *sensor_t;
-
-typedef enum {
-       SENSOR_PRIVILEGE_PUBLIC,
-       SENSOR_PRIVILEGE_INTERNAL,
-} sensor_privilege_t;
-
-#define SENSOR_DATA_VALUE_SIZE 16
-
-/*
- *     When modifying it, check copy_sensor_data()
- */
-typedef struct sensor_data_t {
-/*
- *     Use "accuracy" instead of "data_accuracy"
- *     which is going to be removed soon
- */
-       union {
-               int accuracy;
-               int data_accuracy; //deprecated
-       };
-
-       union {
-               unsigned long long timestamp;
-               unsigned long long time_stamp; //deprecated
-       };
-
-/*
- *     Use "value_count" instead of "values_num"
- *     which is going to be removed soon
- */
-       union {
-               int value_count;
-               int values_num; //deprecated
-       };
-
-       float values[SENSOR_DATA_VALUE_SIZE];
-
-/*
- *     If extra_data_size > 0,
- *     then use extra_data.
- */
-       int extra_data_size;
-       void *extra_data;
-} sensor_data_t;
-
-#define SENSOR_HUB_DATA_SIZE   4096
-
-typedef struct sensorhub_data_t {
-    int version;
-    int sensorhub;
-    int type;
-    int hub_data_size;
-    unsigned long long timestamp;
-    char hub_data[SENSOR_HUB_DATA_SIZE];
-    float data[16];
-} sensorhub_data_t;
-
-enum sensor_accuracy_t {
-       SENSOR_ACCURACY_UNDEFINED = -1,
-       SENSOR_ACCURACY_BAD = 0,
-       SENSOR_ACCURACY_NORMAL =1,
-       SENSOR_ACCURACY_GOOD = 2,
-       SENSOR_ACCURACY_VERYGOOD = 3
-};
-
-/*
- *     To prevent naming confliction as using same enums as sensor CAPI use
- */
-#ifndef __SENSOR_H__
-enum sensor_option_t {
-       SENSOR_OPTION_DEFAULT = 0,
-       SENSOR_OPTION_ON_IN_SCREEN_OFF = 1,
-       SENSOR_OPTION_ON_IN_POWERSAVE_MODE = 2,
-       SENSOR_OPTION_ALWAYS_ON = SENSOR_OPTION_ON_IN_SCREEN_OFF | SENSOR_OPTION_ON_IN_POWERSAVE_MODE,
-       SENSOR_OPTION_END
-};
-
-typedef enum sensor_option_t sensor_option_e;
-#endif
-
-/*
- *     To prevent naming confliction as using same enums as sensor CAPI use
- */
-#ifndef __SENSOR_H__
-enum sensor_wakeup_t {
-       SENSOR_WAKEUP_UNKNOWN = -1,
-       SENSOR_WAKEUP_OFF = 0,
-       SENSOR_WAKEUP_ON = 1,
-};
-
-typedef enum sensor_wakeup_t sensor_wakeup_e;
-#endif
-
-enum sensor_interval_t {
-       SENSOR_INTERVAL_FASTEST = 0,
-       SENSOR_INTERVAL_NORMAL = 200,
-};
-
-typedef enum {
-       CONDITION_NO_OP,
-       CONDITION_EQUAL,
-       CONDITION_GREAT_THAN,
-       CONDITION_LESS_THAN,
-} condition_op_t;
-
-#define COMMAND_CHANNEL_PATH                   "/tmp/sensord_command_socket"
-#define EVENT_CHANNEL_PATH                             "/tmp/sensord_event_socket"
-
-#define MAX_HANDLE                     256
-#define MAX_HANDLE_REACHED     -2
-
-#define CLIENT_ID_INVALID   -1
-
-#define SENSOR_TYPE_MASK  0xFFFF
-
-enum packet_type_t {
-       CMD_NONE = 0,
-       CMD_GET_ID,
-       CMD_GET_SENSOR_LIST,
-       CMD_HELLO,
-       CMD_BYEBYE,
-       CMD_DONE,
-       CMD_START,
-       CMD_STOP,
-       CMD_REG,
-       CMD_UNREG,
-       CMD_SET_OPTION,
-       CMD_SET_WAKEUP,
-       CMD_SET_BATCH,
-       CMD_UNSET_BATCH,
-       CMD_SET_COMMAND,
-       CMD_GET_DATA,
-       CMD_SEND_SENSORHUB_DATA,
-       CMD_CNT,
-};
-
-enum sensor_state_t {
-       SENSOR_STATE_UNKNOWN = -1,
-       SENSOR_STATE_STOPPED = 0,
-       SENSOR_STATE_STARTED = 1,
-       SENSOR_STATE_PAUSED = 2
-};
-
-enum poll_interval_t {
-       POLL_100HZ_MS   = 10,
-       POLL_50HZ_MS    = 20,
-       POLL_25HZ_MS    = 40,
-       POLL_20HZ_MS    = 50,
-       POLL_10HZ_MS    = 100,
-       POLL_5HZ_MS             = 200,
-       POLL_1HZ_MS             = 1000,
-       POLL_MAX_HZ_MS  = POLL_1HZ_MS,
-};
-
-typedef struct {
-       char name[NAME_MAX];
-} cmd_get_id_t;
-
-typedef struct {
-} cmd_get_sensor_list_t;
-
-typedef struct {
-       int client_id;
-       int sensor;
-} cmd_hello_t;
-
-typedef struct {
-} cmd_byebye_t;
-
-
-typedef struct {
-       unsigned int type;
-} cmd_get_data_t;
-
-typedef struct {
-       long value;
-} cmd_done_t;
-
-
-typedef struct {
-       int client_id;
-} cmd_get_id_done_t;
-
-typedef struct {
-       int sensor_cnt;
-       char data[0];
-} cmd_get_sensor_list_done_t;
-
-typedef struct {
-       int state;
-       sensor_data_t base_data;
-} cmd_get_data_done_t;
-
-typedef struct {
-} cmd_start_t;
-
-typedef struct {
-} cmd_stop_t;
-
-typedef struct {
-       unsigned int event_type;
-} cmd_reg_t;
-
-typedef struct {
-       unsigned int event_type;
-} cmd_unreg_t;
-
-typedef struct {
-       unsigned int interval;
-       unsigned int latency;
-} cmd_set_batch_t;
-
-typedef struct {
-} cmd_unset_batch_t;
-
-typedef struct {
-       int option;
-} cmd_set_option_t;
-
-typedef struct {
-       int wakeup;
-} cmd_set_wakeup_t;
-
-typedef struct  {
-       unsigned int cmd;
-       long value;
-} cmd_set_command_t;
-
-typedef struct  {
-       int data_len;
-       char data[0];
-} cmd_send_sensorhub_data_t;
-
-#define EVENT_CHANNEL_MAGIC 0xCAFECAFE
-
-typedef struct {
-       unsigned int magic;
-       int client_id;
-} event_channel_ready_t;
-
-typedef struct {
-       std::string name;
-       std::string vendor;
-       float min_range;
-       float max_range;
-       float resolution;
-       int min_interval;
-       int fifo_count;
-       int max_batch_count;
-       bool wakeup_supported;
-} sensor_properties_s;
-
-/*
- * When modifying it, check copy_sensor*_data()
- */
-typedef struct sensor_event_t {
-       unsigned int event_type;
-       sensor_id_t sensor_id;
-       sensor_data_t data;
-} sensor_event_t;
-
-typedef struct sensorhub_event_t {
-       unsigned int event_type;
-       sensor_id_t sensor_id;
-       sensorhub_data_t data;
-} sensorhub_event_t;
-
-typedef struct {
-       std::vector<void*> devices;
-} sensor_devices;
-
-typedef sensor_devices* (*create_t)(void);
-
-typedef void *(*cmd_func_t)(void *data, void *cb_data);
-
-typedef std::vector<unsigned int> event_type_vector;
-
-enum sensorhub_enable_bit {
-       SENSORHUB_ACCELEROMETER_ENABLE_BIT = 0,
-       SENSORHUB_GYROSCOPE_ENABLE_BIT,
-       SENSORHUB_GEOMAGNETIC_UNCALIB_ENABLE_BIT,
-       SENSORHUB_GEOMAGNETIC_RAW_ENABLE_BIT,
-       SENSORHUB_GEOMAGNETIC_ENABLE_BIT,
-       SENSORHUB_PRESSURE_ENABLE_BIT,
-       SENSORHUB_GESTURE_ENABLE_BIT,
-       SENSORHUB_PROXIMITY_ENABLE_BIT,
-       SENSORHUB_TEMPERATURE_HUMIDITY_ENABLE_BIT,
-       SENSORHUB_LIGHT_ENABLE_BIT,
-       SENSORHUB_PROXIMITY_RAW_ENABLE_BIT,
-       SENSORHUB_ORIENTATION_ENABLE_BIT,
-       SENSORHUB_STEP_DETECTOR_ENABLE_BIT = 12,
-       SENSORHUB_SIG_MOTION_ENABLE_BIT,
-       SENSORHUB_GYRO_UNCALIB_ENABLE_BIT,
-       SENSORHUB_GAME_ROTATION_VECTOR_ENABLE_BIT = 15,
-       SENSORHUB_ROTATION_VECTOR_ENABLE_BIT,
-       SENSORHUB_STEP_COUNTER_ENABLE_BIT,
-       SENSORHUB_BIO_HRM_RAW_ENABLE_BIT,
-       SENSORHUB_BIO_HRM_RAW_FAC_ENABLE_BIT,
-       SENSORHUB_BIO_HRM_LIB_ENABLE_BIT,
-       SENSORHUB_TILT_MOTION,
-       SENSORHUB_UV_SENSOR,
-       SENSORHUB_PIR_ENABLE_BIT,
-       SENSORHUB_ENABLE_BIT_MAX,
-};
-
-enum sensor_permission_t {
-       SENSOR_PERMISSION_NONE  = 0,
-       SENSOR_PERMISSION_STANDARD = (1 << 0),
-       SENSOR_PERMISSION_BIO   =  (1 << 1),
-};
-
-#define BIO_SENSOR_PRIVELEGE_NAME "sensord::bio"
-#define BIO_SENSOR_ACCESS_RIGHT "rw"
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-//! End of a file
diff --git a/src/lib/sensor_logs.cpp b/src/lib/sensor_logs.cpp
deleted file mode 100644 (file)
index 0269835..0000000
+++ /dev/null
@@ -1,111 +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.
- *
- */
-
-/*TODO: clean up header files*/
-#include <syslog.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <dlog.h>
-#include "sensor_logs.h"
-
-#ifndef EXTAPI
-#define EXTAPI __attribute__((visibility("default")))
-#endif
-
-#define SF_SERVER_MSG_LOG_FILE         "/var/log/messages"
-#define FILE_LENGTH 255
-
-static int sf_debug_file_fd;
-static char sf_debug_file_buf[FILE_LENGTH];
-
-EXTAPI void sf_log(int type , int priority , const char *tag , const char *fmt , ...)
-{
-       va_list ap;
-       va_start(ap, fmt);
-
-       switch (type) {
-               case SF_LOG_PRINT_FILE:
-                       sf_debug_file_fd = open(SF_SERVER_MSG_LOG_FILE, O_WRONLY|O_CREAT|O_APPEND, 0644);
-                       if (sf_debug_file_fd != -1) {
-                               vsnprintf(sf_debug_file_buf,255, fmt , ap );
-                               int total_bytes_written = 0;
-                               while (total_bytes_written < (int) strlen(sf_debug_file_buf)){
-                                       int bytes_written = write(sf_debug_file_fd, (sf_debug_file_buf + total_bytes_written), strlen(sf_debug_file_buf) - total_bytes_written);
-                                       if (bytes_written == -1)
-                                               break;
-                                       total_bytes_written = total_bytes_written + bytes_written;
-                               }
-                               close(sf_debug_file_fd);
-                       }
-                       break;
-
-               case SF_LOG_SYSLOG:
-                       int syslog_prio;
-                       switch (priority) {
-                               case SF_LOG_ERR:
-                                       syslog_prio = LOG_ERR|LOG_DAEMON;
-                                       break;
-                               case SF_LOG_WARN:
-                                       syslog_prio = LOG_WARNING|LOG_DAEMON;
-                                       break;
-
-                               case SF_LOG_DBG:
-                                       syslog_prio = LOG_DEBUG|LOG_DAEMON;
-                                       break;
-
-                               case SF_LOG_INFO:
-                                       syslog_prio = LOG_INFO|LOG_DAEMON;
-                                       break;
-
-                               default:
-                                       syslog_prio = priority;
-                                       break;
-                       }
-
-                       vsyslog(syslog_prio, fmt, ap);
-                       break;
-
-               case SF_LOG_DLOG:
-                       if (tag) {
-                               switch (priority) {
-                                       case SF_LOG_ERR:
-                                               SLOG_VA(LOG_ERROR, tag ? tag : "NULL" , fmt ? fmt : "NULL" , ap);
-                                               break;
-
-                                       case SF_LOG_WARN:
-                                               SLOG_VA(LOG_WARN, tag ? tag : "NULL" , fmt ? fmt : "NULL" , ap);
-                                               break;
-
-                                       case SF_LOG_DBG:
-                                               SLOG_VA(LOG_DEBUG, tag ? tag : "NULL", fmt ? fmt : "NULL" , ap);
-                                               break;
-
-                                       case SF_LOG_INFO:
-                                               SLOG_VA(LOG_INFO, tag ? tag : "NULL" , fmt ? fmt : "NULL" , ap);
-                                               break;
-                               }
-                       }
-                       break;
-       }
-
-       va_end(ap);
-}
diff --git a/src/lib/sensor_logs.h b/src/lib/sensor_logs.h
deleted file mode 100755 (executable)
index 5e405ff..0000000
+++ /dev/null
@@ -1,218 +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.
- *
- */
-
-#if !defined(_COMMON_H_)
-#define _COMMON_H_
-
-#ifndef __cplusplus
-#include <stdbool.h>
-#endif /* !__cplusplus */
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#if !defined(PATH_MAX)
-#define PATH_MAX 256
-#endif
-
-#if !defined(NAME_MAX)
-#define NAME_MAX 256
-#endif
-
-
-#define SENSOR_TYPE_SHIFT 16
-
-enum sf_log_type {
-       SF_LOG_PRINT_FILE               = 1,
-       SF_LOG_SYSLOG                   = 2,
-       SF_LOG_DLOG                     = 3,
-};
-
-enum sf_priority_type {
-       SF_LOG_ERR                      = 1,
-       SF_LOG_DBG                      = 2,
-       SF_LOG_INFO                     = 3,
-       SF_LOG_WARN                     = 4,
-};
-
-void sf_log(int type , int priority , const char *tag , const char *fmt , ...);
-
-#define MICROSECONDS(tv)        ((tv.tv_sec * 1000000ll) + tv.tv_usec)
-
-#ifndef __MODULE__
-#include <string.h>
-#define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
-#endif
-
-//for new log system - dlog
-#ifdef LOG_TAG
-       #undef LOG_TAG
-#endif
-#define LOG_TAG        "SENSOR"
-
-#if defined(_DEBUG) || defined(USE_FILE_DEBUG)
-
-#define DbgPrint(fmt, arg...)   do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG , " [SF_MSG_PRT][%s:%d] " fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
-
-#endif
-
-#if defined(USE_SYSLOG_DEBUG)
-
-#define ERR(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_ERR, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define WARN(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_WARN, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define INFO(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_INFO, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define DBG(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_DBG, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-
-#define _E(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_ERR, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define _W(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_WARN, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define _I(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_INFO, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define _D(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_DBG, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define _T(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_DBG, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-
-
-#elif defined(_DEBUG) || defined(USE_DLOG_DEBUG)
-
-#define ERR(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_ERR, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define WARN(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_WARN, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define INFO(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_INFO, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define DBG(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_DBG, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-
-#define _E(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_ERR, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define _W(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_WARN, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define _I(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_INFO, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define _D(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_DBG, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define _T(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_DBG, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-
-#elif defined(USE_FILE_DEBUG)
-
-#define ERR(fmt, arg...)       do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG, "[SF_MSG_ERR][%s:%d] " fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
-#define WARN(fmt, arg...)      do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG, "[SF_MSG_WARN][%s:%d] " fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
-#define DBG(fmt, arg...)       do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG, "[SF_MSG_DBG][%s:%d] " fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
-#define INFO(fmt, arg...)      do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG, "[SF_MSG_INFO][%s:%d] " fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
-
-#define _E(fmt, arg...)        do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG ,"[SF_MSG_ERR][%s:%d] " fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
-#define _W(fmt, arg...)        do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG ,"[SF_MSG_WARN][%s:%d] " fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
-#define _I(fmt, arg...)        do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG ,"[SF_MSG_INFO][%s:%d] " fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
-#define _D(fmt, arg...)        do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG ,"[SF_MSG_DBG][%s:%d] " fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
-#define _T(fmt, arg...)        do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG ,"[SF_MSG_TEMP][%s:%d] " fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
-
-#elif defined(USE_DLOG_LOG)
-
-#define ERR(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_ERR, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define WARN(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_WARN, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define INFO(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_INFO, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-
-#define DBG(...) do{} while(0)
-#define DbgPrint(...) do{} while(0)
-
-
-#define _E(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_ERR, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define _W(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_WARN, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define _I(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_INFO, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define _D(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_DBG, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define _T(...)
-
-#else
-#define ERR(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_ERR, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define WARN(...) do{} while(0)
-#define DbgPrint(...) do{} while(0)
-#define DBG(...) do{} while(0)
-#define INFO(...) do{} while(0)
-
-#define _E(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_ERR, LOG_TAG, "%s:%s(%d)> " fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
-#define _W(...) do{} while(0)
-#define _I(...) do{} while(0)
-#define _D(...) do{} while(0)
-#define _T(...) do{} while(0)
-
-#endif
-
-
-#if defined(_DEBUG)
-#  define warn_if(expr, fmt, arg...) do { \
-               if(expr) { \
-                       DBG("(%s) -> " fmt, #expr, ##arg); \
-               } \
-       } while (0)
-#  define ret_if(expr) do { \
-               if(expr) { \
-                       DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
-                       return; \
-               } \
-       } while (0)
-#  define retv_if(expr, val) do { \
-               if(expr) { \
-                       DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
-                       return (val); \
-               } \
-       } while (0)
-#  define retm_if(expr, fmt, arg...) do { \
-               if(expr) { \
-                       ERR(fmt, ##arg); \
-                       DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
-                       return; \
-               } \
-       } while (0)
-#  define retvm_if(expr, val, fmt, arg...) do { \
-               if(expr) { \
-                       ERR(fmt, ##arg); \
-                       DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
-                       return (val); \
-               } \
-       } while (0)
-
-#else
-#  define warn_if(expr, fmt, arg...) do { \
-               if(expr) { \
-                       ERR(fmt, ##arg); \
-               } \
-       } while (0)
-#  define ret_if(expr) do { \
-               if(expr) { \
-                       return; \
-               } \
-       } while (0)
-#  define retv_if(expr, val) do { \
-               if(expr) { \
-                       return (val); \
-               } \
-       } while (0)
-#  define retm_if(expr, fmt, arg...) do { \
-               if(expr) { \
-                       ERR(fmt, ##arg); \
-                       return; \
-               } \
-       } while (0)
-#  define retvm_if(expr, val, fmt, arg...) do { \
-               if(expr) { \
-                       ERR(fmt, ##arg); \
-                       return (val); \
-               } \
-       } while (0)
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-//! End of a file
diff --git a/src/light/light_sensor_hal.cpp b/src/light/light_sensor_hal.cpp
new file mode 100644 (file)
index 0000000..4f96c55
--- /dev/null
@@ -0,0 +1,227 @@
+/*
+ * light_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 <fstream>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <linux/input.h>
+#include <csensor_config.h>
+#include <light_sensor_hal.h>
+#include <sys/ioctl.h>
+
+using std::ifstream;
+using std::string;
+
+#define SENSOR_TYPE_LIGHT              "LIGHT"
+#define ELEMENT_NAME                   "NAME"
+#define ELEMENT_VENDOR                 "VENDOR"
+#define ELEMENT_RAW_DATA_UNIT  "RAW_DATA_UNIT"
+#define ELEMENT_RESOLUTION             "RESOLUTION"
+#define ATTR_VALUE                             "value"
+#define INITIAL_TIME -1
+#define BIAS   1
+#define INVALID_VALUE  -1
+#define INITIAL_VALUE  -1
+
+light_sensor_hal::light_sensor_hal()
+: m_polling_interval(POLL_1HZ_MS)
+, m_adc(INVALID_VALUE)
+, m_fired_time(INITIAL_TIME)
+, m_node_handle(INITIAL_VALUE)
+{
+       const string sensorhub_interval_node_name = "light_poll_delay";
+       csensor_config &config = csensor_config::get_instance();
+
+       node_info_query query;
+       node_info info;
+
+       if (!find_model_id(SENSOR_TYPE_LIGHT, m_model_id)) {
+               ERR("Failed to find model id");
+               throw ENXIO;
+
+       }
+
+       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
+       query.sensor_type = SENSOR_TYPE_LIGHT;
+       query.key = "light_sensor";
+       query.iio_enable_node_name = "light_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 (!config.get(SENSOR_TYPE_LIGHT, 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_LIGHT, m_model_id, ELEMENT_NAME, m_chip_name)) {
+               ERR("[NAME] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_chip_name = %s\n",m_chip_name.c_str());
+
+       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
+               ERR("Failed to open handle(%d)", m_node_handle);
+               throw ENXIO;
+       }
+
+       int clockId = CLOCK_MONOTONIC;
+       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
+               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
+
+       INFO("light_sensor_hal is created!\n");
+}
+
+light_sensor_hal::~light_sensor_hal()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       INFO("light_sensor_hal is destroyed!\n");
+}
+
+string light_sensor_hal::get_model_id(void)
+{
+       return m_model_id;
+}
+
+
+sensor_hal_type_t light_sensor_hal::get_type(void)
+{
+       return SENSOR_HAL_TYPE_LIGHT;
+}
+
+bool light_sensor_hal::enable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_LIGHT_ENABLE_BIT);
+       set_interval(m_polling_interval);
+
+       m_fired_time = 0;
+       INFO("Light sensor real starting");
+       return true;
+}
+
+bool light_sensor_hal::disable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_LIGHT_ENABLE_BIT);
+
+       INFO("Light sensor real stopping");
+       return true;
+}
+
+bool light_sensor_hal::set_interval(unsigned long val)
+{
+       unsigned long long polling_interval_ns;
+
+       AUTOLOCK(m_mutex);
+
+       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 light_sensor_hal::update_value(void)
+{
+       unsigned short int adc = INITIAL_VALUE;
+
+       struct input_event light_event;
+       DBG("light event detection!");
+
+       int len = read(m_node_handle, &light_event, sizeof(light_event));
+       if (len == -1) {
+               DBG("read(m_node_handle) is error:%s.\n", strerror(errno));
+               return false;
+       }
+
+       if (light_event.type == EV_ABS && light_event.code == ABS_MISC) {
+               adc = light_event.value;
+       } else if (light_event.type == EV_REL && light_event.code == REL_MISC) {
+               adc = light_event.value - BIAS;
+       } else if (light_event.type == EV_REL && light_event.code == REL_RX) {
+               adc = light_event.value - BIAS;
+       } else {
+               DBG("light input event[type = %d, code = %d] is unknown.", light_event.type, light_event.code);
+               return false;
+       }
+
+       DBG("read event, len : %d, type : %x, code : %x, value : %x",
+               len, light_event.type, light_event.code, light_event.value);
+
+       DBG("update_value, adc : %d", adc);
+
+       AUTOLOCK(m_value_mutex);
+       m_adc = adc;
+       m_fired_time = sensor_hal_base::get_timestamp(&light_event.time);
+
+       return true;
+}
+
+bool light_sensor_hal::is_data_ready(void)
+{
+       bool ret;
+       ret = update_value();
+       return ret;
+}
+
+int light_sensor_hal::get_sensor_data(sensor_data_t &data)
+{
+       AUTOLOCK(m_value_mutex);
+       data.accuracy = SENSOR_ACCURACY_GOOD;
+       data.timestamp = m_fired_time;
+       data.value_count = 1;
+       data.values[0] = (float) m_adc;
+
+       return 0;
+}
+
+bool light_sensor_hal::get_properties(sensor_properties_s &properties)
+{
+       properties.name = m_chip_name;
+       properties.vendor = m_vendor;
+       properties.min_range = 0;
+       properties.max_range = 65535;
+       properties.min_interval = 1;
+       properties.resolution = 1;
+       properties.fifo_count = 0;
+       properties.max_batch_count = 0;
+       return true;
+}
diff --git a/src/light/light_sensor_hal.h b/src/light/light_sensor_hal.h
new file mode 100644 (file)
index 0000000..ff98264
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * light_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 _LIGHT_SENSOR_HAL_H_
+#define _LIGHT_SENSOR_HAL_H_
+
+#include <sensor_hal_base.h>
+
+class light_sensor_hal : public sensor_hal_base
+{
+public:
+       light_sensor_hal();
+       virtual ~light_sensor_hal();
+       std::string get_model_id(void);
+       sensor_hal_type_t get_type(void);
+       bool enable(void);
+       bool disable(void);
+       bool set_interval(unsigned long val);
+       bool is_data_ready(void);
+       virtual int get_sensor_data(sensor_data_t &data);
+       bool get_properties(sensor_properties_s &properties);
+private:
+       std::string m_model_id;
+       std::string m_vendor;
+       std::string m_chip_name;
+
+       unsigned long m_polling_interval;
+
+       int m_adc;
+
+       unsigned long long m_fired_time;
+       int m_node_handle;
+
+       std::string m_enable_node;
+       std::string m_data_node;
+       std::string m_interval_node;
+
+       bool m_sensorhub_controlled;
+
+       cmutex m_value_mutex;
+
+       bool update_value(void);
+};
+#endif /*_GYRO_SENSOR_HAL_CLASS_H_*/
diff --git a/src/magnetic/geo_sensor_hal.cpp b/src/magnetic/geo_sensor_hal.cpp
new file mode 100644 (file)
index 0000000..d88287f
--- /dev/null
@@ -0,0 +1,297 @@
+/*
+ * geo_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 <csensor_config.h>
+#include <geo_sensor_hal.h>
+#include <sys/ioctl.h>
+#include <fstream>
+
+using std::ifstream;
+using std::string;
+
+#define SENSOR_TYPE_MAGNETIC   "MAGNETIC"
+#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 ATTR_VALUE                             "value"
+
+geo_sensor_hal::geo_sensor_hal()
+: m_x(0)
+, m_y(0)
+, m_z(0)
+, m_hdst(0)
+, m_fired_time(0)
+, m_node_handle(-1)
+, m_polling_interval(POLL_1HZ_MS)
+{
+       const string sensorhub_interval_node_name = "mag_poll_delay";
+       csensor_config &config = csensor_config::get_instance();
+
+       node_info_query query;
+       node_info info;
+
+       if (!find_model_id(SENSOR_TYPE_MAGNETIC, m_model_id)) {
+               ERR("Failed to find model id");
+               throw ENXIO;
+       }
+
+       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
+       query.sensor_type = SENSOR_TYPE_MAGNETIC;
+       query.key = "geomagnetic_sensor";
+       query.iio_enable_node_name = "geomagnetic_enable";
+       query.sensorhub_interval_node_name = sensorhub_interval_node_name;
+
+       bool error = get_node_info(query, info);
+
+       query.key = "magnetic_sensor";
+       error |= get_node_info(query, info);
+
+       if (!error) {
+               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 (!config.get(SENSOR_TYPE_MAGNETIC, 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_MAGNETIC, m_model_id, ELEMENT_NAME, m_chip_name)) {
+               ERR("[NAME] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_chip_name = %s\n",m_chip_name.c_str());
+
+       double min_range;
+
+       if (!config.get(SENSOR_TYPE_MAGNETIC, 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_MAGNETIC, 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_MAGNETIC, 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);
+
+       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
+               ERR("Failed to open handle(%d)", m_node_handle);
+               throw ENXIO;
+       }
+
+       int clockId = CLOCK_MONOTONIC;
+       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
+               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
+
+       INFO("m_raw_data_unit = %f\n", m_raw_data_unit);
+       INFO("geo_sensor_hal is created!\n");
+}
+
+geo_sensor_hal::~geo_sensor_hal()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       INFO("geo_sensor is destroyed!\n");
+}
+
+string geo_sensor_hal::get_model_id(void)
+{
+       return m_model_id;
+}
+
+sensor_hal_type_t geo_sensor_hal::get_type(void)
+{
+       return SENSOR_HAL_TYPE_GEOMAGNETIC;
+}
+
+bool geo_sensor_hal::enable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_GEOMAGNETIC_ENABLE_BIT);
+       set_interval(m_polling_interval);
+
+       m_fired_time = 0;
+       INFO("Geo sensor real starting");
+       return true;
+}
+
+bool geo_sensor_hal::disable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_GEOMAGNETIC_ENABLE_BIT);
+
+       INFO("Geo sensor real stopping");
+       return true;
+}
+
+bool geo_sensor_hal::set_interval(unsigned long val)
+{
+       unsigned long long polling_interval_ns;
+
+       AUTOLOCK(m_mutex);
+
+       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 geo_sensor_hal::update_value(void)
+{
+       int geo_raw[4] = {0,};
+       bool x,y,z,hdst;
+       int read_input_cnt = 0;
+       const int INPUT_MAX_BEFORE_SYN = 10;
+       unsigned long long fired_time = 0;
+       bool syn = false;
+
+       x = y = z = hdst = false;
+
+       struct input_event geo_input;
+       DBG("geo event detection!");
+
+       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
+               int len = read(m_node_handle, &geo_input, sizeof(geo_input));
+               if (len != sizeof(geo_input)) {
+                       ERR("geo_file read fail, read_len = %d\n",len);
+                       return false;
+               }
+
+               ++read_input_cnt;
+
+               if (geo_input.type == EV_REL) {
+                       switch (geo_input.code) {
+                               case REL_RX:
+                                       geo_raw[0] = (int)geo_input.value;
+                                       x = true;
+                                       break;
+                               case REL_RY:
+                                       geo_raw[1] = (int)geo_input.value;
+                                       y = true;
+                                       break;
+                               case REL_RZ:
+                                       geo_raw[2] = (int)geo_input.value;
+                                       z = true;
+                                       break;
+                               case REL_HWHEEL:
+                                       geo_raw[3] = (int)geo_input.value;
+                                       hdst = true;
+                                       break;
+                               default:
+                                       ERR("geo_input event[type = %d, code = %d] is unknown.", geo_input.type, geo_input.code);
+                                       return false;
+                                       break;
+                       }
+               } else if (geo_input.type == EV_SYN) {
+                       syn = true;
+                       fired_time = sensor_hal_base::get_timestamp(&geo_input.time);
+               } else {
+                       ERR("geo_input event[type = %d, code = %d] is unknown.", geo_input.type, geo_input.code);
+                       return false;
+               }
+       }
+
+       AUTOLOCK(m_value_mutex);
+
+       if (x)
+               m_x =  geo_raw[0];
+       if (y)
+               m_y =  geo_raw[1];
+       if (z)
+               m_z =  geo_raw[2];
+       if (hdst)
+               m_hdst = geo_raw[3] - 1; /* accuracy bias: -1 */
+
+       m_fired_time = fired_time;
+
+       DBG("m_x = %d, m_y = %d, m_z = %d, m_hdst = %d, time = %lluus", m_x, m_y, m_z, m_hdst, m_fired_time);
+
+       return true;
+}
+
+bool geo_sensor_hal::is_data_ready(void)
+{
+       bool ret;
+       ret = update_value();
+       return ret;
+}
+
+int geo_sensor_hal::get_sensor_data(sensor_data_t &data)
+{
+       data.accuracy = (m_hdst == 1) ? 0 : m_hdst; /* hdst 0 and 1 are needed to calibrate */
+       data.timestamp = m_fired_time;
+       data.value_count = 3;
+       data.values[0] = (float)m_x;
+       data.values[1] = (float)m_y;
+       data.values[2] = (float)m_z;
+       return 0;
+}
+
+bool geo_sensor_hal::get_properties(sensor_properties_s &properties)
+{
+       properties.name = m_chip_name;
+       properties.vendor = m_vendor;
+       properties.min_range = m_min_range;
+       properties.max_range = m_max_range;
+       properties.min_interval = 1;
+       properties.resolution = m_raw_data_unit;
+       properties.fifo_count = 0;
+       properties.max_batch_count = 0;
+       return true;
+}
diff --git a/src/magnetic/geo_sensor_hal.h b/src/magnetic/geo_sensor_hal.h
new file mode 100644 (file)
index 0000000..99ee935
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * geo_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 _GEO_SENSOR_HAL_H_
+#define _GEO_SENSOR_HAL_H_
+
+#include <sensor_hal_base.h>
+
+class geo_sensor_hal : public sensor_hal_base
+{
+public:
+       geo_sensor_hal();
+       virtual ~geo_sensor_hal();
+       std::string get_model_id(void);
+       sensor_hal_type_t get_type(void);
+       bool enable(void);
+       bool disable(void);
+       bool set_interval(unsigned long val);
+       bool is_data_ready(void);
+       virtual int get_sensor_data(sensor_data_t &data);
+       bool get_properties(sensor_properties_s &properties);
+private:
+       std::string m_model_id;
+       std::string m_vendor;
+       std::string m_chip_name;
+
+       float m_min_range;
+       float m_max_range;
+       float m_raw_data_unit;
+
+       double m_x;
+       double m_y;
+       double m_z;
+
+       int m_hdst;
+
+       unsigned long long m_fired_time;
+       int m_node_handle;
+       unsigned long m_polling_interval;
+
+       std::string m_enable_node;
+       std::string m_data_node;
+       std::string m_interval_node;
+
+       bool m_sensorhub_controlled;
+
+       cmutex m_value_mutex;
+
+       bool update_value(void);
+};
+#endif /*_GEO_SENSOR_HAL_H_*/
diff --git a/src/plugins/accel/accel_sensor_device.cpp b/src/plugins/accel/accel_sensor_device.cpp
deleted file mode 100755 (executable)
index 129d454..0000000
+++ /dev/null
@@ -1,306 +0,0 @@
-/*
- * 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
deleted file mode 100755 (executable)
index 8c34ae5..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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/bio_led_red/bio_led_red_sensor_hal.cpp b/src/plugins/bio_led_red/bio_led_red_sensor_hal.cpp
deleted file mode 100755 (executable)
index ff4745e..0000000
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * bio_led_red_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 <csensor_config.h>
-#include <bio_led_red_sensor_hal.h>
-#include <sys/ioctl.h>
-#include <fstream>
-
-using std::ifstream;
-using std::string;
-
-#define SENSOR_TYPE_BIO_LED_RED        "BIO_LED_RED"
-#define ELEMENT_NAME                   "NAME"
-#define ELEMENT_VENDOR                 "VENDOR"
-#define ATTR_VALUE                             "value"
-#define PATH_LED_RED_ENABLE            "/sys/class/sensors/hrm_sensor/led_current1";
-#define LED_RED_ENABLE_VALUE   255
-
-#define BIAS   1
-
-bio_led_red_sensor_hal::bio_led_red_sensor_hal()
-: m_polling_interval(POLL_1HZ_MS)
-, m_bio_led_red(0)
-, m_fired_time(0)
-, m_node_handle(-1)
-{
-       const string sensorhub_interval_node_name = "hrm_poll_delay";
-       csensor_config &config = csensor_config::get_instance();
-
-       node_info_query query;
-       node_info info;
-
-       if (!find_model_id(SENSOR_TYPE_BIO_LED_RED, m_model_id)) {
-               ERR("Failed to find model id");
-               throw ENXIO;
-
-       }
-
-       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
-       query.sensor_type = SENSOR_TYPE_BIO_LED_RED;
-       query.key = "hrm_sensor";
-       query.iio_enable_node_name = "hrm_raw_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 (!config.get(SENSOR_TYPE_BIO_LED_RED, 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_BIO_LED_RED, m_model_id, ELEMENT_NAME, m_chip_name)) {
-               ERR("[NAME] is empty\n");
-               throw ENXIO;
-       }
-
-       INFO("m_chip_name = %s\n",m_chip_name.c_str());
-
-       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
-               ERR("Failed to open handle(%d)", m_node_handle);
-               throw ENXIO;
-       }
-
-       int clockId = CLOCK_MONOTONIC;
-       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
-               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
-
-       INFO("bio_led_red_sensor_hal is created!\n");
-}
-
-bio_led_red_sensor_hal::~bio_led_red_sensor_hal()
-{
-       close(m_node_handle);
-       m_node_handle = -1;
-
-       INFO("bio_led_red_sensor_hal is destroyed!\n");
-}
-
-string bio_led_red_sensor_hal::get_model_id(void)
-{
-       return m_model_id;
-}
-
-sensor_hal_type_t bio_led_red_sensor_hal::get_type(void)
-{
-       return SENSOR_HAL_TYPE_BIO_LED_RED;
-}
-
-bool bio_led_red_sensor_hal::enable(void)
-{
-       AUTOLOCK(m_mutex);
-       const string led_red_enable_path = PATH_LED_RED_ENABLE;
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_BIO_HRM_RAW_ENABLE_BIT);
-
-       if (!set_node_value(led_red_enable_path, LED_RED_ENABLE_VALUE)) {
-               ERR("Failed to set led red enable node: %s", led_red_enable_path.c_str());
-               return false;
-       }
-
-       set_interval(m_polling_interval);
-
-       m_fired_time = 0;
-       INFO("bio_led_red sensor starting");
-       return true;
-}
-
-bool bio_led_red_sensor_hal::disable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_BIO_HRM_RAW_ENABLE_BIT);
-
-       INFO("bio_led_red sensor real stopping");
-       return true;
-}
-
-bool bio_led_red_sensor_hal::set_interval(unsigned long val)
-{
-       unsigned long long polling_interval_ns;
-
-       AUTOLOCK(m_mutex);
-
-       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 bio_led_red_sensor_hal::update_value(void)
-{
-       int bio_led_red_raw = -1;
-       bool bio_led_red = false;
-       int read_input_cnt = 0;
-       const int INPUT_MAX_BEFORE_SYN = 10;
-       unsigned long long fired_time = 0;
-       bool syn = false;
-
-       struct input_event bio_led_red_event;
-       DBG("bio_led_red event detection!");
-
-       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
-               int len = read(m_node_handle, &bio_led_red_event, sizeof(bio_led_red_event));
-               if (len != sizeof(bio_led_red_event)) {
-                       ERR("bio_led_red file read fail, read_len = %d\n",len);
-                       return false;
-               }
-
-               ++read_input_cnt;
-
-               if (bio_led_red_event.type == EV_REL && bio_led_red_event.code == REL_X) {
-                       bio_led_red_raw = (int)bio_led_red_event.value;
-                       bio_led_red = true;
-               } else if (bio_led_red_event.type == EV_REL) {
-                       ERR("bio_led_red event[type = %d, code = %d] is skipped.", bio_led_red_event.type, bio_led_red_event.code);
-               } else if (bio_led_red_event.type == EV_SYN) {
-                       syn = true;
-                       fired_time = sensor_hal_base::get_timestamp(&bio_led_red_event.time);
-               } else {
-                       ERR("bio_led_red event[type = %d, code = %d] is unknown.", bio_led_red_event.type, bio_led_red_event.code);
-                       return false;
-               }
-       }
-
-       AUTOLOCK(m_value_mutex);
-
-       if (bio_led_red)
-               m_bio_led_red = bio_led_red_raw - BIAS;
-
-       m_fired_time = fired_time;
-
-       DBG("m_bio_led_red = %d, time = %lluus", m_bio_led_red, m_fired_time);
-
-       return true;
-}
-
-bool bio_led_red_sensor_hal::is_data_ready(void)
-{
-       bool ret;
-       ret = update_value();
-       return ret;
-}
-
-int bio_led_red_sensor_hal::get_sensor_data(sensor_data_t &data)
-{
-       AUTOLOCK(m_value_mutex);
-       data.accuracy = SENSOR_ACCURACY_GOOD;
-       data.timestamp = m_fired_time;
-       data.value_count = 1;
-       data.values[0] = (float) m_bio_led_red;
-
-       return 0;
-}
-
-bool bio_led_red_sensor_hal::get_properties(sensor_properties_s &properties)
-{
-       properties.name = m_chip_name;
-       properties.vendor = m_vendor;
-       properties.min_range = 0.0f;
-       properties.max_range = 1.0f;
-       properties.min_interval = 1;
-       properties.resolution = 1.0f;
-       properties.fifo_count = 0;
-       properties.max_batch_count = 0;
-
-       return true;
-}
diff --git a/src/plugins/bio_led_red/bio_led_red_sensor_hal.h b/src/plugins/bio_led_red/bio_led_red_sensor_hal.h
deleted file mode 100755 (executable)
index 3a13682..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * hrm_red_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 _BIO_LED_RED_SENSOR_HAL_H_
-#define _BIO_LED_RED_SENSOR_HAL_H_
-
-#include <sensor_hal_base.h>
-
-class bio_led_red_sensor_hal : public sensor_hal_base
-{
-public:
-       bio_led_red_sensor_hal();
-       virtual ~bio_led_red_sensor_hal();
-       std::string get_model_id(void);
-       sensor_hal_type_t get_type(void);
-       bool enable(void);
-       bool disable(void);
-       bool set_interval(unsigned long val);
-       bool is_data_ready(void);
-       virtual int get_sensor_data(sensor_data_t &data);
-       bool get_properties(sensor_properties_s &properties);
-
-private:
-       std::string m_model_id;
-       std::string m_vendor;
-       std::string m_chip_name;
-
-       unsigned long m_polling_interval;
-
-       int m_bio_led_red;
-
-       unsigned long long m_fired_time;
-       int m_node_handle;
-
-       std::string m_enable_node;
-       std::string m_data_node;
-       std::string m_interval_node;
-
-       bool m_sensorhub_controlled;
-
-       cmutex m_value_mutex;
-
-       bool update_value(void);
-};
-#endif /*_BIO_LED_RED_SENSOR_HAL_CLASS_H_*/
-
diff --git a/src/plugins/geo/geo_sensor_hal.cpp b/src/plugins/geo/geo_sensor_hal.cpp
deleted file mode 100755 (executable)
index d88287f..0000000
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * geo_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 <csensor_config.h>
-#include <geo_sensor_hal.h>
-#include <sys/ioctl.h>
-#include <fstream>
-
-using std::ifstream;
-using std::string;
-
-#define SENSOR_TYPE_MAGNETIC   "MAGNETIC"
-#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 ATTR_VALUE                             "value"
-
-geo_sensor_hal::geo_sensor_hal()
-: m_x(0)
-, m_y(0)
-, m_z(0)
-, m_hdst(0)
-, m_fired_time(0)
-, m_node_handle(-1)
-, m_polling_interval(POLL_1HZ_MS)
-{
-       const string sensorhub_interval_node_name = "mag_poll_delay";
-       csensor_config &config = csensor_config::get_instance();
-
-       node_info_query query;
-       node_info info;
-
-       if (!find_model_id(SENSOR_TYPE_MAGNETIC, m_model_id)) {
-               ERR("Failed to find model id");
-               throw ENXIO;
-       }
-
-       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
-       query.sensor_type = SENSOR_TYPE_MAGNETIC;
-       query.key = "geomagnetic_sensor";
-       query.iio_enable_node_name = "geomagnetic_enable";
-       query.sensorhub_interval_node_name = sensorhub_interval_node_name;
-
-       bool error = get_node_info(query, info);
-
-       query.key = "magnetic_sensor";
-       error |= get_node_info(query, info);
-
-       if (!error) {
-               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 (!config.get(SENSOR_TYPE_MAGNETIC, 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_MAGNETIC, m_model_id, ELEMENT_NAME, m_chip_name)) {
-               ERR("[NAME] is empty\n");
-               throw ENXIO;
-       }
-
-       INFO("m_chip_name = %s\n",m_chip_name.c_str());
-
-       double min_range;
-
-       if (!config.get(SENSOR_TYPE_MAGNETIC, 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_MAGNETIC, 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_MAGNETIC, 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);
-
-       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
-               ERR("Failed to open handle(%d)", m_node_handle);
-               throw ENXIO;
-       }
-
-       int clockId = CLOCK_MONOTONIC;
-       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
-               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
-
-       INFO("m_raw_data_unit = %f\n", m_raw_data_unit);
-       INFO("geo_sensor_hal is created!\n");
-}
-
-geo_sensor_hal::~geo_sensor_hal()
-{
-       close(m_node_handle);
-       m_node_handle = -1;
-
-       INFO("geo_sensor is destroyed!\n");
-}
-
-string geo_sensor_hal::get_model_id(void)
-{
-       return m_model_id;
-}
-
-sensor_hal_type_t geo_sensor_hal::get_type(void)
-{
-       return SENSOR_HAL_TYPE_GEOMAGNETIC;
-}
-
-bool geo_sensor_hal::enable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_GEOMAGNETIC_ENABLE_BIT);
-       set_interval(m_polling_interval);
-
-       m_fired_time = 0;
-       INFO("Geo sensor real starting");
-       return true;
-}
-
-bool geo_sensor_hal::disable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_GEOMAGNETIC_ENABLE_BIT);
-
-       INFO("Geo sensor real stopping");
-       return true;
-}
-
-bool geo_sensor_hal::set_interval(unsigned long val)
-{
-       unsigned long long polling_interval_ns;
-
-       AUTOLOCK(m_mutex);
-
-       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 geo_sensor_hal::update_value(void)
-{
-       int geo_raw[4] = {0,};
-       bool x,y,z,hdst;
-       int read_input_cnt = 0;
-       const int INPUT_MAX_BEFORE_SYN = 10;
-       unsigned long long fired_time = 0;
-       bool syn = false;
-
-       x = y = z = hdst = false;
-
-       struct input_event geo_input;
-       DBG("geo event detection!");
-
-       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
-               int len = read(m_node_handle, &geo_input, sizeof(geo_input));
-               if (len != sizeof(geo_input)) {
-                       ERR("geo_file read fail, read_len = %d\n",len);
-                       return false;
-               }
-
-               ++read_input_cnt;
-
-               if (geo_input.type == EV_REL) {
-                       switch (geo_input.code) {
-                               case REL_RX:
-                                       geo_raw[0] = (int)geo_input.value;
-                                       x = true;
-                                       break;
-                               case REL_RY:
-                                       geo_raw[1] = (int)geo_input.value;
-                                       y = true;
-                                       break;
-                               case REL_RZ:
-                                       geo_raw[2] = (int)geo_input.value;
-                                       z = true;
-                                       break;
-                               case REL_HWHEEL:
-                                       geo_raw[3] = (int)geo_input.value;
-                                       hdst = true;
-                                       break;
-                               default:
-                                       ERR("geo_input event[type = %d, code = %d] is unknown.", geo_input.type, geo_input.code);
-                                       return false;
-                                       break;
-                       }
-               } else if (geo_input.type == EV_SYN) {
-                       syn = true;
-                       fired_time = sensor_hal_base::get_timestamp(&geo_input.time);
-               } else {
-                       ERR("geo_input event[type = %d, code = %d] is unknown.", geo_input.type, geo_input.code);
-                       return false;
-               }
-       }
-
-       AUTOLOCK(m_value_mutex);
-
-       if (x)
-               m_x =  geo_raw[0];
-       if (y)
-               m_y =  geo_raw[1];
-       if (z)
-               m_z =  geo_raw[2];
-       if (hdst)
-               m_hdst = geo_raw[3] - 1; /* accuracy bias: -1 */
-
-       m_fired_time = fired_time;
-
-       DBG("m_x = %d, m_y = %d, m_z = %d, m_hdst = %d, time = %lluus", m_x, m_y, m_z, m_hdst, m_fired_time);
-
-       return true;
-}
-
-bool geo_sensor_hal::is_data_ready(void)
-{
-       bool ret;
-       ret = update_value();
-       return ret;
-}
-
-int geo_sensor_hal::get_sensor_data(sensor_data_t &data)
-{
-       data.accuracy = (m_hdst == 1) ? 0 : m_hdst; /* hdst 0 and 1 are needed to calibrate */
-       data.timestamp = m_fired_time;
-       data.value_count = 3;
-       data.values[0] = (float)m_x;
-       data.values[1] = (float)m_y;
-       data.values[2] = (float)m_z;
-       return 0;
-}
-
-bool geo_sensor_hal::get_properties(sensor_properties_s &properties)
-{
-       properties.name = m_chip_name;
-       properties.vendor = m_vendor;
-       properties.min_range = m_min_range;
-       properties.max_range = m_max_range;
-       properties.min_interval = 1;
-       properties.resolution = m_raw_data_unit;
-       properties.fifo_count = 0;
-       properties.max_batch_count = 0;
-       return true;
-}
diff --git a/src/plugins/geo/geo_sensor_hal.h b/src/plugins/geo/geo_sensor_hal.h
deleted file mode 100755 (executable)
index 99ee935..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * geo_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 _GEO_SENSOR_HAL_H_
-#define _GEO_SENSOR_HAL_H_
-
-#include <sensor_hal_base.h>
-
-class geo_sensor_hal : public sensor_hal_base
-{
-public:
-       geo_sensor_hal();
-       virtual ~geo_sensor_hal();
-       std::string get_model_id(void);
-       sensor_hal_type_t get_type(void);
-       bool enable(void);
-       bool disable(void);
-       bool set_interval(unsigned long val);
-       bool is_data_ready(void);
-       virtual int get_sensor_data(sensor_data_t &data);
-       bool get_properties(sensor_properties_s &properties);
-private:
-       std::string m_model_id;
-       std::string m_vendor;
-       std::string m_chip_name;
-
-       float m_min_range;
-       float m_max_range;
-       float m_raw_data_unit;
-
-       double m_x;
-       double m_y;
-       double m_z;
-
-       int m_hdst;
-
-       unsigned long long m_fired_time;
-       int m_node_handle;
-       unsigned long m_polling_interval;
-
-       std::string m_enable_node;
-       std::string m_data_node;
-       std::string m_interval_node;
-
-       bool m_sensorhub_controlled;
-
-       cmutex m_value_mutex;
-
-       bool update_value(void);
-};
-#endif /*_GEO_SENSOR_HAL_H_*/
diff --git a/src/plugins/gyro/gyro_sensor_hal.cpp b/src/plugins/gyro/gyro_sensor_hal.cpp
deleted file mode 100755 (executable)
index 8dab83d..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * gyro_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 <csensor_config.h>
-#include <gyro_sensor_hal.h>
-#include <sys/ioctl.h>
-#include <fstream>
-
-using std::ifstream;
-using std::string;
-
-#define DPS_TO_MDPS 1000
-#define MIN_RANGE(RES) (-((1 << (RES))/2))
-#define MAX_RANGE(RES) (((1 << (RES))/2)-1)
-#define RAW_DATA_TO_DPS_UNIT(X) ((float)(X)/((float)DPS_TO_MDPS))
-
-#define SENSOR_TYPE_GYRO               "GYRO"
-#define ELEMENT_NAME                   "NAME"
-#define ELEMENT_VENDOR                 "VENDOR"
-#define ELEMENT_RAW_DATA_UNIT  "RAW_DATA_UNIT"
-#define ELEMENT_RESOLUTION             "RESOLUTION"
-
-#define ATTR_VALUE                             "value"
-
-gyro_sensor_hal::gyro_sensor_hal()
-: m_x(-1)
-, m_y(-1)
-, m_z(-1)
-, m_node_handle(-1)
-, m_polling_interval(POLL_1HZ_MS)
-, m_fired_time(0)
-{
-       const string sensorhub_interval_node_name = "gyro_poll_delay";
-       csensor_config &config = csensor_config::get_instance();
-
-       node_info_query query;
-       node_info info;
-
-       if (!find_model_id(SENSOR_TYPE_GYRO, m_model_id)) {
-               ERR("Failed to find model id");
-               throw ENXIO;
-
-       }
-
-       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
-       query.sensor_type = SENSOR_TYPE_GYRO;
-       query.key = "gyro_sensor";
-       query.iio_enable_node_name = "gyro_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 (!config.get(SENSOR_TYPE_GYRO, 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_GYRO, m_model_id, ELEMENT_NAME, m_chip_name)) {
-               ERR("[NAME] is empty\n");
-               throw ENXIO;
-       }
-
-       INFO("m_chip_name = %s\n",m_chip_name.c_str());
-
-       long resolution;
-
-       if (!config.get(SENSOR_TYPE_GYRO, m_model_id, ELEMENT_RESOLUTION, resolution)) {
-               ERR("[RESOLUTION] is empty\n");
-               throw ENXIO;
-       }
-
-       m_resolution = (int)resolution;
-
-       double raw_data_unit;
-
-       if (!config.get(SENSOR_TYPE_GYRO, 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);
-
-       if ((m_node_handle = open(m_data_node.c_str(), O_RDWR)) < 0) {
-               ERR("gyro handle open fail for gyro processor, error:%s\n", strerror(errno));
-               throw ENXIO;
-       }
-
-       int clockId = CLOCK_MONOTONIC;
-       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
-               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
-
-       INFO("m_raw_data_unit = %f\n",m_raw_data_unit);
-       INFO("RAW_DATA_TO_DPS_UNIT(m_raw_data_unit) = [%f]",RAW_DATA_TO_DPS_UNIT(m_raw_data_unit));
-       INFO("gyro_sensor is created!\n");
-}
-
-gyro_sensor_hal::~gyro_sensor_hal()
-{
-       close(m_node_handle);
-       m_node_handle = -1;
-
-       INFO("gyro_sensor is destroyed!\n");
-}
-
-string gyro_sensor_hal::get_model_id(void)
-{
-       return m_model_id;
-}
-
-sensor_hal_type_t gyro_sensor_hal::get_type(void)
-{
-       return SENSOR_HAL_TYPE_GYROSCOPE;
-}
-
-bool gyro_sensor_hal::enable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_GYROSCOPE_ENABLE_BIT);
-       set_interval(m_polling_interval);
-
-       m_fired_time = 0;
-       INFO("Gyro sensor real starting");
-       return true;
-}
-
-bool gyro_sensor_hal::disable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_GYROSCOPE_ENABLE_BIT);
-
-       INFO("Gyro sensor real stopping");
-       return true;
-
-}
-
-bool gyro_sensor_hal::set_interval(unsigned long val)
-{
-       unsigned long long polling_interval_ns;
-
-       AUTOLOCK(m_mutex);
-
-       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 gyro_sensor_hal::update_value(void)
-{
-       int gyro_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 gyro_input;
-       DBG("gyro event detection!");
-
-       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
-               int len = read(m_node_handle, &gyro_input, sizeof(gyro_input));
-               if (len != sizeof(gyro_input)) {
-                       ERR("gyro_file read fail, read_len = %d\n, %s",len, strerror(errno));
-                       return false;
-               }
-
-               ++read_input_cnt;
-
-               if (gyro_input.type == EV_REL) {
-                       switch (gyro_input.code) {
-                               case REL_RX:
-                                       gyro_raw[0] = (int)gyro_input.value;
-                                       x = true;
-                                       break;
-                               case REL_RY:
-                                       gyro_raw[1] = (int)gyro_input.value;
-                                       y = true;
-                                       break;
-                               case REL_RZ:
-                                       gyro_raw[2] = (int)gyro_input.value;
-                                       z = true;
-                                       break;
-                               default:
-                                       ERR("gyro_input event[type = %d, code = %d] is unknown.", gyro_input.type, gyro_input.code);
-                                       return false;
-                                       break;
-                       }
-               } else if (gyro_input.type == EV_SYN) {
-                       syn = true;
-                       fired_time = sensor_hal_base::get_timestamp(&gyro_input.time);
-               } else {
-                       ERR("gyro_input event[type = %d, code = %d] is unknown.", gyro_input.type, gyro_input.code);
-                       return false;
-               }
-       }
-
-       AUTOLOCK(m_value_mutex);
-
-       if (x)
-               m_x =  gyro_raw[0];
-       if (y)
-               m_y =  gyro_raw[1];
-       if (z)
-               m_z =  gyro_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 gyro_sensor_hal::is_data_ready(void)
-{
-       bool ret;
-       ret = update_value();
-       return ret;
-}
-
-int gyro_sensor_hal::get_sensor_data(sensor_data_t &data)
-{
-       AUTOLOCK(m_value_mutex);
-
-       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;
-
-       return 0;
-}
-
-bool gyro_sensor_hal::get_properties(sensor_properties_s &properties)
-{
-       properties.name = m_chip_name;
-       properties.vendor = m_vendor;
-       properties.min_range = MIN_RANGE(m_resolution)* RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
-       properties.max_range = MAX_RANGE(m_resolution)* RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
-       properties.min_interval = 1;
-       properties.resolution = RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
-       properties.fifo_count = 0;
-       properties.max_batch_count = 0;
-       return true;
-
-}
diff --git a/src/plugins/gyro/gyro_sensor_hal.h b/src/plugins/gyro/gyro_sensor_hal.h
deleted file mode 100755 (executable)
index aedd640..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * gyro_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 _GYRO_SENSOR_HAL_H_
-#define _GYRO_SENSOR_HAL_H_
-
-#include <sensor_hal_base.h>
-
-class gyro_sensor_hal : public sensor_hal_base
-{
-public:
-       gyro_sensor_hal();
-       virtual ~gyro_sensor_hal();
-       std::string get_model_id(void);
-       sensor_hal_type_t get_type(void);
-       bool enable(void);
-       bool disable(void);
-       bool set_interval(unsigned long ms_interval);
-       bool is_data_ready(void);
-       virtual int get_sensor_data(sensor_data_t &data);
-       virtual bool get_properties(sensor_properties_s &properties);
-
-private:
-       int m_x;
-       int m_y;
-       int m_z;
-       int m_node_handle;
-       unsigned long m_polling_interval;
-       unsigned long long m_fired_time;
-
-       std::string m_model_id;
-       std::string m_vendor;
-       std::string m_chip_name;
-
-       float m_min_range;
-       float m_max_range;
-       int m_resolution;
-       float m_raw_data_unit;
-
-       std::string m_data_node;
-       std::string m_enable_node;
-       std::string m_interval_node;
-
-       bool m_sensorhub_controlled;
-
-       cmutex m_value_mutex;
-
-       bool update_value(void);
-};
-#endif /*_GYRO_SENSOR_HAL_CLASS_H_*/
diff --git a/src/plugins/light/light_sensor_hal.cpp b/src/plugins/light/light_sensor_hal.cpp
deleted file mode 100755 (executable)
index 4f96c55..0000000
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * light_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 <fstream>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <linux/input.h>
-#include <csensor_config.h>
-#include <light_sensor_hal.h>
-#include <sys/ioctl.h>
-
-using std::ifstream;
-using std::string;
-
-#define SENSOR_TYPE_LIGHT              "LIGHT"
-#define ELEMENT_NAME                   "NAME"
-#define ELEMENT_VENDOR                 "VENDOR"
-#define ELEMENT_RAW_DATA_UNIT  "RAW_DATA_UNIT"
-#define ELEMENT_RESOLUTION             "RESOLUTION"
-#define ATTR_VALUE                             "value"
-#define INITIAL_TIME -1
-#define BIAS   1
-#define INVALID_VALUE  -1
-#define INITIAL_VALUE  -1
-
-light_sensor_hal::light_sensor_hal()
-: m_polling_interval(POLL_1HZ_MS)
-, m_adc(INVALID_VALUE)
-, m_fired_time(INITIAL_TIME)
-, m_node_handle(INITIAL_VALUE)
-{
-       const string sensorhub_interval_node_name = "light_poll_delay";
-       csensor_config &config = csensor_config::get_instance();
-
-       node_info_query query;
-       node_info info;
-
-       if (!find_model_id(SENSOR_TYPE_LIGHT, m_model_id)) {
-               ERR("Failed to find model id");
-               throw ENXIO;
-
-       }
-
-       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
-       query.sensor_type = SENSOR_TYPE_LIGHT;
-       query.key = "light_sensor";
-       query.iio_enable_node_name = "light_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 (!config.get(SENSOR_TYPE_LIGHT, 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_LIGHT, m_model_id, ELEMENT_NAME, m_chip_name)) {
-               ERR("[NAME] is empty\n");
-               throw ENXIO;
-       }
-
-       INFO("m_chip_name = %s\n",m_chip_name.c_str());
-
-       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
-               ERR("Failed to open handle(%d)", m_node_handle);
-               throw ENXIO;
-       }
-
-       int clockId = CLOCK_MONOTONIC;
-       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
-               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
-
-       INFO("light_sensor_hal is created!\n");
-}
-
-light_sensor_hal::~light_sensor_hal()
-{
-       close(m_node_handle);
-       m_node_handle = -1;
-
-       INFO("light_sensor_hal is destroyed!\n");
-}
-
-string light_sensor_hal::get_model_id(void)
-{
-       return m_model_id;
-}
-
-
-sensor_hal_type_t light_sensor_hal::get_type(void)
-{
-       return SENSOR_HAL_TYPE_LIGHT;
-}
-
-bool light_sensor_hal::enable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_LIGHT_ENABLE_BIT);
-       set_interval(m_polling_interval);
-
-       m_fired_time = 0;
-       INFO("Light sensor real starting");
-       return true;
-}
-
-bool light_sensor_hal::disable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_LIGHT_ENABLE_BIT);
-
-       INFO("Light sensor real stopping");
-       return true;
-}
-
-bool light_sensor_hal::set_interval(unsigned long val)
-{
-       unsigned long long polling_interval_ns;
-
-       AUTOLOCK(m_mutex);
-
-       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 light_sensor_hal::update_value(void)
-{
-       unsigned short int adc = INITIAL_VALUE;
-
-       struct input_event light_event;
-       DBG("light event detection!");
-
-       int len = read(m_node_handle, &light_event, sizeof(light_event));
-       if (len == -1) {
-               DBG("read(m_node_handle) is error:%s.\n", strerror(errno));
-               return false;
-       }
-
-       if (light_event.type == EV_ABS && light_event.code == ABS_MISC) {
-               adc = light_event.value;
-       } else if (light_event.type == EV_REL && light_event.code == REL_MISC) {
-               adc = light_event.value - BIAS;
-       } else if (light_event.type == EV_REL && light_event.code == REL_RX) {
-               adc = light_event.value - BIAS;
-       } else {
-               DBG("light input event[type = %d, code = %d] is unknown.", light_event.type, light_event.code);
-               return false;
-       }
-
-       DBG("read event, len : %d, type : %x, code : %x, value : %x",
-               len, light_event.type, light_event.code, light_event.value);
-
-       DBG("update_value, adc : %d", adc);
-
-       AUTOLOCK(m_value_mutex);
-       m_adc = adc;
-       m_fired_time = sensor_hal_base::get_timestamp(&light_event.time);
-
-       return true;
-}
-
-bool light_sensor_hal::is_data_ready(void)
-{
-       bool ret;
-       ret = update_value();
-       return ret;
-}
-
-int light_sensor_hal::get_sensor_data(sensor_data_t &data)
-{
-       AUTOLOCK(m_value_mutex);
-       data.accuracy = SENSOR_ACCURACY_GOOD;
-       data.timestamp = m_fired_time;
-       data.value_count = 1;
-       data.values[0] = (float) m_adc;
-
-       return 0;
-}
-
-bool light_sensor_hal::get_properties(sensor_properties_s &properties)
-{
-       properties.name = m_chip_name;
-       properties.vendor = m_vendor;
-       properties.min_range = 0;
-       properties.max_range = 65535;
-       properties.min_interval = 1;
-       properties.resolution = 1;
-       properties.fifo_count = 0;
-       properties.max_batch_count = 0;
-       return true;
-}
diff --git a/src/plugins/light/light_sensor_hal.h b/src/plugins/light/light_sensor_hal.h
deleted file mode 100755 (executable)
index ff98264..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * light_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 _LIGHT_SENSOR_HAL_H_
-#define _LIGHT_SENSOR_HAL_H_
-
-#include <sensor_hal_base.h>
-
-class light_sensor_hal : public sensor_hal_base
-{
-public:
-       light_sensor_hal();
-       virtual ~light_sensor_hal();
-       std::string get_model_id(void);
-       sensor_hal_type_t get_type(void);
-       bool enable(void);
-       bool disable(void);
-       bool set_interval(unsigned long val);
-       bool is_data_ready(void);
-       virtual int get_sensor_data(sensor_data_t &data);
-       bool get_properties(sensor_properties_s &properties);
-private:
-       std::string m_model_id;
-       std::string m_vendor;
-       std::string m_chip_name;
-
-       unsigned long m_polling_interval;
-
-       int m_adc;
-
-       unsigned long long m_fired_time;
-       int m_node_handle;
-
-       std::string m_enable_node;
-       std::string m_data_node;
-       std::string m_interval_node;
-
-       bool m_sensorhub_controlled;
-
-       cmutex m_value_mutex;
-
-       bool update_value(void);
-};
-#endif /*_GYRO_SENSOR_HAL_CLASS_H_*/
diff --git a/src/plugins/pressure/pressure_sensor_hal.cpp b/src/plugins/pressure/pressure_sensor_hal.cpp
deleted file mode 100755 (executable)
index badd9bd..0000000
+++ /dev/null
@@ -1,351 +0,0 @@
-/*
- * 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 <csensor_config.h>
-#include <pressure_sensor_hal.h>
-#include <sys/ioctl.h>
-#include <fstream>
-#include <algorithm>
-
-using std::ifstream;
-using std::string;
-
-#define SENSOR_TYPE_PRESSURE           "PRESSURE"
-#define ELEMENT_NAME                   "NAME"
-#define ELEMENT_VENDOR                 "VENDOR"
-#define ELEMENT_RAW_DATA_UNIT  "RAW_DATA_UNIT"
-#define ELEMENT_RESOLUTION             "RESOLUTION"
-#define ELEMENT_MIN_RANGE              "MIN_RANGE"
-#define ELEMENT_MAX_RANGE              "MAX_RANGE"
-#define ELEMENT_TEMPERATURE_RESOLUTION "TEMPERATURE_RESOLUTION"
-#define ELEMENT_TEMPERATURE_OFFSET             "TEMPERATURE_OFFSET"
-#define ATTR_VALUE                             "value"
-
-#define SEA_LEVEL_PRESSURE 101325.0
-#define SEA_LEVEL_RESOLUTION 0.01
-
-pressure_sensor_hal::pressure_sensor_hal()
-: m_pressure(0)
-, m_sea_level_pressure(SEA_LEVEL_PRESSURE)
-, m_temperature(0)
-, m_polling_interval(POLL_1HZ_MS)
-, m_fired_time(0)
-, m_node_handle(-1)
-{
-       const string sensorhub_interval_node_name = "pressure_poll_delay";
-       csensor_config &config = csensor_config::get_instance();
-
-       node_info_query query;
-       node_info info;
-
-       if (!find_model_id(SENSOR_TYPE_PRESSURE, m_model_id)) {
-               ERR("Failed to find model id");
-               throw ENXIO;
-
-       }
-
-       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
-       query.sensor_type = SENSOR_TYPE_PRESSURE;
-       query.key = "pressure_sensor";
-       query.iio_enable_node_name = "pressure_enable";
-       query.sensorhub_interval_node_name = sensorhub_interval_node_name;
-
-       bool error = get_node_info(query, info);
-
-       query.key = "barometer_sensor";
-       error |= get_node_info(query, info);
-
-       if (!error) {
-               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 (!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);
-
-       double resolution;
-
-       if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_RESOLUTION, resolution)) {
-               ERR("[RESOLUTION] is empty\n");
-               throw ENXIO;
-       }
-
-       m_resolution = (float)resolution;
-       INFO("m_resolution = %f\n", m_resolution);
-
-       double temperature_resolution;
-
-       if (!config.get(SENSOR_TYPE_PRESSURE, m_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, m_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);
-
-       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
-               ERR("Failed to open handle(%d)", m_node_handle);
-               throw ENXIO;
-       }
-
-       int clockId = CLOCK_MONOTONIC;
-       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
-               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
-
-       INFO("pressure_sensor_hal is created!\n");
-}
-
-pressure_sensor_hal::~pressure_sensor_hal()
-{
-       close(m_node_handle);
-       m_node_handle = -1;
-
-       INFO("pressure_sensor_hal is destroyed!\n");
-}
-
-string pressure_sensor_hal::get_model_id(void)
-{
-       return m_model_id;
-}
-
-sensor_hal_type_t pressure_sensor_hal::get_type(void)
-{
-       return SENSOR_HAL_TYPE_PRESSURE;
-}
-
-bool pressure_sensor_hal::enable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_PRESSURE_ENABLE_BIT);
-
-       set_interval(m_polling_interval);
-
-       m_fired_time = 0;
-       INFO("Pressure sensor real starting");
-       return true;
-}
-
-bool pressure_sensor_hal::disable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_PRESSURE_ENABLE_BIT);
-
-       INFO("Pressure sensor real stopping");
-       return true;
-}
-
-bool pressure_sensor_hal::set_interval(unsigned long val)
-{
-       unsigned long long polling_interval_ns;
-
-       AUTOLOCK(m_mutex);
-
-       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 pressure_sensor_hal::update_value(void)
-{
-       int pressure_raw[3] = {0,};
-       bool pressure = false;
-       bool sea_level = false;
-       bool temperature = false;
-       int read_input_cnt = 0;
-       const int INPUT_MAX_BEFORE_SYN = 10;
-       unsigned long long fired_time = 0;
-       bool syn = false;
-
-       struct input_event pressure_event;
-       DBG("pressure event detection!");
-
-       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
-               int len = read(m_node_handle, &pressure_event, sizeof(pressure_event));
-               if (len != sizeof(pressure_event)) {
-                       ERR("pressure_file read fail, read_len = %d\n",len);
-                       return false;
-               }
-
-               ++read_input_cnt;
-
-               if (pressure_event.type == EV_REL) {
-                       switch (pressure_event.code) {
-                               case REL_X:
-                               case REL_HWHEEL:
-                                       pressure_raw[0] = (int)pressure_event.value;
-                                       pressure = true;
-                                       break;
-                               case REL_Y:
-                               case REL_DIAL:
-                                       pressure_raw[1] = (int)pressure_event.value;
-                                       sea_level = true;
-                                       break;
-                               case REL_Z:
-                               case REL_WHEEL:
-                                       pressure_raw[2] = (int)pressure_event.value;
-                                       temperature = true;
-                                       break;
-                               default:
-                                       ERR("pressure_event event[type = %d, code = %d] is unknown.", pressure_event.type, pressure_event.code);
-                                       return false;
-                                       break;
-                       }
-               } else if (pressure_event.type == EV_SYN) {
-                       syn = true;
-                       fired_time = sensor_hal_base::get_timestamp(&pressure_event.time);
-               } else {
-                       ERR("pressure_event event[type = %d, code = %d] is unknown.", pressure_event.type, pressure_event.code);
-                       return false;
-               }
-       }
-
-       AUTOLOCK(m_value_mutex);
-
-       if (pressure)
-               m_pressure = pressure_raw[0];
-       if (sea_level)
-               m_sea_level_pressure = pressure_raw[1];
-       if (temperature)
-               m_temperature = pressure_raw[2];
-
-       m_fired_time = fired_time;
-
-       DBG("m_pressure = %d, sea_level = %d, temperature = %d, time = %lluus", m_pressure, m_sea_level_pressure, m_temperature, m_fired_time);
-
-       return true;
-}
-
-bool pressure_sensor_hal::is_data_ready(void)
-{
-       bool ret;
-       ret = update_value();
-       return ret;
-}
-
-
-float pressure_sensor_hal::pressure_to_altitude(float pressure)
-{
-       return 44330.0f * (1.0f - pow(pressure/m_sea_level_pressure, 1.0f/5.255f));
-}
-
-void pressure_sensor_hal::raw_to_base(sensor_data_t &data)
-{
-       data.values[0] = data.values[0] * m_resolution;
-       m_sea_level_pressure = data.values[1] * SEA_LEVEL_RESOLUTION;
-       data.values[1] = pressure_to_altitude(data.values[0]);
-       data.values[2] = data.values[2] * m_temperature_resolution + m_temperature_offset;
-       data.value_count = 3;
-}
-
-int pressure_sensor_hal::get_sensor_data(sensor_data_t &data)
-{
-       AUTOLOCK(m_value_mutex);
-       data.accuracy = SENSOR_ACCURACY_GOOD;
-       data.timestamp = m_fired_time ;
-       data.value_count = 3;
-       data.values[0] = m_pressure;
-       data.values[1] = m_sea_level_pressure;
-       data.values[2] = m_temperature;
-
-       raw_to_base(data);
-
-       return 0;
-}
-
-bool pressure_sensor_hal::get_properties(sensor_properties_s &properties)
-{
-       properties.name = m_chip_name;
-       properties.vendor = m_vendor;
-       properties.min_range = m_min_range;
-       properties.max_range = m_max_range;
-       properties.min_interval = 1;
-       properties.resolution = m_raw_data_unit;
-       properties.fifo_count = 0;
-       properties.max_batch_count = 0;
-       return true;
-}
diff --git a/src/plugins/pressure/pressure_sensor_hal.h b/src/plugins/pressure/pressure_sensor_hal.h
deleted file mode 100755 (executable)
index 677b15d..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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_base.h>
-
-class pressure_sensor_hal : public sensor_hal_base
-{
-public:
-       pressure_sensor_hal();
-       virtual ~pressure_sensor_hal();
-       std::string get_model_id(void);
-       sensor_hal_type_t get_type(void);
-
-       bool enable(void);
-       bool disable(void);
-       bool set_interval(unsigned long val);
-       bool is_data_ready(void);
-       virtual int get_sensor_data(sensor_data_t &data);
-       virtual bool get_properties(sensor_properties_s &properties);
-private:
-       std::string m_model_id;
-       std::string m_vendor;
-       std::string m_chip_name;
-
-       float m_pressure;
-       float m_sea_level_pressure;
-       float m_temperature;
-       float m_temperature_offset;
-       float m_temperature_resolution;
-
-       int m_resolution;
-
-       float m_min_range;
-       float m_max_range;
-       float m_raw_data_unit;
-       float m_temp_resolution;
-       float m_temp_offset;
-       unsigned long m_polling_interval;
-
-       unsigned long long m_fired_time;
-       int m_node_handle;
-
-       std::string m_enable_node;
-       std::string m_data_node;
-       std::string m_interval_node;
-
-       bool m_sensorhub_controlled;
-
-       cmutex m_value_mutex;
-
-       bool update_value(void);
-       float pressure_to_altitude(float pressure);
-       void raw_to_base(sensor_data_t &data);
-};
-#endif /*_PRESSURE_SENSOR_HAL_CLASS_H_*/
diff --git a/src/plugins/proxi/proxi_sensor_device.cpp b/src/plugins/proxi/proxi_sensor_device.cpp
deleted file mode 100644 (file)
index 29410a6..0000000
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * 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
deleted file mode 100755 (executable)
index 368c0a2..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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/rotation_vector/rv_raw/rv_raw_sensor_hal.cpp b/src/plugins/rotation_vector/rv_raw/rv_raw_sensor_hal.cpp
deleted file mode 100755 (executable)
index 216e04d..0000000
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * rv_raw_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 <csensor_config.h>
-#include <rv_raw_sensor_hal.h>
-#include <sys/ioctl.h>
-#include <fstream>
-
-using std::ifstream;
-using std::string;
-
-#define SENSOR_TYPE_RV_RAW     "ROTATION_VECTOR"
-#define ELEMENT_NAME                   "NAME"
-#define ELEMENT_VENDOR                 "VENDOR"
-#define ATTR_VALUE                             "value"
-
-rv_raw_sensor_hal::rv_raw_sensor_hal()
-: m_quat_a(0)
-, m_quat_b(0)
-, m_quat_c(0)
-, m_quat_d(0)
-, m_polling_interval(POLL_1HZ_MS)
-{
-       const string sensorhub_interval_node_name = "rot_poll_delay";
-       csensor_config &config = csensor_config::get_instance();
-
-       node_info_query query;
-       node_info info;
-
-       if (!find_model_id(SENSOR_TYPE_RV_RAW, m_model_id)) {
-               ERR("Failed to find model id");
-               throw ENXIO;
-
-       }
-
-       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
-       query.sensor_type = SENSOR_TYPE_RV_RAW;
-       query.key = "rot_sensor";
-       query.iio_enable_node_name = "rot_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 (!config.get(SENSOR_TYPE_RV_RAW, 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_RV_RAW, 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());
-
-       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
-               ERR("Failed to open handle(%d)", m_node_handle);
-               throw ENXIO;
-       }
-
-       int clockId = CLOCK_MONOTONIC;
-       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
-               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
-
-       INFO("rv_raw_sensor_hal is created!\n");
-}
-
-rv_raw_sensor_hal::~rv_raw_sensor_hal()
-{
-       close(m_node_handle);
-       m_node_handle = -1;
-
-       INFO("rv_raw_sensor_hal is destroyed!\n");
-}
-
-string rv_raw_sensor_hal::get_model_id(void)
-{
-       return m_model_id;
-}
-
-sensor_hal_type_t rv_raw_sensor_hal::get_type(void)
-{
-       return SENSOR_HAL_TYPE_RV_RAW;
-}
-
-bool rv_raw_sensor_hal::enable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_ROTATION_VECTOR_ENABLE_BIT);
-       set_interval(m_polling_interval);
-
-       m_fired_time = 0;
-       INFO("Rotation vector raw sensor real starting");
-       return true;
-}
-
-bool rv_raw_sensor_hal::disable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_ROTATION_VECTOR_ENABLE_BIT);
-
-       INFO("Rotation vector raw sensor real stopping");
-       return true;
-}
-
-bool rv_raw_sensor_hal::set_interval(unsigned long val)
-{
-       unsigned long long polling_interval_ns;
-
-       AUTOLOCK(m_mutex);
-
-       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 rv_raw_sensor_hal::update_value(void)
-{
-       int rot_raw[5] = {0,};
-       bool quat_a,quat_b,quat_c,quat_d,acc_rot;
-       int read_input_cnt = 0;
-       const int INPUT_MAX_BEFORE_SYN = 10;
-       unsigned long long fired_time = 0;
-       bool syn = false;
-
-       quat_a = quat_b = quat_c = quat_d = acc_rot = false;
-
-       struct input_event rot_input;
-       DBG("geo event detection!");
-
-       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
-               int len = read(m_node_handle, &rot_input, sizeof(rot_input));
-               if (len != sizeof(rot_input)) {
-                       ERR("rot_file read fail, read_len = %d\n",len);
-                       return false;
-               }
-
-               ++read_input_cnt;
-
-               if (rot_input.type == EV_REL) {
-                       switch (rot_input.code) {
-                               case REL_X:
-                                       rot_raw[0] = (int)rot_input.value;
-                                       quat_a = true;
-                                       break;
-                               case REL_Y:
-                                       rot_raw[1] = (int)rot_input.value;
-                                       quat_b = true;
-                                       break;
-                               case REL_Z:
-                                       rot_raw[2] = (int)rot_input.value;
-                                       quat_c = true;
-                                       break;
-                               case REL_RX:
-                                       rot_raw[3] = (int)rot_input.value;
-                                       quat_d = true;
-                                       break;
-                               case REL_RY:
-                                       rot_raw[4] = (int)rot_input.value;
-                                       acc_rot = true;
-                                       break;
-                               default:
-                                       ERR("rot_input event[type = %d, code = %d] is unknown.", rot_input.type, rot_input.code);
-                                       return false;
-                                       break;
-                       }
-               } else if (rot_input.type == EV_SYN) {
-                       syn = true;
-                       fired_time = sensor_hal_base::get_timestamp(&rot_input.time);
-               } else {
-                       ERR("rot_input event[type = %d, code = %d] is unknown.", rot_input.type, rot_input.code);
-                       return false;
-               }
-       }
-
-       AUTOLOCK(m_value_mutex);
-
-       if (quat_a)
-               m_quat_a =  rot_raw[0];
-       if (quat_b)
-               m_quat_b =  rot_raw[1];
-       if (quat_c)
-               m_quat_c =  rot_raw[2];
-       if (quat_d)
-               m_quat_d =  rot_raw[3];
-       if (acc_rot)
-               m_accuracy =  rot_raw[4] - 1; /* accuracy bias: -1 */
-
-       m_fired_time = fired_time;
-
-       DBG("m_quat_a = %d, m_quat_a = %d, m_quat_a = %d, m_quat_d = %d, m_accuracy = %d, time = %lluus",
-               m_quat_a, m_quat_a, m_quat_a, m_quat_d, m_accuracy, m_fired_time);
-
-       return true;
-}
-
-bool rv_raw_sensor_hal::is_data_ready(void)
-{
-       bool ret;
-       ret = update_value();
-       return ret;
-}
-
-int rv_raw_sensor_hal::get_sensor_data(sensor_data_t &data)
-{
-       const float QUAT_SIG_FIGS = 1000000.0f;
-
-       data.accuracy = (m_accuracy == 1) ? 0 : m_accuracy; /* hdst 0 and 1 are needed to calibrate */
-       data.timestamp = m_fired_time;
-       data.value_count = 4;
-       data.values[0] = (float)m_quat_a / QUAT_SIG_FIGS;
-       data.values[1] = (float)m_quat_b / QUAT_SIG_FIGS;
-       data.values[2] = (float)m_quat_c / QUAT_SIG_FIGS;
-       data.values[3] = (float)m_quat_d / QUAT_SIG_FIGS;
-       return 0;
-}
-
-bool rv_raw_sensor_hal::get_properties(sensor_properties_s &properties)
-{
-       properties.name = m_chip_name;
-       properties.vendor = m_vendor;
-       properties.min_range = 0;
-       properties.max_range = 1200;
-       properties.min_interval = 1;
-       properties.resolution = 1;
-       properties.fifo_count = 0;
-       properties.max_batch_count = 0;
-       return true;
-}
diff --git a/src/plugins/rotation_vector/rv_raw/rv_raw_sensor_hal.h b/src/plugins/rotation_vector/rv_raw/rv_raw_sensor_hal.h
deleted file mode 100755 (executable)
index 3a2b0ef..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * rv_raw_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 _RV_RAW_SENSOR_HAL_H_
-#define _RV_RAW_SENSOR_HAL_H_
-
-#include <sensor_hal_base.h>
-
-class rv_raw_sensor_hal : public sensor_hal_base
-{
-public:
-       rv_raw_sensor_hal();
-       virtual ~rv_raw_sensor_hal();
-       std::string get_model_id(void);
-       sensor_hal_type_t get_type(void);
-       bool enable(void);
-       bool disable(void);
-       bool set_interval(unsigned long val);
-       bool is_data_ready(void);
-       virtual int get_sensor_data(sensor_data_t &data);
-       virtual bool get_properties(sensor_properties_s &properties);
-private:
-       std::string m_model_id;
-       std::string m_vendor;
-       std::string m_chip_name;
-
-       unsigned long m_polling_interval;
-
-       int m_quat_a;
-       int m_quat_b;
-       int m_quat_c;
-       int m_quat_d;
-       int m_accuracy;
-
-       unsigned long long m_fired_time;
-       int m_node_handle;
-
-       std::string m_enable_node;
-       std::string m_data_node;
-       std::string m_interval_node;
-
-       bool m_sensorhub_controlled;
-
-       cmutex m_value_mutex;
-
-       bool update_value(void);
-};
-#endif /*_RV_RAW_SENSOR_HAL_H_*/
-
diff --git a/src/plugins/temperature/temperature_sensor_hal.cpp b/src/plugins/temperature/temperature_sensor_hal.cpp
deleted file mode 100755 (executable)
index e491c6d..0000000
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * temperature_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 <linux/input.h>
-#include <csensor_config.h>
-#include <temperature_sensor_hal.h>
-#include <sys/ioctl.h>
-
-using std::string;
-
-#define SENSOR_TYPE_TEMPERATURE                "TEMPERATURE"
-#define ELEMENT_NAME                           "NAME"
-#define ELEMENT_VENDOR                         "VENDOR"
-#define ELEMENT_RAW_DATA_UNIT          "RAW_DATA_UNIT"
-
-#define TEMP_INPUT_NAME                                        "temperature_sensor"
-#define TEMP_IIO_ENABLE_NODE_NAME              "temp_enable"
-#define TEMP_SENSORHUB_POLL_NODE_NAME  "temp_poll_delay"
-#define INITIAL_TIME -1
-
-temperature_sensor_hal::temperature_sensor_hal()
-: m_temperature(0)
-, m_node_handle(-1)
-, m_polling_interval(POLL_1HZ_MS)
-, m_fired_time(INITIAL_TIME)
-{
-       const string sensorhub_interval_node_name = TEMP_SENSORHUB_POLL_NODE_NAME;
-
-       node_info_query query;
-       node_info info;
-
-       if (!find_model_id(SENSOR_TYPE_TEMPERATURE, m_model_id)) {
-               ERR("Failed to find model id");
-               throw ENXIO;
-       }
-
-       query.sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
-       query.sensor_type = SENSOR_TYPE_TEMPERATURE;
-       query.key = TEMP_INPUT_NAME;
-       query.iio_enable_node_name = TEMP_IIO_ENABLE_NODE_NAME;
-       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;
-
-       csensor_config &config = csensor_config::get_instance();
-
-       if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_VENDOR, m_vendor)) {
-               ERR("[VENDOR] is empty\n");
-               throw ENXIO;
-       }
-
-       if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_NAME, m_chip_name)) {
-               ERR("[NAME] is empty\n");
-               throw ENXIO;
-       }
-
-       double raw_data_unit;
-
-       if (!config.get(SENSOR_TYPE_TEMPERATURE, 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);
-
-       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
-               ERR("Failed to open handle(%d)", m_node_handle);
-               throw ENXIO;
-       }
-
-       int clockId = CLOCK_MONOTONIC;
-       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
-               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
-
-       INFO("m_vendor = %s", m_vendor.c_str());
-       INFO("m_chip_name = %s", m_chip_name.c_str());
-       INFO("m_raw_data_unit = %f\n", m_raw_data_unit);
-       INFO("temperature_sensor_hal is created!\n");
-}
-
-temperature_sensor_hal::~temperature_sensor_hal()
-{
-       close(m_node_handle);
-       m_node_handle = -1;
-
-       INFO("temperature_sensor_hal is destroyed!\n");
-}
-
-string temperature_sensor_hal::get_model_id(void)
-{
-       return m_model_id;
-}
-
-sensor_hal_type_t temperature_sensor_hal::get_type(void)
-{
-       return SENSOR_HAL_TYPE_TEMPERATURE;
-}
-
-bool temperature_sensor_hal::enable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, true,
-                       SENSORHUB_TEMPERATURE_HUMIDITY_ENABLE_BIT);
-       set_interval(m_polling_interval);
-
-       m_fired_time = 0;
-       INFO("Temperature sensor real starting");
-       return true;
-}
-
-bool temperature_sensor_hal::disable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, false,
-                       SENSORHUB_TEMPERATURE_HUMIDITY_ENABLE_BIT);
-
-       INFO("Temperature sensor real stopping");
-       return true;
-}
-
-bool temperature_sensor_hal::set_interval(unsigned long val)
-{
-       unsigned long long polling_interval_ns;
-
-       AUTOLOCK(m_mutex);
-
-       polling_interval_ns = ((unsigned long long)(val) * 1000llu * 1000llu);
-
-       if (!set_node_value(m_interval_node, polling_interval_ns)) {
-               ERR("Failed to set polling node: %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 temperature_sensor_hal::update_value(void)
-{
-       int temperature_raw = 0;
-       bool temperature = false;
-       int read_input_cnt = 0;
-       const int INPUT_MAX_BEFORE_SYN = 10;
-       unsigned long long fired_time = 0;
-       bool syn = false;
-
-       struct input_event temperature_event;
-       DBG("temperature event detection!");
-
-       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
-               int len = read(m_node_handle, &temperature_event, sizeof(temperature_event));
-               if (len != sizeof(temperature_event)) {
-                       ERR("temperature_file read fail, read_len = %d\n",len);
-                       return false;
-               }
-
-               ++read_input_cnt;
-
-               if (temperature_event.type == EV_REL) {
-                       switch (temperature_event.code) {
-                               case REL_HWHEEL:
-                                       temperature_raw = (int)temperature_event.value;
-                                       temperature = true;
-                                       break;
-                               default:
-                                       ERR("temperature_event event[type = %d, code = %d] is unknown.", temperature_event.type, temperature_event.code);
-                                       return false;
-                                       break;
-                       }
-               } else if (temperature_event.type == EV_SYN) {
-                       syn = true;
-                       fired_time = sensor_hal_base::get_timestamp(&temperature_event.time);
-               } else {
-                       ERR("temperature_event event[type = %d, code = %d] is unknown.", temperature_event.type, temperature_event.code);
-                       return false;
-               }
-       }
-
-       if (syn == false) {
-               ERR("EV_SYN didn't come until %d inputs had come", read_input_cnt);
-               return false;
-       }
-
-       AUTOLOCK(m_value_mutex);
-
-       if (temperature)
-               m_temperature = temperature_raw;
-
-       m_fired_time = fired_time;
-
-       DBG("m_temperature = %d, time = %lluus", m_temperature, m_fired_time);
-
-       return true;
-}
-
-bool temperature_sensor_hal::is_data_ready(void)
-{
-       bool ret;
-       ret = update_value();
-       return ret;
-}
-
-int temperature_sensor_hal::get_sensor_data(sensor_data_t &data)
-{
-       AUTOLOCK(m_value_mutex);
-       data.accuracy = SENSOR_ACCURACY_GOOD;
-       data.timestamp = m_fired_time ;
-       data.value_count = 1;
-       data.values[0] = (float) m_temperature;
-
-       return 0;
-}
-
-bool temperature_sensor_hal::get_properties(sensor_properties_s &properties)
-{
-       properties.name = m_chip_name;
-       properties.vendor = m_vendor;
-       properties.min_range = -45;
-       properties.max_range = 130;
-       properties.min_interval = 1;
-       properties.resolution = 1;
-       properties.fifo_count = 0;
-       properties.max_batch_count = 0;
-
-       return true;
-}
diff --git a/src/plugins/temperature/temperature_sensor_hal.h b/src/plugins/temperature/temperature_sensor_hal.h
deleted file mode 100755 (executable)
index 7dd06d6..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * temperature_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 _TEMPERATURE_SENSOR_HAL_H_
-#define _TEMPERATURE_SENSOR_HAL_H_
-
-#include <sensor_hal_base.h>
-
-class temperature_sensor_hal : public sensor_hal_base
-{
-public:
-       temperature_sensor_hal();
-       virtual ~temperature_sensor_hal();
-       std::string get_model_id(void);
-       sensor_hal_type_t get_type(void);
-       bool enable(void);
-       bool disable(void);
-       bool set_interval(unsigned long val);
-       bool is_data_ready(void);
-       virtual int get_sensor_data(sensor_data_t &data);
-       bool get_properties(sensor_properties_s &properties);
-private:
-       float m_temperature;
-       int m_node_handle;
-       unsigned long m_polling_interval;
-       unsigned long long m_fired_time;
-
-       std::string m_model_id;
-       std::string m_vendor;
-       std::string m_chip_name;
-
-       float m_raw_data_unit;
-
-       std::string m_data_node;
-       std::string m_enable_node;
-       std::string m_interval_node;
-
-       bool m_sensorhub_controlled;
-
-       cmutex m_value_mutex;
-
-       bool update_value(void);
-};
-#endif /*_TEMPERATURE_SENSOR_HAL_CLASS_H_*/
diff --git a/src/plugins/ultraviolet/ultraviolet_sensor_hal.cpp b/src/plugins/ultraviolet/ultraviolet_sensor_hal.cpp
deleted file mode 100755 (executable)
index 6723e3f..0000000
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * ultraviolet_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 <csensor_config.h>
-#include <ultraviolet_sensor_hal.h>
-#include <sys/ioctl.h>
-#include <fstream>
-
-using std::ifstream;
-using std::string;
-
-#define SENSOR_TYPE_ULTRAVIOLET        "ULTRAVIOLET"
-#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 ATTR_VALUE                             "value"
-
-#define BIAS   1
-
-ultraviolet_sensor_hal::ultraviolet_sensor_hal()
-: m_polling_interval(POLL_1HZ_MS)
-, m_ultraviolet(0)
-, m_fired_time(0)
-, m_node_handle(-1)
-{
-       const string sensorhub_interval_node_name = "uv_poll_delay";
-       csensor_config &config = csensor_config::get_instance();
-
-       node_info_query query;
-       node_info info;
-
-       if (!find_model_id(SENSOR_TYPE_ULTRAVIOLET, m_model_id)) {
-               ERR("Failed to find model id");
-               throw ENXIO;
-
-       }
-
-       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
-       query.sensor_type = SENSOR_TYPE_ULTRAVIOLET;
-       query.key = "uv_sensor";
-       query.iio_enable_node_name = "uv_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 (!config.get(SENSOR_TYPE_ULTRAVIOLET, 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_ULTRAVIOLET, m_model_id, ELEMENT_NAME, m_chip_name)) {
-               ERR("[NAME] is empty\n");
-               throw ENXIO;
-       }
-
-       INFO("m_chip_name = %s\n",m_chip_name.c_str());
-
-       double min_range;
-
-       if (!config.get(SENSOR_TYPE_ULTRAVIOLET, 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_ULTRAVIOLET, 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_ULTRAVIOLET, 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);
-
-       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
-               ERR("Failed to open handle(%d)", m_node_handle);
-               throw ENXIO;
-       }
-
-       int clockId = CLOCK_MONOTONIC;
-       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
-               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
-
-       INFO("m_raw_data_unit = %f\n", m_raw_data_unit);
-       INFO("ultraviolet_sensor_hal is created!\n");
-}
-
-ultraviolet_sensor_hal::~ultraviolet_sensor_hal()
-{
-       close(m_node_handle);
-       m_node_handle = -1;
-
-       INFO("ultraviolet_sensor_hal is destroyed!\n");
-}
-
-string ultraviolet_sensor_hal::get_model_id(void)
-{
-       return m_model_id;
-}
-
-
-sensor_hal_type_t ultraviolet_sensor_hal::get_type(void)
-{
-       return SENSOR_HAL_TYPE_ULTRAVIOLET;
-}
-
-bool ultraviolet_sensor_hal::enable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_UV_SENSOR);
-       set_interval(m_polling_interval);
-
-       m_fired_time = 0;
-       INFO("ultraviolet sensor real starting");
-       return true;
-}
-
-bool ultraviolet_sensor_hal::disable(void)
-{
-       AUTOLOCK(m_mutex);
-
-       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_UV_SENSOR);
-
-       INFO("ultraviolet sensor real stopping");
-       return true;
-}
-
-bool ultraviolet_sensor_hal::set_interval(unsigned long val)
-{
-       unsigned long long polling_interval_ns;
-
-       AUTOLOCK(m_mutex);
-
-       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 ultraviolet_sensor_hal::update_value(void)
-{
-       int ultraviolet_raw = -1;
-       bool ultraviolet_sign = false;
-       bool ultraviolet = false;
-       int read_input_cnt = 0;
-       const int INPUT_MAX_BEFORE_SYN = 10;
-       unsigned long long fired_time = 0;
-       bool syn = false;
-
-       struct input_event ultraviolet_event;
-       DBG("ultraviolet event detection!");
-
-       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
-               int len = read(m_node_handle, &ultraviolet_event, sizeof(ultraviolet_event));
-               if (len != sizeof(ultraviolet_event)) {
-                       ERR("ultraviolet file read fail, read_len = %d\n",len);
-                       return false;
-               }
-
-               ++read_input_cnt;
-
-               if (ultraviolet_event.type == EV_REL && ultraviolet_event.code == REL_X) {
-                       ultraviolet_raw = (int)ultraviolet_event.value;
-                       ultraviolet = true;
-               } else if (ultraviolet_event.type == EV_REL && ultraviolet_event.code == REL_Y) {
-                       ultraviolet_sign = ((int)ultraviolet_event.value < 0) ? false : true;
-               } else if (ultraviolet_event.type == EV_SYN) {
-                       syn = true;
-                       fired_time = sensor_hal_base::get_timestamp(&ultraviolet_event.time);
-               } else {
-                       ERR("ultraviolet event[type = %d, code = %d] is unknown.", ultraviolet_event.type, ultraviolet_event.code);
-                       return false;
-               }
-       }
-
-       AUTOLOCK(m_value_mutex);
-
-       if (ultraviolet && ultraviolet_sign)
-               m_ultraviolet = ultraviolet_raw - BIAS;
-       else
-               return false;
-
-       m_fired_time = fired_time;
-
-       DBG("m_ultraviolet = %d, time = %lluus", m_ultraviolet, m_fired_time);
-
-       return true;
-}
-
-bool ultraviolet_sensor_hal::is_data_ready(void)
-{
-       bool ret;
-       ret = update_value();
-       return ret;
-}
-
-int ultraviolet_sensor_hal::get_sensor_data(sensor_data_t &data)
-{
-       AUTOLOCK(m_value_mutex);
-       data.accuracy = SENSOR_ACCURACY_GOOD;
-       data.timestamp = m_fired_time;
-       data.value_count = 1;
-       data.values[0] = (float) m_ultraviolet;
-
-       return 0;
-}
-
-bool ultraviolet_sensor_hal::get_properties(sensor_properties_s &properties)
-{
-       properties.name = m_chip_name;
-       properties.vendor = m_vendor;
-       properties.min_range = m_min_range;
-       properties.max_range = m_max_range;
-       properties.min_interval = 1;
-       properties.resolution = m_raw_data_unit;
-       properties.fifo_count = 0;
-       properties.max_batch_count = 0;
-
-       return true;
-}
diff --git a/src/plugins/ultraviolet/ultraviolet_sensor_hal.h b/src/plugins/ultraviolet/ultraviolet_sensor_hal.h
deleted file mode 100755 (executable)
index dfe684c..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * ultraviolet_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 _ULTRAVIOLET_SENSOR_HAL_H_
-#define _ULTRAVIOLET_SENSOR_HAL_H_
-
-#include <sensor_hal_base.h>
-
-class ultraviolet_sensor_hal : public sensor_hal_base
-{
-public:
-       ultraviolet_sensor_hal();
-       virtual ~ultraviolet_sensor_hal();
-       std::string get_model_id(void);
-       sensor_hal_type_t get_type(void);
-       bool enable(void);
-       bool disable(void);
-       bool set_interval(unsigned long val);
-       bool is_data_ready(void);
-       virtual int get_sensor_data(sensor_data_t &data);
-       bool get_properties(sensor_properties_s &properties);
-
-private:
-       std::string m_model_id;
-       std::string m_vendor;
-       std::string m_chip_name;
-
-       float m_min_range;
-       float m_max_range;
-       float m_raw_data_unit;
-
-       unsigned long m_polling_interval;
-
-       int m_ultraviolet;
-
-       unsigned long long m_fired_time;
-       int m_node_handle;
-
-       std::string m_enable_node;
-       std::string m_data_node;
-       std::string m_interval_node;
-
-       bool m_sensorhub_controlled;
-
-       cmutex m_value_mutex;
-
-       bool update_value(void);
-};
-#endif /*_ULTRAVIOLET_SENSOR_HAL_CLASS_H_*/
-
diff --git a/src/pressure/pressure_sensor_hal.cpp b/src/pressure/pressure_sensor_hal.cpp
new file mode 100644 (file)
index 0000000..badd9bd
--- /dev/null
@@ -0,0 +1,351 @@
+/*
+ * 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 <csensor_config.h>
+#include <pressure_sensor_hal.h>
+#include <sys/ioctl.h>
+#include <fstream>
+#include <algorithm>
+
+using std::ifstream;
+using std::string;
+
+#define SENSOR_TYPE_PRESSURE           "PRESSURE"
+#define ELEMENT_NAME                   "NAME"
+#define ELEMENT_VENDOR                 "VENDOR"
+#define ELEMENT_RAW_DATA_UNIT  "RAW_DATA_UNIT"
+#define ELEMENT_RESOLUTION             "RESOLUTION"
+#define ELEMENT_MIN_RANGE              "MIN_RANGE"
+#define ELEMENT_MAX_RANGE              "MAX_RANGE"
+#define ELEMENT_TEMPERATURE_RESOLUTION "TEMPERATURE_RESOLUTION"
+#define ELEMENT_TEMPERATURE_OFFSET             "TEMPERATURE_OFFSET"
+#define ATTR_VALUE                             "value"
+
+#define SEA_LEVEL_PRESSURE 101325.0
+#define SEA_LEVEL_RESOLUTION 0.01
+
+pressure_sensor_hal::pressure_sensor_hal()
+: m_pressure(0)
+, m_sea_level_pressure(SEA_LEVEL_PRESSURE)
+, m_temperature(0)
+, m_polling_interval(POLL_1HZ_MS)
+, m_fired_time(0)
+, m_node_handle(-1)
+{
+       const string sensorhub_interval_node_name = "pressure_poll_delay";
+       csensor_config &config = csensor_config::get_instance();
+
+       node_info_query query;
+       node_info info;
+
+       if (!find_model_id(SENSOR_TYPE_PRESSURE, m_model_id)) {
+               ERR("Failed to find model id");
+               throw ENXIO;
+
+       }
+
+       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
+       query.sensor_type = SENSOR_TYPE_PRESSURE;
+       query.key = "pressure_sensor";
+       query.iio_enable_node_name = "pressure_enable";
+       query.sensorhub_interval_node_name = sensorhub_interval_node_name;
+
+       bool error = get_node_info(query, info);
+
+       query.key = "barometer_sensor";
+       error |= get_node_info(query, info);
+
+       if (!error) {
+               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 (!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);
+
+       double resolution;
+
+       if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_RESOLUTION, resolution)) {
+               ERR("[RESOLUTION] is empty\n");
+               throw ENXIO;
+       }
+
+       m_resolution = (float)resolution;
+       INFO("m_resolution = %f\n", m_resolution);
+
+       double temperature_resolution;
+
+       if (!config.get(SENSOR_TYPE_PRESSURE, m_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, m_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);
+
+       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
+               ERR("Failed to open handle(%d)", m_node_handle);
+               throw ENXIO;
+       }
+
+       int clockId = CLOCK_MONOTONIC;
+       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
+               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
+
+       INFO("pressure_sensor_hal is created!\n");
+}
+
+pressure_sensor_hal::~pressure_sensor_hal()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       INFO("pressure_sensor_hal is destroyed!\n");
+}
+
+string pressure_sensor_hal::get_model_id(void)
+{
+       return m_model_id;
+}
+
+sensor_hal_type_t pressure_sensor_hal::get_type(void)
+{
+       return SENSOR_HAL_TYPE_PRESSURE;
+}
+
+bool pressure_sensor_hal::enable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_PRESSURE_ENABLE_BIT);
+
+       set_interval(m_polling_interval);
+
+       m_fired_time = 0;
+       INFO("Pressure sensor real starting");
+       return true;
+}
+
+bool pressure_sensor_hal::disable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_PRESSURE_ENABLE_BIT);
+
+       INFO("Pressure sensor real stopping");
+       return true;
+}
+
+bool pressure_sensor_hal::set_interval(unsigned long val)
+{
+       unsigned long long polling_interval_ns;
+
+       AUTOLOCK(m_mutex);
+
+       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 pressure_sensor_hal::update_value(void)
+{
+       int pressure_raw[3] = {0,};
+       bool pressure = false;
+       bool sea_level = false;
+       bool temperature = false;
+       int read_input_cnt = 0;
+       const int INPUT_MAX_BEFORE_SYN = 10;
+       unsigned long long fired_time = 0;
+       bool syn = false;
+
+       struct input_event pressure_event;
+       DBG("pressure event detection!");
+
+       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
+               int len = read(m_node_handle, &pressure_event, sizeof(pressure_event));
+               if (len != sizeof(pressure_event)) {
+                       ERR("pressure_file read fail, read_len = %d\n",len);
+                       return false;
+               }
+
+               ++read_input_cnt;
+
+               if (pressure_event.type == EV_REL) {
+                       switch (pressure_event.code) {
+                               case REL_X:
+                               case REL_HWHEEL:
+                                       pressure_raw[0] = (int)pressure_event.value;
+                                       pressure = true;
+                                       break;
+                               case REL_Y:
+                               case REL_DIAL:
+                                       pressure_raw[1] = (int)pressure_event.value;
+                                       sea_level = true;
+                                       break;
+                               case REL_Z:
+                               case REL_WHEEL:
+                                       pressure_raw[2] = (int)pressure_event.value;
+                                       temperature = true;
+                                       break;
+                               default:
+                                       ERR("pressure_event event[type = %d, code = %d] is unknown.", pressure_event.type, pressure_event.code);
+                                       return false;
+                                       break;
+                       }
+               } else if (pressure_event.type == EV_SYN) {
+                       syn = true;
+                       fired_time = sensor_hal_base::get_timestamp(&pressure_event.time);
+               } else {
+                       ERR("pressure_event event[type = %d, code = %d] is unknown.", pressure_event.type, pressure_event.code);
+                       return false;
+               }
+       }
+
+       AUTOLOCK(m_value_mutex);
+
+       if (pressure)
+               m_pressure = pressure_raw[0];
+       if (sea_level)
+               m_sea_level_pressure = pressure_raw[1];
+       if (temperature)
+               m_temperature = pressure_raw[2];
+
+       m_fired_time = fired_time;
+
+       DBG("m_pressure = %d, sea_level = %d, temperature = %d, time = %lluus", m_pressure, m_sea_level_pressure, m_temperature, m_fired_time);
+
+       return true;
+}
+
+bool pressure_sensor_hal::is_data_ready(void)
+{
+       bool ret;
+       ret = update_value();
+       return ret;
+}
+
+
+float pressure_sensor_hal::pressure_to_altitude(float pressure)
+{
+       return 44330.0f * (1.0f - pow(pressure/m_sea_level_pressure, 1.0f/5.255f));
+}
+
+void pressure_sensor_hal::raw_to_base(sensor_data_t &data)
+{
+       data.values[0] = data.values[0] * m_resolution;
+       m_sea_level_pressure = data.values[1] * SEA_LEVEL_RESOLUTION;
+       data.values[1] = pressure_to_altitude(data.values[0]);
+       data.values[2] = data.values[2] * m_temperature_resolution + m_temperature_offset;
+       data.value_count = 3;
+}
+
+int pressure_sensor_hal::get_sensor_data(sensor_data_t &data)
+{
+       AUTOLOCK(m_value_mutex);
+       data.accuracy = SENSOR_ACCURACY_GOOD;
+       data.timestamp = m_fired_time ;
+       data.value_count = 3;
+       data.values[0] = m_pressure;
+       data.values[1] = m_sea_level_pressure;
+       data.values[2] = m_temperature;
+
+       raw_to_base(data);
+
+       return 0;
+}
+
+bool pressure_sensor_hal::get_properties(sensor_properties_s &properties)
+{
+       properties.name = m_chip_name;
+       properties.vendor = m_vendor;
+       properties.min_range = m_min_range;
+       properties.max_range = m_max_range;
+       properties.min_interval = 1;
+       properties.resolution = m_raw_data_unit;
+       properties.fifo_count = 0;
+       properties.max_batch_count = 0;
+       return true;
+}
diff --git a/src/pressure/pressure_sensor_hal.h b/src/pressure/pressure_sensor_hal.h
new file mode 100644 (file)
index 0000000..677b15d
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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_base.h>
+
+class pressure_sensor_hal : public sensor_hal_base
+{
+public:
+       pressure_sensor_hal();
+       virtual ~pressure_sensor_hal();
+       std::string get_model_id(void);
+       sensor_hal_type_t get_type(void);
+
+       bool enable(void);
+       bool disable(void);
+       bool set_interval(unsigned long val);
+       bool is_data_ready(void);
+       virtual int get_sensor_data(sensor_data_t &data);
+       virtual bool get_properties(sensor_properties_s &properties);
+private:
+       std::string m_model_id;
+       std::string m_vendor;
+       std::string m_chip_name;
+
+       float m_pressure;
+       float m_sea_level_pressure;
+       float m_temperature;
+       float m_temperature_offset;
+       float m_temperature_resolution;
+
+       int m_resolution;
+
+       float m_min_range;
+       float m_max_range;
+       float m_raw_data_unit;
+       float m_temp_resolution;
+       float m_temp_offset;
+       unsigned long m_polling_interval;
+
+       unsigned long long m_fired_time;
+       int m_node_handle;
+
+       std::string m_enable_node;
+       std::string m_data_node;
+       std::string m_interval_node;
+
+       bool m_sensorhub_controlled;
+
+       cmutex m_value_mutex;
+
+       bool update_value(void);
+       float pressure_to_altitude(float pressure);
+       void raw_to_base(sensor_data_t &data);
+};
+#endif /*_PRESSURE_SENSOR_HAL_CLASS_H_*/
diff --git a/src/proximity/proxi_sensor_device.cpp b/src/proximity/proxi_sensor_device.cpp
new file mode 100644 (file)
index 0000000..54dce10
--- /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/proximity/proxi_sensor_device.h b/src/proximity/proxi_sensor_device.h
new file mode 100644 (file)
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/rotation_vector/rv_raw/rv_raw_sensor_hal.cpp b/src/rotation_vector/rv_raw/rv_raw_sensor_hal.cpp
new file mode 100644 (file)
index 0000000..216e04d
--- /dev/null
@@ -0,0 +1,268 @@
+/*
+ * rv_raw_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 <csensor_config.h>
+#include <rv_raw_sensor_hal.h>
+#include <sys/ioctl.h>
+#include <fstream>
+
+using std::ifstream;
+using std::string;
+
+#define SENSOR_TYPE_RV_RAW     "ROTATION_VECTOR"
+#define ELEMENT_NAME                   "NAME"
+#define ELEMENT_VENDOR                 "VENDOR"
+#define ATTR_VALUE                             "value"
+
+rv_raw_sensor_hal::rv_raw_sensor_hal()
+: m_quat_a(0)
+, m_quat_b(0)
+, m_quat_c(0)
+, m_quat_d(0)
+, m_polling_interval(POLL_1HZ_MS)
+{
+       const string sensorhub_interval_node_name = "rot_poll_delay";
+       csensor_config &config = csensor_config::get_instance();
+
+       node_info_query query;
+       node_info info;
+
+       if (!find_model_id(SENSOR_TYPE_RV_RAW, m_model_id)) {
+               ERR("Failed to find model id");
+               throw ENXIO;
+
+       }
+
+       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
+       query.sensor_type = SENSOR_TYPE_RV_RAW;
+       query.key = "rot_sensor";
+       query.iio_enable_node_name = "rot_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 (!config.get(SENSOR_TYPE_RV_RAW, 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_RV_RAW, 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());
+
+       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
+               ERR("Failed to open handle(%d)", m_node_handle);
+               throw ENXIO;
+       }
+
+       int clockId = CLOCK_MONOTONIC;
+       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
+               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
+
+       INFO("rv_raw_sensor_hal is created!\n");
+}
+
+rv_raw_sensor_hal::~rv_raw_sensor_hal()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       INFO("rv_raw_sensor_hal is destroyed!\n");
+}
+
+string rv_raw_sensor_hal::get_model_id(void)
+{
+       return m_model_id;
+}
+
+sensor_hal_type_t rv_raw_sensor_hal::get_type(void)
+{
+       return SENSOR_HAL_TYPE_RV_RAW;
+}
+
+bool rv_raw_sensor_hal::enable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_ROTATION_VECTOR_ENABLE_BIT);
+       set_interval(m_polling_interval);
+
+       m_fired_time = 0;
+       INFO("Rotation vector raw sensor real starting");
+       return true;
+}
+
+bool rv_raw_sensor_hal::disable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_ROTATION_VECTOR_ENABLE_BIT);
+
+       INFO("Rotation vector raw sensor real stopping");
+       return true;
+}
+
+bool rv_raw_sensor_hal::set_interval(unsigned long val)
+{
+       unsigned long long polling_interval_ns;
+
+       AUTOLOCK(m_mutex);
+
+       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 rv_raw_sensor_hal::update_value(void)
+{
+       int rot_raw[5] = {0,};
+       bool quat_a,quat_b,quat_c,quat_d,acc_rot;
+       int read_input_cnt = 0;
+       const int INPUT_MAX_BEFORE_SYN = 10;
+       unsigned long long fired_time = 0;
+       bool syn = false;
+
+       quat_a = quat_b = quat_c = quat_d = acc_rot = false;
+
+       struct input_event rot_input;
+       DBG("geo event detection!");
+
+       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
+               int len = read(m_node_handle, &rot_input, sizeof(rot_input));
+               if (len != sizeof(rot_input)) {
+                       ERR("rot_file read fail, read_len = %d\n",len);
+                       return false;
+               }
+
+               ++read_input_cnt;
+
+               if (rot_input.type == EV_REL) {
+                       switch (rot_input.code) {
+                               case REL_X:
+                                       rot_raw[0] = (int)rot_input.value;
+                                       quat_a = true;
+                                       break;
+                               case REL_Y:
+                                       rot_raw[1] = (int)rot_input.value;
+                                       quat_b = true;
+                                       break;
+                               case REL_Z:
+                                       rot_raw[2] = (int)rot_input.value;
+                                       quat_c = true;
+                                       break;
+                               case REL_RX:
+                                       rot_raw[3] = (int)rot_input.value;
+                                       quat_d = true;
+                                       break;
+                               case REL_RY:
+                                       rot_raw[4] = (int)rot_input.value;
+                                       acc_rot = true;
+                                       break;
+                               default:
+                                       ERR("rot_input event[type = %d, code = %d] is unknown.", rot_input.type, rot_input.code);
+                                       return false;
+                                       break;
+                       }
+               } else if (rot_input.type == EV_SYN) {
+                       syn = true;
+                       fired_time = sensor_hal_base::get_timestamp(&rot_input.time);
+               } else {
+                       ERR("rot_input event[type = %d, code = %d] is unknown.", rot_input.type, rot_input.code);
+                       return false;
+               }
+       }
+
+       AUTOLOCK(m_value_mutex);
+
+       if (quat_a)
+               m_quat_a =  rot_raw[0];
+       if (quat_b)
+               m_quat_b =  rot_raw[1];
+       if (quat_c)
+               m_quat_c =  rot_raw[2];
+       if (quat_d)
+               m_quat_d =  rot_raw[3];
+       if (acc_rot)
+               m_accuracy =  rot_raw[4] - 1; /* accuracy bias: -1 */
+
+       m_fired_time = fired_time;
+
+       DBG("m_quat_a = %d, m_quat_a = %d, m_quat_a = %d, m_quat_d = %d, m_accuracy = %d, time = %lluus",
+               m_quat_a, m_quat_a, m_quat_a, m_quat_d, m_accuracy, m_fired_time);
+
+       return true;
+}
+
+bool rv_raw_sensor_hal::is_data_ready(void)
+{
+       bool ret;
+       ret = update_value();
+       return ret;
+}
+
+int rv_raw_sensor_hal::get_sensor_data(sensor_data_t &data)
+{
+       const float QUAT_SIG_FIGS = 1000000.0f;
+
+       data.accuracy = (m_accuracy == 1) ? 0 : m_accuracy; /* hdst 0 and 1 are needed to calibrate */
+       data.timestamp = m_fired_time;
+       data.value_count = 4;
+       data.values[0] = (float)m_quat_a / QUAT_SIG_FIGS;
+       data.values[1] = (float)m_quat_b / QUAT_SIG_FIGS;
+       data.values[2] = (float)m_quat_c / QUAT_SIG_FIGS;
+       data.values[3] = (float)m_quat_d / QUAT_SIG_FIGS;
+       return 0;
+}
+
+bool rv_raw_sensor_hal::get_properties(sensor_properties_s &properties)
+{
+       properties.name = m_chip_name;
+       properties.vendor = m_vendor;
+       properties.min_range = 0;
+       properties.max_range = 1200;
+       properties.min_interval = 1;
+       properties.resolution = 1;
+       properties.fifo_count = 0;
+       properties.max_batch_count = 0;
+       return true;
+}
diff --git a/src/rotation_vector/rv_raw/rv_raw_sensor_hal.h b/src/rotation_vector/rv_raw/rv_raw_sensor_hal.h
new file mode 100644 (file)
index 0000000..3a2b0ef
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * rv_raw_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 _RV_RAW_SENSOR_HAL_H_
+#define _RV_RAW_SENSOR_HAL_H_
+
+#include <sensor_hal_base.h>
+
+class rv_raw_sensor_hal : public sensor_hal_base
+{
+public:
+       rv_raw_sensor_hal();
+       virtual ~rv_raw_sensor_hal();
+       std::string get_model_id(void);
+       sensor_hal_type_t get_type(void);
+       bool enable(void);
+       bool disable(void);
+       bool set_interval(unsigned long val);
+       bool is_data_ready(void);
+       virtual int get_sensor_data(sensor_data_t &data);
+       virtual bool get_properties(sensor_properties_s &properties);
+private:
+       std::string m_model_id;
+       std::string m_vendor;
+       std::string m_chip_name;
+
+       unsigned long m_polling_interval;
+
+       int m_quat_a;
+       int m_quat_b;
+       int m_quat_c;
+       int m_quat_d;
+       int m_accuracy;
+
+       unsigned long long m_fired_time;
+       int m_node_handle;
+
+       std::string m_enable_node;
+       std::string m_data_node;
+       std::string m_interval_node;
+
+       bool m_sensorhub_controlled;
+
+       cmutex m_value_mutex;
+
+       bool update_value(void);
+};
+#endif /*_RV_RAW_SENSOR_HAL_H_*/
+
diff --git a/src/sensor_common.h b/src/sensor_common.h
new file mode 100644 (file)
index 0000000..5b58340
--- /dev/null
@@ -0,0 +1,413 @@
+/*
+ * 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_COMMON_H__
+#define __SENSOR_COMMON_H__
+
+#include <unistd.h>
+#include <sensor_logs.h>
+#include <string>
+#include <vector>
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+#ifndef DEPRECATED
+#define DEPRECATED __attribute__((deprecated))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * @defgroup SENSOR_FRAMEWORK SensorFW
+ * To support the unified API for the various sensors
+ */
+
+/**
+ * @defgroup SENSOR_FRAMEWORK_COMMON Sensor Framework Common API
+ * @ingroup SENSOR_FRAMEWORK
+ *
+ * These APIs are used to control the sensors.
+ * @{
+ */
+
+typedef enum {
+       ALL_SENSOR = -1,
+       UNKNOWN_SENSOR = 0,
+       ACCELEROMETER_SENSOR,
+       GEOMAGNETIC_SENSOR,
+       LIGHT_SENSOR,
+       PROXIMITY_SENSOR,
+       THERMOMETER_SENSOR,
+       GYROSCOPE_SENSOR,
+       PRESSURE_SENSOR,
+       MOTION_SENSOR,
+       FUSION_SENSOR,
+       PEDOMETER_SENSOR,
+       CONTEXT_SENSOR,
+       FLAT_SENSOR,
+       BIO_SENSOR,
+       BIO_HRM_SENSOR,
+       AUTO_ROTATION_SENSOR,
+       GRAVITY_SENSOR,
+       LINEAR_ACCEL_SENSOR,
+       ROTATION_VECTOR_SENSOR,
+       GEOMAGNETIC_RV_SENSOR,
+       GAMING_RV_SENSOR,
+       ORIENTATION_SENSOR,
+       TILT_SENSOR,
+       PIR_SENSOR,
+       PIR_LONG_SENSOR,
+       TEMPERATURE_SENSOR,
+       HUMIDITY_SENSOR,
+       ULTRAVIOLET_SENSOR,
+       DUST_SENSOR,
+       BIO_LED_GREEN_SENSOR,
+       BIO_LED_IR_SENSOR,
+       BIO_LED_RED_SENSOR,
+       RV_RAW_SENSOR,
+       UNCAL_GYROSCOPE_SENSOR,
+       UNCAL_GEOMAGNETIC_SENSOR
+} sensor_type_t;
+
+typedef unsigned int sensor_id_t;
+
+typedef void *sensor_t;
+
+typedef enum {
+       SENSOR_PRIVILEGE_PUBLIC,
+       SENSOR_PRIVILEGE_INTERNAL,
+} sensor_privilege_t;
+
+#define SENSOR_DATA_VALUE_SIZE 16
+
+/*
+ *     When modifying it, check copy_sensor_data()
+ */
+typedef struct sensor_data_t {
+/*
+ *     Use "accuracy" instead of "data_accuracy"
+ *     which is going to be removed soon
+ */
+       union {
+               int accuracy;
+               int data_accuracy; //deprecated
+       };
+
+       union {
+               unsigned long long timestamp;
+               unsigned long long time_stamp; //deprecated
+       };
+
+/*
+ *     Use "value_count" instead of "values_num"
+ *     which is going to be removed soon
+ */
+       union {
+               int value_count;
+               int values_num; //deprecated
+       };
+
+       float values[SENSOR_DATA_VALUE_SIZE];
+
+/*
+ *     If extra_data_size > 0,
+ *     then use extra_data.
+ */
+       int extra_data_size;
+       void *extra_data;
+} sensor_data_t;
+
+#define SENSOR_HUB_DATA_SIZE   4096
+
+typedef struct sensorhub_data_t {
+    int version;
+    int sensorhub;
+    int type;
+    int hub_data_size;
+    unsigned long long timestamp;
+    char hub_data[SENSOR_HUB_DATA_SIZE];
+    float data[16];
+} sensorhub_data_t;
+
+enum sensor_accuracy_t {
+       SENSOR_ACCURACY_UNDEFINED = -1,
+       SENSOR_ACCURACY_BAD = 0,
+       SENSOR_ACCURACY_NORMAL =1,
+       SENSOR_ACCURACY_GOOD = 2,
+       SENSOR_ACCURACY_VERYGOOD = 3
+};
+
+/*
+ *     To prevent naming confliction as using same enums as sensor CAPI use
+ */
+#ifndef __SENSOR_H__
+enum sensor_option_t {
+       SENSOR_OPTION_DEFAULT = 0,
+       SENSOR_OPTION_ON_IN_SCREEN_OFF = 1,
+       SENSOR_OPTION_ON_IN_POWERSAVE_MODE = 2,
+       SENSOR_OPTION_ALWAYS_ON = SENSOR_OPTION_ON_IN_SCREEN_OFF | SENSOR_OPTION_ON_IN_POWERSAVE_MODE,
+       SENSOR_OPTION_END
+};
+
+typedef enum sensor_option_t sensor_option_e;
+#endif
+
+/*
+ *     To prevent naming confliction as using same enums as sensor CAPI use
+ */
+#ifndef __SENSOR_H__
+enum sensor_wakeup_t {
+       SENSOR_WAKEUP_UNKNOWN = -1,
+       SENSOR_WAKEUP_OFF = 0,
+       SENSOR_WAKEUP_ON = 1,
+};
+
+typedef enum sensor_wakeup_t sensor_wakeup_e;
+#endif
+
+enum sensor_interval_t {
+       SENSOR_INTERVAL_FASTEST = 0,
+       SENSOR_INTERVAL_NORMAL = 200,
+};
+
+typedef enum {
+       CONDITION_NO_OP,
+       CONDITION_EQUAL,
+       CONDITION_GREAT_THAN,
+       CONDITION_LESS_THAN,
+} condition_op_t;
+
+#define COMMAND_CHANNEL_PATH                   "/tmp/sensord_command_socket"
+#define EVENT_CHANNEL_PATH                             "/tmp/sensord_event_socket"
+
+#define MAX_HANDLE                     256
+#define MAX_HANDLE_REACHED     -2
+
+#define CLIENT_ID_INVALID   -1
+
+#define SENSOR_TYPE_MASK  0xFFFF
+
+enum packet_type_t {
+       CMD_NONE = 0,
+       CMD_GET_ID,
+       CMD_GET_SENSOR_LIST,
+       CMD_HELLO,
+       CMD_BYEBYE,
+       CMD_DONE,
+       CMD_START,
+       CMD_STOP,
+       CMD_REG,
+       CMD_UNREG,
+       CMD_SET_OPTION,
+       CMD_SET_WAKEUP,
+       CMD_SET_BATCH,
+       CMD_UNSET_BATCH,
+       CMD_SET_COMMAND,
+       CMD_GET_DATA,
+       CMD_SEND_SENSORHUB_DATA,
+       CMD_CNT,
+};
+
+enum sensor_state_t {
+       SENSOR_STATE_UNKNOWN = -1,
+       SENSOR_STATE_STOPPED = 0,
+       SENSOR_STATE_STARTED = 1,
+       SENSOR_STATE_PAUSED = 2
+};
+
+enum poll_interval_t {
+       POLL_100HZ_MS   = 10,
+       POLL_50HZ_MS    = 20,
+       POLL_25HZ_MS    = 40,
+       POLL_20HZ_MS    = 50,
+       POLL_10HZ_MS    = 100,
+       POLL_5HZ_MS             = 200,
+       POLL_1HZ_MS             = 1000,
+       POLL_MAX_HZ_MS  = POLL_1HZ_MS,
+};
+
+typedef struct {
+       char name[NAME_MAX];
+} cmd_get_id_t;
+
+typedef struct {
+} cmd_get_sensor_list_t;
+
+typedef struct {
+       int client_id;
+       int sensor;
+} cmd_hello_t;
+
+typedef struct {
+} cmd_byebye_t;
+
+
+typedef struct {
+       unsigned int type;
+} cmd_get_data_t;
+
+typedef struct {
+       long value;
+} cmd_done_t;
+
+
+typedef struct {
+       int client_id;
+} cmd_get_id_done_t;
+
+typedef struct {
+       int sensor_cnt;
+       char data[0];
+} cmd_get_sensor_list_done_t;
+
+typedef struct {
+       int state;
+       sensor_data_t base_data;
+} cmd_get_data_done_t;
+
+typedef struct {
+} cmd_start_t;
+
+typedef struct {
+} cmd_stop_t;
+
+typedef struct {
+       unsigned int event_type;
+} cmd_reg_t;
+
+typedef struct {
+       unsigned int event_type;
+} cmd_unreg_t;
+
+typedef struct {
+       unsigned int interval;
+       unsigned int latency;
+} cmd_set_batch_t;
+
+typedef struct {
+} cmd_unset_batch_t;
+
+typedef struct {
+       int option;
+} cmd_set_option_t;
+
+typedef struct {
+       int wakeup;
+} cmd_set_wakeup_t;
+
+typedef struct  {
+       unsigned int cmd;
+       long value;
+} cmd_set_command_t;
+
+typedef struct  {
+       int data_len;
+       char data[0];
+} cmd_send_sensorhub_data_t;
+
+#define EVENT_CHANNEL_MAGIC 0xCAFECAFE
+
+typedef struct {
+       unsigned int magic;
+       int client_id;
+} event_channel_ready_t;
+
+typedef struct {
+       std::string name;
+       std::string vendor;
+       float min_range;
+       float max_range;
+       float resolution;
+       int min_interval;
+       int fifo_count;
+       int max_batch_count;
+       bool wakeup_supported;
+} sensor_properties_s;
+
+/*
+ * When modifying it, check copy_sensor*_data()
+ */
+typedef struct sensor_event_t {
+       unsigned int event_type;
+       sensor_id_t sensor_id;
+       sensor_data_t data;
+} sensor_event_t;
+
+typedef struct sensorhub_event_t {
+       unsigned int event_type;
+       sensor_id_t sensor_id;
+       sensorhub_data_t data;
+} sensorhub_event_t;
+
+typedef struct {
+       std::vector<void*> devices;
+} sensor_devices;
+
+typedef sensor_devices* (*create_t)(void);
+
+typedef void *(*cmd_func_t)(void *data, void *cb_data);
+
+typedef std::vector<unsigned int> event_type_vector;
+
+enum sensorhub_enable_bit {
+       SENSORHUB_ACCELEROMETER_ENABLE_BIT = 0,
+       SENSORHUB_GYROSCOPE_ENABLE_BIT,
+       SENSORHUB_GEOMAGNETIC_UNCALIB_ENABLE_BIT,
+       SENSORHUB_GEOMAGNETIC_RAW_ENABLE_BIT,
+       SENSORHUB_GEOMAGNETIC_ENABLE_BIT,
+       SENSORHUB_PRESSURE_ENABLE_BIT,
+       SENSORHUB_GESTURE_ENABLE_BIT,
+       SENSORHUB_PROXIMITY_ENABLE_BIT,
+       SENSORHUB_TEMPERATURE_HUMIDITY_ENABLE_BIT,
+       SENSORHUB_LIGHT_ENABLE_BIT,
+       SENSORHUB_PROXIMITY_RAW_ENABLE_BIT,
+       SENSORHUB_ORIENTATION_ENABLE_BIT,
+       SENSORHUB_STEP_DETECTOR_ENABLE_BIT = 12,
+       SENSORHUB_SIG_MOTION_ENABLE_BIT,
+       SENSORHUB_GYRO_UNCALIB_ENABLE_BIT,
+       SENSORHUB_GAME_ROTATION_VECTOR_ENABLE_BIT = 15,
+       SENSORHUB_ROTATION_VECTOR_ENABLE_BIT,
+       SENSORHUB_STEP_COUNTER_ENABLE_BIT,
+       SENSORHUB_BIO_HRM_RAW_ENABLE_BIT,
+       SENSORHUB_BIO_HRM_RAW_FAC_ENABLE_BIT,
+       SENSORHUB_BIO_HRM_LIB_ENABLE_BIT,
+       SENSORHUB_TILT_MOTION,
+       SENSORHUB_UV_SENSOR,
+       SENSORHUB_PIR_ENABLE_BIT,
+       SENSORHUB_ENABLE_BIT_MAX,
+};
+
+enum sensor_permission_t {
+       SENSOR_PERMISSION_NONE  = 0,
+       SENSOR_PERMISSION_STANDARD = (1 << 0),
+       SENSOR_PERMISSION_BIO   =  (1 << 1),
+};
+
+#define BIO_SENSOR_PRIVELEGE_NAME "sensord::bio"
+#define BIO_SENSOR_ACCESS_RIGHT "rw"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+//! End of a file
diff --git a/src/sensor_device_base.cpp b/src/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/sensor_device_base.h b/src/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_*/
diff --git a/src/sensor_device_create.cpp.in b/src/sensor_device_create.cpp.in
deleted file mode 100644 (file)
index c840a42..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-#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;
-}
diff --git a/src/sensor_hal.h b/src/sensor_hal.h
new file mode 100644 (file)
index 0000000..3dee6a0
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * libsensord-share
+ *
+ * Copyright (c) 2015 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_H_
+#define _SENSOR_HAL_H_
+
+#include <stdint.h>
+#include <string>
+#include <vector>
+#include <sensor_common.h>
+
+#define SENSOR_HAL_VERSION(maj,min) \
+                       ((((maj) & 0xffff) << 24) | ((min) & 0xffff))
+
+/*
+ * Sensor Types
+ * These types are used to controll the sensors
+ *
+ * - base unit
+ *   acceleration values : meter per second^2 (m/s^2)
+ *   magnetic values     : micro-Tesla (uT)
+ *   orientation values  : degrees
+ *   gyroscope values    : degree/s
+ *   temperature values  : degrees centigrade
+ *   proximity valeus    : distance
+ *   light values        : lux
+ *   pressure values     : hectopascal (hPa)
+ *   humidity            : relative humidity (%)
+ */
+typedef enum {
+       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
+ * ID can be assigned from HAL developer. so it has to be unique in HAL.
+ */
+typedef struct sensor_handle_t {
+       uint32_t id;
+       std::string name;
+       sensor_device_type type;
+       unsigned int event_type; // for Internal API
+       sensor_properties_s properties;
+} sensor_handle_t;
+
+/*
+ * Sensor device interface
+ * 1 HAL must be abstracted from 1 device event node
+ */
+class sensor_device
+{
+public:
+       virtual ~sensor_device() {}
+
+       uint32_t get_hal_version(void)
+       {
+               return SENSOR_HAL_VERSION(1, 0);
+       }
+
+       virtual int get_poll_fd(void) = 0;
+       virtual bool get_sensors(std::vector<sensor_handle_t> &sensors) = 0;
+
+       /* enable/disable sensor device */
+       virtual bool enable(uint32_t id) = 0;
+       virtual bool disable(uint32_t id) = 0;
+
+       /* set_command or set_option? */
+       virtual bool set_command(uint32_t id, std::string command, std::string value) = 0;
+
+       /* the belows can be merged to one */
+       virtual bool set_interval(uint32_t id, unsigned long val) = 0;
+       virtual bool set_batch_latency(uint32_t id, unsigned long val) = 0;
+
+       /* sensor fw read the data when is_data_ready() is true */
+       virtual bool is_data_ready() = 0;
+       virtual bool get_sensor_data(uint32_t id, sensor_data_t &data) = 0;
+       virtual int get_sensor_event(uint32_t id, sensor_event_t **event) = 0;
+
+       /* TODO: use get_sensors() instead of get_properties() */
+       virtual bool get_properties(uint32_t id, sensor_properties_s &properties) = 0;
+};
+#endif /* _SENSOR_HAL_H_ */
diff --git a/src/sensor_logs.h b/src/sensor_logs.h
new file mode 100644 (file)
index 0000000..9682c42
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * 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_LOG_H_
+#define _SENSOR_LOG_H_
+
+#include <dlog.h>
+
+#if !defined(NAME_MAX)
+#define NAME_MAX 256
+#endif
+
+#define SENSOR_TYPE_SHIFT 16
+
+enum sf_log_type {
+       SF_LOG_PRINT_FILE               = 1,
+       SF_LOG_SYSLOG                   = 2,
+       SF_LOG_DLOG                     = 3,
+};
+
+enum sf_priority_type {
+       SF_LOG_ERR                      = 1,
+       SF_LOG_DBG                      = 2,
+       SF_LOG_INFO                     = 3,
+       SF_LOG_WARN                     = 4,
+};
+
+#define MICROSECONDS(tv)        ((tv.tv_sec * 1000000ll) + tv.tv_usec)
+
+//for new log system - dlog
+#ifdef LOG_TAG
+       #undef LOG_TAG
+#endif
+#define LOG_TAG        "SENSOR"
+
+#ifdef _DEBUG
+#define DBG SLOGD
+#else
+#define DBG(...) do{} while(0)
+#endif
+
+#define ERR SLOGE
+#define WARN SLOGW
+#define INFO SLOGI
+#define _E ERR
+#define _W WARN
+#define _I INFO
+#define _D DBG
+
+#if defined(_DEBUG)
+#  define warn_if(expr, fmt, arg...) do { \
+               if(expr) { \
+                       DBG("(%s) -> " fmt, #expr, ##arg); \
+               } \
+       } while (0)
+#  define ret_if(expr) do { \
+               if(expr) { \
+                       DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
+                       return; \
+               } \
+       } while (0)
+#  define retv_if(expr, val) do { \
+               if(expr) { \
+                       DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
+                       return (val); \
+               } \
+       } while (0)
+#  define retm_if(expr, fmt, arg...) do { \
+               if(expr) { \
+                       ERR(fmt, ##arg); \
+                       DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
+                       return; \
+               } \
+       } while (0)
+#  define retvm_if(expr, val, fmt, arg...) do { \
+               if(expr) { \
+                       ERR(fmt, ##arg); \
+                       DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
+                       return (val); \
+               } \
+       } while (0)
+
+#else
+#  define warn_if(expr, fmt, arg...) do { \
+               if(expr) { \
+                       ERR(fmt, ##arg); \
+               } \
+       } while (0)
+#  define ret_if(expr) do { \
+               if(expr) { \
+                       return; \
+               } \
+       } while (0)
+#  define retv_if(expr, val) do { \
+               if(expr) { \
+                       return (val); \
+               } \
+       } while (0)
+#  define retm_if(expr, fmt, arg...) do { \
+               if(expr) { \
+                       ERR(fmt, ##arg); \
+                       return; \
+               } \
+       } while (0)
+#  define retvm_if(expr, val, fmt, arg...) do { \
+               if(expr) { \
+                       ERR(fmt, ##arg); \
+                       return (val); \
+               } \
+       } while (0)
+
+#endif
+
+#endif /* _SENSOR_LOG_H_ */
diff --git a/src/temperature/temperature_sensor_hal.cpp b/src/temperature/temperature_sensor_hal.cpp
new file mode 100644 (file)
index 0000000..e491c6d
--- /dev/null
@@ -0,0 +1,255 @@
+/*
+ * temperature_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 <linux/input.h>
+#include <csensor_config.h>
+#include <temperature_sensor_hal.h>
+#include <sys/ioctl.h>
+
+using std::string;
+
+#define SENSOR_TYPE_TEMPERATURE                "TEMPERATURE"
+#define ELEMENT_NAME                           "NAME"
+#define ELEMENT_VENDOR                         "VENDOR"
+#define ELEMENT_RAW_DATA_UNIT          "RAW_DATA_UNIT"
+
+#define TEMP_INPUT_NAME                                        "temperature_sensor"
+#define TEMP_IIO_ENABLE_NODE_NAME              "temp_enable"
+#define TEMP_SENSORHUB_POLL_NODE_NAME  "temp_poll_delay"
+#define INITIAL_TIME -1
+
+temperature_sensor_hal::temperature_sensor_hal()
+: m_temperature(0)
+, m_node_handle(-1)
+, m_polling_interval(POLL_1HZ_MS)
+, m_fired_time(INITIAL_TIME)
+{
+       const string sensorhub_interval_node_name = TEMP_SENSORHUB_POLL_NODE_NAME;
+
+       node_info_query query;
+       node_info info;
+
+       if (!find_model_id(SENSOR_TYPE_TEMPERATURE, m_model_id)) {
+               ERR("Failed to find model id");
+               throw ENXIO;
+       }
+
+       query.sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
+       query.sensor_type = SENSOR_TYPE_TEMPERATURE;
+       query.key = TEMP_INPUT_NAME;
+       query.iio_enable_node_name = TEMP_IIO_ENABLE_NODE_NAME;
+       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;
+
+       csensor_config &config = csensor_config::get_instance();
+
+       if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_VENDOR, m_vendor)) {
+               ERR("[VENDOR] is empty\n");
+               throw ENXIO;
+       }
+
+       if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_NAME, m_chip_name)) {
+               ERR("[NAME] is empty\n");
+               throw ENXIO;
+       }
+
+       double raw_data_unit;
+
+       if (!config.get(SENSOR_TYPE_TEMPERATURE, 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);
+
+       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
+               ERR("Failed to open handle(%d)", m_node_handle);
+               throw ENXIO;
+       }
+
+       int clockId = CLOCK_MONOTONIC;
+       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
+               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
+
+       INFO("m_vendor = %s", m_vendor.c_str());
+       INFO("m_chip_name = %s", m_chip_name.c_str());
+       INFO("m_raw_data_unit = %f\n", m_raw_data_unit);
+       INFO("temperature_sensor_hal is created!\n");
+}
+
+temperature_sensor_hal::~temperature_sensor_hal()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       INFO("temperature_sensor_hal is destroyed!\n");
+}
+
+string temperature_sensor_hal::get_model_id(void)
+{
+       return m_model_id;
+}
+
+sensor_hal_type_t temperature_sensor_hal::get_type(void)
+{
+       return SENSOR_HAL_TYPE_TEMPERATURE;
+}
+
+bool temperature_sensor_hal::enable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, true,
+                       SENSORHUB_TEMPERATURE_HUMIDITY_ENABLE_BIT);
+       set_interval(m_polling_interval);
+
+       m_fired_time = 0;
+       INFO("Temperature sensor real starting");
+       return true;
+}
+
+bool temperature_sensor_hal::disable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, false,
+                       SENSORHUB_TEMPERATURE_HUMIDITY_ENABLE_BIT);
+
+       INFO("Temperature sensor real stopping");
+       return true;
+}
+
+bool temperature_sensor_hal::set_interval(unsigned long val)
+{
+       unsigned long long polling_interval_ns;
+
+       AUTOLOCK(m_mutex);
+
+       polling_interval_ns = ((unsigned long long)(val) * 1000llu * 1000llu);
+
+       if (!set_node_value(m_interval_node, polling_interval_ns)) {
+               ERR("Failed to set polling node: %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 temperature_sensor_hal::update_value(void)
+{
+       int temperature_raw = 0;
+       bool temperature = false;
+       int read_input_cnt = 0;
+       const int INPUT_MAX_BEFORE_SYN = 10;
+       unsigned long long fired_time = 0;
+       bool syn = false;
+
+       struct input_event temperature_event;
+       DBG("temperature event detection!");
+
+       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
+               int len = read(m_node_handle, &temperature_event, sizeof(temperature_event));
+               if (len != sizeof(temperature_event)) {
+                       ERR("temperature_file read fail, read_len = %d\n",len);
+                       return false;
+               }
+
+               ++read_input_cnt;
+
+               if (temperature_event.type == EV_REL) {
+                       switch (temperature_event.code) {
+                               case REL_HWHEEL:
+                                       temperature_raw = (int)temperature_event.value;
+                                       temperature = true;
+                                       break;
+                               default:
+                                       ERR("temperature_event event[type = %d, code = %d] is unknown.", temperature_event.type, temperature_event.code);
+                                       return false;
+                                       break;
+                       }
+               } else if (temperature_event.type == EV_SYN) {
+                       syn = true;
+                       fired_time = sensor_hal_base::get_timestamp(&temperature_event.time);
+               } else {
+                       ERR("temperature_event event[type = %d, code = %d] is unknown.", temperature_event.type, temperature_event.code);
+                       return false;
+               }
+       }
+
+       if (syn == false) {
+               ERR("EV_SYN didn't come until %d inputs had come", read_input_cnt);
+               return false;
+       }
+
+       AUTOLOCK(m_value_mutex);
+
+       if (temperature)
+               m_temperature = temperature_raw;
+
+       m_fired_time = fired_time;
+
+       DBG("m_temperature = %d, time = %lluus", m_temperature, m_fired_time);
+
+       return true;
+}
+
+bool temperature_sensor_hal::is_data_ready(void)
+{
+       bool ret;
+       ret = update_value();
+       return ret;
+}
+
+int temperature_sensor_hal::get_sensor_data(sensor_data_t &data)
+{
+       AUTOLOCK(m_value_mutex);
+       data.accuracy = SENSOR_ACCURACY_GOOD;
+       data.timestamp = m_fired_time ;
+       data.value_count = 1;
+       data.values[0] = (float) m_temperature;
+
+       return 0;
+}
+
+bool temperature_sensor_hal::get_properties(sensor_properties_s &properties)
+{
+       properties.name = m_chip_name;
+       properties.vendor = m_vendor;
+       properties.min_range = -45;
+       properties.max_range = 130;
+       properties.min_interval = 1;
+       properties.resolution = 1;
+       properties.fifo_count = 0;
+       properties.max_batch_count = 0;
+
+       return true;
+}
diff --git a/src/temperature/temperature_sensor_hal.h b/src/temperature/temperature_sensor_hal.h
new file mode 100644 (file)
index 0000000..7dd06d6
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * temperature_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 _TEMPERATURE_SENSOR_HAL_H_
+#define _TEMPERATURE_SENSOR_HAL_H_
+
+#include <sensor_hal_base.h>
+
+class temperature_sensor_hal : public sensor_hal_base
+{
+public:
+       temperature_sensor_hal();
+       virtual ~temperature_sensor_hal();
+       std::string get_model_id(void);
+       sensor_hal_type_t get_type(void);
+       bool enable(void);
+       bool disable(void);
+       bool set_interval(unsigned long val);
+       bool is_data_ready(void);
+       virtual int get_sensor_data(sensor_data_t &data);
+       bool get_properties(sensor_properties_s &properties);
+private:
+       float m_temperature;
+       int m_node_handle;
+       unsigned long m_polling_interval;
+       unsigned long long m_fired_time;
+
+       std::string m_model_id;
+       std::string m_vendor;
+       std::string m_chip_name;
+
+       float m_raw_data_unit;
+
+       std::string m_data_node;
+       std::string m_enable_node;
+       std::string m_interval_node;
+
+       bool m_sensorhub_controlled;
+
+       cmutex m_value_mutex;
+
+       bool update_value(void);
+};
+#endif /*_TEMPERATURE_SENSOR_HAL_CLASS_H_*/
diff --git a/src/ultraviolet/ultraviolet_sensor_hal.cpp b/src/ultraviolet/ultraviolet_sensor_hal.cpp
new file mode 100644 (file)
index 0000000..6723e3f
--- /dev/null
@@ -0,0 +1,271 @@
+/*
+ * ultraviolet_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 <csensor_config.h>
+#include <ultraviolet_sensor_hal.h>
+#include <sys/ioctl.h>
+#include <fstream>
+
+using std::ifstream;
+using std::string;
+
+#define SENSOR_TYPE_ULTRAVIOLET        "ULTRAVIOLET"
+#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 ATTR_VALUE                             "value"
+
+#define BIAS   1
+
+ultraviolet_sensor_hal::ultraviolet_sensor_hal()
+: m_polling_interval(POLL_1HZ_MS)
+, m_ultraviolet(0)
+, m_fired_time(0)
+, m_node_handle(-1)
+{
+       const string sensorhub_interval_node_name = "uv_poll_delay";
+       csensor_config &config = csensor_config::get_instance();
+
+       node_info_query query;
+       node_info info;
+
+       if (!find_model_id(SENSOR_TYPE_ULTRAVIOLET, m_model_id)) {
+               ERR("Failed to find model id");
+               throw ENXIO;
+
+       }
+
+       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
+       query.sensor_type = SENSOR_TYPE_ULTRAVIOLET;
+       query.key = "uv_sensor";
+       query.iio_enable_node_name = "uv_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 (!config.get(SENSOR_TYPE_ULTRAVIOLET, 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_ULTRAVIOLET, m_model_id, ELEMENT_NAME, m_chip_name)) {
+               ERR("[NAME] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_chip_name = %s\n",m_chip_name.c_str());
+
+       double min_range;
+
+       if (!config.get(SENSOR_TYPE_ULTRAVIOLET, 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_ULTRAVIOLET, 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_ULTRAVIOLET, 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);
+
+       if ((m_node_handle = open(m_data_node.c_str(),O_RDWR)) < 0) {
+               ERR("Failed to open handle(%d)", m_node_handle);
+               throw ENXIO;
+       }
+
+       int clockId = CLOCK_MONOTONIC;
+       if (ioctl(m_node_handle, EVIOCSCLOCKID, &clockId) != 0)
+               ERR("Fail to set monotonic timestamp for %s", m_data_node.c_str());
+
+       INFO("m_raw_data_unit = %f\n", m_raw_data_unit);
+       INFO("ultraviolet_sensor_hal is created!\n");
+}
+
+ultraviolet_sensor_hal::~ultraviolet_sensor_hal()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       INFO("ultraviolet_sensor_hal is destroyed!\n");
+}
+
+string ultraviolet_sensor_hal::get_model_id(void)
+{
+       return m_model_id;
+}
+
+
+sensor_hal_type_t ultraviolet_sensor_hal::get_type(void)
+{
+       return SENSOR_HAL_TYPE_ULTRAVIOLET;
+}
+
+bool ultraviolet_sensor_hal::enable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_UV_SENSOR);
+       set_interval(m_polling_interval);
+
+       m_fired_time = 0;
+       INFO("ultraviolet sensor real starting");
+       return true;
+}
+
+bool ultraviolet_sensor_hal::disable(void)
+{
+       AUTOLOCK(m_mutex);
+
+       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_UV_SENSOR);
+
+       INFO("ultraviolet sensor real stopping");
+       return true;
+}
+
+bool ultraviolet_sensor_hal::set_interval(unsigned long val)
+{
+       unsigned long long polling_interval_ns;
+
+       AUTOLOCK(m_mutex);
+
+       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 ultraviolet_sensor_hal::update_value(void)
+{
+       int ultraviolet_raw = -1;
+       bool ultraviolet_sign = false;
+       bool ultraviolet = false;
+       int read_input_cnt = 0;
+       const int INPUT_MAX_BEFORE_SYN = 10;
+       unsigned long long fired_time = 0;
+       bool syn = false;
+
+       struct input_event ultraviolet_event;
+       DBG("ultraviolet event detection!");
+
+       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
+               int len = read(m_node_handle, &ultraviolet_event, sizeof(ultraviolet_event));
+               if (len != sizeof(ultraviolet_event)) {
+                       ERR("ultraviolet file read fail, read_len = %d\n",len);
+                       return false;
+               }
+
+               ++read_input_cnt;
+
+               if (ultraviolet_event.type == EV_REL && ultraviolet_event.code == REL_X) {
+                       ultraviolet_raw = (int)ultraviolet_event.value;
+                       ultraviolet = true;
+               } else if (ultraviolet_event.type == EV_REL && ultraviolet_event.code == REL_Y) {
+                       ultraviolet_sign = ((int)ultraviolet_event.value < 0) ? false : true;
+               } else if (ultraviolet_event.type == EV_SYN) {
+                       syn = true;
+                       fired_time = sensor_hal_base::get_timestamp(&ultraviolet_event.time);
+               } else {
+                       ERR("ultraviolet event[type = %d, code = %d] is unknown.", ultraviolet_event.type, ultraviolet_event.code);
+                       return false;
+               }
+       }
+
+       AUTOLOCK(m_value_mutex);
+
+       if (ultraviolet && ultraviolet_sign)
+               m_ultraviolet = ultraviolet_raw - BIAS;
+       else
+               return false;
+
+       m_fired_time = fired_time;
+
+       DBG("m_ultraviolet = %d, time = %lluus", m_ultraviolet, m_fired_time);
+
+       return true;
+}
+
+bool ultraviolet_sensor_hal::is_data_ready(void)
+{
+       bool ret;
+       ret = update_value();
+       return ret;
+}
+
+int ultraviolet_sensor_hal::get_sensor_data(sensor_data_t &data)
+{
+       AUTOLOCK(m_value_mutex);
+       data.accuracy = SENSOR_ACCURACY_GOOD;
+       data.timestamp = m_fired_time;
+       data.value_count = 1;
+       data.values[0] = (float) m_ultraviolet;
+
+       return 0;
+}
+
+bool ultraviolet_sensor_hal::get_properties(sensor_properties_s &properties)
+{
+       properties.name = m_chip_name;
+       properties.vendor = m_vendor;
+       properties.min_range = m_min_range;
+       properties.max_range = m_max_range;
+       properties.min_interval = 1;
+       properties.resolution = m_raw_data_unit;
+       properties.fifo_count = 0;
+       properties.max_batch_count = 0;
+
+       return true;
+}
diff --git a/src/ultraviolet/ultraviolet_sensor_hal.h b/src/ultraviolet/ultraviolet_sensor_hal.h
new file mode 100644 (file)
index 0000000..dfe684c
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * ultraviolet_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 _ULTRAVIOLET_SENSOR_HAL_H_
+#define _ULTRAVIOLET_SENSOR_HAL_H_
+
+#include <sensor_hal_base.h>
+
+class ultraviolet_sensor_hal : public sensor_hal_base
+{
+public:
+       ultraviolet_sensor_hal();
+       virtual ~ultraviolet_sensor_hal();
+       std::string get_model_id(void);
+       sensor_hal_type_t get_type(void);
+       bool enable(void);
+       bool disable(void);
+       bool set_interval(unsigned long val);
+       bool is_data_ready(void);
+       virtual int get_sensor_data(sensor_data_t &data);
+       bool get_properties(sensor_properties_s &properties);
+
+private:
+       std::string m_model_id;
+       std::string m_vendor;
+       std::string m_chip_name;
+
+       float m_min_range;
+       float m_max_range;
+       float m_raw_data_unit;
+
+       unsigned long m_polling_interval;
+
+       int m_ultraviolet;
+
+       unsigned long long m_fired_time;
+       int m_node_handle;
+
+       std::string m_enable_node;
+       std::string m_data_node;
+       std::string m_interval_node;
+
+       bool m_sensorhub_controlled;
+
+       cmutex m_value_mutex;
+
+       bool update_value(void);
+};
+#endif /*_ULTRAVIOLET_SENSOR_HAL_CLASS_H_*/
+