Merge "Removed warning - use of deprecated function" into tizen
authorKibak Yoon <kibak.yoon@samsung.com>
Mon, 5 Jan 2015 01:09:52 +0000 (17:09 -0800)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Mon, 5 Jan 2015 01:09:52 +0000 (17:09 -0800)
18 files changed:
packaging/sensord.spec
sensor_plugins.xml.in
src/libsensord/sensor_internal.h
src/libsensord/sensor_internal_deprecated.h
src/linear_accel/linear_accel_sensor.cpp
src/orientation/orientation_sensor.cpp
src/rotation_vector/CMakeLists.txt [new file with mode: 0644]
src/rotation_vector/rv/CMakeLists.txt [new file with mode: 0755]
src/rotation_vector/rv/rv_sensor.cpp [new file with mode: 0755]
src/rotation_vector/rv/rv_sensor.h [new file with mode: 0755]
src/sensor_fusion/orientation_filter.cpp
src/shared/iio_common.cpp
test/src/gyro.c
test/src/light.c
test/src/pressure.c
test/src/proxi.c
test/src/temperature.c
virtual_sensors.xml.in

index 2e1fff7..1d305ff 100755 (executable)
@@ -18,6 +18,7 @@ Source2:    sensord.socket
 %define orientation_state ON
 %define gravity_state ON
 %define linear_accel_state ON
+%define rv_state ON
 
 %define build_test_suite OFF
 
@@ -79,7 +80,7 @@ cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DACCEL=%{accel_state} \
        -DGYRO=%{gyro_state} -DPROXI=%{proxi_state} -DLIGHT=%{light_state} \
        -DGEO=%{geo_state} -DPRESSURE=%{pressure_state} -DTEMPERATURE=%{temperature_state} \
        -DORIENTATION=%{orientation_state} -DGRAVITY=%{gravity_state} \
-       -DLINEAR_ACCEL=%{linear_accel_state} \
+       -DLINEAR_ACCEL=%{linear_accel_state} -DRV=%{rv_state} \
        -DTEST_SUITE=%{build_test_suite}
 
 make %{?jobs:-j%jobs}
index f40f79a..aca8a81 100755 (executable)
@@ -20,5 +20,6 @@
                <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"/>
+               <MODULE path = "/usr/lib/sensord/librv_sensor.so"/>
        </SENSOR>
 </PLUGIN>
index bec1487..3bc8311 100755 (executable)
@@ -49,6 +49,7 @@ extern "C"
 #include <sensor_gravity.h>
 #include <sensor_linear_accel.h>
 #include <sensor_orientation.h>
+#include <sensor_rv.h>
 #include <sensor_temperature.h>
 
 
index f0a1a74..dc4a8b3 100755 (executable)
@@ -48,6 +48,7 @@ extern "C"
 #include <sensor_linear_accel.h>
 #include <sensor_orientation.h>
 #include <sensor_temperature.h>
