%define light_state ON
%define geo_state ON
%define pressure_state ON
-%define temperature_state OFF
+%define temperature_state ON
%define orientation_state ON
%define gravity_state ON
%define linear_accel_state ON
<MODULE path = "/usr/lib/sensord/libproxi_sensor_hal.so"/>
<MODULE path = "/usr/lib/sensord/liblight_sensor_hal.so"/>
<MODULE path = "/usr/lib/sensord/libpressure_sensor_hal.so"/>
+ <MODULE path = "/usr/lib/sensord/libtemperature_sensor_hal.so"/>
</HAL>
<SENSOR>
<MODULE path = "/usr/lib/sensord/liborientation_sensor.so"/>
<MODULE path = "/usr/lib/sensord/libgravity_sensor.so"/>
<MODULE path = "/usr/lib/sensord/liblinear_accel_sensor.so"/>
+ <MODULE path = "/usr/lib/sensord/libtemperature_sensor.so"/>
</SENSOR>
</PLUGIN>
<TEMPERATURE_OFFSET value="42.5"/>
</MODEL>
</PRESSURE>
+
+ <TEMPERATURE>
+ <MODEL id="LPS331">
+ <NAME value="LPS331" />
+ <VENDOR value="ST Microelectronics"/>
+ <RAW_DATA_UNIT value="0.01"/>
+ <RESOLUTION value="1"/>
+ </MODEL>
+ </TEMPERATURE>
</SENSOR>
IF("${PRESSURE}" STREQUAL "ON")
add_subdirectory(pressure)
ENDIF()
+IF("${TEMPERATURE}" STREQUAL "ON")
+add_subdirectory(temperature)
+ENDIF()
IF("${ORIENTATION}" STREQUAL "ON")
set(SENSOR_FUSION_ENABLE "1")
set(ORIENTATION_ENABLE "1")
#include <sensor_motion.h>
#include <sensor_gyro.h>
#include <sensor_pressure.h>
+#include <sensor_temperature.h>
#include <sensor_gravity.h>
#include <sensor_linear_accel.h>
#include <sensor_orientation.h>
--- /dev/null
+/*
+ * libsensord
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SENSOR_TEMPERATURE_H__
+#define __SENSOR_TEMPERATURE_H__
+
+//! Pre-defined events for the temperature scope sensor
+//! Sensor Plugin developer can add more event to their own headers
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * @defgroup SENSOR_TEMPERATURE temperature Sensor
+ * @ingroup SENSOR_FRAMEWORK
+ *
+ * These APIs are used to control the temperature sensor.
+ * @{
+ */
+
+enum temperature_data_id {
+ TEMPERATURE_BASE_DATA_SET = (TEMPERATURE_SENSOR << 16) | 0x0001,
+};
+
+enum temperature_evet_type {
+ TEMPERATURE_EVENT_RAW_DATA_REPORT_ON_TIME = (TEMPERATURE_SENSOR << 16) | 0x0001,
+};
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+//! End of a file
LINEAR_ACCEL_SENSOR,
ROTATION_VECTOR_SENSOR,
ORIENTATION_SENSOR,
+ TEMPERATURE_SENSOR
} sensor_type_t;
typedef struct sensor_data_t {
--- /dev/null
+cmake_minimum_required(VERSION 2.6)
+project(temperature CXX)
+
+# to install pkgconfig setup file.
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(VERSION 1.0)
+
+SET(SENSOR_NAME temperature_sensor)
+SET(SENSOR_HAL_NAME temperature_sensor_hal)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
+
+include(FindPkgConfig)
+pkg_check_modules(rpkgs REQUIRED vconf)
+add_definitions(${rpkgs_CFLAGS} -DUSE_ONLY_ONE_MODULE -DUSE_LCD_TYPE_CHECK)
+
+set(PROJECT_MAJOR_VERSION "0")
+set(PROJECT_MINOR_VERSION "0")
+set(PROJECT_RELEASE_VERSION "1")
+set(CMAKE_VERBOSE_MAKEFILE OFF)
+
+
+FIND_PROGRAM(UNAME NAMES uname)
+EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
+IF("${ARCH}" MATCHES "^arm.*")
+ ADD_DEFINITIONS("-DTARGET -DHWREV_CHECK")
+ MESSAGE("add -DTARGET -DHWREV_CHECK")
+ELSE("${ARCH}" MATCHES "^arm.*")
+ ADD_DEFINITIONS("-DSIMULATOR")
+ MESSAGE("add -DSIMULATOR")
+ENDIF("${ARCH}" MATCHES "^arm.*")
+
+add_definitions(-Wall -O3 -omit-frame-pointer)
+#add_definitions(-Wall -g -D_DEBUG)
+add_definitions(-DUSE_DLOG_LOG)
+add_definitions(-Iinclude)
+
+add_library(${SENSOR_NAME} SHARED
+ temperature_sensor.cpp
+ )
+
+add_library(${SENSOR_HAL_NAME} SHARED
+ temperature_sensor_hal.cpp
+ )
+
+target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm")
+target_link_libraries(${SENSOR_HAL_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS})
+
+install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord)
+install(TARGETS ${SENSOR_HAL_NAME} DESTINATION lib/sensord)
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <common.h>
+#include <sf_common.h>
+#include <temperature_sensor.h>
+#include <sensor_plugin_loader.h>
+
+#define SENSOR_NAME "TEMPERATURE_SENSOR"
+#define NO_OF_DATA_VAL 1
+
+temperature_sensor::temperature_sensor()
+: m_sensor_hal(NULL)
+, m_resolution(0.0f)
+{
+ m_name = string(SENSOR_NAME);
+
+ register_supported_event(TEMPERATURE_EVENT_RAW_DATA_REPORT_ON_TIME);
+
+ physical_sensor::set_poller(temperature_sensor::working, this);
+}
+
+temperature_sensor::~temperature_sensor()
+{
+ INFO("temperature_sensor is destroyed!");
+}
+
+bool temperature_sensor::init()
+{
+ m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(TEMPERATURE_SENSOR);
+
+ if (!m_sensor_hal)
+ {
+ ERR("cannot load sensor_hal[%s]", sensor_base::get_name());
+ return false;
+ }
+
+ sensor_properties_t properties;
+
+ if (!m_sensor_hal->get_properties(properties))
+ {
+ ERR("sensor->get_properties() is failed!\n");
+ return false;
+ }
+
+ m_resolution = properties.sensor_resolution;
+
+ INFO("%s is created!", sensor_base::get_name());
+
+ return true;
+}
+
+sensor_type_t temperature_sensor::get_type(void)
+{
+ return TEMPERATURE_SENSOR;
+}
+
+bool temperature_sensor::working(void *inst)
+{
+ temperature_sensor *sensor = (temperature_sensor*)inst;
+ return sensor->process_event();
+}
+
+bool temperature_sensor::process_event(void)
+{
+ sensor_event_t event;
+
+ if (!m_sensor_hal->is_data_ready(true))
+ return true;
+
+ m_sensor_hal->get_sensor_data(event.data);
+
+ AUTOLOCK(m_client_info_mutex);
+
+ if (get_client_cnt(TEMPERATURE_EVENT_RAW_DATA_REPORT_ON_TIME))
+ {
+ event.event_type = TEMPERATURE_EVENT_RAW_DATA_REPORT_ON_TIME;
+ raw_to_base(event.data);
+ push(event);
+ }
+
+ return true;
+}
+
+bool temperature_sensor::on_start(void)
+{
+ if (!m_sensor_hal->enable())
+ {
+ ERR("m_sensor_hal start fail\n");
+ return false;
+ }
+
+ return start_poll();
+}
+
+bool temperature_sensor::on_stop(void)
+{
+ if (!m_sensor_hal->disable())
+ {
+ ERR("m_sensor_hal stop fail\n");
+ return false;
+ }
+
+ return stop_poll();
+}
+
+bool temperature_sensor::get_properties(sensor_properties_t &properties)
+{
+ return m_sensor_hal->get_properties(properties);
+}
+
+int temperature_sensor::get_sensor_data(unsigned int type, sensor_data_t &data)
+{
+ int ret;
+
+ ret = m_sensor_hal->get_sensor_data(data);
+
+ if (ret < 0)
+ return -1;
+
+ if (type == TEMPERATURE_BASE_DATA_SET)
+ {
+ raw_to_base(data);
+ return 0;
+ }
+
+ return -1;
+}
+
+bool temperature_sensor::set_interval(unsigned long interval)
+{
+ AUTOLOCK(m_mutex);
+
+ INFO("Polling interval is set to %dms", interval);
+
+ return m_sensor_hal->set_interval(interval);
+}
+
+void temperature_sensor::raw_to_base(sensor_data_t &data)
+{
+ data.values_num = NO_OF_DATA_VAL;
+}
+
+extern "C" void *create(void)
+{
+ temperature_sensor *inst;
+
+ try
+ {
+ inst = new temperature_sensor();
+ }
+ catch (int err)
+ {
+ ERR("temperature_sensor class create fail , errno : %d , errstr : %s\n", err, strerror(err));
+ return NULL;
+ }
+
+ return (void*)inst;
+}
+
+extern "C" void destroy(void *inst)
+{
+ delete (temperature_sensor*)inst;;
+}
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _TEMPERATURE_SENSOR_H_
+#define _TEMPERATURE_SENSOR_H_
+
+#include <sensor_common.h>
+
+#include <physical_sensor.h>
+#include <sensor_hal.h>
+
+class temperature_sensor : public physical_sensor {
+public:
+ temperature_sensor();
+ virtual ~temperature_sensor();
+
+ bool init();
+ sensor_type_t get_type(void);
+
+ static bool working(void *inst);
+
+ bool set_interval(unsigned long interval);
+ virtual bool get_properties(sensor_properties_t &properties);
+ int get_sensor_data(unsigned int type, sensor_data_t &data);
+
+private:
+ sensor_hal *m_sensor_hal;
+ float m_temperature;
+ float m_resolution;
+
+ virtual bool on_start(void);
+ virtual bool on_stop(void);
+ bool process_event(void);
+ void raw_to_base(sensor_data_t &data);
+};
+
+#endif
--- /dev/null
+/*
+ * temperature_sensor_hal
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <dirent.h>
+
+#include <linux/input.h>
+#include <cconfig.h>
+
+#include <temperature_sensor_hal.h>
+#include <fstream>
+#include <cconfig.h>
+#include <iio_common.h>
+
+using std::ifstream;
+using config::CConfig;
+
+#define SENSOR_TYPE_TEMPERATURE "TEMPERATURE"
+#define ELEMENT_NAME "NAME"
+#define ELEMENT_VENDOR "VENDOR"
+#define ELEMENT_RAW_DATA_UNIT "RAW_DATA_UNIT"
+
+#define ENABLE_VAL true
+#define DISABLE_VAL false
+#define NO_FLAG 0
+#define TIMEOUT 1
+#define INITIAL_TIME 0
+#define NO_OF_DATA_VAL 1
+
+temperature_sensor_hal::temperature_sensor_hal()
+: m_temperature(0)
+, m_sensorhub_supported(false)
+{
+ int fd, ret;
+ string file_name;
+
+ if (!check_hw_node())
+ {
+ ERR("check_hw_node() fail");
+ throw ENXIO;
+ }
+
+ CConfig &config = CConfig::get_instance();
+
+ if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_VENDOR, m_vendor))
+ {
+ ERR("[VENDOR] is empty\n");
+ throw ENXIO;
+ }
+
+ INFO("m_vendor = %s", m_vendor.c_str());
+
+ if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_NAME, m_chip_name))
+ {
+ ERR("[NAME] is empty\n");
+ throw ENXIO;
+ }
+
+ INFO("m_chip_name = %s", m_chip_name.c_str());
+
+ double raw_data_unit;
+
+ if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_RAW_DATA_UNIT, raw_data_unit))
+ {
+ ERR("[RAW_DATA_UNIT] is empty\n");
+ throw ENXIO;
+ }
+
+ m_raw_data_unit = (float)(raw_data_unit);
+ INFO("m_raw_data_unit = %f\n", m_raw_data_unit);
+
+ file_name = string(IIO_DIR) + m_temperature_dir + string(TEMP_SCALE);
+ if (!read_node_value<int>(file_name, m_temp_scale))
+ throw ENXIO;
+
+ file_name = string(IIO_DIR) + m_temperature_dir + string(TEMP_OFFSET);
+ if (!read_node_value<float>(file_name, m_temp_offset))
+ throw ENXIO;
+
+ INFO("Temperature scale:%d", m_temp_scale);
+ INFO("Temperature offset:%f", m_temp_offset);
+
+ INFO("temperature_sensor_hal is created!\n");
+}
+
+temperature_sensor_hal::~temperature_sensor_hal()
+{
+ INFO("temperature_sensor_hal is destroyed!\n");
+}
+
+string temperature_sensor_hal::get_model_id(void)
+{
+ return m_model_id;
+}
+
+sensor_type_t temperature_sensor_hal::get_type(void)
+{
+ return TEMPERATURE_SENSOR;
+}
+
+bool temperature_sensor_hal::enable_resource(bool enable)
+{
+ INFO("Enable not supported");
+ return true;
+}
+
+bool temperature_sensor_hal::enable(void)
+{
+ enable_resource(ENABLE_VAL);
+ return true;
+}
+
+bool temperature_sensor_hal::disable(void)
+{
+ enable_resource(DISABLE_VAL);
+ return true;
+}
+
+bool temperature_sensor_hal::set_interval(unsigned long val)
+{
+ return true;
+}
+
+bool temperature_sensor_hal::update_value(bool wait)
+{
+ int raw_temp_count;
+
+ if (!read_node_value<int>(m_temp_node, raw_temp_count))
+ return false;
+ m_temperature = m_temp_offset + ((float)raw_temp_count)/((float)m_temp_scale);
+ return true;
+}
+
+bool temperature_sensor_hal::is_data_ready(bool wait)
+{
+ bool ret;
+ ret = update_value(wait);
+ return ret;
+}
+
+int temperature_sensor_hal::get_sensor_data(sensor_data_t &data)
+{
+ AUTOLOCK(m_value_mutex);
+ data.data_accuracy = SENSOR_ACCURACY_GOOD;
+ data.data_unit_idx = SENSOR_UNIT_CELSIUS;
+ data.timestamp = INITIAL_TIME;
+ data.values_num = NO_OF_DATA_VAL;
+ data.values[0] = m_temperature;
+ return 0;
+}
+
+bool temperature_sensor_hal::get_properties(sensor_properties_t &properties)
+{
+ properties.sensor_unit_idx = SENSOR_UNIT_CELSIUS;
+ snprintf(properties.sensor_name, sizeof(properties.sensor_name), "%s", m_chip_name.c_str());
+ snprintf(properties.sensor_vendor, sizeof(properties.sensor_vendor), "%s", m_vendor.c_str());
+ properties.sensor_resolution = m_raw_data_unit;
+ return true;
+}
+
+bool temperature_sensor_hal::is_sensorhub_supported(void)
+{
+ return false;
+}
+
+bool temperature_sensor_hal::check_hw_node(void)
+{
+ string name_node;
+ string hw_name;
+ string file_name;
+
+ DIR *main_dir = NULL;
+ struct dirent *dir_entry = NULL;
+ bool find_node = false;
+
+ INFO("======================start check_hw_node=============================\n");
+
+ m_sensorhub_supported = is_sensorhub_supported();
+
+ main_dir = opendir(IIO_DIR);
+
+ if (!main_dir)
+ {
+ ERR("Could not open IIO directory\n");
+ return false;
+ }
+
+ while (!find_node)
+ {
+ dir_entry = readdir(main_dir);
+ if(dir_entry == NULL)
+ break;
+
+ if ((strncasecmp(dir_entry->d_name ,".",1 ) != 0) && (strncasecmp(dir_entry->d_name ,"..",2 ) != 0) && (dir_entry->d_ino != 0))
+ {
+ file_name = string(IIO_DIR) + string(dir_entry->d_name) + string(NAME_NODE);
+
+ ifstream infile(file_name.c_str());
+
+ if (!infile)
+ continue;
+
+ infile >> hw_name;
+
+ if (strncmp(dir_entry->d_name, IIO_DEV_BASE_NAME, IIO_DEV_STR_LEN) == 0)
+ {
+ if (CConfig::get_instance().is_supported(SENSOR_TYPE_TEMPERATURE, hw_name) == true)
+ {
+ m_model_id = hw_name;
+ m_temperature_dir = string(dir_entry->d_name);
+ m_temp_node = string(IIO_DIR) + m_temperature_dir + string(TEMP_RAW);
+
+ INFO("m_model_id = %s", m_model_id.c_str());
+ INFO("m_temperature_dir = %s", m_temperature_dir.c_str());
+
+ find_node = true;
+ break;
+ }
+ }
+ }
+ }
+
+ closedir(main_dir);
+ return find_node;
+}
+
+extern "C" void *create(void)
+{
+ temperature_sensor_hal *inst;
+
+ try
+ {
+ inst = new temperature_sensor_hal();
+ }
+ catch (int err)
+ {
+ ERR("temperature_sensor_hal class create fail , errno : %d , errstr : %s\n", err, strerror(err));
+ return NULL;
+ }
+
+ return (void*)inst;
+}
+
+extern "C" void destroy(void *inst)
+{
+ delete (temperature_sensor_hal*)inst;
+}
--- /dev/null
+/*
+ * temperature_sensor_hal
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _TEMPERATURE_SENSOR_HAL_H_
+#define _TEMPERATURE_SENSOR_HAL_H_
+
+#include <sensor_hal.h>
+#include <string>
+
+
+#define IIO_DIR "/sys/bus/iio/devices/"
+#define IIO_DEV_BASE_NAME "iio:device"
+#define IIO_DEV_STR_LEN 10
+#define NAME_NODE "/name"
+#define TEMP_OFFSET "/in_temp_offset"
+#define TEMP_SCALE "/in_temp_scale"
+#define TEMP_RAW "/in_temp_raw"
+
+using std::string;
+
+class temperature_sensor_hal : public sensor_hal
+{
+public:
+ temperature_sensor_hal();
+ virtual ~temperature_sensor_hal();
+ string get_model_id(void);
+ sensor_type_t get_type(void);
+ bool enable(void);
+ bool disable(void);
+ bool set_interval(unsigned long val);
+ bool is_data_ready(bool wait);
+ virtual int get_sensor_data(sensor_data_t &data);
+ bool get_properties(sensor_properties_t &properties);
+
+private:
+ int m_temperature;
+
+ string m_model_id;
+ string m_vendor;
+ string m_chip_name;
+
+ int m_temp_scale;
+ float m_raw_data_unit;
+ float m_temp_offset;
+
+ string m_temp_node;
+ string m_temperature_dir;
+
+ bool m_sensorhub_supported;
+
+ cmutex m_value_mutex;
+
+ bool update_value(bool wait);
+ bool is_sensorhub_supported(void);
+ bool check_hw_node(void);
+ bool enable_resource(bool enable);
+};
+#endif /*_TEMPERATURE_SENSOR_HAL_CLASS_H_*/