CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(sensor-plugins-tm1 CXX)
+PROJECT(sensor-hal CXX)
INCLUDE(GNUInstallDirs)
SET(ACCEL "ON")
-SET(GYRO "OFF")
SET(PROXIMITY "OFF")
-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")
#ADD_DEFINITIONS(-Wall -g -D_DEBUG)
INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(plugin_pkgs REQUIRED dlog)
+PKG_CHECK_MODULES(hal_pkgs REQUIRED dlog)
-FOREACH(flag ${plugin_pkgs_LDFLAGS})
+FOREACH(flag ${hal_pkgs_LDFLAGS})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
ENDFOREACH(flag)
-FOREACH(flag ${plugin_pkgs_CFLAGS})
+FOREACH(flag ${hal_pkgs_CFLAGS})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
ENDFOREACH(flag)
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})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal_pkgs_LDFLAGS})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor)
+++ /dev/null
-/*
- * 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;
-
-}
+++ /dev/null
-/*
- * 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_*/
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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_*/
-
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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_*/
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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_*/
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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_*/
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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_*/
-
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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_*/
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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_*/
-