1 /*
2  $License:
3     Copyright (C) 2011-2012 InvenSense Corporation, All Rights Reserved.
4     See included License.txt for License information.
5  $
6  */
7 #include "mltypes.h"
8 
9 #ifndef INV_RESULTS_HOLDER_H__
10 #define INV_RESULTS_HOLDER_H__
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 #define INV_MOTION                       0x0001
17 #define INV_NO_MOTION                    0x0002
18 
19 
20 
21     /**************************************************************************/
22     /*  The value of inv_get_gyro_sum_of_sqr is scaled such the (1 dps)^2 =   */
23     /*  2^GYRO_MAG_SQR_SHIFT. This number must be >=0 and even.               */
24     /*  The value of inv_accel_sum_of_sqr is scaled such that (1g)^2 =        */
25     /*  2^ACC_MAG_SQR_SHIFT                                                   */
26     /**************************************************************************/
27 #define ACC_MAG_SQR_SHIFT 16
28 
29 enum compass_local_field_e {
30     // status for user input earth magnetic local field
31     LOCAL_FILED_NOT_SET_BY_USER                     = 0,
32     LOCAL_FILED_SET_BY_USER                         = 1,
33 
34     // status for mpl calibrated based magnetical field
35     LOCAL_FILED_NOT_SET_BY_USER_BUT_SET_BY_MPL      = 2,
36     LOCAL_FIELD_SET_BUT_NOT_MATCH_WITH_MPL          = 3,
37     LOCAL_FIELD_SET_MATCH_WITH_MPL                  = 4,
38 };
39 
40 struct local_field_t {
41     float intensity;  // radius
42     float inclination; // dip angle angle degree
43     float declination; // yaw deviation angle from true north, eastward as positive
44     enum compass_local_field_e mpl_match_status;
45 };
46 
47 // earth magnetic field access API
48 enum compass_local_field_e inv_get_local_field_status(void);
49 void inv_set_local_field_status(enum compass_local_field_e status);
50 
51 void inv_set_earth_magnetic_local_field_parameter(struct local_field_t *parameters);
52 void inv_get_earth_magnetic_local_field_parameter(struct local_field_t *parameters);
53 
54 // mpl calibrated magnetic field access API
55 enum compass_local_field_e inv_get_mpl_mag_field_status(void);
56 void inv_set_mpl_mag_field_status(enum compass_local_field_e status);
57 
58 inv_error_t inv_set_mpl_magnetic_local_field_parameter(struct local_field_t *parameters);
59 void inv_get_mpl_magnetic_local_field_parameter(struct local_field_t *parameters);
60 
61 // quaternion store API
62 void inv_store_gaming_quaternion(const long *quat, inv_time_t timestamp);
63 void inv_store_accel_quaternion(const long *quat, inv_time_t timestamp);
64 void inv_store_nav_quaternion(const float *quat, inv_time_t timestamp);
65 void inv_store_game_quaternion(const float *quat, inv_time_t timestamp);
66 void inv_store_geomag_quaternion(const float *quat, inv_time_t timestamp);
67 
68 // States
69 #define SF_NORMAL 0
70 #define SF_UNCALIBRATED 1
71 #define SF_STARTUP_SETTLE 2
72 #define SF_FAST_SETTLE 3
73 #define SF_DISTURBANCE 4
74 #define SF_SLOW_SETTLE 5
75 
76 // These 2 status bits are used to control when the 9 axis quaternion is updated
77 #define INV_COMPASS_CORRECTION_SET 1
78 #define INV_6_AXIS_QUAT_SET 2
79 #define INV_GEOMAGNETIC_CORRECTION_SET 4
80 
81 int inv_get_acc_state();
82 void inv_set_acc_state(int state);
83 int inv_get_motion_state(unsigned int *cntr);
84 void inv_set_motion_state(unsigned char state);
85 inv_error_t inv_get_gravity(long *data);
86 inv_error_t inv_get_gravity_6x(long *data);
87 inv_error_t inv_get_6axis_quaternion(long *data, inv_time_t *timestamp);
88 inv_error_t inv_get_quaternion(long *data);
89 inv_error_t inv_get_quaternion_float(float *data);
90 inv_error_t inv_get_6axis_quaternion_float(float *data, inv_time_t *timestamp);
91 inv_error_t inv_get_geomagnetic_quaternion_float(float *data, inv_time_t *timestamp);
92 #ifdef WIN32
93 inv_error_t inv_get_last_quaternion(long *data);
94 inv_error_t inv_set_last_quaternion(long *data);
95 #endif
96 void inv_get_quaternion_set(long *data, int *accuracy, inv_time_t *timestamp);
97 inv_error_t inv_get_accel_quaternion(long *data);
98 inv_error_t inv_get_geomagnetic_quaternion(long *data, inv_time_t *timestamp);
99 void inv_set_geomagnetic_compass_correction(const long *data, inv_time_t timestamp);
100 void inv_get_geomagnetic_compass_correction(long *data, inv_time_t *timestamp);
101 inv_error_t inv_get_result_holder_status(long *rh_status);
102 inv_error_t inv_set_result_holder_status(long rh_status);
103 inv_error_t inv_get_quaternion_validity(int *value);
104 inv_error_t inv_set_quaternion_validity(int value);
105 
106 // set magnetic field by location
107 inv_error_t inv_set_local_magnetic_field(float intensity, float inclination, float declination);
108 
109 inv_error_t inv_enable_results_holder();
110 inv_error_t inv_init_results_holder(void);
111 
112 /* Magnetic Field Parameters*/
113 void inv_set_mag_scale(const long *data);
114 void inv_get_mag_scale(long *data);
115 void inv_set_compass_correction(const long *data, inv_time_t timestamp);
116 void inv_get_compass_correction(long *data, inv_time_t *timestamp);
117 int inv_got_compass_bias();
118 void inv_set_compass_bias_found(int state);
119 int inv_get_large_mag_field();
120 void inv_set_large_mag_field(int state);
121 void inv_set_compass_state(int state);
122 int inv_get_compass_state();
123 void inv_set_compass_bias_error(const long *bias_error);
124 void inv_get_compass_bias_error(long *bias_error);
125 inv_error_t inv_get_linear_accel(long *data);
126 inv_error_t inv_get_accel(long *data);
127 inv_error_t inv_get_accel_float(float *data);
128 inv_error_t inv_get_gyro_float(float *data);
129 inv_error_t inv_get_linear_accel_float(float *data);
130 void inv_set_heading_confidence_interval(float ci);
131 float inv_get_heading_confidence_interval(void);
132 
133 void inv_set_accel_compass_confidence_interval(float ci);
134 float inv_get_accel_compass_confidence_interval(void);
135 
136 int inv_got_accel_bias();
137 void inv_set_accel_bias_found(int state);
138 
139 
140 #ifdef __cplusplus
141 }
142 #endif
143 
144 #endif // INV_RESULTS_HOLDER_H__
145