1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MAG_CAL_H_
18 
19 #define MAG_CAL_H_
20 
21 #include <stdint.h>
22 #include <stdbool.h>
23 #include <sys/types.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 struct MagCal {
30     uint64_t start_time;
31     uint64_t update_time;
32 
33     float acc_x, acc_y, acc_z, acc_w;
34     float acc_xx, acc_xy, acc_xz, acc_xw;
35     float acc_yy, acc_yz, acc_yw, acc_zz, acc_zw;
36 
37     float x_bias, y_bias, z_bias;
38     float radius;
39 
40     float c00, c01, c02, c10, c11, c12, c20, c21, c22;
41 
42     size_t nsamples;
43 };
44 
45 void initMagCal(struct MagCal *moc,
46                   float x_bias, float y_bias, float z_bias,
47                   float c00, float c01, float c02,
48                   float c10, float c11, float c12,
49                   float c20, float c21, float c22);
50 
51 void destroy_mag_cal(struct MagCal *moc);
52 
53 bool magCalUpdate(struct MagCal *moc, uint64_t sample_time_us,
54                    float x, float y, float z);
55 
56 void magCalGetBias(struct MagCal *moc, float *x, float *y, float *z);
57 
58 void magCalAddBias(struct MagCal *moc, float x, float y, float z);
59 
60 void magCalRemoveBias(struct MagCal *moc, float xi, float yi, float zi,
61                          float *xo, float *yo, float *zo);
62 
63 void magCalSetSoftiron(struct MagCal *moc,
64                           float c00, float c01, float c02,
65                           float c10, float c11, float c12,
66                           float c20, float c21, float c22);
67 
68 void magCalRemoveSoftiron(struct MagCal *moc, float xi, float yi, float zi,
69                              float *xo, float *yo, float *zo);
70 
71 #ifdef __cplusplus
72 }
73 #endif
74 
75 #endif  // MAG_CAL_H_
76