+#include <sensor_rv.h>
 
 typedef struct {
        condition_op_t cond_op;
index 1af20bc..fb2dabd 100755 (executable)
@@ -273,11 +273,9 @@ int linear_accel_sensor::get_sensor_data(const unsigned int event_type, sensor_d
 
 bool linear_accel_sensor::get_properties(sensor_properties_t &properties)
 {
-       m_gravity_sensor->get_properties(properties);
+       m_accel_sensor->get_properties(properties);
        properties.name = "Linear Acceleration Sensor";
        properties.vendor = m_vendor;
-       properties.min_range = - 2 * GRAVITY;
-       properties.max_range = 2 * GRAVITY;
        properties.resolution = 0.000001;
 
        return true;
index dd0f818..7653ef3 100755 (executable)
@@ -436,7 +436,7 @@ bool orientation_sensor::get_properties(sensor_properties_t &properties)
                properties.min_range = -PI;
                properties.max_range = 2 * PI;
        }
-       properties.resolution = 0.000001;;
+       properties.resolution = 0.000001;
 
        properties.vendor = m_vendor;
        properties.name = SENSOR_NAME;
diff --git a/src/rotation_vector/CMakeLists.txt b/src/rotation_vector/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c111931
--- /dev/null
@@ -0,0 +1,4 @@
+IF("${RV}" STREQUAL "ON")
+add_subdirectory(rv)
+ENDIF()
+
diff --git a/src/rotation_vector/rv/CMakeLists.txt b/src/rotation_vector/rv/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..33ac289
--- /dev/null
@@ -0,0 +1,47 @@
+cmake_minimum_required(VERSION 2.6)
+project(rv 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 rv_sensor)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
+include_directories(${CMAKE_SOURCE_DIR}/src/sensor_fusion)
+
+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")
+       MESSAGE("add -DTARGET")
+ELSE("${ARCH}" MATCHES "^arm.*")
+       ADD_DEFINITIONS("-DSIMULATOR")
+       MESSAGE("add -DSIMULATOR")
+ENDIF("${ARCH}" MATCHES "^arm.*")
+
+add_definitions(-Wall -O3 -omit-frame-pointer)
+add_definitions(-DUSE_DLOG_LOG)
+#add_definitions(-Wall -g -D_DEBUG)
+add_definitions(-Iinclude)
+
+add_library(${SENSOR_NAME} SHARED
+               rv_sensor.cpp
+)
+
+target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm")
+
+install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord)
diff --git a/src/rotation_vector/rv/rv_sensor.cpp b/src/rotation_vector/rv/rv_sensor.cpp
new file mode 100755 (executable)
index 0000000..cee3a94
--- /dev/null
@@ -0,0 +1,390 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <math.h>
+#include <time.h>
+#include <sys/types.h>
+#include <dlfcn.h>
+#include <common.h>
+#include <sf_common.h>
+#include <rv_sensor.h>
+#include <sensor_plugin_loader.h>
+#include <orientation_filter.h>
+#include <cvirtual_sensor_config.h>
+
+#define SENSOR_NAME "RV_SENSOR"
+#define SENSOR_TYPE_RV         "ROTATION_VECTOR"
+
+#define ACCELEROMETER_ENABLED 0x01
+#define GYROSCOPE_ENABLED 0x02
+#define GEOMAGNETIC_ENABLED 0x04
+#define ORIENTATION_ENABLED 7
+
+#define INITIAL_VALUE -1
+
+#define MS_TO_US 1000
+
+#define ELEMENT_NAME                                                                                   "NAME"
+#define ELEMENT_VENDOR                                                                                 "VENDOR"
+#define ELEMENT_RAW_DATA_UNIT                                                                  "RAW_DATA_UNIT"
+#define ELEMENT_DEFAULT_SAMPLING_TIME                                                  "DEFAULT_SAMPLING_TIME"
+#define ELEMENT_ACCEL_STATIC_BIAS                                                              "ACCEL_STATIC_BIAS"
+#define ELEMENT_GYRO_STATIC_BIAS                                                               "GYRO_STATIC_BIAS"
+#define ELEMENT_GEOMAGNETIC_STATIC_BIAS                                                        "GEOMAGNETIC_STATIC_BIAS"
+#define ELEMENT_ACCEL_ROTATION_DIRECTION_COMPENSATION                  "ACCEL_ROTATION_DIRECTION_COMPENSATION"
+#define ELEMENT_GYRO_ROTATION_DIRECTION_COMPENSATION                   "GYRO_ROTATION_DIRECTION_COMPENSATION"
+#define ELEMENT_GEOMAGNETIC_ROTATION_DIRECTION_COMPENSATION            "GEOMAGNETIC_ROTATION_DIRECTION_COMPENSATION"
+#define ELEMENT_ACCEL_SCALE                                                                            "ACCEL_SCALE"
+#define ELEMENT_GYRO_SCALE                                                                             "GYRO_SCALE"
+#define ELEMENT_GEOMAGNETIC_SCALE                                                              "GEOMAGNETIC_SCALE"
+#define ELEMENT_MAGNETIC_ALIGNMENT_FACTOR                                              "MAGNETIC_ALIGNMENT_FACTOR"
+
+void pre_process_data(sensor_data<float> &data_out, const float *data_in, float *bias, int *sign, float scale)
+{
+       data_out.m_data.m_vec[0] = sign[0] * (data_in[0] - bias[0]) / scale;
+       data_out.m_data.m_vec[1] = sign[1] * (data_in[1] - bias[1]) / scale;
+       data_out.m_data.m_vec[2] = sign[2] * (data_in[2] - bias[2]) / scale;
+}
+
+rv_sensor::rv_sensor()
+: m_accel_sensor(NULL)
+, m_gyro_sensor(NULL)
+, m_magnetic_sensor(NULL)
+, m_x(-1)
+, m_y(-1)
+, m_z(-1)
+, m_w(-1)
+, m_accuracy(-1)
+, m_time(0)
+{
+       cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance();
+
+       m_name = string(SENSOR_NAME);
+       register_supported_event(ROTATION_VECTOR_EVENT_RAW_DATA_REPORT_ON_TIME);
+       m_enable_orientation = 0;
+
+       if (!config.get(SENSOR_TYPE_RV, ELEMENT_VENDOR, m_vendor)) {
+               ERR("[VENDOR] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_vendor = %s", m_vendor.c_str());
+
+       if (!config.get(SENSOR_TYPE_RV, ELEMENT_DEFAULT_SAMPLING_TIME, &m_default_sampling_time)) {
+               ERR("[DEFAULT_SAMPLING_TIME] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_default_sampling_time = %d", m_default_sampling_time);
+
+       if (!config.get(SENSOR_TYPE_RV, ELEMENT_ACCEL_STATIC_BIAS, m_accel_static_bias, 3)) {
+               ERR("[ACCEL_STATIC_BIAS] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_accel_static_bias = (%f, %f, %f)", m_accel_static_bias[0], m_accel_static_bias[1], m_accel_static_bias[2]);
+
+       if (!config.get(SENSOR_TYPE_RV, ELEMENT_GYRO_STATIC_BIAS, m_gyro_static_bias,3)) {
+               ERR("[GYRO_STATIC_BIAS] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_gyro_static_bias = (%f, %f, %f)", m_gyro_static_bias[0], m_gyro_static_bias[1], m_gyro_static_bias[2]);
+
+       if (!config.get(SENSOR_TYPE_RV, ELEMENT_GEOMAGNETIC_STATIC_BIAS, m_geomagnetic_static_bias, 3)) {
+               ERR("[GEOMAGNETIC_STATIC_BIAS] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_geomagnetic_static_bias = (%f, %f, %f)", m_geomagnetic_static_bias[0], m_geomagnetic_static_bias[1], m_geomagnetic_static_bias[2]);
+
+       if (!config.get(SENSOR_TYPE_RV, ELEMENT_ACCEL_ROTATION_DIRECTION_COMPENSATION, m_accel_rotation_direction_compensation, 3)) {
+               ERR("[ACCEL_ROTATION_DIRECTION_COMPENSATION] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_accel_rotation_direction_compensation = (%d, %d, %d)", m_accel_rotation_direction_compensation[0], m_accel_rotation_direction_compensation[1], m_accel_rotation_direction_compensation[2]);
+
+       if (!config.get(SENSOR_TYPE_RV, ELEMENT_GYRO_ROTATION_DIRECTION_COMPENSATION, m_gyro_rotation_direction_compensation, 3)) {
+               ERR("[GYRO_ROTATION_DIRECTION_COMPENSATION] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_gyro_rotation_direction_compensation = (%d, %d, %d)", m_gyro_rotation_direction_compensation[0], m_gyro_rotation_direction_compensation[1], m_gyro_rotation_direction_compensation[2]);
+
+       if (!config.get(SENSOR_TYPE_RV, ELEMENT_GEOMAGNETIC_ROTATION_DIRECTION_COMPENSATION, m_geomagnetic_rotation_direction_compensation, 3)) {
+               ERR("[GEOMAGNETIC_ROTATION_DIRECTION_COMPENSATION] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_geomagnetic_rotation_direction_compensation = (%d, %d, %d)", m_geomagnetic_rotation_direction_compensation[0], m_geomagnetic_rotation_direction_compensation[1], m_geomagnetic_rotation_direction_compensation[2]);
+
+       if (!config.get(SENSOR_TYPE_RV, ELEMENT_ACCEL_SCALE, &m_accel_scale)) {
+               ERR("[ACCEL_SCALE] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_accel_scale = %f", m_accel_scale);
+
+       if (!config.get(SENSOR_TYPE_RV, ELEMENT_GYRO_SCALE, &m_gyro_scale)) {
+               ERR("[GYRO_SCALE] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_gyro_scale = %f", m_gyro_scale);
+
+       if (!config.get(SENSOR_TYPE_RV, ELEMENT_GEOMAGNETIC_SCALE, &m_geomagnetic_scale)) {
+               ERR("[GEOMAGNETIC_SCALE] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_geomagnetic_scale = %f", m_geomagnetic_scale);
+
+       if (!config.get(SENSOR_TYPE_RV, ELEMENT_MAGNETIC_ALIGNMENT_FACTOR, &m_magnetic_alignment_factor)) {
+               ERR("[MAGNETIC_ALIGNMENT_FACTOR] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_magnetic_alignment_factor = %d", m_magnetic_alignment_factor);
+
+       m_interval = m_default_sampling_time * MS_TO_US;
+
+}
+
+rv_sensor::~rv_sensor()
+{
+       INFO("rv_sensor is destroyed!\n");
+}
+
+bool rv_sensor::init()
+{
+       m_accel_sensor = sensor_plugin_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR);
+       m_gyro_sensor = sensor_plugin_loader::get_instance().get_sensor(GYROSCOPE_SENSOR);
+       m_magnetic_sensor = sensor_plugin_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR);
+
+       if (!m_accel_sensor || !m_gyro_sensor || !m_magnetic_sensor) {
+               ERR("Failed to load sensors,  accel: 0x%x, gyro: 0x%x, mag: 0x%x",
+                       m_accel_sensor, m_gyro_sensor, m_magnetic_sensor);
+               return false;
+       }
+
+       INFO("%s is created!\n", sensor_base::get_name());
+
+       return true;
+}
+
+sensor_type_t rv_sensor::get_type(void)
+{
+       return ROTATION_VECTOR_SENSOR;
+}
+
+bool rv_sensor::on_start(void)
+{
+       AUTOLOCK(m_mutex);
+
+       m_accel_sensor->add_client(ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME);
+       m_accel_sensor->add_interval((int)this, (m_interval/MS_TO_US), false);
+       m_accel_sensor->start();
+       m_gyro_sensor->add_client(GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME);
+       m_gyro_sensor->add_interval((int)this, (m_interval/MS_TO_US), false);
+       m_gyro_sensor->start();
+       m_magnetic_sensor->add_client(GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME);
+       m_magnetic_sensor->add_interval((int)this, (m_interval/MS_TO_US), false);
+       m_magnetic_sensor->start();
+
+       activate();
+       return true;
+}
+
+bool rv_sensor::on_stop(void)
+{
+       AUTOLOCK(m_mutex);
+
+       m_accel_sensor->delete_client(ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME);
+       m_accel_sensor->delete_interval((int)this, false);
+       m_accel_sensor->stop();
+       m_gyro_sensor->delete_client(GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME);
+       m_gyro_sensor->delete_interval((int)this, false);
+       m_gyro_sensor->stop();
+       m_magnetic_sensor->delete_client(GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME);
+       m_magnetic_sensor->delete_interval((int)this, false);
+       m_magnetic_sensor->stop();
+
+       deactivate();
+       return true;
+}
+
+bool rv_sensor::add_interval(int client_id, unsigned int interval)
+{
+       AUTOLOCK(m_mutex);
+
+       m_accel_sensor->add_interval(client_id, interval, false);
+       m_gyro_sensor->add_interval(client_id, interval, false);
+       m_magnetic_sensor->add_interval(client_id, interval, false);
+
+       return sensor_base::add_interval(client_id, interval, false);
+}
+
+bool rv_sensor::delete_interval(int client_id)
+{
+       AUTOLOCK(m_mutex);
+
+       m_accel_sensor->delete_interval(client_id, false);
+       m_gyro_sensor->delete_interval(client_id, false);
+       m_magnetic_sensor->delete_interval(client_id, false);
+
+       return sensor_base::delete_interval(client_id, false);
+}
+
+void rv_sensor::synthesize(const sensor_event_t& event, vector<sensor_event_t> &outs)
+{
+       const float MIN_DELIVERY_DIFF_FACTOR = 0.75f;
+       unsigned long long diff_time;
+
+       sensor_event_t rv_event;
+       quaternion<float> quaternion_orientation;
+
+       if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) {
+               diff_time = event.data.timestamp - m_time;
+
+               if (m_time && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR))
+                       return;
+
+               pre_process_data(m_accel, event.data.values, m_accel_static_bias, m_accel_rotation_direction_compensation, m_accel_scale);
+
+               m_accel.m_time_stamp = event.data.timestamp;
+
+               m_enable_orientation |= ACCELEROMETER_ENABLED;
+       }
+       else if (event.event_type == GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME) {
+               diff_time = event.data.timestamp - m_time;
+
+               if (m_time && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR))
+                       return;
+
+               pre_process_data(m_gyro, event.data.values, m_gyro_static_bias, m_gyro_rotation_direction_compensation, m_gyro_scale);
+
+               m_gyro.m_time_stamp = event.data.timestamp;
+
+               m_enable_orientation |= GYROSCOPE_ENABLED;
+       }
+       else if (event.event_type == GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME) {
+               diff_time = event.data.timestamp - m_time;
+
+               if (m_time && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR))
+                       return;
+
+               pre_process_data(m_magnetic, event.data.values, m_geomagnetic_static_bias, m_geomagnetic_rotation_direction_compensation, m_geomagnetic_scale);
+
+               m_magnetic.m_time_stamp = event.data.timestamp;
+
+               m_enable_orientation |= GEOMAGNETIC_ENABLED;
+       }
+
+       if (m_enable_orientation == ORIENTATION_ENABLED) {
+               m_enable_orientation = 0;
+
+               m_orientation.m_pitch_phase_compensation = m_pitch_rotation_compensation;
+               m_orientation.m_roll_phase_compensation = m_roll_rotation_compensation;
+               m_orientation.m_azimuth_phase_compensation = m_azimuth_rotation_compensation;
+               m_orientation.m_magnetic_alignment_factor = m_magnetic_alignment_factor;
+
+               {
+                       AUTOLOCK(m_fusion_mutex);
+                       quaternion_orientation = m_orientation.get_quaternion(m_accel, m_gyro, m_magnetic);
+               }
+
+               rv_event.sensor_id = get_id();
+               rv_event.event_type = ROTATION_VECTOR_EVENT_RAW_DATA_REPORT_ON_TIME;
+               rv_event.data.accuracy = SENSOR_ACCURACY_GOOD;
+               rv_event.data.timestamp = get_timestamp();
+               rv_event.data.value_count = 4;
+               rv_event.data.values[0] = quaternion_orientation.m_quat.m_vec[1];
+               rv_event.data.values[1] = quaternion_orientation.m_quat.m_vec[2];
+               rv_event.data.values[2] = quaternion_orientation.m_quat.m_vec[3];
+               rv_event.data.values[3] = quaternion_orientation.m_quat.m_vec[0];
+
+               push(rv_event);
+
+               {
+                       AUTOLOCK(m_value_mutex);
+                       m_time = rv_event.data.value_count;
+                       m_x = rv_event.data.values[0];
+                       m_y = rv_event.data.values[1];
+                       m_z = rv_event.data.values[2];
+                       m_w = rv_event.data.values[3];
+               }
+       }
+
+       return;
+}
+
+int rv_sensor::get_sensor_data(unsigned int data_id, sensor_data_t &data)
+{
+       if (data_id != ROTATION_VECTOR_BASE_DATA_SET)
+               return -1;
+
+       data.accuracy = SENSOR_ACCURACY_GOOD;
+
+       AUTOLOCK(m_value_mutex);
+       data.timestamp = m_time;
+       data.values[0] = m_x;
+       data.values[1] = m_y;
+       data.values[2] = m_z;
+       data.values[3] = m_w;
+       data.value_count = 4;
+
+       return 0;
+}
+
+bool rv_sensor::get_properties(sensor_properties_t &properties)
+{
+       properties.vendor = m_vendor;
+       properties.name = SENSOR_NAME;
+       properties.min_range = 0;
+       properties.max_range = 1;
+       properties.resolution = 0.000001;
+       properties.fifo_count = 0;
+       properties.max_batch_count = 0;
+       properties.min_interval = 1;
+
+       return true;
+}
+
+extern "C" sensor_module* create(void)
+{
+       rv_sensor *sensor;
+
+       try {
+               sensor = new(std::nothrow) rv_sensor;
+       } catch (int err) {
+               ERR("Failed to create module, err: %d, cause: %s", err, strerror(err));
+               return NULL;
+       }
+
+       sensor_module *module = new(std::nothrow) sensor_module;
+       retvm_if(!module || !sensor, NULL, "Failed to allocate memory");
+
+       module->sensors.push_back(sensor);
+       return module;
+}
diff --git a/src/rotation_vector/rv/rv_sensor.h b/src/rotation_vector/rv/rv_sensor.h
new file mode 100755 (executable)
index 0000000..3d84a80
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * 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 _RV_SENSOR_H_
+#define _RV_SENSOR_H_
+
+#include <sensor_internal.h>
+#include <virtual_sensor.h>
+#include <orientation_filter.h>
+
+class rv_sensor : public virtual_sensor {
+public:
+       rv_sensor();
+       virtual ~rv_sensor();
+
+       bool init(void);
+
+       void synthesize(const sensor_event_t &event, vector<sensor_event_t> &outs);
+
+       bool add_interval(int client_id, unsigned int interval);
+       bool delete_interval(int client_id);
+       bool get_properties(sensor_properties_t &properties);
+       sensor_type_t get_type(void);
+
+       int get_sensor_data(const unsigned int data_id, sensor_data_t &data);
+
+private:
+       sensor_base *m_accel_sensor;
+       sensor_base *m_gyro_sensor;
+       sensor_base *m_magnetic_sensor;
+
+       sensor_data<float> m_accel;
+       sensor_data<float> m_gyro;
+       sensor_data<float> m_magnetic;
+
+       cmutex m_value_mutex;
+
+       orientation_filter<float> m_orientation;
+
+       unsigned int m_enable_orientation;
+
+       float m_x;
+       float m_y;
+       float m_z;
+       float m_w;
+       int m_accuracy;
+       unsigned long long m_time;
+       unsigned int m_interval;
+
+       string m_vendor;
+       string m_raw_data_unit;
+       int m_default_sampling_time;
+       float m_accel_static_bias[3];
+       float m_gyro_static_bias[3];
+       float m_geomagnetic_static_bias[3];
+       int m_accel_rotation_direction_compensation[3];
+       int m_gyro_rotation_direction_compensation[3];
+       int m_geomagnetic_rotation_direction_compensation[3];
+       float m_accel_scale;
+       float m_gyro_scale;
+       float m_geomagnetic_scale;
+       int m_magnetic_alignment_factor;
+       int m_azimuth_rotation_compensation;
+       int m_pitch_rotation_compensation;
+       int m_roll_rotation_compensation;
+
+       bool on_start(void);
+       bool on_stop(void);
+};
+
+#endif /*_RV_SENSOR_H_*/
index 05537a3..5e0a354 100644 (file)
 #define QWB_CONST      ((2 * (ZIGMA_W * ZIGMA_W)) / TAU_W)
 #define F_CONST                (-1 / TAU_W)
 
+#define NEGLIGIBLE_VAL 0.0000001
+
+#define ABS(val) (((val) < 0) ? -(val) : (val))
+
 // M-matrix, V-vector, MxN=> matrix dimension, R-RowCount, C-Column count
 #define M3X3R  3
 #define M3X3C  3
@@ -96,8 +100,6 @@ template <typename TYPE>
 inline void orientation_filter<TYPE>::initialize_sensor_data(const sensor_data<TYPE> accel,
                const sensor_data<TYPE> gyro, const sensor_data<TYPE> magnetic)
 {
-       vect<TYPE> acc_data(V1x3S);
-       vect<TYPE> gyr_data(V1x3S);
        unsigned long long sample_interval_gyro = SAMPLE_INTV;
 
        m_accel.m_data = accel.m_data;
@@ -258,10 +260,8 @@ inline void orientation_filter<TYPE>::measurement_update()
        matrix<TYPE> gain(M6X6R, M6X6C);
        TYPE iden = 0;
 
-       for (int j = 0; j < M6X6C; j++)
-       {
-               for (int i = 0; i < M6X6R; i++)
-               {
+       for (int j=0; j<M6X6C; ++j) {
+               for (int i=0; i<M6X6R; ++i)     {
                        gain.m_mat[i][j] = m_pred_cov.m_mat[j][i] / (m_pred_cov.m_mat[j][j] + m_aid_cov.m_mat[j][j]);
 
                        m_state_new.m_vec[i] = m_state_new.m_vec[i] + gain.m_mat[i][j] * m_state_error.m_vec[j];
@@ -271,8 +271,11 @@ inline void orientation_filter<TYPE>::measurement_update()
                        else
                                iden = 0;
 
-                       m_pred_cov.m_mat[i][j] = (iden - (gain.m_mat[i][j] * m_measure_mat.m_mat[j][i])) *
-                                       m_pred_cov.m_mat[i][j];
+                       m_pred_cov.m_mat[j][i] = (iden - (gain.m_mat[i][j] * m_measure_mat.m_mat[j][i])) *
+                                       m_pred_cov.m_mat[j][i];
+
+                       if (ABS(m_pred_cov.m_mat[j][i]) < NEGLIGIBLE_VAL)
+                               m_pred_cov.m_mat[j][i] = NEGLIGIBLE_VAL;
                }
        }
 
index a127ca0..7cfcba5 100644 (file)
@@ -103,7 +103,9 @@ int add_channel_to_array(const char *device_dir, const char *ch_name, struct cha
        if (i == 0)
                return -1;
 
-       asprintf(&(channel->prefix_str), "%s", ch_name);
+       if (asprintf(&(channel->prefix_str), "%s", ch_name) == -1)
+               return -1;
+
        channel->is_en = 1;
        channel->scale = 1.0;
        channel->offset = 0.0;
index b74d98d..915971b 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdbool.h>
 #include <sensor_common.h>
 #include <unistd.h>
+#include <string.h>
 
 static GMainLoop *mainloop;
 
index 454d5c2..e2b6e69 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdbool.h>
 #include <sensor_common.h>
 #include <unistd.h>
+#include <string.h>
 
 static GMainLoop *mainloop;
 
index a92ad59..12f5734 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdbool.h>
 #include <sensor_common.h>
 #include <unistd.h>
+#include <string.h>
 
 static GMainLoop *mainloop;
 
index 70185bd..4d3092d 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdbool.h>
 #include <sensor_common.h>
 #include <unistd.h>
+#include <string.h>
 
 static GMainLoop *mainloop;
 
index ffdb2e9..3f852c8 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdbool.h>
 #include <sensor_common.h>
 #include <unistd.h>
+#include <string.h>
 
 static GMainLoop *mainloop;
 
index 42c9d72..680745e 100644 (file)
                <ACCEL_SCALE value="1" />
                <LINEAR_ACCEL_SIGN_COMPENSATION value1="1" value2="1" value3="1" />
        </LINEAR_ACCEL>
+
+       <ROTATION_VECTOR>
+               <NAME value="RV_SENSOR" />
+               <VENDOR value="SAMSUNG" />
+               <DEFAULT_SAMPLING_TIME value="100" />
+               <ACCEL_STATIC_BIAS value1="0" value2="0" value3="0" />
+               <GYRO_STATIC_BIAS value1="0" value2="0" value3="0" />
+               <GEOMAGNETIC_STATIC_BIAS value1="0" value2="0" value3="0" />
+               <ACCEL_ROTATION_DIRECTION_COMPENSATION value1="-1" value2="-1" value3="-1" />
+               <GYRO_ROTATION_DIRECTION_COMPENSATION value1="1" value2="1" value3="1" />
+               <GEOMAGNETIC_ROTATION_DIRECTION_COMPENSATION value1="-1" value2="-1" value3="-1" />
+               <ACCEL_SCALE value="1" />
+               <GYRO_SCALE value="1146" />
+               <GEOMAGNETIC_SCALE value="1" />
+               <MAGNETIC_ALIGNMENT_FACTOR value="1" />
+       </ROTATION_VECTOR>
 </VIRTUAL_SENSOR>