# Installing files
CONFIGURE_FILE(sensor_plugins.xml.in sensor_plugins.xml @ONLY)
-CONFIGURE_FILE(sensors.xml.in sensors.xml @ONLY)
-INSTALL(FILES sensor_plugins.xml sensors.xml DESTINATION etc)
+INSTALL(FILES sensor_plugins.xml DESTINATION etc)
INSTALL(FILES virtual_sensors.xml virtual_sensors.xml DESTINATION etc)
# Sub-directory
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(libsystemd-daemon)
BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(sensor-hal)
BuildRequires: pkgconfig(cynara-creds-socket)
BuildRequires: pkgconfig(cynara-client)
BuildRequires: pkgconfig(cynara-session)
%files -n sensord
%attr(0644,root,root)/usr/etc/sensor_plugins.xml
-%attr(0644,root,root)/usr/etc/sensors.xml
%attr(0644,root,root)/usr/etc/virtual_sensors.xml
%manifest sensord.manifest
%{_bindir}/sensord
<PLUGIN>
<HAL>
- <MODULE path = "/usr/lib/sensord/libaccel_sensor_hal.so"/>
- <MODULE path = "/usr/lib/sensord/libgyro_sensor_hal.so"/>
- <MODULE path = "/usr/lib/sensord/libgeo_sensor_hal.so"/>
- <MODULE path = "/usr/lib/sensord/libproxi_sensor_hal.so"/>
- <MODULE path = "/usr/lib/sensord/liblight_sensor_hal.so"/>
- <MODULE path = "/usr/lib/sensord/libpressure_sensor_hal.so"/>
- <MODULE path = "/usr/lib/sensord/libtemperature_sensor_hal.so"/>
- <MODULE path = "/usr/lib/sensord/libultraviolet_sensor_hal.so"/>
- <MODULE path = "/usr/lib/sensord/libbio_led_red_sensor_hal.so"/>
+ <MODULE path = "/usr/lib/sensor-hal/libaccel_sensor_hal.so"/>
+ <MODULE path = "/usr/lib/sensor-hal/libgyro_sensor_hal.so"/>
+ <MODULE path = "/usr/lib/sensor-hal/libgeo_sensor_hal.so"/>
+ <MODULE path = "/usr/lib/sensor-hal/libproxi_sensor_hal.so"/>
+ <MODULE path = "/usr/lib/sensor-hal/liblight_sensor_hal.so"/>
+ <MODULE path = "/usr/lib/sensor-hal/libpressure_sensor_hal.so"/>
+ <MODULE path = "/usr/lib/sensor-hal/libtemperature_sensor_hal.so"/>
+ <MODULE path = "/usr/lib/sensor-hal/libultraviolet_sensor_hal.so"/>
+ <MODULE path = "/usr/lib/sensor-hal/libbio_led_red_sensor_hal.so"/>
</HAL>
<SENSOR>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<SENSOR>
- <ACCEL>
- <MODEL id="lsm330dlc-accel">
- <NAME value="LSM330DLC"/>
- <VENDOR value="ST Microelectronics"/>
- <RAW_DATA_UNIT value="1" />
- <RESOLUTION value="12" />
- </MODEL>
-
- <MODEL id="LSM330">
- <NAME value="LSM330"/>
- <VENDOR value="ST Microelectronics"/>
- <RAW_DATA_UNIT value="1" />
- <RESOLUTION value="12" />
- </MODEL>
-
- <MODEL id="K2HH">
- <NAME value="K2HH" />
- <VENDOR value="ST Microelectronics"/>
- <RAW_DATA_UNIT value="0.061"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="MPU6500">
- <NAME value="MPU6500"/>
- <VENDOR value="Invensense"/>
- <RAW_DATA_UNIT SM-Z910F="0.061" SM-Z9005="0.061" value="0.244"/>
- <RESOLUTION value="16" />
- </MODEL>
-
- <MODEL id="MPU6515">
- <NAME value="MPU6515"/>
- <VENDOR value="Invensense"/>
- <RAW_DATA_UNIT value="0.061"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="MPU6050">
- <NAME value="MPU6050"/>
- <VENDOR value="Invensense"/>
- <RAW_DATA_UNIT value="0.061"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="MPU6051">
- <NAME value="MPU6051"/>
- <VENDOR value="Invensense"/>
- <RAW_DATA_UNIT value="0.061"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="MPU9250">
- <NAME value="MPU9250"/>
- <VENDOR value="Invensense"/>
- <RAW_DATA_UNIT value="0.244"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="ICM20628">
- <NAME value="ICM20628"/>
- <VENDOR value="Invensense"/>
- <RAW_DATA_UNIT value="0.244" />
- <RESOLUTION value="16" />
- </MODEL>
-
- <MODEL id="bma222e">
- <NAME value="BMA222E"/>
- <VENDOR value="BOSCH"/>
- <RAW_DATA_UNIT value="15.63"/>
- <RESOLUTION value="8"/>
- </MODEL>
-
- <MODEL id="BMI160">
- <NAME value="BMI160"/>
- <VENDOR value="Bosch"/>
- <RAW_DATA_UNIT value="0.244"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="maru_sensor_accel_1">
- <NAME value="maru_sensor_accel_1"/>
- <VENDOR value="Tizen_SDK"/>
- <RAW_DATA_UNIT value="0.061"/>
- <RESOLUTION value="16"/>
- </MODEL>
- </ACCEL>
-
- <GYRO>
- <MODEL id="lsm330dlc-gyro">
- <NAME value="LSM330DLC"/>
- <VENDOR value="ST Microelectronics"/>
- <RAW_DATA_UNIT value="17.50"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="LSM330">
- <NAME value="LSM330"/>
- <VENDOR value="ST Microelectronics"/>
- <RAW_DATA_UNIT value="17.50" />
- <RESOLUTION value="16" />
- </MODEL>
-
- <MODEL id="MPU6500">
- <NAME value="MPU6500"/>
- <VENDOR value="Invensense"/>
- <RAW_DATA_UNIT value="15.26"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="MPU6515">
- <NAME value="MPU6515"/>
- <VENDOR value="Invensense"/>
- <RAW_DATA_UNIT value="15.26"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="MPU6050">
- <NAME value="MPU6050"/>
- <VENDOR value="Invensense"/>
- <RAW_DATA_UNIT value="15.26"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="MPU6051">
- <NAME value="MPU6051"/>
- <VENDOR value="Invensense"/>
- <RAW_DATA_UNIT value="15.26"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="MPU9250">
- <NAME value="MPU9250"/>
- <VENDOR value="Invensense"/>
- <RAW_DATA_UNIT value="15.26"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="ICM20628">
- <NAME value="ICM20628"/>
- <VENDOR value="Invensense"/>
- <RAW_DATA_UNIT value="61.04"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="BMI160">
- <NAME value="BMI160"/>
- <VENDOR value="Bosch"/>
- <RAW_DATA_UNIT value="61.04"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="maru_sensor_gyro_1">
- <NAME value="maru_sensor_gyro_1"/>
- <VENDOR value="Tizen_SDK"/>
- <RAW_DATA_UNIT value="1000"/>
- <RESOLUTION value="16"/>
- <MIN_RANGE value="-573"/>
- <MAX_RANGE value="573"/>
- </MODEL>
- </GYRO>
-
- <PROXI>
- <MODEL id="taos">
- <NAME value="TMD27723"/>
- <VENDOR value="TAOS"/>
- </MODEL>
-
- <MODEL id="TMD3782">
- <NAME value="TMD3782"/>
- <VENDOR value="TAOS"/>
- </MODEL>
-
- <MODEL id="gp2a">
- <NAME value="GP2AP020"/>
- <VENDOR value="Sharp"/>
- </MODEL>
-
- <MODEL id="gp2ap002s">
- <NAME value="GP2AP002S"/>
- <VENDOR value="Sharp"/>
- </MODEL>
-
- <MODEL id="CM36651">
- <NAME value="CM36651"/>
- <VENDOR value="Capella"/>
- </MODEL>
-
- <MODEL id="MAX88922">
- <NAME value="MAX88922"/>
- <VENDOR value="MAXIM"/>
- </MODEL>
-
- <MODEL id="maru_sensor_proxi_1">
- <NAME value="maru_sensor_proxi_1"/>
- <VENDOR value="Tizen_SDK"/>
- </MODEL>
- </PROXI>
-
- <LIGHT>
- <MODEL id="taos">
- <NAME value="TMD27723"/>
- <VENDOR value="TAOS"/>
- </MODEL>
-
- <MODEL id="TMD3782">
- <NAME value="TMD3782"/>
- <VENDOR value="TAOS"/>
- </MODEL>
-
- <MODEL id="gp2a">
- <NAME value="GP2AP020"/>
- <VENDOR value="Sharp"/>
- </MODEL>
-
- <MODEL id="CM36651">
- <NAME value="CM36651"/>
- <VENDOR value="Capella"/>
- </MODEL>
-
- <MODEL id="MAX88922">
- <NAME value="MAX88922"/>
- <VENDOR value="MAXIM"/>
- </MODEL>
-
- <MODEL id="AL3320">
- <NAME value="AL3320"/>
- <VENDOR value="LITEON"/>
- </MODEL>
-
- <MODEL id="BH1733">
- <NAME value="BH1733"/>
- <VENDOR value="ROHM"/>
- </MODEL>
-
- <MODEL id="maru_sensor_light_1">
- <NAME value="maru_sensor_light_1"/>
- <VENDOR value="Tizen_SDK"/>
- </MODEL>
- </LIGHT>
-
- <MAGNETIC>
- <MODEL id="AK8975C">
- <NAME value="AK8975C" />
- <VENDOR value="AKM"/>
- <RAW_DATA_UNIT value="0.06"/>
- <MIN_RANGE value="-1200"/>
- <MAX_RANGE value="1200"/>
- </MODEL>
-
- <MODEL id="AK09911C">
- <NAME value="AK09911C"/>
- <VENDOR value="AKM"/>
- <RAW_DATA_UNIT value="0.06"/>
- <MIN_RANGE value="-4900"/>
- <MAX_RANGE value="4900"/>
- </MODEL>
-
- <MODEL id="ak8975">
- <NAME value="AK8975"/>
- <VENDOR value="AKM"/>
- <RAW_DATA_UNIT value="0.03"/>
- <MIN_RANGE value="-1200"/>
- <MAX_RANGE value="1200"/>
- </MODEL>
-
- <MODEL id="MPU9250">
- <NAME value="MPU9250"/>
- <VENDOR value="Invensense"/>
- <RAW_DATA_UNIT value="1.0"/>
- <MIN_RANGE value="-4800"/>
- <MAX_RANGE value="4800"/>
- </MODEL>
-
- <MODEL id="YAS537">
- <NAME value="YAS537"/>
- <VENDOR value="Yamaha"/>
- <RAW_DATA_UNIT value="0.1"/>
- <MIN_RANGE value="-4800"/>
- <MAX_RANGE value="4800"/>
- </MODEL>
-
- <MODEL id="maru_sensor_geo_1">
- <NAME value="maru_sensor_geo_1"/>
- <VENDOR value="Tizen_SDK"/>
- <RAW_DATA_UNIT value="0.6"/>
- <RESOLUTION value="14"/>
- <MIN_RANGE value="-2000"/>
- <MAX_RANGE value="2000"/>
- </MODEL>
- </MAGNETIC>
-
- <PRESSURE>
- <MODEL id="LPS25H">
- <NAME value="LPS25H"/>
- <VENDOR value="ST Microelectronics"/>
- <RAW_DATA_UNIT value="0.000244"/>
- <MIN_RANGE value="260"/>
- <MAX_RANGE value="1260"/>
- <RESOLUTION value="1"/>
- <TEMPERATURE_RESOLUTION value="0.002083"/>
- <TEMPERATURE_OFFSET value="42.5"/>
- </MODEL>
-
- <MODEL id="LPS331">
- <NAME value="LPS331"/>
- <VENDOR value="ST Microelectronics"/>
- <RAW_DATA_UNIT value="0.000244"/>
- <MIN_RANGE value="260"/>
- <MAX_RANGE value="1260"/>
- <RESOLUTION value="1"/>
- <TEMPERATURE_RESOLUTION value="0.002083"/>
- <TEMPERATURE_OFFSET value="42.5"/>
- </MODEL>
- <MODEL id="maru_sensor_pressure_1">
- <NAME value="maru_sensor_pressure_1" />
- <VENDOR value="Tizen_SDK"/>
- <RAW_DATA_UNIT value="0.0193"/>
- <MIN_RANGE value="260"/>
- <MAX_RANGE value="1260"/>
- <RESOLUTION value="1"/>
- <TEMPERATURE_RESOLUTION value="0.05"/>
- <TEMPERATURE_OFFSET value="0"/>
- </MODEL>
- </PRESSURE>
-
- <TEMPERATURE>
- <MODEL id="LPS331">
- <NAME value="LPS331" />
- <VENDOR value="ST Microelectronics"/>
- <RAW_DATA_UNIT value="0.01"/>
- <RESOLUTION value="1"/>
- </MODEL>
-
- <MODEL id="SHTC1">
- <NAME value="SHTC1" />
- <VENDOR value="SENSIRION"/>
- <RAW_DATA_UNIT value="0.01"/>
- <RESOLUTION value="1"/>
- </MODEL>
- </TEMPERATURE>
-
- <HUMIDITY>
- <MODEL id="SHTC1">
- <NAME value="SHTC1" />
- <VENDOR value="SENSIRION"/>
- <RAW_DATA_UNIT value="0.01"/>
- <MIN_RANGE value="-10"/>
- <MAX_RANGE value="110"/>
- <RESOLUTION value="1"/>
- </MODEL>
- </HUMIDITY>
-
- <ULTRAVIOLET>
- <MODEL id="UVIS25">
- <NAME value="UVIS25" />
- <VENDOR value="STM"/>
- <RAW_DATA_UNIT value="0.0625"/>
- <MIN_RANGE value="0"/>
- <MAX_RANGE value="15"/>
- </MODEL>
- <MODEL id="maru_sensor_uv_1">
- <NAME value="maru_sensor_uv_1" />
- <VENDOR value="Tizen_SDK"/>
- <RAW_DATA_UNIT value="0.1"/>
- <MIN_RANGE value="0"/>
- <MAX_RANGE value="15"/>
- </MODEL>
- <MODEL id="MAX86902_UV">
- <NAME value="MAX86902_UV" />
- <VENDOR value="MAXIM"/>
- <RAW_DATA_UNIT value="0.1"/>
- <MIN_RANGE value="0"/>
- <MAX_RANGE value="15"/>
- </MODEL>
- </ULTRAVIOLET>
-
- <BIO_LED_RED>
- <MODEL id="MAX86902">
- <NAME value="MAX86902" />
- <VENDOR value="MAXIM"/>
- </MODEL>
- </BIO_LED_RED>
-</SENSOR>
poller.cpp
)
-target_link_libraries(${PROJECT_NAME} ${lib_pkgs_LDFLAGS} "sensord-share")
+target_link_libraries(${PROJECT_NAME} ${lib_pkgs_LDFLAGS} "sensord-share" "sensor-hal")
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
project(accel CXX)
SET(SENSOR_NAME accel_sensor)
-SET(SENSOR_HAL_NAME accel_sensor_hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
accel_sensor.cpp
)
-add_library(${SENSOR_HAL_NAME} SHARED
- accel_sensor_hal.cpp
- )
-
target_link_libraries(${SENSOR_NAME} ${accel_pkgs_LDFLAGS} "-lm")
-target_link_libraries(${SENSOR_HAL_NAME} ${accel_pkgs_LDFLAGS})
install(TARGETS ${SENSOR_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
-install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
+++ /dev/null
-/*
- * accel_sensor_hal
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <linux/input.h>
-#include <csensor_config.h>
-#include <accel_sensor_hal.h>
-#include <sys/poll.h>
-
-using std::ifstream;
-using std::string;
-
-#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 SENSOR_TYPE_ACCEL "ACCEL"
-#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 INPUT_NAME "accelerometer_sensor"
-#define ACCEL_SENSORHUB_POLL_NODE_NAME "accel_poll_delay"
-
-accel_sensor_hal::accel_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 = "accel_poll_delay";
- csensor_config &config = csensor_config::get_instance();
-
- node_info_query query;
- node_info info;
-
- if (!find_model_id(SENSOR_TYPE_ACCEL, 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_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_method = info.method;
- 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_ACCEL, 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_ACCEL, 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_ACCEL, m_model_id, ELEMENT_RESOLUTION, resolution)) {
- ERR("[RESOLUTION] is empty\n");
- throw ENXIO;
- }
-
- m_resolution = (int)resolution;
-
- INFO("m_resolution = %d\n",m_resolution);
-
- double raw_data_unit;
-
- if (!config.get(SENSOR_TYPE_ACCEL, 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);
-
- 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;
- }
-
- if (m_method == INPUT_EVENT_METHOD) {
- 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());
-
- update_value = [=](bool wait) {
- return this->update_value_input_event(wait);
- };
- } else {
- if (!info.buffer_length_node_path.empty())
- set_node_value(info.buffer_length_node_path, 480);
-
- if (!info.buffer_enable_node_path.empty())
- set_node_value(info.buffer_enable_node_path, 1);
-
- update_value = [=](bool wait) {
- return this->update_value_iio(wait);
- };
- }
-
- INFO("accel_sensor is created!\n");
-}
-
-accel_sensor_hal::~accel_sensor_hal()
-{
- close(m_node_handle);
- m_node_handle = -1;
-
- INFO("accel_sensor is destroyed!\n");
-}
-
-string accel_sensor_hal::get_model_id(void)
-{
- return m_model_id;
-}
-
-sensor_hal_type_t accel_sensor_hal::get_type(void)
-{
- return SENSOR_HAL_TYPE_ACCELEROMETER;
-}
-
-bool accel_sensor_hal::enable(void)
-{
- AUTOLOCK(m_mutex);
-
- set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
- set_interval(m_polling_interval);
-
- m_fired_time = 0;
- INFO("Accel sensor real starting");
- return true;
-}
-
-bool accel_sensor_hal::disable(void)
-{
- AUTOLOCK(m_mutex);
-
- set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
-
- INFO("Accel sensor real stopping");
- return true;
-}
-
-bool accel_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 accel_sensor_hal::update_value_input_event(bool wait)
-{
- int accel_raw[3] = {0,};
- bool x,y,z;
- int read_input_cnt = 0;
- const int INPUT_MAX_BEFORE_SYN = 10;
- unsigned long long fired_time = 0;
- bool syn = false;
-
- x = y = z = false;
-
- struct input_event accel_input;
- DBG("accel event detection!");
-
- while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
- int len = read(m_node_handle, &accel_input, sizeof(accel_input));
- if (len != sizeof(accel_input)) {
- ERR("accel_file read fail, read_len = %d\n",len);
- return false;
- }
-
- ++read_input_cnt;
-
- if (accel_input.type == EV_REL) {
- switch (accel_input.code) {
- case REL_X:
- accel_raw[0] = (int)accel_input.value;
- x = true;
- break;
- case REL_Y:
- accel_raw[1] = (int)accel_input.value;
- y = true;
- break;
- case REL_Z:
- accel_raw[2] = (int)accel_input.value;
- z = true;
- break;
- default:
- ERR("accel_input event[type = %d, code = %d] is unknown.", accel_input.type, accel_input.code);
- return false;
- break;
- }
- } else if (accel_input.type == EV_SYN) {
- syn = true;
- fired_time = sensor_hal::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;
- }
-
- AUTOLOCK(m_value_mutex);
-
- if (x)
- m_x = accel_raw[0];
- if (y)
- m_y = accel_raw[1];
- if (z)
- m_z = accel_raw[2];
-
- m_fired_time = fired_time;
-
- DBG("m_x = %d, m_y = %d, m_z = %d, time = %lluus", m_x, m_y, m_z, m_fired_time);
-
- return true;
-}
-
-
-bool accel_sensor_hal::update_value_iio(bool wait)
-{
- const int READ_LEN = 14;
- char data[READ_LEN] = {0,};
-
- struct pollfd pfd;
-
- pfd.fd = m_node_handle;
- pfd.events = POLLIN | POLLERR;
- pfd.revents = 0;
-
- int ret = poll(&pfd, 1, -1);
-
- if (ret == -1) {
- ERR("poll error:%s m_node_handle:d", strerror(errno), m_node_handle);
- return false;
- } else if (!ret) {
- ERR("poll timeout m_node_handle:%d", m_node_handle);
- return false;
- }
-
- if (pfd.revents & POLLERR) {
- ERR("poll exception occurred! m_node_handle:%d", m_node_handle);
- return false;
- }
-
- if (!(pfd.revents & POLLIN)) {
- ERR("poll nothing to read! m_node_handle:%d, pfd.revents = %d", m_node_handle, pfd.revents);
- return false;
- }
-
- int len = read(m_node_handle, data, sizeof(data));
-
- if (len != sizeof(data)) {
- ERR("Failed to read data, m_node_handle:%d read_len:%d", m_node_handle, len);
- return false;
- }
-
- AUTOLOCK(m_value_mutex);
-
- short *short_data = (short *)(data);
- m_x = *(short_data);
- m_y = *((short *)(data + 2));
- m_z = *((short *)(data + 4));
-
- m_fired_time = *((long long*)(data + 6));
-
- INFO("m_x = %d, m_y = %d, m_z = %d, time = %lluus", m_x, m_y, m_z, m_fired_time);
-
- return true;
-
-}
-
-bool accel_sensor_hal::is_data_ready(bool wait)
-{
- bool ret;
- ret = update_value(wait);
- return ret;
-}
-
-int accel_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 accel_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_METRE_PER_SECOND_SQUARED_UNIT(m_raw_data_unit);
- properties.max_range = MAX_RANGE(m_resolution)* RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(m_raw_data_unit);
- properties.min_interval = 1;
- properties.resolution = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(m_raw_data_unit);
- properties.fifo_count = 0;
- properties.max_batch_count = 0;
- return true;
-}
-
-extern "C" sensor_module* create(void)
-{
- accel_sensor_hal *sensor;
-
- try {
- sensor = new(std::nothrow) accel_sensor_hal;
- } catch (int err) {
- ERR("Failed to create module, err: %d, cause: %s", err, strerror(err));
- return NULL;
- }
-
- sensor_module *module = new(std::nothrow) sensor_module;
- retvm_if(!module || !sensor, NULL, "Failed to allocate memory");
-
- module->sensors.push_back(sensor);
- return module;
-}
+++ /dev/null
-/*
- * accel_sensor_hal
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _ACCEL_SENSOR_HAL_H_
-#define _ACCEL_SENSOR_HAL_H_
-
-#include <sensor_hal.h>
-#include <functional>
-
-class accel_sensor_hal : public sensor_hal
-{
-public:
- accel_sensor_hal();
- virtual ~accel_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(bool wait);
- virtual int get_sensor_data(sensor_data_t &data);
- 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;
-
- int m_resolution;
- float m_raw_data_unit;
-
- int m_method;
- std::string m_data_node;
- std::string m_enable_node;
- std::string m_interval_node;
-
- std::function<bool (bool)> update_value;
-
- bool m_sensorhub_controlled;
-
- cmutex m_value_mutex;
-
- bool update_value_input_event(bool wait);
- bool update_value_iio(bool wait);
-};
-#endif /*_ACCEL_SENSOR_HAL_CLASS_H_*/
project(bio_led_red CXX)
SET(SENSOR_NAME bio_led_red_sensor)
-SET(SENSOR_HAL_NAME bio_led_red_sensor_hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
bio_led_red_sensor.cpp
)
-add_library(${SENSOR_HAL_NAME} SHARED
- bio_led_red_sensor_hal.cpp
- )
-
target_link_libraries(${SENSOR_NAME} ${bio_led_red_pkgs_LDFLAGS} "-lm")
-target_link_libraries(${SENSOR_HAL_NAME} ${bio_led_red_pkgs_LDFLAGS})
install(TARGETS ${SENSOR_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
-install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
+++ /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(bool wait)
-{
- 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::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(bool wait)
-{
- bool ret;
- ret = update_value(wait);
- 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;
-}
-
-extern "C" sensor_module* create(void)
-{
- bio_led_red_sensor_hal *sensor;
-
- try {
- sensor = new(std::nothrow) bio_led_red_sensor_hal;
- } catch (int err) {
- ERR("Failed to create module, err: %d, cause: %s", err, strerror(err));
- return NULL;
- }
-
- sensor_module *module = new(std::nothrow) sensor_module;
- retvm_if(!module || !sensor, NULL, "Failed to allocate memory");
-
- module->sensors.push_back(sensor);
- return module;
-}
+++ /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.h>
-
-class bio_led_red_sensor_hal : public sensor_hal
-{
-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(bool wait);
- 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(bool wait);
-};
-#endif /*_BIO_LED_RED_SENSOR_HAL_CLASS_H_*/
-
project(geo CXX)
SET(SENSOR_NAME geo_sensor)
-SET(SENSOR_HAL_NAME geo_sensor_hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
geo_sensor.cpp
)
-add_library(${SENSOR_HAL_NAME} SHARED
- geo_sensor_hal.cpp
-)
-
target_link_libraries(${SENSOR_NAME} ${geo_pkgs_LDFLAGS} "-lm")
-target_link_libraries(${SENSOR_HAL_NAME} ${geo_pkgs_LDFLAGS})
install(TARGETS ${SENSOR_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
-install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
+++ /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(bool wait)
-{
- 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 = 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(bool wait)
-{
- bool ret;
- ret = update_value(wait);
- 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;
-}
-
-extern "C" sensor_module* create(void)
-{
- geo_sensor_hal *sensor;
-
- try {
- sensor = new(std::nothrow) geo_sensor_hal;
- } catch (int err) {
- ERR("Failed to create module, err: %d, cause: %s", err, strerror(err));
- return NULL;
- }
-
- sensor_module *module = new(std::nothrow) sensor_module;
- retvm_if(!module || !sensor, NULL, "Failed to allocate memory");
-
- module->sensors.push_back(sensor);
- return module;
-}
+++ /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.h>
-
-class geo_sensor_hal : public sensor_hal
-{
-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(bool wait);
- 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(bool wait);
-};
-#endif /*_GEO_SENSOR_HAL_H_*/
project(gyro CXX)
SET(SENSOR_NAME gyro_sensor)
-SET(SENSOR_HAL_NAME gyro_sensor_hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
add_library(${SENSOR_NAME} SHARED
gyro_sensor.cpp
)
-add_library(${SENSOR_HAL_NAME} SHARED
- gyro_sensor_hal.cpp
- )
target_link_libraries(${SENSOR_NAME} ${gyro_pkgs_LDFLAGS} "-lm")
-target_link_libraries(${SENSOR_HAL_NAME} ${gyro_pkgs_LDFLAGS})
install(TARGETS ${SENSOR_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
-install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
+++ /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(bool wait)
-{
- 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::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(bool wait)
-{
- bool ret;
- ret = update_value(wait);
- 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;
-
-}
-
-extern "C" sensor_module* create(void)
-{
- gyro_sensor_hal *sensor;
-
- try {
- sensor = new(std::nothrow) gyro_sensor_hal;
- } catch (int err) {
- ERR("Failed to create module, err: %d, cause: %s", err, strerror(err));
- return NULL;
- }
-
- sensor_module *module = new(std::nothrow) sensor_module;
- retvm_if(!module || !sensor, NULL, "Failed to allocate memory");
-
- module->sensors.push_back(sensor);
- return module;
-}
+++ /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.h>
-
-class gyro_sensor_hal : public sensor_hal
-{
-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(bool wait);
- 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(bool wait);
-};
-#endif /*_GYRO_SENSOR_HAL_CLASS_H_*/
project(light CXX)
SET(SENSOR_NAME light_sensor)
-SET(SENSOR_HAL_NAME light_sensor_hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
light_sensor.cpp
)
-add_library(${SENSOR_HAL_NAME} SHARED
- light_sensor_hal.cpp
- )
-
target_link_libraries(${SENSOR_NAME} ${light_pkgs_LDFLAGS} "-lm")
-target_link_libraries(${SENSOR_HAL_NAME} ${light_pkgs_LDFLAGS})
install(TARGETS ${SENSOR_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
-install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
+++ /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(bool wait)
-{
- 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 = get_timestamp(&light_event.time);
-
- return true;
-}
-
-bool light_sensor_hal::is_data_ready(bool wait)
-{
- bool ret;
- ret = update_value(wait);
- 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;
-}
-
-extern "C" sensor_module* create(void)
-{
- light_sensor_hal *sensor;
-
- try {
- sensor = new(std::nothrow) light_sensor_hal;
- } catch (int err) {
- ERR("Failed to create module, err: %d, cause: %s", err, strerror(err));
- return NULL;
- }
-
- sensor_module *module = new(std::nothrow) sensor_module;
- retvm_if(!module || !sensor, NULL, "Failed to allocate memory");
-
- module->sensors.push_back(sensor);
- return module;
-}
+++ /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.h>
-
-class light_sensor_hal : public sensor_hal
-{
-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(bool wait);
- 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(bool wait);
-};
-#endif /*_GYRO_SENSOR_HAL_CLASS_H_*/
project(pressure CXX)
SET(SENSOR_NAME pressure_sensor)
-SET(SENSOR_HAL_NAME pressure_sensor_hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
pressure_sensor.cpp
)
-add_library(${SENSOR_HAL_NAME} SHARED
- pressure_sensor_hal.cpp
- )
-
target_link_libraries(${SENSOR_NAME} ${pressure_pkgs_LDFLAGS} "-lm")
-target_link_libraries(${SENSOR_HAL_NAME} ${pressure_pkgs_LDFLAGS})
install(TARGETS ${SENSOR_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
-install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
+++ /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>
-
-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
-
-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);
-
- 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(bool wait)
-{
- 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::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(bool wait)
-{
- bool ret;
- ret = update_value(wait);
- return ret;
-}
-
-int pressure_sensor_hal::get_sensor_data(sensor_data_t &data)
-{
- AUTOLOCK(m_value_mutex);
- data.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;
-
- 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;
-}
-
-extern "C" sensor_module* create(void)
-{
- pressure_sensor_hal *sensor;
-
- try {
- sensor = new(std::nothrow) pressure_sensor_hal;
- } catch (int err) {
- ERR("Failed to create module, err: %d, cause: %s", err, strerror(err));
- return NULL;
- }
-
- sensor_module *module = new(std::nothrow) sensor_module;
- retvm_if(!module || !sensor, NULL, "Failed to allocate memory");
-
- module->sensors.push_back(sensor);
- return module;
-}
+++ /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.h>
-
-class pressure_sensor_hal : public sensor_hal
-{
-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(bool wait);
- 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;
-
- 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(bool wait);
-};
-#endif /*_PRESSURE_SENSOR_HAL_CLASS_H_*/
project(proxi CXX)
SET(SENSOR_NAME proxi_sensor)
-SET(SENSOR_HAL_NAME proxi_sensor_hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
proxi_sensor.cpp
)
-add_library(${SENSOR_HAL_NAME} SHARED
- proxi_sensor_hal.cpp
-)
-
target_link_libraries(${SENSOR_NAME} ${proxi_pkgs_LDFLAGS} "-lm")
-target_link_libraries(${SENSOR_HAL_NAME} ${proxi_pkgs_LDFLAGS})
install(TARGETS ${SENSOR_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
-install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
+++ /dev/null
-/*
- * proxi_sensor_hal
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <linux/input.h>
-#include <csensor_config.h>
-#include <proxi_sensor_hal.h>
-#include <sys/ioctl.h>
-#include <fstream>
-
-using std::string;
-using std::ifstream;
-
-#define SENSOR_TYPE_PROXI "PROXI"
-#define ELEMENT_NAME "NAME"
-#define ELEMENT_VENDOR "VENDOR"
-#define ATTR_VALUE "value"
-
-#define PROXI_CODE 0x0019
-
-proxi_sensor_hal::proxi_sensor_hal()
-: m_state(-1)
-, m_fired_time(0)
-, m_node_handle(-1)
-{
- const string sensorhub_interval_node_name = "prox_poll_delay";
- csensor_config &config = csensor_config::get_instance();
-
- node_info_query query;
- node_info info;
-
- if (!find_model_id(SENSOR_TYPE_PROXI, 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_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 (!config.get(SENSOR_TYPE_PROXI, 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_PROXI, 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("Proxi handle(%d) open fail", 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("Proxi_sensor_hal is created!\n");
-
-}
-
-proxi_sensor_hal::~proxi_sensor_hal()
-{
- close(m_node_handle);
- m_node_handle = -1;
-
- INFO("Proxi_sensor_hal is destroyed!\n");
-}
-
-string proxi_sensor_hal::get_model_id(void)
-{
- return m_model_id;
-}
-
-sensor_hal_type_t proxi_sensor_hal::get_type(void)
-{
- return SENSOR_HAL_TYPE_PROXIMITY;
-}
-
-bool proxi_sensor_hal::enable(void)
-{
- AUTOLOCK(m_mutex);
-
- set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_PROXIMITY_ENABLE_BIT);
-
- m_fired_time = 0;
- INFO("Proxi sensor real starting");
- return true;
-}
-
-bool proxi_sensor_hal::disable(void)
-{
- AUTOLOCK(m_mutex);
-
- set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_PROXIMITY_ENABLE_BIT);
-
- INFO("Proxi sensor real stopping");
- return true;
-}
-
-bool proxi_sensor_hal::update_value(bool wait)
-{
- struct input_event proxi_event;
- INFO("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;
- }
-
- DBG("read event, len : %d , type : %x , code : %x , value : %x", len, proxi_event.type, proxi_event.code, proxi_event.value);
- if ((proxi_event.type == EV_ABS) && (proxi_event.code == PROXI_CODE)) {
- AUTOLOCK(m_value_mutex);
- m_state = proxi_event.value;
- m_fired_time = sensor_hal::get_timestamp(&proxi_event.time);
- } else {
- return false;
- }
- return true;
-}
-
-bool proxi_sensor_hal::is_data_ready(bool wait)
-{
- bool ret;
- ret = update_value(wait);
- return ret;
-}
-
-int proxi_sensor_hal::get_sensor_data(sensor_data_t &data)
-{
- AUTOLOCK(m_value_mutex);
- data.accuracy = SENSOR_ACCURACY_UNDEFINED;
- data.timestamp = m_fired_time;
- data.value_count = 1;
- data.values[0] = m_state;
-
- return 0;
-}
-
-bool proxi_sensor_hal::get_properties(sensor_properties_s &properties)
-{
- properties.name = m_chip_name;
- properties.vendor = m_vendor;
- properties.min_range = 0;
- properties.max_range = 1;
- properties.min_interval = 1;
- properties.resolution = 1;
- properties.fifo_count = 0;
- properties.max_batch_count = 0;
- return true;
-}
-
-extern "C" sensor_module* create(void)
-{
- proxi_sensor_hal *sensor;
-
- try {
- sensor = new(std::nothrow) proxi_sensor_hal;
- } catch (int err) {
- ERR("Failed to create module, err: %d, cause: %s", err, strerror(err));
- return NULL;
- }
-
- sensor_module *module = new(std::nothrow) sensor_module;
- retvm_if(!module || !sensor, NULL, "Failed to allocate memory");
-
- module->sensors.push_back(sensor);
- return module;
-}
+++ /dev/null
-/*
- * proxi_sensor_hal
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _PROXI_SENSOR_HAL_H_
-#define _PROXI_SENSOR_HAL_H_
-
-#include <sensor_hal.h>
-
-class proxi_sensor_hal : public sensor_hal
-{
-public:
- proxi_sensor_hal();
- virtual ~proxi_sensor_hal();
- std::string get_model_id(void);
- sensor_hal_type_t get_type(void);
- bool enable(void);
- bool disable(void);
- bool is_data_ready(bool wait);
- 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;
-
- std::string m_enable_node;
- std::string m_data_node;
-
- unsigned int m_state;
-
- unsigned long long m_fired_time;
-
- int m_node_handle;
- bool m_sensorhub_controlled;
- cmutex m_value_mutex;
-
- bool update_value(bool wait);
-};
-#endif /*_PROXI_SENSOR_HAL_H_*/
project(rv_raw CXX)
SET(SENSOR_NAME rv_raw_sensor)
-SET(SENSOR_HAL_NAME rv_raw_sensor_hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
rv_raw_sensor.cpp
)
-add_library(${SENSOR_HAL_NAME} SHARED
- rv_raw_sensor_hal.cpp
-)
-
target_link_libraries(${SENSOR_NAME} ${rv_raw_pkgs_LDFLAGS} "-lm")
-target_link_libraries(${SENSOR_HAL_NAME} ${rv_raw_pkgs_LDFLAGS})
install(TARGETS ${SENSOR_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
-install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
+++ /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(bool wait)
-{
- 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 = 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(bool wait)
-{
- bool ret;
- ret = update_value(wait);
- 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_t &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;
-}
-
-extern "C" sensor_module* create(void)
-{
- rv_raw_sensor_hal *sensor;
-
- try {
- sensor = new(std::nothrow) rv_raw_sensor_hal;
- } catch (int err) {
- ERR("Failed to create module, err: %d, cause: %s", err, strerror(err));
- return NULL;
- }
-
- sensor_module *module = new(std::nothrow) sensor_module;
- retvm_if(!module || !sensor, NULL, "Failed to allocate memory");
-
- module->sensors.push_back(sensor);
- return module;
-}
+++ /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.h>
-
-class rv_raw_sensor_hal : public sensor_hal
-{
-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(bool wait);
- virtual int get_sensor_data(sensor_data_t &data);
- virtual bool get_properties(sensor_properties_t &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(bool wait);
-};
-#endif /*_RV_RAW_SENSOR_HAL_H_*/
-
project(temperature CXX)
SET(SENSOR_NAME temperature_sensor)
-SET(SENSOR_HAL_NAME temperature_sensor_hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
temperature_sensor.cpp
)
-add_library(${SENSOR_HAL_NAME} SHARED
- temperature_sensor_hal.cpp
- )
-
target_link_libraries(${SENSOR_NAME} ${temp_pkgs_LDFLAGS} "-lm")
-target_link_libraries(${SENSOR_HAL_NAME} ${temp_pkgs_LDFLAGS})
install(TARGETS ${SENSOR_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
-install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
+++ /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(bool wait)
-{
- 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::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(bool wait)
-{
- bool ret;
- ret = update_value(wait);
- 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;
-}
-
-extern "C" sensor_module* create(void)
-{
- temperature_sensor_hal *sensor;
-
- try {
- sensor = new(std::nothrow) temperature_sensor_hal;
- } catch (int err) {
- ERR("Failed to create module, err: %d, cause: %s", err, strerror(err));
- return NULL;
- }
-
- sensor_module *module = new(std::nothrow) sensor_module;
- retvm_if(!module || !sensor, NULL, "Failed to allocate memory");
-
- module->sensors.push_back(sensor);
- return module;
-}
+++ /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.h>
-
-class temperature_sensor_hal : public sensor_hal
-{
-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(bool wait);
- 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(bool wait);
-};
-#endif /*_TEMPERATURE_SENSOR_HAL_CLASS_H_*/
project(ultraviolet CXX)
SET(SENSOR_NAME ultraviolet_sensor)
-SET(SENSOR_HAL_NAME ultraviolet_sensor_hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
ultraviolet_sensor.cpp
)
-add_library(${SENSOR_HAL_NAME} SHARED
- ultraviolet_sensor_hal.cpp
- )
-
target_link_libraries(${SENSOR_NAME} ${uv_pkgs_LDFLAGS} "-lm")
-target_link_libraries(${SENSOR_HAL_NAME} ${uv_pkgs_LDFLAGS})
install(TARGETS ${SENSOR_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
-install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
+++ /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(bool wait)
-{
- 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::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(bool wait)
-{
- bool ret;
- ret = update_value(wait);
- 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;
-}
-
-extern "C" sensor_module* create(void)
-{
- ultraviolet_sensor_hal *sensor;
-
- try {
- sensor = new(std::nothrow) ultraviolet_sensor_hal;
- } catch (int err) {
- ERR("Failed to create module, err: %d, cause: %s", err, strerror(err));
- return NULL;
- }
-
- sensor_module *module = new(std::nothrow) sensor_module;
- retvm_if(!module || !sensor, NULL, "Failed to allocate memory");
-
- module->sensors.push_back(sensor);
- return module;
-}
+++ /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.h>
-
-class ultraviolet_sensor_hal : public sensor_hal
-{
-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(bool wait);
- 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(bool wait);
-};
-#endif /*_ULTRAVIOLET_SENSOR_HAL_CLASS_H_*/
-
add_executable(${PROJECT_NAME} ${SERVER_SRCS})
-target_link_libraries(${PROJECT_NAME} ${server_pkgs_LDFLAGS} "sensord-server")
+target_link_libraries(${PROJECT_NAME} ${server_pkgs_LDFLAGS} "sensord-server" "sensor-hal")
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
add_library(sensord-server SHARED
worker_thread.cpp
- cconfig.cpp
- csensor_config.cpp
cvirtual_sensor_config.cpp
csensor_event_queue.cpp
csensor_event_dispatcher.cpp
cclient_sensor_record.cpp
cplugin_info_list.cpp
sensor_plugin_loader.cpp
- sensor_hal.cpp
sensor_base.cpp
physical_sensor.cpp
virtual_sensor.cpp
add_library(sensord-share SHARED
cpacket.cpp
csocket.cpp
- cbase_lock.cpp
- cmutex.cpp
- common.cpp
sensor_info.cpp
)
install(FILES ${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(FILES
worker_thread.h
- cconfig.h
- csensor_config.h
cvirtual_sensor_config.h
csensor_event_queue.h
cplugin_info_list.h
sensor_plugin_loader.h
- sensor_hal.h
sensor_base.h
physical_sensor.h
virtual_sensor.h
- sf_common.h
cpacket.h
csocket.h
cbase_lock.h
- cmutex.h
- common.h
sensor_info.h
iio_common.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)
-install(FILES
- sensor_common.h
- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor
-)
install(FILES sensor_accel.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor/)
install(FILES sensor_geomag.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor/)
install(FILES sensor_light.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor/)