Adding AK8975 geo-sensor info in sensors.xml.in required by geo-plugin
[platform/core/system/sensord.git] / src / sensor_fusion / lib_sensor_fusion.cpp
1 /*
2  * sensord
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <errno.h>
24 #include <math.h>
25 #include <time.h>
26 #include <sys/types.h>
27 #include <dlfcn.h>
28 #include <sensor.h>
29 #include <common.h>
30 #include <sf_common.h>
31 #include <lib_sensor_fusion.h>
32 #include <sensor_plugin_loader.h>
33
34 #define SENSOR_NAME "Sensor Fusion"
35
36 lib_sensor_fusion::lib_sensor_fusion()
37 {
38         m_name = string(SENSOR_NAME);
39 }
40
41 lib_sensor_fusion::~lib_sensor_fusion()
42 {
43 }
44
45 bool lib_sensor_fusion::init(void)
46 {
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);
50
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);
54                 return false;
55         }
56
57         INFO("%s is created!", sensor_base::get_name());
58         return true;
59 }
60
61 bool lib_sensor_fusion::on_start(void)
62 {
63         AUTOLOCK(m_mutex);
64
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();
71         return true;
72 }
73
74 bool lib_sensor_fusion::on_stop(void)
75 {
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();
82         return true;
83 }
84
85 bool lib_sensor_fusion::add_interval(int client_id, unsigned int interval)
86 {
87         AUTOLOCK(m_mutex);
88
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);
92         return true;
93 }
94
95 bool lib_sensor_fusion::delete_interval(int client_id)
96 {
97         AUTOLOCK(m_mutex);
98
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);
102         return true;
103 }
104
105 bool lib_sensor_fusion::get_properties(sensor_properties_t &properties)
106 {
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);
113         return true;
114 }
115
116 void lib_sensor_fusion::fuse(const sensor_event_t &event)
117 {
118         return;
119 }
120
121 bool lib_sensor_fusion::get_rotation_matrix(arr33_t &rot)
122 {
123         return true;
124 }
125
126 bool lib_sensor_fusion::get_attitude(float &x, float &y, float &z, float &w)
127 {
128         return true;
129 }
130
131 bool lib_sensor_fusion::get_gyro_bias(float &x, float &y, float &z)
132 {
133         return true;
134 }
135
136 bool lib_sensor_fusion::get_rotation_vector(float &x, float &y, float &z, float &w, float &heading_accuracy)
137 {
138         return true;
139 }
140
141 bool lib_sensor_fusion::get_linear_acceleration(float &x, float &y, float &z)
142 {
143         return true;
144 }
145
146 bool lib_sensor_fusion::get_gravity(float &x, float &y, float &z)
147 {
148         return true;
149 }
150
151 bool lib_sensor_fusion::get_rotation_vector_6axis(float &x, float &y, float &z, float &w, float &heading_accuracy)
152 {
153         return true;
154 }
155
156 bool lib_sensor_fusion::get_geomagnetic_rotation_vector(float &x, float &y, float &z, float &w)
157 {
158         return true;
159 }
160
161 bool lib_sensor_fusion::get_orientation(float &azimuth, float &pitch, float &roll)
162 {
163         return true;
164 }
165
166 extern "C" void *create(void)
167 {
168         lib_sensor_fusion *inst;
169
170         try {
171                 inst = new lib_sensor_fusion();
172         } catch (int err) {
173                 ERR("lib_sensor_fusion class create fail , errno : %d , errstr : %s", err, strerror(err));
174                 return NULL;
175         }
176
177         return (void *)inst;
178 }
179
180 extern "C" void destroy(void *inst)
181 {
182         delete (lib_sensor_fusion *)inst;
183 }