4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
26 #include <sys/types.h>
30 #include <sf_common.h>
31 #include <lib_sensor_fusion.h>
32 #include <sensor_plugin_loader.h>
34 #define SENSOR_NAME "Sensor Fusion"
36 lib_sensor_fusion::lib_sensor_fusion()
38 m_name = string(SENSOR_NAME);
41 lib_sensor_fusion::~lib_sensor_fusion()
45 bool lib_sensor_fusion::init(void)
47 m_accel_sensor = sensor_plugin_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR);
48 m_gyro_sensor = sensor_plugin_loader::get_instance().get_sensor(GYROSCOPE_SENSOR);
49 m_magnetic_sensor = sensor_plugin_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR);
51 if (!m_accel_sensor || !m_gyro_sensor || !m_magnetic_sensor) {
52 ERR("Fail to load sensors, accel: 0x%x, gyro: 0x%x, mag: 0x%x",
53 m_accel_sensor, m_gyro_sensor, m_magnetic_sensor);
57 INFO("%s is created!", sensor_base::get_name());
61 bool lib_sensor_fusion::on_start(void)
65 m_accel_sensor->add_client(ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME);
66 m_accel_sensor->start();
67 m_gyro_sensor->add_client(GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME);
68 m_gyro_sensor->start();
69 m_magnetic_sensor->add_client(GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME);
70 m_magnetic_sensor->start();
74 bool lib_sensor_fusion::on_stop(void)
76 m_accel_sensor->delete_client(ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME);
77 m_accel_sensor->stop();
78 m_gyro_sensor->delete_client(GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME);
79 m_gyro_sensor->stop();
80 m_magnetic_sensor->delete_client(GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME);
81 m_magnetic_sensor->stop();
85 bool lib_sensor_fusion::add_interval(int client_id, unsigned int interval)
89 m_accel_sensor->add_interval(client_id, interval, true);
90 m_gyro_sensor->add_interval(client_id, interval, true);
91 m_magnetic_sensor->add_interval(client_id, interval, true);
95 bool lib_sensor_fusion::delete_interval(int client_id)
99 m_accel_sensor->delete_interval(client_id, true);
100 m_gyro_sensor->delete_interval(client_id, true);
101 m_magnetic_sensor->delete_interval(client_id, true);
105 bool lib_sensor_fusion::get_properties(sensor_properties_t &properties)
107 properties.sensor_unit_idx = SENSOR_UNDEFINED_UNIT;
108 properties.sensor_min_range = 0;
109 properties.sensor_max_range = 1;
110 properties.sensor_resolution = 1;
111 strncpy(properties.sensor_vendor, "Samsung", MAX_KEY_LENGTH);
112 strncpy(properties.sensor_name, SENSOR_NAME, MAX_KEY_LENGTH);
116 void lib_sensor_fusion::fuse(const sensor_event_t &event)
121 bool lib_sensor_fusion::get_rotation_matrix(arr33_t &rot)
126 bool lib_sensor_fusion::get_attitude(float &x, float &y, float &z, float &w)
131 bool lib_sensor_fusion::get_gyro_bias(float &x, float &y, float &z)
136 bool lib_sensor_fusion::get_rotation_vector(float &x, float &y, float &z, float &w, float &heading_accuracy)
141 bool lib_sensor_fusion::get_linear_acceleration(float &x, float &y, float &z)
146 bool lib_sensor_fusion::get_gravity(float &x, float &y, float &z)
151 bool lib_sensor_fusion::get_rotation_vector_6axis(float &x, float &y, float &z, float &w, float &heading_accuracy)
156 bool lib_sensor_fusion::get_geomagnetic_rotation_vector(float &x, float &y, float &z, float &w)
161 bool lib_sensor_fusion::get_orientation(float &azimuth, float &pitch, float &roll)
166 extern "C" void *create(void)
168 lib_sensor_fusion *inst;
171 inst = new lib_sensor_fusion();
173 ERR("lib_sensor_fusion class create fail , errno : %d , errstr : %s", err, strerror(err));
180 extern "C" void destroy(void *inst)
182 delete (lib_sensor_fusion *)inst;