#ADD_DEFINITIONS(-Wall -g -D_DEBUG)
INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(HAL_PKGS REQUIRED dlog glib-2.0 gio-2.0 gobject-2.0 vconf libxml-2.0)
+PKG_CHECK_MODULES(HAL_PKGS REQUIRED dlog)
FOREACH(flag ${HAL_PKGS_CFLAGS})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${HAL_PKGS_LDFLAGS})
-CONFIGURE_FILE(sensor.xml.in sensor.xml @ONLY)
-
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.APLv2 DESTINATION share/license RENAME ${PROJECT_NAME})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor)
-INSTALL(FILES sensor.xml DESTINATION etc)
BuildRequires: cmake
BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(glib-2.0)
-BuildRequires: pkgconfig(gio-2.0)
-BuildRequires: pkgconfig(libxml-2.0)
-BuildRequires: pkgconfig(vconf)
BuildRequires: sensor-hal-devel
%description
/sbin/ldconfig
%files
-%attr(0644,root,root)/usr/etc/sensor.xml
%manifest packaging/%{name}.manifest
%{_libdir}/udev/rules.d/99-sensor.rules
%{_libdir}/sensor/*.so
+++ /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="BMC150">
- <NAME value="BMC150" />
- <VENDOR value="Bosch"/>
- <RAW_DATA_UNIT value="0.244"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="BMI168">
- <NAME value="BMI168" />
- <VENDOR value="Bosch"/>
- <RAW_DATA_UNIT value="0.244"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="K6DS3TR">
- <NAME value="K6DS3TR" />
- <VENDOR value="ST Microelectronics"/>
- <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="12" />
- </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="BMI168">
- <NAME value="BMI168" />
- <VENDOR value="Bosch"/>
- <RAW_DATA_UNIT value="61.04"/>
- <RESOLUTION value="16"/>
- </MODEL>
-
- <MODEL id="K6DS3TR">
- <NAME value="K6DS3TR" />
- <VENDOR value="ST Microelectronics"/>
- <RAW_DATA_UNIT value="70.00"/>
- <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="CM36686">
- <NAME value="CM36686" />
- <VENDOR value="Capella"/>
- </MODEL>
-
- <MODEL id="MAX88922">
- <NAME value="MAX88922" />
- <VENDOR value="MAXIM"/>
- </MODEL>
-
- <MODEL id="IMS1911">
- <NAME value="IMS1911" />
- <VENDOR value="ITM"/>
- </MODEL>
-
- <MODEL id="TMG399X">
- <NAME value="TMG399X" />
- <VENDOR value="AMS"/>
- </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="CM36686">
- <NAME value="CM36686" />
- <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="TSL2584">
- <NAME value="TSL2584" />
- <VENDOR value="AMS"/>
- </MODEL>
-
- <MODEL id=" TMG399X">
- <NAME value=" TMG399X" />
- <VENDOR value="AMS"/>
- </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_INTERVAL value="20"/>
- <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="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_INTERVAL value="1"/>
- <MIN_RANGE value="-2000"/>
- <MAX_RANGE value="2000"/>
- </MODEL>
- </MAGNETIC>
-
- <PEDO>
- <MODEL id="MPU6051">
- <NAME value="MPU6051" />
- <VENDOR value="Invensense"/>
- </MODEL>
-
- <MODEL id="MPU6500">
- <NAME value="MPU6500" />
- <VENDOR value="Invensense"/>
- </MODEL>
-
- <MODEL id="MPU6515">
- <NAME value="MPU6515" />
- <VENDOR value="Invensense"/>
- </MODEL>
- </PEDO>
-
- <FLAT>
- <MODEL id="MPU6051">
- <NAME value="MPU6051" />
- <VENDOR value="Invensense"/>
- </MODEL>
-
- <MODEL id="MPU6500">
- <NAME value="MPU6500" />
- <VENDOR value="Invensense"/>
- </MODEL>
-
- <MODEL id="MPU6515">
- <NAME value="MPU6515" />
- <VENDOR value="Invensense"/>
- </MODEL>
- </FLAT>
-
- <HRM_RAW>
- <MODEL id="ADPD142">
- <NAME value="ADPD142" />
- <VENDOR value="ANALOG DEVICES"/>
- <READER SM-Z910F="adi" value="standard"/>
- </MODEL>
-
- <MODEL id="ADPD142RI">
- <NAME value="ADPD142RI" />
- <VENDOR value="ANALOG DEVICES"/>
- <READER SM-Z910F="adi" value="standard"/>
- </MODEL>
-
- <MODEL id="AD45251">
- <NAME value="AD45251" />
- <VENDOR value="ANALOG DEVICES"/>
- <READER SM-Z910F="adi" value="standard"/>
- </MODEL>
-
- <MODEL id="AD45265">
- <NAME value="AD45265" />
- <VENDOR value="ANALOG DEVICES"/>
- <READER SM-Z910F="adi" value="standard"/>
- </MODEL>
-
- <MODEL id="PPS960">
- <NAME value="PPS960" />
- <VENDOR value="TI"/>
- <READER SM-Z910F="adi" value="standard"/>
- </MODEL>
- </HRM_RAW>
-
- <HRM>
- <MODEL id="ADPD142">
- <NAME value="ADPD142" />
- <VENDOR value="ANALOG DEVICES"/>
- </MODEL>
-
- <MODEL id="ADPD142RI">
- <NAME value="ADPD142RI" />
- <VENDOR value="ANALOG DEVICES"/>
- </MODEL>
-
- <MODEL id="AD45251">
- <NAME value="AD45251" />
- <VENDOR value="ANALOG DEVICES"/>
- </MODEL>
-
- <MODEL id="AD45265">
- <NAME value="AD45265" />
- <VENDOR value="ANALOG DEVICES"/>
- </MODEL>
-
- <MODEL id="PPS960">
- <NAME value="PPS960" />
- <VENDOR value="TI"/>
- </MODEL>
-
- <MODEL id="maru_sensor_hrm_1">
- <NAME value="maru_sensor_hrm_1" />
- <VENDOR value="Tizen_SDK"/>
- <RAW_DATA_UNIT value="0.1"/>
- </MODEL>
- </HRM>
-
- <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="LPS22H">
- <NAME value="LPS22H" />
- <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.001"/>
- <TEMPERATURE_OFFSET value="0.0"/>
- </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>
-
- <ROTATION_VECTOR>
- <MODEL id="MPU6500">
- <NAME value="MPU6500" />
- <VENDOR value="Invensense"/>
- </MODEL>
-
- <MODEL id="MPU9250">
- <NAME value="MPU9250" />
- <VENDOR value="Invensense"/>
- </MODEL>
-
- <MODEL id="AK09911C">
- <NAME value="AK09911C" />
- <VENDOR value="AKM"/>
- </MODEL>
-
- <MODEL id="YAS537">
- <NAME value="YAS537" />
- <VENDOR value="Yamaha"/>
- </MODEL>
-
- <MODEL id="maru_sensor_rotation_vector_1">
- <NAME value="maru_sensor_rotation_vector_1" />
- <VENDOR value="Tizen_SDK"/>
- </MODEL>
- </ROTATION_VECTOR>
-
- <PIR>
- <MODEL id="EKMC1601111">
- <NAME value="EKMC1601111" />
- <VENDOR value="PANASONIC"/>
- </MODEL>
- <MODEL id="PYD1798">
- <NAME value="PYD1798" />
- <VENDOR value="PYRO-ELECTRIC"/>
- </MODEL>
- </PIR>
-
- <PIR_LONG>
- <MODEL id="EKMC1603111">
- <NAME value="EKMC1603111" />
- <VENDOR value="PANASONIC"/>
- </MODEL>
- <MODEL id="PYD1798">
- <NAME value="PYD1798" />
- <VENDOR value="PYRO-ELECTRIC"/>
- </MODEL>
- </PIR_LONG>
-
- <TEMPERATURE>
- <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>
-
- <TEMP_HUMIDITY>
- <MODEL id="SHTC1">
- <NAME value="SHTC1" />
- <VENDOR value="SENSIRION"/>
- <TEMPERATURE_RESOLUTION value="0.01"/>
- <TEMPERATURE_MIN_RANGE value="-165.0" />
- <TEMPERATURE_MAX_RANGE value="165.0" />
- <HUMIDITY_RESOLUTION value="0.04"/>
- <HUMIDITY_MIN_RANGE value="0.0" />
- <HUMIDITY_MAX_RANGE value="100.0" />
- </MODEL>
- </TEMP_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>
- </ULTRAVIOLET>
-
- <DUST>
- <MODEL id="GP2Y1023AU0F">
- <NAME value="GP2Y1023AU0F" />
- <VENDOR value="SHARP"/>
- <RAW_DATA_UNIT value="1"/>
- </MODEL>
- </DUST>
-
- <GSR>
- <MODEL id="HM121">
- <NAME value="HM121" />
- <VENDOR value="STM"/>
- <RAW_DATA_UNIT value="0.001"/>
- <MIN_RANGE value="0"/>
- <MAX_RANGE value="524287"/>
- <RESOLUTION value="1"/>
- </MODEL>
- </GSR>
-</SENSOR>
#include <util.h>
#include <sensor_common.h>
#include <sensor_log.h>
-#include <sensor_config.h>
-#include "accel_device.h"
-
-#define GRAVITY 9.80665
-#define G_TO_MG 1000
-#define RAW_DATA_TO_G_UNIT(X) (((float)(X))/((float)G_TO_MG))
-#define RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(X) (GRAVITY * (RAW_DATA_TO_G_UNIT(X)))
-#define MIN_RANGE(RES) (-((1 << (RES))/2))
-#define MAX_RANGE(RES) (((1 << (RES))/2)-1)
+#include "accel_device.h"
-#define MODEL_NAME "UNKNOWN"
-#define VENDOR "UNKNOWN"
-#define RESOLUTION 0
-#define RAW_DATA_UNIT 0
-#define MIN_INTERVAL 0
+#define MODEL_NAME "maru_sensor_accel_1"
+#define VENDOR "Tizen_SDK"
+#define RESOLUTION 16
+#define RAW_DATA_UNIT 0.061
+#define MIN_INTERVAL 1
#define MAX_BATCH_COUNT 0
#define SENSOR_NAME "SENSOR_ACCELEROMETER"
#define INPUT_NAME "accelerometer_sensor"
#define ACCEL_SENSORHUB_POLL_NODE_NAME "accel_poll_delay"
+#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)
+
static sensor_info_t sensor_info = {
id: 0x1,
name: SENSOR_NAME,
, m_sensorhub_controlled(false)
{
const std::string sensorhub_interval_node_name = ACCEL_SENSORHUB_POLL_NODE_NAME;
- config::sensor_config &config = config::sensor_config::get_instance();
node_info_query query;
node_info info;
- if (!util::find_model_id(SENSOR_TYPE_ACCEL, m_model_id)) {
- _E("Failed to find model id");
- throw ENXIO;
- }
-
query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
query.sensor_type = SENSOR_TYPE_ACCEL;
query.key = INPUT_NAME;
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)) {
- _E("[VENDOR] is empty");
- throw ENXIO;
- }
-
- _I("m_vendor = %s", m_vendor.c_str());
-
- if (!config.get(SENSOR_TYPE_ACCEL, m_model_id, ELEMENT_NAME, m_chip_name)) {
- _E("[NAME] is empty");
- throw ENXIO;
- }
-
- _I("m_chip_name = %s",m_chip_name.c_str());
-
- long resolution;
-
- if (!config.get(SENSOR_TYPE_ACCEL, m_model_id, ELEMENT_RESOLUTION, resolution)) {
- _E("[RESOLUTION] is empty");
- throw ENXIO;
- }
-
- m_resolution = (int)resolution;
-
- _I("m_resolution = %d",m_resolution);
-
- double raw_data_unit;
-
- if (!config.get(SENSOR_TYPE_ACCEL, m_model_id, ELEMENT_RAW_DATA_UNIT, raw_data_unit)) {
- _E("[RAW_DATA_UNIT] is empty");
- throw ENXIO;
- }
-
- m_raw_data_unit = (float)(raw_data_unit);
- _I("m_raw_data_unit = %f", m_raw_data_unit);
-
m_node_handle = open(m_data_node.c_str(), O_RDONLY);
if (m_node_handle < 0) {
};
}
- _I("accel_sensor is created!");
+ _I("accel_device is created!");
}
accel_device::~accel_device()
close(m_node_handle);
m_node_handle = -1;
- _I("accel_sensor is destroyed!");
+ _I("accel_device is destroyed!");
}
-int accel_device::get_poll_fd()
+int accel_device::get_poll_fd(void)
{
return m_node_handle;
}
int accel_device::get_sensors(const sensor_info_t **sensors)
{
- sensor_info.model_name = m_chip_name.c_str();
- sensor_info.vendor = m_vendor.c_str();
- sensor_info.min_range = MIN_RANGE(m_resolution) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(m_raw_data_unit);
- sensor_info.max_range = MAX_RANGE(m_resolution) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(m_raw_data_unit);
- sensor_info.resolution = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(m_raw_data_unit);
- sensor_info.min_interval = 1;
- sensor_info.max_batch_count = 0;
*sensors = &sensor_info;
return 1;
int accel_device::get_data(uint32_t id, sensor_data_t **data, int *length)
{
- int remains = 1;
sensor_data_t *sensor_data;
sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
retvm_if(!sensor_data, -ENOMEM, "Memory allocation failed");
*data = sensor_data;
*length = sizeof(sensor_data_t);
- return --remains;
+ return 0;
}
void accel_device::raw_to_base(sensor_data_t *data)
{
- data->value_count = 3;
- data->values[0] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data->values[0] * m_raw_data_unit);
- data->values[1] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data->values[1] * m_raw_data_unit);
- data->values[2] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data->values[2] * m_raw_data_unit);
+ data->values[0] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data->values[0] * RAW_DATA_UNIT);
+ data->values[1] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data->values[1] * RAW_DATA_UNIT);
+ data->values[2] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data->values[2] * RAW_DATA_UNIT);
}
std::string m_enable_node;
std::string m_interval_node;
- std::string m_model_id;
- std::string m_vendor;
- std::string m_chip_name;
-
- int m_resolution;
- float m_raw_data_unit;
-
std::function<bool (void)> update_value;
std::vector<uint32_t> event_ids;
#include <sensor_log.h>
#include <vector>
-#ifdef ENABLE_ACCEL
#include "accel/accel_device.h"
-#endif
-#ifdef ENABLE_GYRO
#include "gyro/gyro_device.h"
-#endif
-#ifdef ENABLE_GYRO_UNCAL
-#include "gyro_uncal/gyro_uncal_device.h"
-#endif
-#ifdef ENABLE_GEOMAG
#include "geomag/geomag_device.h"
-#endif
-#ifdef ENABLE_PRESSURE
#include "pressure/pressure_device.h"
-#endif
-#ifdef ENABLE_UV
#include "ultraviolet/uv_device.h"
-#endif
-#ifdef ENABLE_LIGHT
#include "light/light_device.h"
-#endif
-#ifdef ENABLE_PROXIMITY
#include "proxi/proxi_device.h"
-#endif
-#ifdef ENABLE_HRM_RAW
-#include "hrm_raw/hrm_raw_device.h"
-#endif
-#ifdef ENABLE_HRM
#include "hrm/hrm_device.h"
-#endif
-#ifdef ENABLE_SENSORHUB
-#include "sensorhub/sensorhub.h"
-#endif
static std::vector<sensor_device_t> devs;
extern "C" int create(sensor_device_t **devices)
{
-#ifdef ENABLE_ACCEL
create_sensor<accel_device>("Accelerometer");
-#endif
-#ifdef ENABLE_GYRO
create_sensor<gyro_device>("Gyroscope");
-#endif
-#ifdef ENABLE_GYRO_UNCAL
- create_sensor<gyro_uncal_device>("Gyroscope Uncal");
-#endif
-#ifdef ENABLE_GEOMAG
create_sensor<geomag_device>("Geomagnetic");
-#endif
-#ifdef ENABLE_PRESSURE
create_sensor<pressure_device>("Pressure");
-#endif
-#ifdef ENABLE_UV
create_sensor<uv_device>("Ultra Violet");
-#endif
-#ifdef ENABLE_LIGHT
create_sensor<light_device>("Light");
-#endif
-#ifdef ENABLE_PROXIMITY
create_sensor<proxi_device>("Proximity");
-#endif
-#ifdef ENABLE_HRM_RAW
- create_sensor<hrm_raw_device>("HRM Raw");
-#endif
-#ifdef ENABLE_HRM
create_sensor<hrm_device>("HRM");
-#endif
-#ifdef ENABLE_SENSORHUB
- create_sensor<sensorhub_device>("Sensorhub");
-#endif
*devices = &devs[0];
return devs.size();
#include <util.h>
#include <sensor_common.h>
#include <sensor_log.h>
-#include <sensor_config.h>
+
#include "geomag_device.h"
+#define MODEL_NAME "maru_sensor_geo_1"
+#define VENDOR "Tizen_SDK"
+#define RESOLUTION 14
+#define RAW_DATA_UNIT 0.6
+#define MIN_RANGE -2000
+#define MAX_RANGE 2000
+#define MIN_INTERVAL 1
+#define MAX_BATCH_COUNT 0
+
#define SENSOR_NAME "SENSOR_GEOMAGNETIC"
#define SENSOR_TYPE_MAGNETIC "MAGNETIC"
name: SENSOR_NAME,
type: SENSOR_DEVICE_GEOMAGNETIC,
event_type: (SENSOR_DEVICE_GEOMAGNETIC << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
- model_name: UNKNOWN_NAME,
- vendor: UNKNOWN_NAME,
- min_range: 0,
- max_range: 0,
- resolution: 0,
- min_interval: 0,
- max_batch_count: 0,
+ model_name: MODEL_NAME,
+ vendor: VENDOR,
+ min_range: MIN_RANGE,
+ max_range: MAX_RANGE,
+ resolution: RAW_DATA_UNIT,
+ min_interval: MIN_INTERVAL,
+ max_batch_count: MAX_BATCH_COUNT,
wakeup_supported: false
};
, m_sensorhub_controlled(false)
{
const std::string sensorhub_interval_node_name = GEOMAG_SENSORHUB_POLL_NODE_NAME;
- config::sensor_config &config = config::sensor_config::get_instance();
node_info_query query;
node_info info;
- if (!util::find_model_id(SENSOR_TYPE_MAGNETIC, m_model_id)) {
- _E("Failed to find model id");
- throw ENXIO;
-
- }
-
query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
query.sensor_type = SENSOR_TYPE_MAGNETIC;
query.key = INPUT_NAME;
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)) {
- _E("[VENDOR] is empty\n");
- throw ENXIO;
- }
-
- _I("m_vendor = %s", m_vendor.c_str());
-
- if (!config.get(SENSOR_TYPE_MAGNETIC, m_model_id, ELEMENT_NAME, m_chip_name)) {
- _E("[NAME] is empty\n");
- throw ENXIO;
- }
-
- _I("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)) {
- _E("[MIN_RANGE] is empty\n");
- throw ENXIO;
- }
-
- m_min_range = (float)min_range;
- _I("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)) {
- _E("[MAX_RANGE] is empty\n");
- throw ENXIO;
- }
-
- m_max_range = (float)max_range;
- _I("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)) {
- _E("[RAW_DATA_UNIT] is empty\n");
- throw ENXIO;
- }
-
- m_raw_data_unit = (float)(raw_data_unit);
- _I("m_raw_data_unit = %f\n", m_raw_data_unit);
-
m_node_handle = open(m_data_node.c_str(), O_RDONLY);
if (m_node_handle < 0) {
- _ERRNO(errno, _E, "geomag handle open fail for geomag device");
+ _ERRNO(errno, _E, "Failed to open geomags handle");
throw ENXIO;
}
};
}
- _I("geomag_device is created!\n");
+ _I("geomag_device is created!");
}
geomag_device::~geomag_device()
close(m_node_handle);
m_node_handle = -1;
- _I("geomag_sensor is destroyed!\n");
+ _I("geomag_sensor is destroyed!");
}
int geomag_device::get_poll_fd(void)
int geomag_device::get_sensors(const sensor_info_t **sensors)
{
- sensor_info.model_name = m_chip_name.c_str();
- sensor_info.vendor = m_vendor.c_str();
- sensor_info.min_range = m_min_range;
- sensor_info.max_range = m_max_range;
- sensor_info.resolution = m_raw_data_unit;
- sensor_info.min_interval = 1;
- sensor_info.max_batch_count = 0;
*sensors = &sensor_info;
return 1;
set_interval(id, m_polling_interval);
m_fired_time = 0;
- INFO("Enable geomagnetic sensor");
+ _I("Enable geomagnetic sensor");
return true;
}
{
util::set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_GEOMAGNETIC_ENABLE_BIT);
- INFO("Disable geomagnetic sensor");
+ _I("Disable geomagnetic sensor");
return true;
}
polling_interval_ns = ((unsigned long long)(val) * 1000llu * 1000llu);
if (!util::set_node_value(m_interval_node, polling_interval_ns)) {
- ERR("Failed to set polling resource: %s\n", m_interval_node.c_str());
+ _E("Failed to set polling resource: %s", m_interval_node.c_str());
return false;
}
- INFO("Interval is changed from %dms to %dms", m_polling_interval, val);
+ _I("Interval is changed from %dms to %dms", m_polling_interval, val);
m_polling_interval = val;
return true;
}
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)) {
- _E("geo_file read fail, read_len = %d\n",len);
+ _E("geo_file read fail, read_len = %d",len);
return false;
}
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:
- _E("geo_input event[type = %d, code = %d] is unknown.", geo_input.type, geo_input.code);
- return false;
- break;
+ 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:
+ _E("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;
return true;
}
-
bool geomag_device::update_value_iio(void)
{
struct {
int geomag_device::read_fd(uint32_t **ids)
{
if (!update_value()) {
- DBG("Failed to update value");
+ _D("Failed to update value");
return false;
}
int geomag_device::get_data(uint32_t id, sensor_data_t **data, int *length)
{
- int remains = 1;
sensor_data_t *sensor_data;
sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
retvm_if(!sensor_data, -ENOMEM, "Memory allocation failed");
*data = sensor_data;
*length = sizeof(sensor_data_t);
- return --remains;
+ return 0;
}
void geomag_device::raw_to_base(sensor_data_t *data)
{
- data->values[0] = data->values[0] * m_raw_data_unit;
- data->values[1] = data->values[1] * m_raw_data_unit;
- data->values[2] = data->values[2] * m_raw_data_unit;
+ data->values[0] = data->values[0] * RAW_DATA_UNIT;
+ data->values[1] = data->values[1] * RAW_DATA_UNIT;
+ data->values[2] = data->values[2] * RAW_DATA_UNIT;
}
std::string m_enable_node;
std::string m_interval_node;
- std::string m_model_id;
- std::string m_vendor;
- std::string m_chip_name;
-
- int m_resolution;
- float m_min_range;
- float m_max_range;
- float m_raw_data_unit;
-
long a_x;
long a_y;
long a_z;
#include <util.h>
#include <sensor_common.h>
#include <sensor_log.h>
-#include <sensor_config.h>
+
#include "gyro_device.h"
-#define DPS_TO_MDPS 1000
-#define RAW_DATA_TO_DPS_UNIT(X) ((float)(X)/((float)DPS_TO_MDPS))
-#define MIN_RANGE(RES) (-((1 << (RES))/2))
-#define MAX_RANGE(RES) (((1 << (RES))/2)-1)
+#define MODEL_NAME "maru_sensor_gyro_1"
+#define VENDOR "Tizen_SDK"
+#define RESOLUTION 16
+#define RAW_DATA_UNIT 1000
+#define MIN_INTERVAL 1
+#define MAX_BATCH_COUNT 0
#define SENSOR_NAME "SENSOR_GYROSCOPE"
#define SENSOR_TYPE_GYRO "GYRO"
#define INPUT_NAME "gyro_sensor"
#define GYRO_SENSORHUB_POLL_NODE_NAME "gyro_poll_delay"
+#define DPS_TO_MDPS 1000
+#define RAW_DATA_TO_DPS_UNIT(X) ((float)(X)/((float)DPS_TO_MDPS))
+#define MIN_RANGE(RES) (-((1 << (RES))/2))
+#define MAX_RANGE(RES) (((1 << (RES))/2)-1)
+
static sensor_info_t sensor_info = {
id: 0x1,
name: SENSOR_NAME,
type: SENSOR_DEVICE_GYROSCOPE,
event_type: (SENSOR_DEVICE_GYROSCOPE << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
- model_name: UNKNOWN_NAME,
- vendor: UNKNOWN_NAME,
- min_range: 0,
- max_range: 0,
- resolution: 0,
- min_interval: 0,
- max_batch_count: 0,
+ model_name: MODEL_NAME,
+ vendor: VENDOR,
+ min_range: MIN_RANGE(RESOLUTION) * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT),
+ max_range: MAX_RANGE(RESOLUTION) * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT),
+ resolution: RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT),
+ min_interval: MIN_INTERVAL,
+ max_batch_count: MAX_BATCH_COUNT,
wakeup_supported: false
};
, m_sensorhub_controlled(false)
{
const std::string sensorhub_interval_node_name = GYRO_SENSORHUB_POLL_NODE_NAME;
- config::sensor_config &config = config::sensor_config::get_instance();
node_info_query query;
node_info info;
- if (!util::find_model_id(SENSOR_TYPE_GYRO, m_model_id)) {
- _E("Failed to find model id");
- throw ENXIO;
- }
-
query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
query.sensor_type = SENSOR_TYPE_GYRO;
query.key = INPUT_NAME;
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)) {
- _E("[VENDOR] is empty");
- throw ENXIO;
- }
-
- _I("m_vendor = %s", m_vendor.c_str());
-
- if (!config.get(SENSOR_TYPE_GYRO, m_model_id, ELEMENT_NAME, m_chip_name)) {
- _E("[NAME] is empty");
- throw ENXIO;
- }
-
- _I("m_chip_name = %s",m_chip_name.c_str());
-
- long resolution;
-
- if (!config.get(SENSOR_TYPE_GYRO, m_model_id, ELEMENT_RESOLUTION, resolution)) {
- _E("[RESOLUTION] is empty");
- throw ENXIO;
- }
-
- m_resolution = (int)resolution;
- _I("m_resolution = %d",m_resolution);
-
- double raw_data_unit;
-
- if (!config.get(SENSOR_TYPE_GYRO, m_model_id, ELEMENT_RAW_DATA_UNIT, raw_data_unit)) {
- _E("[RAW_DATA_UNIT] is empty");
- throw ENXIO;
- }
-
- m_raw_data_unit = (float)(raw_data_unit);
- _I("m_raw_data_unit = %f", m_raw_data_unit);
-
m_node_handle = open(m_data_node.c_str(), O_RDONLY);
if (m_node_handle < 0) {
- _ERRNO(errno, _E, "gyro handle open fail for gyro device");
+ _ERRNO(errno, _E, "Failed to open gyro handle");
throw ENXIO;
}
};
}
- _I("RAW_DATA_TO_DPS_UNIT(m_raw_data_unit) = [%f]",RAW_DATA_TO_DPS_UNIT(m_raw_data_unit));
- _I("gyro_sensor is created!");
+ _I("gyro_device is created!");
}
gyro_device::~gyro_device()
close(m_node_handle);
m_node_handle = -1;
- _I("gyro_sensor is destroyed!");
+ _I("gyro_device is destroyed!");
}
int gyro_device::get_poll_fd(void)
int gyro_device::get_sensors(const sensor_info_t **sensors)
{
- sensor_info.model_name = m_chip_name.c_str();
- sensor_info.vendor = m_vendor.c_str();
- sensor_info.min_range = MIN_RANGE(m_resolution) * RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
- sensor_info.max_range = MAX_RANGE(m_resolution) * RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
- sensor_info.resolution = RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
- sensor_info.min_interval = 1;
- sensor_info.max_batch_count = 0;
*sensors = &sensor_info;
return 1;
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)) {
- _E("gyro_file read fail, read_len = %d",len);
+ _E("gyro_file read fail, read_len = %d", len);
return false;
}
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:
- _E("gyro_input event[type = %d, code = %d] is unknown.", gyro_input.type, gyro_input.code);
- return false;
- break;
+ 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:
+ _E("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;
int gyro_device::get_data(uint32_t id, sensor_data_t **data, int *length)
{
- int remains = 1;
sensor_data_t *sensor_data;
sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
retvm_if(!sensor_data, -ENOMEM, "Memory allocation failed");
*data = sensor_data;
*length = sizeof(sensor_data_t);
- return --remains;
+ return 0;
}
void gyro_device::raw_to_base(sensor_data_t *data)
{
- data->value_count = 3;
- data->values[0] = data->values[0] * RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
- data->values[1] = data->values[1] * RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
- data->values[2] = data->values[2] * RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
+ data->values[0] = data->values[0] * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT);
+ data->values[1] = data->values[1] * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT);
+ data->values[2] = data->values[2] * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT);
}
std::string m_enable_node;
std::string m_interval_node;
- std::string m_model_id;
- std::string m_vendor;
- std::string m_chip_name;
-
- int m_resolution;
- float m_raw_data_unit;
-
std::function<bool (void)> update_value;
std::vector<uint32_t> event_ids;
#include <util.h>
#include <sensor_common.h>
#include <sensor_log.h>
-#include <sensor_config.h>
+
#include "gyro_uncal_device.h"
-#define DPS_TO_MDPS 1000
-#define RAW_DATA_TO_DPS_UNIT(X) ((float)(X)/((float)DPS_TO_MDPS))
-#define MIN_RANGE(RES) (-((1 << (RES))/2))
-#define MAX_RANGE(RES) (((1 << (RES))/2)-1)
+#define MODEL_NAME "maru_sensor_gyro_1"
+#define VENDOR "Tizen_SDK"
+#define RESOLUTION 16
+#define RAW_DATA_UNIT 1000
+#define MIN_INTERVAL 1
+#define MAX_BATCH_COUNT 0
#define SENSOR_NAME "SENSOR_GYROSCOPE_UNCALIBRATED"
#define SENSOR_TYPE_GYRO_UNCAL "GYRO"
#define INPUT_NAME "uncal_gyro_sensor"
#define GYRO_UNCAL_SENSORHUB_POLL_NODE_NAME "uncal_gyro_poll_delay"
+#define DPS_TO_MDPS 1000
+#define RAW_DATA_TO_DPS_UNIT(X) ((float)(X)/((float)DPS_TO_MDPS))
+#define MIN_RANGE(RES) (-((1 << (RES))/2))
+#define MAX_RANGE(RES) (((1 << (RES))/2)-1)
+
static sensor_info_t sensor_info = {
id: 0x1,
name: SENSOR_NAME,
type: SENSOR_DEVICE_GYROSCOPE_UNCAL,
event_type: (SENSOR_DEVICE_GYROSCOPE_UNCAL << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
- model_name: UNKNOWN_NAME,
- vendor: UNKNOWN_NAME,
- min_range: 0,
- max_range: 0,
- resolution: 0,
- min_interval: 0,
- max_batch_count: 0,
+ model_name: MODEL_NAME,
+ vendor: VENDOR,
+ min_range: MIN_RANGE(RESOLUTION) * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT),
+ max_range: MAX_RANGE(RESOLUTION) * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT),
+ resolution: RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT),
+ min_interval: MIN_INTERVAL,
+ max_batch_count: MAX_BATCH_COUNT,
wakeup_supported: false
};
, m_sensorhub_controlled(false)
{
const std::string sensorhub_interval_node_name = GYRO_UNCAL_SENSORHUB_POLL_NODE_NAME;
- config::sensor_config &config = config::sensor_config::get_instance();
node_info_query query;
node_info info;
- if (!util::find_model_id(SENSOR_TYPE_GYRO_UNCAL, m_model_id)) {
- _E("Failed to find model id");
- throw ENXIO;
- }
-
query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
query.sensor_type = SENSOR_TYPE_GYRO_UNCAL;
query.key = INPUT_NAME;
m_enable_node = info.enable_node_path;
m_interval_node = info.interval_node_path;
- if (!config.get(SENSOR_TYPE_GYRO_UNCAL, m_model_id, ELEMENT_VENDOR, m_vendor)) {
- _E("[VENDOR] is empty");
- throw ENXIO;
- }
-
- _I("m_vendor = %s", m_vendor.c_str());
-
- if (!config.get(SENSOR_TYPE_GYRO_UNCAL, m_model_id, ELEMENT_NAME, m_chip_name)) {
- _E("[NAME] is empty");
- throw ENXIO;
- }
-
- _I("m_chip_name = %s",m_chip_name.c_str());
-
- long resolution;
-
- if (!config.get(SENSOR_TYPE_GYRO_UNCAL, m_model_id, ELEMENT_RESOLUTION, resolution)) {
- _E("[RESOLUTION] is empty");
- throw ENXIO;
- }
-
- m_resolution = (int)resolution;
- _I("m_resolution = %d",m_resolution);
-
- double raw_data_unit;
-
- if (!config.get(SENSOR_TYPE_GYRO_UNCAL, m_model_id, ELEMENT_RAW_DATA_UNIT, raw_data_unit)) {
- _E("[RAW_DATA_UNIT] is empty");
- throw ENXIO;
- }
-
- m_raw_data_unit = (float)(raw_data_unit);
- _I("m_raw_data_unit = %f",m_raw_data_unit);
-
- double min_range;
-
- if (!config.get(SENSOR_TYPE_GYRO_UNCAL, m_model_id, ELEMENT_MIN_RANGE, min_range))
- min_range = MIN_RANGE(m_resolution)* RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
-
- m_min_range = (float)min_range;
- _I("m_min_range = %f",m_min_range);
-
- double max_range;
-
- if (!config.get(SENSOR_TYPE_GYRO_UNCAL, m_model_id, ELEMENT_MAX_RANGE, max_range))
- max_range = MAX_RANGE(m_resolution)* RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
-
- m_max_range = (float)max_range;
- _I("m_max_range = %f",m_max_range);
-
m_node_handle = open(m_data_node.c_str(), O_RDONLY);
if (m_node_handle < 0) {
};
}
- _I("RAW_DATA_TO_DPS_UNIT(m_raw_data_unit) = [%f]",RAW_DATA_TO_DPS_UNIT(m_raw_data_unit));
_I("gyro_uncal_device is created!");
}
int gyro_uncal_device::get_sensors(const sensor_info_t **sensors)
{
- sensor_info.model_name = m_chip_name.c_str();
- sensor_info.vendor = m_vendor.c_str();
- sensor_info.min_range = MIN_RANGE(m_resolution) * RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
- sensor_info.max_range = MAX_RANGE(m_resolution) * RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
- sensor_info.resolution = RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
- sensor_info.min_interval = 1;
- sensor_info.max_batch_count = 0;
*sensors = &sensor_info;
return 1;
set_interval(id, m_polling_interval);
m_fired_time = 0;
- INFO("Enable gyroscope uncalibration sensor");
+ _I("Enable gyroscope uncalibration sensor");
return true;
}
{
util::set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_GYRO_UNCALIB_ENABLE_BIT);
- INFO("Disable gyroscope uncalibration sensor");
+ _I("Disable gyroscope uncalibration sensor");
return true;
}
if (gyro_uncal_input.type == EV_REL) {
switch (gyro_uncal_input.code) {
- case REL_RX:
- gyro_uncal_raw[0] = (int)gyro_uncal_input.value;
- x = true;
- break;
- case REL_RY:
- gyro_uncal_raw[1] = (int)gyro_uncal_input.value;
- y = true;
- break;
- case REL_RZ:
- gyro_uncal_raw[2] = (int)gyro_uncal_input.value;
- z = true;
- break;
- case REL_HWHEEL:
- gyro_uncal_raw[3] = (int)gyro_uncal_input.value;
- x_offset = true;
- break;
- case REL_DIAL:
- gyro_uncal_raw[4] = (int)gyro_uncal_input.value;
- y_offset = true;
- break;
- case REL_WHEEL:
- gyro_uncal_raw[5] = (int)gyro_uncal_input.value;
- z_offset= true;
- break;
- default:
- _E("gyro_uncal_input event[type = %d, code = %d] is unknown.", gyro_uncal_input.type, gyro_uncal_input.code);
- return false;
- break;
+ case REL_RX:
+ gyro_uncal_raw[0] = (int)gyro_uncal_input.value;
+ x = true;
+ break;
+ case REL_RY:
+ gyro_uncal_raw[1] = (int)gyro_uncal_input.value;
+ y = true;
+ break;
+ case REL_RZ:
+ gyro_uncal_raw[2] = (int)gyro_uncal_input.value;
+ z = true;
+ break;
+ case REL_HWHEEL:
+ gyro_uncal_raw[3] = (int)gyro_uncal_input.value;
+ x_offset = true;
+ break;
+ case REL_DIAL:
+ gyro_uncal_raw[4] = (int)gyro_uncal_input.value;
+ y_offset = true;
+ break;
+ case REL_WHEEL:
+ gyro_uncal_raw[5] = (int)gyro_uncal_input.value;
+ z_offset= true;
+ break;
+ default:
+ _E("gyro_uncal_input event[type = %d, code = %d] is unknown.", gyro_uncal_input.type, gyro_uncal_input.code);
+ return false;
+ break;
}
} else if (gyro_uncal_input.type == EV_SYN) {
syn = true;
int gyro_uncal_device::get_data(uint32_t id, sensor_data_t **data, int *length)
{
- int remains = 1;
sensor_data_t *sensor_data;
sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
retvm_if(!sensor_data, -ENOMEM, "Memory allocation failed");
*data = sensor_data;
*length = sizeof(sensor_data_t);
- return --remains;
+ return 0;
}
void gyro_uncal_device::raw_to_base(sensor_data_t *data)
{
- data->values[0] = data->values[0] * RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
- data->values[1] = data->values[1] * RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
- data->values[2] = data->values[2] * RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
- data->values[3] = data->values[3] * RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
- data->values[4] = data->values[4] * RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
- data->values[5] = data->values[5] * RAW_DATA_TO_DPS_UNIT(m_raw_data_unit);
+ data->values[0] = data->values[0] * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT);
+ data->values[1] = data->values[1] * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT);
+ data->values[2] = data->values[2] * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT);
+ data->values[3] = data->values[3] * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT);
+ data->values[4] = data->values[4] * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT);
+ data->values[5] = data->values[5] * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT);
}
std::string m_enable_node;
std::string m_interval_node;
- std::string m_model_id;
- std::string m_vendor;
- std::string m_chip_name;
-
- int m_resolution;
- float m_raw_data_unit;
- float m_min_range;
- float m_max_range;
-
std::function<bool (void)> update_value;
std::vector<uint32_t> event_ids;
#include <util.h>
#include <sensor_common.h>
#include <sensor_log.h>
-#include <sensor_config.h>
+
#include "hrm_device.h"
+#define MODEL_NAME "maru_sensor_hrm_1"
+#define VENDOR "Tizen_SDK"
+#define MIN_RANGE 0
+#define MAX_RANGE 1000
+#define RESOLUTION 1
+#define RAW_DATA_UNIT 0.1
+#define MIN_INTERVAL 1
+#define MAX_BATCH_COUNT 0
+
#define SENSOR_NAME "SENSOR_HRM"
#define SENSOR_TYPE_HRM "HRM"
name: SENSOR_NAME,
type: SENSOR_DEVICE_HRM,
event_type: (SENSOR_DEVICE_HRM << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
- model_name: UNKNOWN_NAME,
- vendor: UNKNOWN_NAME,
- min_range: 0,
- max_range: 1,
- resolution: 1,
- min_interval: 1,
- max_batch_count: 0,
+ model_name: MODEL_NAME,
+ vendor: VENDOR,
+ min_range: MIN_RANGE,
+ max_range: MAX_RANGE,
+ resolution: RAW_DATA_UNIT,
+ min_interval: MIN_INTERVAL,
+ max_batch_count: MAX_BATCH_COUNT,
wakeup_supported: false
};
, m_spo2(0)
, m_peek_to_peek(0)
, m_snr(0.0f)
-, m_raw_data_unit(DEFAULT_RAW_DATA_UNIT)
, m_polling_interval(1000)
, m_fired_time(0)
, m_interval_supported(false)
, m_sensorhub_controlled(false)
{
- double raw_data_unit = DEFAULT_RAW_DATA_UNIT;
-
const std::string sensorhub_interval_node_name = HRM_SENSORHUB_POLL_NODE_NAME;
- config::sensor_config &config = config::sensor_config::get_instance();
node_info_query query;
node_info info;
- if (!util::find_model_id(SENSOR_TYPE_HRM, m_model_id)) {
- _E("Failed to find model id");
- throw ENXIO;
- }
-
query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
query.sensor_type = SENSOR_TYPE_HRM;
query.key = INPUT_NAME;
if (access(m_interval_node.c_str(), F_OK) == 0)
m_interval_supported = true;
- if (!config.get(SENSOR_TYPE_HRM, m_model_id, ELEMENT_VENDOR, m_vendor)) {
- _E("[VENDOR] is empty");
- throw ENXIO;
- }
-
- _I("m_vendor = %s", m_vendor.c_str());
-
- if (!config.get(SENSOR_TYPE_HRM, m_model_id, ELEMENT_NAME, m_chip_name)) {
- _E("[NAME] is empty");
- throw ENXIO;
- }
-
- _I("m_chip_name = %s",m_chip_name.c_str());
-
- if (!config.get(SENSOR_TYPE_HRM, m_model_id, ELEMENT_RAW_DATA_UNIT, raw_data_unit)) {
- _I("[RAW_DATA_UNIT] is empty");
- }
-
- m_raw_data_unit = (float)(raw_data_unit);
- _I("m_raw_data_unit = %f", m_raw_data_unit);
-
m_node_handle = open(m_data_node.c_str(), O_RDONLY);
if (m_node_handle < 0) {
int hrm_device::get_sensors(const sensor_info_t **sensors)
{
- sensor_info.model_name = m_chip_name.c_str();
- sensor_info.vendor = m_vendor.c_str();
*sensors = &sensor_info;
return 1;
}
}
- if ((hrm_raw[0] * m_raw_data_unit) > HR_MAX) {
+ if (hrm_raw[0] * RAW_DATA_UNIT > HR_MAX) {
_E("Drop abnormal HR: %d", hrm_raw[0]);
return false;
}
int hrm_device::get_data(uint32_t id, sensor_data_t **data, int *length)
{
- int remains = 1;
sensor_data_t *sensor_data;
sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
retvm_if(!sensor_data, -ENOMEM, "Memory allocation failed");
*data = sensor_data;
*length = sizeof(sensor_data_t);
- return --remains;
+ return 0;
}
void hrm_device::raw_to_base(sensor_data_t *data)
{
- data->values[0] = data->values[0] * m_raw_data_unit;
+ data->values[0] = data->values[0] * RAW_DATA_UNIT;
}
int m_spo2;
int m_peek_to_peek;
float m_snr;
- float m_raw_data_unit;
unsigned long m_polling_interval;
unsigned long long m_fired_time;
bool m_interval_supported;
std::string m_enable_node;
std::string m_interval_node;
- std::string m_model_id;
- std::string m_vendor;
- std::string m_chip_name;
-
std::function<bool (void)> update_value;
std::vector<uint32_t> event_ids;
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_log.h>
-#include "hrm_raw_data_reader.h"
-
-hrm_raw_data_reader::hrm_raw_data_reader()
-{
-}
-hrm_raw_data_reader::~hrm_raw_data_reader()
-{
-}
-
-bool hrm_raw_data_reader::open(void)
-{
- return true;
-}
-
-bool hrm_raw_data_reader::close(void)
-{
- return true;
-}
-
-
-bool hrm_raw_data_reader::start(void)
-{
- return true;
-}
-
-bool hrm_raw_data_reader::stop(void)
-{
- return true;
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef _HRM_RAW_DATA_READER_H_
-#define _HRM_RAW_DATA_READER_H_
-
-#include <sys/time.h>
-#include <sensor/sensor_hal.h>
-
-class hrm_raw_data_reader {
-public:
- hrm_raw_data_reader();
- virtual ~hrm_raw_data_reader();
-
- virtual bool open(void);
- virtual bool close(void);
- virtual bool start(void);
- virtual bool stop(void);
- virtual bool get_data(int handle, sensor_data_t &data) = 0;
-};
-#endif /* _HRM_RAW_DATA_READER_ */
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <unistd.h>
-#include <linux/input.h>
-#include <util.h>
-#include <sensor_log.h>
-#include <sensor_common.h>
-#include "hrm_raw_data_reader_standard.h"
-
-#define INPUT_MAX_BEFORE_SYN 20
-#define INPUT_EVENT_BIAS 1
-#define INPUT_VALUE_COUNT 10
-
-hrm_raw_data_reader_standard::hrm_raw_data_reader_standard()
-{
-}
-
-hrm_raw_data_reader_standard::~hrm_raw_data_reader_standard()
-{
-}
-
-bool hrm_raw_data_reader_standard::get_data(int handle, sensor_data_t &data)
-{
- bool syn = false;
- int read_input_cnt = 0;
- int index = 0;
- struct input_event hrm_raw_input;
-
- while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
- int len = read(handle, &hrm_raw_input, sizeof(hrm_raw_input));
- if (len != sizeof(hrm_raw_input)) {
- _E("hrm_raw_file read fail, read_len = %d", len);
- return false;
- }
-
- ++read_input_cnt;
-
- if (hrm_raw_input.type == EV_REL) {
- index = hrm_raw_input.code - REL_X;
-
- /* Check an avaiable value REL_X(0x00) ~ REL_MISC(0x09) */
- if (index >= INPUT_VALUE_COUNT) {
- _E("hrm_raw_input event[type = %d, code = %d] is unknown.", hrm_raw_input.type, index);
- return false;
- }
- data.values[index] = (unsigned int)hrm_raw_input.value - INPUT_EVENT_BIAS;
-
- } else if (hrm_raw_input.type == EV_SYN) {
- syn = true;
- data.timestamp = util::get_timestamp(&hrm_raw_input.time);
- data.value_count = INPUT_VALUE_COUNT;
- } else {
- _E("hrm_raw_input event[type = %d, code = %d] is unknown.", hrm_raw_input.type, hrm_raw_input.code);
- return false;
- }
- }
-
- if (!syn) {
- _E("EV_SYN didn't come until %d inputs had come", read_input_cnt);
- return false;
- }
- return true;
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include "hrm_raw_data_reader.h"
-
-#ifndef _HRM_RAW_DATA_READER_STANDARD_H_
-#define _HRM_RAW_DATA_READER_STANDARD_H_
-
-class hrm_raw_data_reader_standard : public hrm_raw_data_reader {
-public:
- hrm_raw_data_reader_standard();
- ~hrm_raw_data_reader_standard();
-
- virtual bool get_data(int handle, sensor_data_t &data);
-};
-#endif /* _HRM_RAW_DATA_READER_STANDARD_H_ */
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <linux/input.h>
-#include <sys/ioctl.h>
-#include <poll.h>
-
-#include <macro.h>
-#include <util.h>
-#include <sensor_common.h>
-#include <sensor_log.h>
-#include <sensor_config.h>
-
-#include "hrm_raw_data_reader_standard.h"
-#include "hrm_raw_device.h"
-
-#define SENSOR_NAME "SENSOR_HRM_RAW"
-#define SENSOR_TYPE_HRM_RAW "HRM_RAW"
-
-#define INPUT_NAME "hrm_raw_sensor"
-#define HRM_SENSORHUB_POLL_NODE_NAME "hrm_poll_delay"
-
-#define INDEX_HRM_RAW 0x1
-#define INDEX_HRM_LED_GREEN 0x2
-
-#define ELEMENT_READER "READER"
-#define POLL_1HZ_MS 1000
-
-static sensor_info_t sensor_info[] = {
- {
- id: INDEX_HRM_RAW,
- name: SENSOR_NAME,
- type: SENSOR_DEVICE_HRM_RAW,
- event_type: (SENSOR_DEVICE_HRM_RAW << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
- model_name: UNKNOWN_NAME,
- vendor: UNKNOWN_NAME,
- min_range: 0,
- max_range: 1,
- resolution: 1,
- min_interval: 1,
- max_batch_count: 0,
- wakeup_supported: false
- },
- {
- id: INDEX_HRM_LED_GREEN,
- name: "HRM LED GREEN SENSOR",
- type: SENSOR_DEVICE_HRM_LED_GREEN,
- event_type: (SENSOR_DEVICE_HRM_LED_GREEN << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
- model_name: UNKNOWN_NAME,
- vendor: UNKNOWN_NAME,
- min_range: 0,
- max_range: 1,
- resolution: 1,
- min_interval: 1,
- max_batch_count: 0,
- wakeup_supported: false
- }
-};
-
-hrm_raw_device::hrm_raw_device()
-: m_node_handle(-1)
-, m_polling_interval(POLL_1HZ_MS)
-, m_raw_interval(POLL_1HZ_MS)
-, m_led_green_interval(POLL_1HZ_MS)
-, m_interval_supported(false)
-, m_sensorhub_controlled(false)
-, m_enable(0)
-, m_reader(NULL)
-{
- const std::string sensorhub_interval_node_name = HRM_SENSORHUB_POLL_NODE_NAME;
- config::sensor_config &config = config::sensor_config::get_instance();
-
- node_info_query query;
- node_info info;
-
- if (!util::find_model_id(SENSOR_TYPE_HRM_RAW, m_model_id)) {
- _E("Failed to find model id");
- throw ENXIO;
- }
-
- query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
- query.sensor_type = SENSOR_TYPE_HRM_RAW;
- query.key = INPUT_NAME;
- query.iio_enable_node_name = "hrm_raw_enable";
- query.sensorhub_interval_node_name = sensorhub_interval_node_name;
-
- if (!util::get_node_info(query, info)) {
- _E("Failed to get node info");
- throw ENXIO;
- }
-
- util::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 (access(m_interval_node.c_str(), F_OK) == 0)
- m_interval_supported = true;
-
- if (!config.get(SENSOR_TYPE_HRM_RAW, m_model_id, ELEMENT_VENDOR, m_vendor)) {
- _E("[VENDOR] is empty");
- throw ENXIO;
- }
-
- _I("m_vendor = %s", m_vendor.c_str());
-
- if (!config.get(SENSOR_TYPE_HRM_RAW, m_model_id, ELEMENT_NAME, m_chip_name)) {
- _E("[NAME] is empty");
- throw ENXIO;
- }
-
- _I("m_chip_name = %s",m_chip_name.c_str());
-
- std::string reader;
-
- if (!config.get(SENSOR_TYPE_HRM_RAW, m_model_id, ELEMENT_READER, reader)) {
- _E("[READER] is empty");
- throw ENXIO;
- }
-
- _I("reader = %s", reader.c_str());
-
- m_node_handle = open(m_data_node.c_str(), O_RDONLY);
-
- if (m_node_handle < 0) {
- _ERRNO(errno, _E, "hrm raw handle open fail for hrm raw sensor");
- throw ENXIO;
- }
-
- if (m_method != INPUT_EVENT_METHOD)
- throw ENXIO;
-
- if (!util::set_monotonic_clock(m_node_handle))
- throw ENXIO;
-
- m_reader = get_reader(reader);
-
- if (!m_reader) {
- _E("Not supported HRM sensor: %s", m_model_id.c_str());
- throw ENXIO;
- }
-
- if (!m_reader->open())
- throw ENXIO;
-
- _I("hrm_raw_device is created!");
-}
-
-hrm_raw_device::~hrm_raw_device()
-{
- delete m_reader;
- close(m_node_handle);
- m_node_handle = -1;
-
- _I("hrm_raw_device is destroyed!");
-}
-
-int hrm_raw_device::get_poll_fd()
-{
- return m_node_handle;
-}
-
-int hrm_raw_device::get_sensors(const sensor_info_t **sensors)
-{
- int size = ARRAY_SIZE(sensor_info);
-
- for (int i = 0; i < size; ++i) {
- sensor_info[i].model_name = m_chip_name.c_str();
- sensor_info[i].vendor = m_vendor.c_str();
- }
-
- *sensors = sensor_info;
-
- return size;
-}
-
-bool hrm_raw_device::enable(uint32_t id)
-{
- ++m_enable;
-
- if (m_enable > 1)
- return true;
-
- util::set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_HRM_RAW_ENABLE_BIT);
- if (m_interval_supported)
- set_interval(id, m_polling_interval);
-
- m_data.timestamp = 0;
-
- m_reader->start();
- _I("Enable HRM Raw sensor");
- return true;
-}
-
-bool hrm_raw_device::disable(uint32_t id)
-{
- --m_enable;
-
- if (m_enable > 0)
- return true;
-
- util::set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_HRM_RAW_ENABLE_BIT);
-
- m_reader->stop();
- m_enable = 0;
- _I("Disable HRM Raw sensor");
- return true;
-}
-
-bool hrm_raw_device::set_interval(uint32_t id, unsigned long val)
-{
- unsigned long interval = 100;
- unsigned long long polling_interval_ns;
-
- if (!m_interval_supported)
- return true;
-
- if (id == INDEX_HRM_LED_GREEN)
- interval = (val > m_raw_interval)?m_raw_interval:val;
- else
- interval = (val > m_led_green_interval)?m_led_green_interval:val;
-
- polling_interval_ns = ((unsigned long long)(interval) * 1000llu * 1000llu);
-
- if (!util::set_node_value(m_interval_node, polling_interval_ns)) {
- _E("Failed to set polling resource: %s", m_interval_node.c_str());
- return false;
- }
-
- _I("Interval is changed from %dms to %dms", m_polling_interval, interval);
- m_polling_interval = interval;
-
- if (id == INDEX_HRM_LED_GREEN)
- m_led_green_interval = val;
- else
- m_raw_interval = val;
-
- return true;
-}
-
-int hrm_raw_device::read_fd(uint32_t **ids)
-{
- if (!m_reader->get_data(m_node_handle, m_data)) {
- _D("Failed to update value");
- return false;
- }
-
- int size = ARRAY_SIZE(sensor_info);
-
- event_ids.clear();
-
- for (int i = 0; i < size; ++i)
- event_ids.push_back(sensor_info[i].id);
-
- *ids = &event_ids[0];
-
- return event_ids.size();
-}
-
-int hrm_raw_device::get_data(uint32_t id, sensor_data_t **data, int *length)
-{
- int remains = 1;
- sensor_data_t *sensor_data;
- sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
- retvm_if(!sensor_data, -ENOMEM, "Memory allocation failed");
-
- sensor_data->accuracy = SENSOR_ACCURACY_GOOD;
- sensor_data->timestamp = m_data.timestamp;
-
- if (id == INDEX_HRM_LED_GREEN) {
- sensor_data->value_count = 1;
- sensor_data->values[0] = m_data.values[5];
- } else {
- sensor_data->value_count = m_data.value_count;
- memcpy(sensor_data->values, m_data.values, m_data.value_count * sizeof(m_data.values[0]));
- }
-
- *data = sensor_data;
- *length = sizeof(sensor_data_t);
-
- return --remains;
-}
-
-hrm_raw_data_reader* hrm_raw_device::get_reader(const std::string& reader)
-{
- return new(std::nothrow) hrm_raw_data_reader_standard();
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _HRM_RAW_DEVICE_H_
-#define _HRM_RAW_DEVICE_H_
-
-#include <sensor/sensor_hal.h>
-#include <string>
-#include <vector>
-#include <functional>
-#include "hrm_raw_data_reader.h"
-
-class hrm_raw_device : public sensor_device {
-public:
- hrm_raw_device();
- virtual ~hrm_raw_device();
-
- int get_poll_fd(void);
- int get_sensors(const sensor_info_t **sensors);
-
- bool enable(uint32_t id);
- bool disable(uint32_t id);
-
- bool set_interval(uint32_t id, unsigned long val);
-
- int read_fd(uint32_t **ids);
- int get_data(uint32_t id, sensor_data_t **data, int *length);
-
-private:
- int m_node_handle;
- sensor_data_t m_data;
- unsigned long m_polling_interval;
- unsigned long m_raw_interval;
- unsigned long m_led_green_interval;
-
- bool m_interval_supported;
- bool m_sensorhub_controlled;
- int m_enable;
-
- hrm_raw_data_reader *m_reader;
-
- int m_method;
- std::string m_data_node;
- std::string m_enable_node;
- std::string m_interval_node;
-
- std::string m_model_id;
- std::string m_vendor;
- std::string m_chip_name;
-
- std::vector<uint32_t> event_ids;
-
- hrm_raw_data_reader* get_reader(const std::string& reader);
-};
-#endif /* _HRM_RAW_DEVICE_H_ */
#include <util.h>
#include <sensor_common.h>
#include <sensor_log.h>
-#include <sensor_config.h>
+
#include "light_device.h"
-#define BIAS 1
+#define MODEL_NAME "maru_sensor_light_1"
+#define VENDOR "Tizen_SDK"
+#define MIN_RANGE 0
+#define MAX_RANGE 65536
+#define RESOLUTION 1
+#define RAW_DATA_UNIT 1
+#define MIN_INTERVAL 1
+#define MAX_BATCH_COUNT 0
#define SENSOR_NAME "SENSOR_LIGHT"
-
-/* ADC value received from Kernel */
-#define MODEL_ID_CAPELLA "CM36686"
-
#define SENSOR_TYPE_LIGHT "LIGHT"
#define INPUT_NAME "light_sensor"
#define LIGHT_SENSORHUB_POLL_NODE_NAME "light_poll_delay"
-const static int light_level[] = {0, 1, 165, 288, 497, 869, 1532, 2692, 4692, 8280, 21428, 65535, 137852};
+#define BIAS 1
static sensor_info_t sensor_info = {
id: 0x1,
name: SENSOR_NAME,
type: SENSOR_DEVICE_LIGHT,
event_type: (SENSOR_DEVICE_LIGHT << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
- model_name: UNKNOWN_NAME,
- vendor: UNKNOWN_NAME,
- min_range: 0,
- max_range: 65536,
- resolution: 1,
- min_interval: 1,
- max_batch_count: 0,
+ model_name: MODEL_NAME,
+ vendor: VENDOR,
+ min_range: MIN_RANGE,
+ max_range: MAX_RANGE,
+ resolution: RAW_DATA_UNIT,
+ min_interval: MIN_INTERVAL,
+ max_batch_count: MAX_BATCH_COUNT,
wakeup_supported: false
};
, m_sensorhub_controlled(false)
{
const std::string sensorhub_interval_node_name = LIGHT_SENSORHUB_POLL_NODE_NAME;
- config::sensor_config &config = config::sensor_config::get_instance();
node_info_query query;
node_info info;
- if (!util::find_model_id(SENSOR_TYPE_LIGHT, m_model_id)) {
- _E("Failed to find model id");
- throw ENXIO;
- }
-
query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
query.sensor_type = SENSOR_TYPE_LIGHT;
query.key = INPUT_NAME;
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)) {
- _E("[VENDOR] is empty");
- throw ENXIO;
- }
-
- _I("m_vendor = %s", m_vendor.c_str());
-
- if (!config.get(SENSOR_TYPE_LIGHT, m_model_id, ELEMENT_NAME, m_chip_name)) {
- _E("[NAME] is empty");
- throw ENXIO;
- }
-
- _I("m_chip_name = %s",m_chip_name.c_str());
-
m_node_handle = open(m_data_node.c_str(), O_RDONLY);
if (m_node_handle < 0) {
throw ENXIO;
}
- if (m_method == INPUT_EVENT_METHOD) {
- if (!util::set_monotonic_clock(m_node_handle))
- throw ENXIO;
-
- if (m_chip_name == MODEL_ID_CAPELLA) {
- update_value = [=]() {
- return this->update_value_adc();
- };
- } else {
- update_value = [=]() {
- return this->update_value_lux();
- };
- }
- }
+ if (m_method != INPUT_EVENT_METHOD)
+ throw ENXIO;
+
+ if (!util::set_monotonic_clock(m_node_handle))
+ throw ENXIO;
+
+ update_value = [=]() {
+ return this->update_value_lux();
+ };
_I("light_device is created!");
}
_I("light_device is destroyed!");
}
-int light_device::get_poll_fd()
+int light_device::get_poll_fd(void)
{
return m_node_handle;
}
int light_device::get_sensors(const sensor_info_t **sensors)
{
- sensor_info.model_name = m_chip_name.c_str();
- sensor_info.vendor = m_vendor.c_str();
*sensors = &sensor_info;
return 1;
{
util::set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_LIGHT_ENABLE_BIT);
- INFO("Disable light sensor");
+ _I("Disable light sensor");
return true;
}
return true;
}
-bool light_device::update_value_adc(void)
-{
- int light_raw[2] = {0,};
- int als = -1;
- int w = -1;
- int lux = -1;
- float i_cf = 0.0f;
- bool adc, white;
- int read_input_cnt = 0;
- const int INPUT_MAX_BEFORE_SYN = 10;
- unsigned long long fired_time = 0;
- bool syn = false;
-
- adc = white = false;
-
- struct input_event light_input;
- _D("light event detection!");
-
- while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
- int len = read(m_node_handle, &light_input, sizeof(light_input));
- if (len != sizeof(light_input)) {
- _E("light_file read fail, read_len = %d",len);
- return false;
- }
-
- ++read_input_cnt;
-
- if (light_input.type == EV_REL) {
- switch (light_input.code) {
- case REL_DIAL:
- light_raw[0] = (int)light_input.value - BIAS;
- adc = true;
- break;
- case REL_WHEEL:
- light_raw[1] = (int)light_input.value - BIAS;
- white = true;
- break;
- default:
- _E("light_input event[type = %d, code = %d] is unknown.", light_input.type, light_input.code);
- return false;
- break;
- }
- } else if (light_input.type == EV_SYN) {
- syn = true;
- fired_time = util::get_timestamp(&light_input.time);
- } else {
- _E("light_input event[type = %d, code = %d] is unknown.", light_input.type, light_input.code);
- return false;
- }
- }
-
- if (syn == false) {
- _E("EV_SYN didn't come until %d inputs had come", read_input_cnt);
- return false;
- }
-
- if (adc && white) {
- als = light_raw[0];
- w = (light_raw[1])? light_raw[1] : 1;
- i_cf = als / (float) w;
- if (i_cf >= 0.33f) {
- lux = 0.6985f * pow(als, 0.9943f);
- } else {
- lux = 0.25f * pow(als, 1.0552f);
- }
- }
-
- _D("update_value_lux, lux : %d", lux);
-
- m_fired_time = fired_time;
- m_lux = lux;
-
- return true;
-}
-
bool light_device::update_value_lux(void)
{
int lux = -1;
int light_device::read_fd(uint32_t **ids)
{
if (!update_value()) {
- DBG("Failed to update value");
+ _D("Failed to update value");
return false;
}
int light_device::get_data(uint32_t id, sensor_data_t **data, int *length)
{
- int remains = 1;
sensor_data_t *sensor_data;
sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
retvm_if(!sensor_data, -ENOMEM, "Memory allocation failed");
*data = sensor_data;
*length = sizeof(sensor_data_t);
- return --remains;
-}
-
-int light_device::adc_to_light_level(int adc)
-{
- int level_cnt = ARRAY_SIZE(light_level) - 1;
-
- for (int i = 0; i < level_cnt; ++i) {
- if (adc >= light_level[i] && adc < light_level[i + 1])
- return i;
- }
-
- return -1;
+ return 0;
}
std::string m_data_node;
std::string m_interval_node;
- std::string m_model_id;
- std::string m_vendor;
- std::string m_chip_name;
-
std::function<bool (void)> update_value;
std::vector<uint32_t> event_ids;
- bool update_value_adc(void);
bool update_value_lux(void);
- int adc_to_light_level(int adc);
};
#endif /* _LIGHT_DEVICE_H_ */
#include <util.h>
#include <sensor_common.h>
#include <sensor_log.h>
-#include <sensor_config.h>
#include "pressure_device.h"
#define SEA_LEVEL_RESOLUTION 0.01
#define SEA_LEVEL_PRESSURE 101325.0
#define SEA_LEVEL_EPSILON 0.00001
+#define MODEL_NAME "maru_sensor_pressure_1"
+#define VENDOR "Tizen_SDK"
+#define RESOLUTION 1
+#define RAW_DATA_UNIT 0.0193
+#define MIN_INTERVAL 1
+#define MIN_RANGE 260
+#define MAX_RANGE 1260
+#define TEMPERATURE_RESOLUTION 0.05
+#define TEMPERATURE_OFFSET 0
+#define MAX_BATCH_COUNT 0
+
#define SENSOR_NAME "SENSOR_PRESSURE"
#define SENSOR_TYPE_PRESSURE "PRESSURE"
-#define ELEMENT_TEMPERATURE_RESOLUTION "TEMPERATURE_RESOLUTION"
-#define ELEMENT_TEMPERATURE_OFFSET "TEMPERATURE_OFFSET"
-
#define INPUT_NAME "pressure_sensor"
#define PRESSURE_SENSORHUB_POLL_NODE_NAME "pressure_poll_delay"
name: SENSOR_NAME,
type: SENSOR_DEVICE_PRESSURE,
event_type: (SENSOR_DEVICE_PRESSURE << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
- model_name: UNKNOWN_NAME,
- vendor: UNKNOWN_NAME,
- min_range: 0,
- max_range: 0,
- resolution: 0,
- min_interval: 0,
- max_batch_count: 0,
+ model_name: MODEL_NAME,
+ vendor: VENDOR,
+ min_range: MIN_RANGE,
+ max_range: MAX_RANGE,
+ resolution: RAW_DATA_UNIT,
+ min_interval: MIN_INTERVAL,
+ max_batch_count: MAX_BATCH_COUNT,
wakeup_supported: false
};
pressure_device::pressure_device()
: m_node_handle(-1)
, m_pressure(0)
-, m_resolution(0)
, m_temperature(0)
, m_sea_level_pressure(SEA_LEVEL_PRESSURE)
-, m_temperature_resolution(0)
-, m_temperature_offset(0)
, m_polling_interval(1000)
, m_fired_time(0)
, m_sensorhub_controlled(false)
{
const std::string sensorhub_interval_node_name = PRESSURE_SENSORHUB_POLL_NODE_NAME;
- config::sensor_config &config = config::sensor_config::get_instance();
node_info_query query;
node_info info;
- if (!util::find_model_id(SENSOR_TYPE_PRESSURE, m_model_id)) {
- _E("Failed to find model id");
- throw ENXIO;
-
- }
-
query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
query.sensor_type = SENSOR_TYPE_PRESSURE;
query.key = INPUT_NAME;
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)) {
- _E("[VENDOR] is empty\n");
- throw ENXIO;
- }
-
- _I("m_vendor = %s", m_vendor.c_str());
-
- if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_NAME, m_chip_name)) {
- _E("[NAME] is empty\n");
- throw ENXIO;
- }
-
- _I("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)) {
- _E("[MIN_RANGE] is empty\n");
- throw ENXIO;
- }
-
- m_min_range = (float)min_range;
- _I("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)) {
- _E("[MAX_RANGE] is empty\n");
- throw ENXIO;
- }
-
- m_max_range = (float)max_range;
- _I("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)) {
- _E("[RAW_DATA_UNIT] is empty\n");
- throw ENXIO;
- }
-
- m_raw_data_unit = (float)(raw_data_unit);
- _I("m_raw_data_unit = %f\n", m_raw_data_unit);
-
- double temperature_resolution;
- if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_TEMPERATURE_RESOLUTION, temperature_resolution)) {
- ERR("[TEMPERATURE_RESOLUTION] is empty\n");
- throw ENXIO;
- }
-
- m_temperature_resolution = (float)temperature_resolution;
- INFO("m_temperature_resolution = %f\n", m_temperature_resolution);
-
- double temperature_offset;
-
- if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_TEMPERATURE_OFFSET, temperature_offset)) {
- ERR("[TEMPERATURE_OFFSET] is empty\n");
- throw ENXIO;
- }
-
- m_temperature_offset = (float)temperature_offset;
- INFO("m_temperature_offset = %f\n", m_temperature_offset);
-
m_node_handle = open(m_data_node.c_str(), O_RDONLY);
if (m_node_handle < 0) {
};
}
- _I("pressure_device is created!\n");
+ _I("pressure_device is created!");
}
pressure_device::~pressure_device()
close(m_node_handle);
m_node_handle = -1;
- _I("pressure_device is destroyed!\n");
+ _I("pressure_device is destroyed!");
}
int pressure_device::get_poll_fd(void)
int pressure_device::get_sensors(const sensor_info_t **sensors)
{
- sensor_info.model_name = m_chip_name.c_str();
- sensor_info.vendor = m_vendor.c_str();
- sensor_info.min_range = m_min_range;
- sensor_info.max_range = m_max_range;
- sensor_info.resolution = m_raw_data_unit;
- sensor_info.min_interval = 1;
- sensor_info.max_batch_count = 0;
*sensors = &sensor_info;
return 1;
set_interval(id, m_polling_interval);
m_fired_time = 0;
- INFO("Enable pressure sensor");
+ _I("Enable pressure sensor");
return true;
}
{
util::set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_PRESSURE_ENABLE_BIT);
- INFO("Disable pressure sensor");
+ _I("Disable pressure sensor");
return true;
-
}
bool pressure_device::set_interval(uint32_t id, unsigned long val)
polling_interval_ns = ((unsigned long long)(val) * 1000llu * 1000llu);
if (!util::set_node_value(m_interval_node, polling_interval_ns)) {
- ERR("Failed to set polling resource: %s\n", m_interval_node.c_str());
+ _E("Failed to set polling resource: %s", m_interval_node.c_str());
return false;
}
- INFO("Interval is changed from %dms to %dms", m_polling_interval, val);
+ _I("Interval is changed from %dms to %dms", m_polling_interval, val);
m_polling_interval = val;
return true;
}
int pressure_device::read_fd(uint32_t **ids)
{
if (!update_value()) {
- DBG("Failed to update value");
+ _D("Failed to update value");
return false;
}
int pressure_device::get_data(uint32_t id, sensor_data_t **data, int *length)
{
- int remains = 1;
sensor_data_t *sensor_data;
sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
retvm_if(!sensor_data, -ENOMEM, "Memory allocation failed");
*data = sensor_data;
*length = sizeof(sensor_data_t);
- return --remains;
+ return 0;
}
void pressure_device::raw_to_base(sensor_data_t *data)
{
- data->values[0] = data->values[0] * m_raw_data_unit;
+ data->values[0] = data->values[0] * RAW_DATA_UNIT;
m_sea_level_pressure = data->values[1] * SEA_LEVEL_RESOLUTION;
data->values[1] = pressure_to_altitude(data->values[0]);
- data->values[2] = data->values[2] * m_temperature_resolution + m_temperature_offset;
+ data->values[2] = data->values[2] * TEMPERATURE_RESOLUTION + TEMPERATURE_OFFSET;
}
float pressure_device::pressure_to_altitude(float pressure)
private:
int m_node_handle;
int m_pressure;
- int m_resolution;
int m_temperature;
float m_sea_level_pressure;
- float m_temperature_resolution;
- float m_temperature_offset;
unsigned long m_polling_interval;
unsigned long long m_fired_time;
bool m_sensorhub_controlled;
std::string m_enable_node;
std::string m_interval_node;
- 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;
-
std::function<bool (void)> update_value;
std::vector<uint32_t> event_ids;
#include <util.h>
#include <sensor_common.h>
#include <sensor_log.h>
-#include <sensor_config.h>
+
#include "proxi_device.h"
-#define MODEL_NAME "UNKNOWN"
-#define VENDOR "UNKNOWN"
+#define MODEL_NAME "maru_sensor_proxi_1"
+#define VENDOR "Tizen_SDK"
#define MIN_RANGE 0
#define MAX_RANGE 5
#define RESOLUTION 1
+#define RAW_DATA_UNIT 1
#define MIN_INTERVAL 1
#define MAX_BATCH_COUNT 0
vendor: VENDOR,
min_range: MIN_RANGE,
max_range: MAX_RANGE,
- resolution: RESOLUTION,
+ resolution: RAW_DATA_UNIT,
min_interval: MIN_INTERVAL,
max_batch_count: MAX_BATCH_COUNT,
wakeup_supported: false
, m_sensorhub_controlled(false)
{
const std::string sensorhub_interval_node_name = PROXI_SENSORHUB_POLL_NODE_NAME;
- config::sensor_config &config = config::sensor_config::get_instance();
node_info_query query;
node_info info;
- if (!util::find_model_id(SENSOR_TYPE_PROXI, m_model_id)) {
- _E("Failed to find model id");
- throw ENXIO;
-
- }
-
query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
query.sensor_type = SENSOR_TYPE_PROXI;
query.key = INPUT_NAME;
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)) {
- _E("[VENDOR] is empty");
- throw ENXIO;
- }
-
- _I("m_vendor = %s", m_vendor.c_str());
-
- if (!config.get(SENSOR_TYPE_PROXI, m_model_id, ELEMENT_NAME, m_chip_name)) {
- _E("[NAME] is empty");
- throw ENXIO;
- }
-
- _I("m_chip_name = %s",m_chip_name.c_str());
-
m_node_handle = open(m_data_node.c_str(), O_RDONLY);
if (m_node_handle < 0) {
throw ENXIO;
}
- if (m_method == INPUT_EVENT_METHOD) {
- if (!util::set_monotonic_clock(m_node_handle))
- throw ENXIO;
+ if (m_method != INPUT_EVENT_METHOD)
+ throw ENXIO;
- update_value = [=]() {
- return this->update_value_input_event();
- };
- }
+ if (!util::set_monotonic_clock(m_node_handle))
+ throw ENXIO;
+
+ update_value = [=]() {
+ return this->update_value_input_event();
+ };
- _I("Proxi_sensor_hal is created!");
+ _I("Proxi_device is created!");
}
proxi_device::~proxi_device()
close(m_node_handle);
m_node_handle = -1;
- _I("Proxi_sensor_hal is destroyed!");
+ _I("Proxi_device is destroyed!");
}
int proxi_device::get_poll_fd(void)
int proxi_device::get_sensors(const sensor_info_t **sensors)
{
- sensor_info.model_name = m_chip_name.c_str();
- sensor_info.vendor = m_vendor.c_str();
*sensors = &sensor_info;
return 1;
util::set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_PROXIMITY_ENABLE_BIT);
m_fired_time = 0;
- INFO("Enable proxi sensor");
+ _I("Enable proxi sensor");
return true;
}
{
util::set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_PROXIMITY_ENABLE_BIT);
- INFO("Disable proxi sensor");
+ _I("Disable proxi sensor");
return true;
}
int proxi_device::read_fd(uint32_t **ids)
{
if (!update_value()) {
- DBG("Failed to update value");
+ _D("Failed to update value");
return false;
}
int proxi_device::get_data(uint32_t id, sensor_data_t **data, int *length)
{
- int remains = 1;
sensor_data_t *sensor_data;
sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
retvm_if(!sensor_data, -ENOMEM, "Memory allocation failed");
*data = sensor_data;
*length = sizeof(sensor_data_t);
- return --remains;
+ return 0;
}
std::string m_data_node;
std::string m_enable_node;
- std::string m_model_id;
- std::string m_vendor;
- std::string m_chip_name;
-
std::function<bool (void)> update_value;
std::vector<uint32_t> event_ids;
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_config.h>
-#include <sensor_log.h>
-#include <libxml/xmlmemory.h>
-#include <libxml/parser.h>
-#include <sstream>
-#include <iostream>
-#include <fstream>
-#include <string>
-
-using namespace config;
-using std::ifstream;
-using std::string;
-using std::istringstream;
-
-#define ROOT_ELEMENT "SENSOR"
-#define TEXT_ELEMENT "text"
-#define MODEL_ID_ATTR "id"
-#define DEFAULT_ATTR "value"
-
-sensor_config::sensor_config()
-{
-}
-
-sensor_config& sensor_config::get_instance(void)
-{
- static bool load_done = false;
- static sensor_config inst;
-
- if (load_done)
- return inst;
-
- inst.load_config();
- inst.get_device_id();
- if (!inst.m_device_id.empty())
- _I("Device ID = %s", inst.m_device_id.c_str());
- else
- _E("Failed to get Device ID");
- load_done = true;
-
- return inst;
-}
-
-bool sensor_config::load_config(const string& config_path)
-{
- xmlDocPtr doc;
- xmlNodePtr cur;
-
- _D("sensor_config::load_config(\"%s\") is called!\n",config_path.c_str());
-
- doc = xmlParseFile(config_path.c_str());
-
- if (doc == NULL) {
- _E("There is no %s\n",config_path.c_str());
- return false;
- }
-
- cur = xmlDocGetRootElement(doc);
- if(cur == NULL) {
- _E("There is no root element in %s\n",config_path.c_str());
- xmlFreeDoc(doc);
- return false;
- }
-
- if(xmlStrcmp(cur->name, (const xmlChar *)ROOT_ELEMENT)) {
- _E("Wrong type document: there is no [%s] root element in %s\n",ROOT_ELEMENT,config_path.c_str());
- xmlFreeDoc(doc);
- return false;
- }
-
- xmlNodePtr model_list_node_ptr;
- xmlNodePtr model_node_ptr;
- xmlNodePtr element_node_ptr;
- xmlAttrPtr attr_ptr;
- char* prop = NULL;
-
- model_list_node_ptr = cur->xmlChildrenNode;
-
- while (model_list_node_ptr != NULL) {
- //skip garbage element, [text]
- if (!xmlStrcmp(model_list_node_ptr->name,(const xmlChar *)TEXT_ELEMENT)) {
- model_list_node_ptr = model_list_node_ptr->next;
- continue;
- }
-
- //insert Model_list to config map
- m_sensor_config[(const char*)model_list_node_ptr->name];
- _D("<%s>\n",(const char*)model_list_node_ptr->name);
-
- model_node_ptr = model_list_node_ptr->xmlChildrenNode;
- while (model_node_ptr != NULL){
- //skip garbage element, [text]
- if (!xmlStrcmp(model_node_ptr->name,(const xmlChar *)TEXT_ELEMENT)) {
- model_node_ptr = model_node_ptr->next;
- continue;
- }
-
-
- string model_id;
- prop = (char*)xmlGetProp(model_node_ptr,(const xmlChar*)MODEL_ID_ATTR);
- model_id = prop;
- free(prop);
-
- //insert Model to Model_list
- m_sensor_config[(const char*)model_list_node_ptr->name][model_id];
- _D("<%s id=\"%s\">\n",(const char*)model_list_node_ptr->name,model_id.c_str());
-
- element_node_ptr = model_node_ptr->xmlChildrenNode;
- while (element_node_ptr != NULL) {
- //skip garbage element, [text]
- if (!xmlStrcmp(element_node_ptr->name,(const xmlChar *)TEXT_ELEMENT)) {
- element_node_ptr = element_node_ptr->next;
- continue;
- }
-
- //insert Element to Model
- m_sensor_config[(const char*)model_list_node_ptr->name][model_id][(const char*)element_node_ptr->name];
- _D("<%s id=\"%s\"><%s>\n",(const char*)model_list_node_ptr->name,model_id.c_str(),(const char*)element_node_ptr->name);
-
- attr_ptr = element_node_ptr->properties;
- while (attr_ptr != NULL) {
-
- string key,value;
- key = (const char*)attr_ptr->name;
- prop = (char*)xmlGetProp(element_node_ptr,attr_ptr->name);
- value = prop;
- free(prop);
-
- //insert attribute to Element
- m_sensor_config[(const char*)model_list_node_ptr->name][model_id][(const char*)element_node_ptr->name][key]=value;
- _D("<%s id=\"%s\"><%s \"%s\"=\"%s\">\n",(const char*)model_list_node_ptr->name,model_id.c_str(),(const char*)element_node_ptr->name,key.c_str(),value.c_str());
- attr_ptr = attr_ptr->next;
- }
-
-
- element_node_ptr = element_node_ptr->next;
- }
-
- _D("\n");
- model_node_ptr = model_node_ptr->next;
- }
-
- _D("\n");
- model_list_node_ptr = model_list_node_ptr->next;
- }
-
- xmlFreeDoc(doc);
- return true;
-}
-
-
-bool sensor_config::get(const string& sensor_type,const string& model_id, const string& element, const string& attr, string& value)
-{
- auto it_model_list = m_sensor_config.find(sensor_type);
-
- if (it_model_list == m_sensor_config.end()) {
- _E("There is no <%s> element\n",sensor_type.c_str());
- return false;
- }
-
- auto it_model = it_model_list->second.find(model_id);
-
- if (it_model == it_model_list->second.end()) {
- _E("There is no <%s id=\"%s\"> element\n",sensor_type.c_str(),model_id.c_str());
- return false;
- }
-
- auto it_element = it_model->second.find(element);
-
- if (it_element == it_model->second.end()) {
- _D("There is no <%s id=\"%s\"><%s> element\n",sensor_type.c_str(),model_id.c_str(),element.c_str());
- return false;
- }
-
- auto it_attr = it_element->second.find(attr);
-
- if (it_attr == it_element->second.end()) {
- _D("There is no <%s id=\"%s\"><%s \"%s\">\n",sensor_type.c_str(),model_id.c_str(),element.c_str(),attr.c_str());
- return false;
- }
-
- value = it_attr->second;
-
- return true;
-}
-
-bool sensor_config::get(const string& sensor_type, const string& model_id, const string& element, const string& attr, double& value)
-{
- string str_value;
-
- if (get(sensor_type,model_id,element,attr,str_value) == false)
- return false;
-
- istringstream convert(str_value);
-
- if ( !(convert >> value))
- value = 0;
-
- return true;
-}
-
-bool sensor_config::get(const string& sensor_type, const string& model_id, const string& element, const string& attr, long& value)
-{
- string str_value;
-
- if (get(sensor_type,model_id,element,attr,str_value) == false)
- return false;
-
- istringstream convert(str_value);
-
- if ( !(convert >> value))
- value = 0;
-
- return true;
-}
-
-bool sensor_config::get(const string& sensor_type, const string& model_id, const string& element, string& value)
-{
- if (get(sensor_type, model_id, element, m_device_id, value))
- return true;
-
- if (get(sensor_type, model_id, element, DEFAULT_ATTR, value))
- return true;
-
- return false;
-}
-
-bool sensor_config::get(const string& sensor_type, const string& model_id, const string& element, double& value)
-{
- if (get(sensor_type, model_id, element, m_device_id, value))
- return true;
-
- if (get(sensor_type, model_id, element, DEFAULT_ATTR, value))
- return true;
-
- return false;
-}
-
-bool sensor_config::get(const string& sensor_type, const string& model_id, const string& element, long& value)
-{
- if (get(sensor_type, model_id, element, m_device_id, value))
- return true;
-
- if (get(sensor_type, model_id, element, DEFAULT_ATTR, value))
- return true;
-
- return false;
-}
-
-bool sensor_config::is_supported(const string& sensor_type,const string& model_id)
-{
- auto it_model_list = m_sensor_config.find(sensor_type);
-
- if (it_model_list == m_sensor_config.end())
- return false;
-
- auto it_model = it_model_list->second.find(model_id);
-
- if (it_model == it_model_list->second.end())
- return false;
-
- return true;
-}
-
-bool sensor_config::get_device_id(void)
-{
- const string INFO_INI_PATH = "/etc/info.ini";
- const string START_DELIMETER = "Model=";
- const string END_DELIMETER = ";";
- string line;
- ifstream in_file;
- std::size_t start_pos, end_pos;
- bool ret = false;
-
- in_file.open(INFO_INI_PATH);
-
- if (!in_file.is_open())
- return false;
-
- while (!in_file.eof()) {
- getline(in_file, line);
- start_pos = line.find(START_DELIMETER);
-
- if (start_pos == std::string::npos)
- continue;
-
- start_pos = start_pos + START_DELIMETER.size();
- end_pos = line.find(END_DELIMETER, start_pos);
-
- if (end_pos == std::string::npos)
- continue;
-
- m_device_id = line.substr(start_pos, end_pos - start_pos);
- ret = true;
- break;
- }
-
- in_file.close();
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _SENSOR_CONFIG_H_
-#define _SENSOR_CONFIG_H_
-
-#include <string>
-#include <unordered_map>
-#include <sensor_log.h>
-
-#define CONFIG_FILE_PATH "/usr/etc/sensor.xml"
-
-#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 ELEMENT_MIN_RANGE "MIN_RANGE"
-#define ELEMENT_MAX_RANGE "MAX_RANGE"
-
-typedef std::unordered_map<std::string,std::string> Element;
-/*
-* an Element is a group of attributes
-* <Element value1 = "10.0", value2 = "20.0"/>
-*
-* "value" -> "LSM330DLC"
-*
-*/
-
-typedef std::unordered_map<std::string,Element> Model;
-/*
-* a Model is a group of elements to consist of specific vendor's one sensor configuration
-* <NAME value = "LSM330DLC" />
-* <VENDOR value = "ST Microelectronics"/>
-* <RAW_DATA_UNIT value = "1" />
-* <RESOLUTION value = "12" />
-*
-* <NAME> -> <value = "LSM330DLC"/>
-*
-*/
-
-typedef std::unordered_map<std::string,Model> Model_list;
-/*
-* a Model_list is a group of Model
-* <MODEL id = "lsm330dlc_accel">
-* </MODEL>
-* <MODEL id = "mpu6500">
-* </MODEL>
-*
-* "lsm330dlc_accel" -> <Model>
-*
-*/
-
-typedef std::unordered_map<std::string,Model_list> Sensor_config;
-/*
-* a SensorConfig represents sensors.xml
-* <ACCEL/>
-* <GYRO/>
-* <PROXIMITY/>
-*
-* "ACCEL" -> Model_list
-*
-*/
-
-namespace config {
- class sensor_config {
- private:
- sensor_config();
- sensor_config(sensor_config const&) {};
- sensor_config& operator=(sensor_config const&);
- bool load_config(const std::string& config_path = CONFIG_FILE_PATH);
- Sensor_config m_sensor_config;
- std::string m_device_id;
- public:
- static sensor_config& get_instance(void);
-
- bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, const std::string& attr, std::string& value);
- bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, const std::string& attr, double& value);
- bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, const std::string& attr, long& value);
-
- bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, std::string& value);
- bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, double& value);
- bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, long& value);
-
- bool is_supported(const std::string &sensor_type, const std::string &model_id);
- bool get_device_id(void);
- };
-}
-#endif /* _SENSOR_CONFIG_H_ */
#include <util.h>
#include <sensor_common.h>
#include <sensor_log.h>
-#include <sensor_config.h>
+
#include "uv_device.h"
-#define UNKNOWN_NAME "UNKNOWN"
-#define SENSOR_NAME "ULTRAVIOLET_SENSOR"
+#define MODEL_NAME "maru_sensor_uv_1"
+#define VENDOR "Tizen_SDK"
+#define MIN_RANGE 0
+#define MAX_RANGE 15
+#define RESOLUTION 1
+#define RAW_DATA_UNIT 0.1
+#define MIN_INTERVAL 1
+#define MAX_BATCH_COUNT 0
+#define SENSOR_NAME "ULTRAVIOLET_SENSOR"
#define SENSOR_TYPE_ULTRAVIOLET "ULTRAVIOLET"
-#define UV_SENSORHUB_POLL_NODE_NAME "uv_poll_dealy"
+
#define INPUT_NAME "uv_sensor"
+#define UV_SENSORHUB_POLL_NODE_NAME "uv_poll_dealy"
+
#define IIO_ENABLE_NAME "uv_enable"
#define BIAS 1
name: SENSOR_NAME,
type: SENSOR_DEVICE_ULTRAVIOLET,
event_type: (SENSOR_DEVICE_ULTRAVIOLET << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
- model_name: UNKNOWN_NAME,
- vendor: UNKNOWN_NAME,
- min_range: 0,
- max_range: 0,
- resolution: 0,
- min_interval: 0,
- max_batch_count: 0,
+ model_name: MODEL_NAME,
+ vendor: VENDOR,
+ min_range: MIN_RANGE,
+ max_range: MAX_RANGE,
+ resolution: RAW_DATA_UNIT,
+ min_interval: MIN_INTERVAL,
+ max_batch_count: MAX_BATCH_COUNT,
wakeup_supported: false
};
-std::vector<uint32_t> uv_device::event_ids;
-
uv_device::uv_device()
: m_node_handle(-1)
, m_ultraviolet(0)
, m_polling_interval(1000)
, m_fired_time(0)
-, m_raw_data_unit(0)
-, m_min_range(0)
-, m_max_range(0)
, m_sensorhub_controlled(false)
{
const std::string sensorhub_interval_node_name = UV_SENSORHUB_POLL_NODE_NAME;
- config::sensor_config &config = config::sensor_config::get_instance();
node_info_query query;
node_info info;
- if (!util::find_model_id(SENSOR_TYPE_ULTRAVIOLET, m_model_id)) {
- _E("Failed to find model id");
- throw ENXIO;
- }
-
query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
query.sensor_type = SENSOR_TYPE_ULTRAVIOLET;
query.key = INPUT_NAME;
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)) {
- _E("[VENDOR] is empty");
- throw ENXIO;
- }
-
- _I("m_vendor = %s", m_vendor.c_str());
-
- if (!config.get(SENSOR_TYPE_ULTRAVIOLET, m_model_id, ELEMENT_NAME, m_chip_name)) {
- _E("[NAME] is empty");
- throw ENXIO;
- }
-
- _I("m_chip_name = %s",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;
+ m_node_handle = open(m_data_node.c_str(), O_RDONLY);
- if (!config.get(SENSOR_TYPE_ULTRAVIOLET, m_model_id, ELEMENT_MAX_RANGE, max_range)) {
- ERR("[MAX_RANGE] is empty\n");
+ if (m_node_handle < 0) {
+ _ERRNO(errno, _E, "uv handle open fail for uv device");
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)) {
- _E("[RAW_DATA_UNIT] is empty");
+ if (m_method != INPUT_EVENT_METHOD)
throw ENXIO;
- }
-
- m_raw_data_unit = (float)(raw_data_unit);
- _I("m_raw_data_unit = %f", m_raw_data_unit);
-
- m_node_handle = open(m_data_node.c_str(), O_RDONLY);
- if (m_node_handle < 0) {
- _ERRNO(errno, _E, "uv handle open fail for uv processor");
+ if (!util::set_monotonic_clock(m_node_handle))
throw ENXIO;
- }
-
- if (m_method == INPUT_EVENT_METHOD) {
- if (!util::set_monotonic_clock(m_node_handle))
- throw ENXIO;
- }
update_value = [=]() {
return this->update_value_input_event();
};
- _I("uv_sensor is created!");
+ _I("uv_device is created!");
}
uv_device::~uv_device()
_I("uv_sensor is destroyed!");
}
-int uv_device::get_poll_fd()
+int uv_device::get_poll_fd(void)
{
return m_node_handle;
}
int uv_device::get_sensors(const sensor_info_t **sensors)
{
- sensor_info.model_name = m_chip_name.c_str();
- sensor_info.vendor = m_vendor.c_str();
- sensor_info.min_range = m_min_range;
- sensor_info.max_range = m_max_range;
- sensor_info.resolution = m_raw_data_unit;
- sensor_info.min_interval = 1;
- sensor_info.max_batch_count = 0;
*sensors = &sensor_info;
return 1;
int uv_device::get_data(uint32_t id, sensor_data_t **data, int *length)
{
- int remains = 1;
sensor_data_t *sensor_data;
sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
retvm_if(!sensor_data, -ENOMEM, "Memory allocation failed");
*data = sensor_data;
*length = sizeof(sensor_data_t);
- return --remains;
+ return 0;
}
void uv_device::raw_to_base(sensor_data_t *data)
{
- data->values[0] = data->values[0] * m_raw_data_unit;
+ data->values[0] = data->values[0] * RAW_DATA_UNIT;
}
int m_ultraviolet;
unsigned long m_polling_interval;
unsigned long long m_fired_time;
- float m_raw_data_unit;
- float m_min_range;
- float m_max_range;
bool m_sensorhub_controlled;
int m_method;
std::string m_enable_node;
std::string m_interval_node;
- std::string m_model_id;
- std::string m_vendor;
- std::string m_chip_name;
-
std::function<bool (void)> update_value;
- static std::vector<uint32_t> event_ids;
+ std::vector<uint32_t> event_ids;
bool update_value_input_event(void);
#include <linux/input.h>
#include <util.h>
#include <sensor_log.h>
-#include <sensor_config.h>
#include <fstream>
using std::ifstream;
return true;
}
-bool util::find_model_id(const string &sensor_type, string &model_id)
-{
- std::string dir_path = "/sys/class/sensors/";
- std::string name_node, name;
- std::string d_name;
- DIR *dir = NULL;
- struct dirent dir_entry;
- struct dirent *result = NULL;
- int error;
- bool find = false;
-
- dir = opendir(dir_path.c_str());
- if (!dir) {
- _D("Failed to open dir: %s", dir_path.c_str());
- return false;
- }
-
- while (true) {
- error = readdir_r(dir, &dir_entry, &result);
-
- if (error != 0)
- continue;
-
- if (result == NULL)
- break;
-
- d_name = std::string(dir_entry.d_name);
-
- if ((d_name == ".") || (d_name == "..") || (dir_entry.d_ino == 0))
- continue;
-
- name_node = dir_path + d_name + string("/name");
-
- ifstream infile(name_node.c_str());
-
- if (!infile)
- continue;
-
- infile >> name;
-
- if (!config::sensor_config::get_instance().is_supported(sensor_type, name))
- continue;
-
- model_id = name;
- find = true;
- break;
- }
-
- closedir(dir);
-
- return find;
-}
-
bool util::set_enable_node(const string &node_path, bool sensorhub_controlled, bool enable, int enable_bit)
{
int prev_status, status;
namespace util {
bool set_monotonic_clock(int fd);
- bool find_model_id(const std::string &sensor_type, std::string &model_id);
bool set_enable_node(const std::string &node_path, bool sensorhub_controlled, bool enable, int enable_bit = 0);
unsigned long long get_timestamp(void);