Adding AK8975 geo-sensor info in sensors.xml.in required by geo-plugin
[platform/core/system/sensord.git] / src / sensor_fusion / standalone / util / sensor_data.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 #if defined (_SENSOR_DATA_H) && defined (_VECTOR_H)
21
22 #include "math.h"
23
24 #define SENSOR_DATA_SIZE 3
25
26 template <typename TYPE>
27 sensor_data<TYPE>::sensor_data() : m_data(SENSOR_DATA_SIZE), m_time_stamp(0)
28 {
29 }
30
31 template <typename TYPE>
32 sensor_data<TYPE>::sensor_data(const TYPE x, const TYPE y,
33                 const TYPE z, const unsigned long long time_stamp = 0)
34 {
35         TYPE vec_data[SENSOR_DATA_SIZE] = {x, y, z};
36
37         vector<TYPE> v(SENSOR_DATA_SIZE, vec_data);
38         m_data = v;
39         m_time_stamp = time_stamp;
40 }
41
42 template <typename TYPE>
43 sensor_data<TYPE>::sensor_data(const vector<TYPE> v,
44                 const unsigned long long time_stamp = 0)
45 {
46         m_data = v;
47         m_time_stamp = time_stamp;
48 }
49
50 template <typename TYPE>
51 sensor_data<TYPE>::sensor_data(const sensor_data<TYPE>& s)
52 {
53         m_data = s.m_data;
54         m_time_stamp = s.m_time_stamp;
55 }
56
57 template <typename TYPE>
58 sensor_data<TYPE>::~sensor_data()
59 {
60 }
61
62 template <typename TYPE>
63 sensor_data<TYPE> sensor_data<TYPE>::operator =(const sensor_data<TYPE>& s)
64 {
65         m_data = s.m_data;
66         m_time_stamp = s.m_time_stamp;
67
68         return *this;
69 }
70
71 template <typename T>
72 sensor_data<T> operator +(sensor_data<T> data1, sensor_data<T> data2)
73 {
74         return (data1.m_data + data2.m_data);
75 }
76
77 template <typename T>
78 void normalize(sensor_data<T>& data)
79 {
80         T x, y, z;
81
82         x = data.m_data.m_vec[0];
83         y = data.m_data.m_vec[1];
84         z = data.m_data.m_vec[2];
85
86         T val = sqrt(x*x + y*y + z*z);
87
88         data.m_data.m_vec[0] = x / val;
89         data.m_data.m_vec[1] = y / val;
90         data.m_data.m_vec[2] = z / val;
91 }
92
93 template <typename T>
94 sensor_data<T> scale_data(sensor_data<T> data, T scaling_factor)
95 {
96         T x, y, z;
97
98         x = data.m_data.m_vec[0] / scaling_factor;
99         y = data.m_data.m_vec[1] / scaling_factor;
100         z = data.m_data.m_vec[2] / scaling_factor;
101
102         sensor_data<T> s(x, y, z, data.m_time_stamp);
103
104         return s;
105 }
106
107 #endif /* _SENSOR_DATA_H */
108