coverity issues fix
[platform/core/system/sensord.git] / src / fusion-sensor / rotation_vector / design / documentation / hardware_fusion_sensor.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2 <HTML>
3 <HEAD>
4         <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
5         <TITLE></TITLE>
6         <META NAME="GENERATOR" CONTENT="LibreOffice 3.5  (Linux)">
7         <META NAME="AUTHOR" CONTENT="Ankur Garg">
8         <META NAME="CREATED" CONTENT="20150520;15471000">
9         <META NAME="CHANGEDBY" CONTENT="Ankur Garg">
10         <META NAME="CHANGED" CONTENT="20150522;13492000">
11         <META NAME="CHANGEDBY" CONTENT="Ankur Garg">
12         <META NAME="CHANGEDBY" CONTENT="Ankur Garg">
13         <STYLE TYPE="text/css">
14         <!--
15                 @page { margin: 2cm }
16         -->
17         </STYLE>
18 </HEAD>
19 <BODY LANG="en-IN" DIR="LTR">
20 <P ALIGN=CENTER STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">Supporting
21 Virtual Sensors based on On-Chip(Hardware Based) Sensor Fusion
22 Solution</FONT></P>
23 <P ALIGN=CENTER STYLE="margin-bottom: 0cm"><BR>
24 </P>
25 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">Software
26 Fusion Sensor:</FONT></P>
27 <P STYLE="margin-bottom: 0cm"><BR>
28 </P>
29 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">The
30 fusion sensor registers for accelerometer, gyroscope and geomagnetic
31 sensors. Uses the data from these three sensors to fusion_event,
32 which is used by various sensors to generate their specific sensor
33 events.</FONT></P>
34 <P STYLE="margin-bottom: 0cm"><BR>
35 </P>
36 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">-&gt;The
37 virtual sensor starts the hardware and fusion sensor.</FONT></P>
38 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">-&gt;Fusion
39 sensor registers for hardware sensors. It received accelerometer,
40 gyroscope and/or geomagnetic sensor events.</FONT></P>
41 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">-&gt;Based
42 on what all events are received, fusion sensor generates a fusion
43 sensor event.</FONT></P>
44 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">-&gt;The
45 FUSION_EVENT is sent to all virtual sensors which have registered for
46 fusion sensor.</FONT></P>
47 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">-&gt;The
48 virtual sensors then use the data from FUSION_EVENT to create their
49 specific virtual sensor events.</FONT></P>
50 <P STYLE="margin-bottom: 0cm"><BR>
51 </P>
52 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">Hardware
53 Fusion Sensor:</FONT></P>
54 <P STYLE="margin-bottom: 0cm"><BR>
55 </P>
56 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">In
57 case hardware based fusion sensor is present, individual sensors
58 won't be required by fusion sensor to generate FUSION_EVENT.</FONT></P>
59 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">So,
60 virtual sensors won't have to register and start the individual
61 hardware sensors (accel, gyro or geomagnetic) for receiving
62 FUSION_EVENT. They will just have to register for hardware fusion
63 sensor event and they will receive the hardware sensor event.</FONT></P>
64 <P STYLE="margin-bottom: 0cm"><BR>
65 </P>
66 <P STYLE="margin-bottom: 0cm; text-decoration: none"><FONT FACE="Liberation Serif, serif">Adding
67 hardware fusion sensor in virtual sensors:</FONT></P>
68 <P STYLE="margin-bottom: 0cm; text-decoration: none"><FONT FACE="Liberation Serif, serif">In
69 case hardware fusion sensor is present, instead of registering of
70 individual hardware sensors and fusion sensor, virtual sensor will
71 register for just sensor hal fusion sensor. </FONT>
72 </P>
73 <P STYLE="margin-bottom: 0cm"><BR>
74 </P>
75 <P STYLE="margin-bottom: 0cm; text-decoration: none"><FONT FACE="Liberation Serif, serif">Also,
76 fusion sensor will register for just fusion_sensor_hal and send the
77 events to all virtual sensor registered for fusion sensor events.</FONT></P>
78 <P STYLE="margin-bottom: 0cm"><BR>
79 </P>
80 <P STYLE="margin-bottom: 0cm; text-decoration: none"><FONT FACE="Liberation Serif, serif">For
81 this, the virtual sensor must register/start specific sensors in case
82 hardware fusion sensor is present or not.</FONT></P>
83 <P STYLE="margin-bottom: 0cm"><BR>
84 </P>
85 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">In
86 any virtual sensor class, to add support for both hardware and
87 software sensor fusion, </FONT>
88 </P>
89 <P STYLE="margin-bottom: 0cm"><BR>
90 </P>
91 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">-&gt;In
92 the constructor use sensor_plugin_loader to check if the hal sensor
93 fusion is present or not:</FONT></P>
94 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION)</FONT></P>
95 <P STYLE="margin-bottom: 0cm"><BR>
96 </P>
97 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">-&gt;If
98 it returns NULL, in that case, hardware fusion sensor is not present,
99 else the hardware fusion is present.</FONT></P>
100 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">-&gt;Store
101 this result in virtual_sensor::m_hardware_fusion</FONT></P>
102 <P STYLE="margin-bottom: 0cm"><BR>
103 </P>
104 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">sensor_hal
105 *fusion_sensor_hal =
106 sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION);</FONT></P>
107 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">if
108 (!fusion_sensor_hal)</FONT></P>
109 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;m_hardware_fusion
110 = false;</FONT></P>
111 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">else</FONT></P>
112 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;m_hardware_fusion
113 = true;</FONT></P>
114 <P STYLE="margin-bottom: 0cm"><BR>
115 </P>
116 <P STYLE="margin-bottom: 0cm"><BR>
117 </P>
118 <P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">-&gt;Bases
119 on this, in on_start, on_stop, add_interval, delete_interval etc
120 functions, the physical sensors will be started in case hardware
121 fusion sensor is not present and only fusion sensor will be started
122 in case hardware fusion sensor is present.</FONT></P>
123 <P STYLE="margin-bottom: 0cm"><BR>
124 </P>
125 <P STYLE="margin-bottom: 0cm"><BR>
126 </P>
127 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">bool
128 orientation_sensor::on_start(void)</FONT></P>
129 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">{</FONT></P>
130 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;AUTOLOCK(m_mutex);</FONT></P>
131 <P STYLE="margin-bottom: 0cm"><BR>
132 </P>
133 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;if
134 (!m_hardware_fusion) {</FONT></P>
135 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;&emsp;&emsp;m_accel_sensor-&gt;add_client(ACCELEROMETER_RAW_DATA_EVENT);</FONT></P>
136 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;&emsp;&emsp;m_accel_sensor-&gt;add_interval((intptr_t)this,
137 (m_interval/MS_TO_US), false);</FONT></P>
138 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;&emsp;&emsp;m_accel_sensor-&gt;start();</FONT></P>
139 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;&emsp;&emsp;m_gyro_sensor-&gt;add_client(GYROSCOPE_RAW_DATA_EVENT);</FONT></P>
140 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;&emsp;&emsp;m_gyro_sensor-&gt;add_interval((intptr_t)this,
141 (m_interval/MS_TO_US), false);</FONT></P>
142 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;&emsp;&emsp;m_gyro_sensor-&gt;start();</FONT></P>
143 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;&emsp;&emsp;m_magnetic_sensor-&gt;add_client(GEOMAGNETIC_RAW_DATA_EVENT);</FONT></P>
144 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;&emsp;&emsp;m_magnetic_sensor-&gt;add_interval((intptr_t)this,
145 (m_interval/MS_TO_US), false);</FONT></P>
146 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;&emsp;&emsp;m_magnetic_sensor-&gt;start();</FONT></P>
147 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;}</FONT></P>
148 <P STYLE="margin-bottom: 0cm"><BR>
149 </P>
150 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;m_fusion_sensor-&gt;register_supported_event(FUSION_EVENT);</FONT></P>
151 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;m_fusion_sensor-&gt;register_supported_event(FUSION_ORIENTATION_ENABLED);</FONT></P>
152 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;m_fusion_sensor-&gt;add_client(FUSION_EVENT);</FONT></P>
153 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;m_fusion_sensor-&gt;add_interval((intptr_t)this,
154 (m_interval/MS_TO_US), false);</FONT></P>
155 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;m_fusion_sensor-&gt;start();</FONT></P>
156 <P STYLE="margin-bottom: 0cm"><BR>
157 </P>
158 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;activate();</FONT></P>
159 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">&emsp;&emsp;return
160 true;</FONT></P>
161 <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">}</FONT></P>
162 </BODY>
163 </HTML>