1 /* 2 * Copyright (C) 2017 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 #ifndef LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_MAGNETOMETER_MAG_SPHERE_FIT_H_ 17 #define LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_MAGNETOMETER_MAG_SPHERE_FIT_H_ 18 19 #include "calibration/common/sphere_fit_calibration.h" 20 #include "calibration/magnetometer/mag_cal.h" 21 22 #define NUM_SPHERE_FIT_DATA 50 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 struct SphereFit { 29 struct LmParams params; 30 struct LmData lm_data; 31 struct SphereFitCal sphere_cal; 32 struct ThreeAxisCalData sphere_param; 33 }; 34 35 struct MagCalSphere { 36 // KASA Fit Struct. 37 struct MagCal moc; 38 39 // Sphere fit Struct. 40 struct SphereFit sphere_fit; 41 42 // down sampler control. 43 uint32_t number_of_data_samples; 44 uint32_t sample_counter; 45 uint32_t sample_drop; 46 float inv_data_size; 47 float batch_time_in_sec; 48 49 // Sphere fit data set. 50 float sphere_data[THREE_AXIS_DATA_DIM * NUM_SPHERE_FIT_DATA]; 51 }; 52 53 void initMagCalSphere(struct MagCalSphere *mocs, 54 float x_bias, float y_bias, float z_bias, 55 float c00, float c01, float c02, float c10, float c11, 56 float c12, float c20, float c21, float c22, 57 uint32_t min_batch_window_in_micros, 58 size_t min_num_diverse_vectors, 59 size_t max_num_max_distance, 60 float var_threshold, 61 float max_min_threshold, 62 float local_field, 63 float threshold_tuning_param, 64 float max_distance_tuning_param); 65 66 void magCalSphereDestroy(struct MagCalSphere *mocs); 67 68 enum MagUpdate magCalSphereUpdate(struct MagCalSphere *mocs, 69 uint64_t sample_time_us, 70 float x, float y, float z); 71 72 void magCalSphereOdrUpdate(struct MagCalSphere *mocs, float odr_in_hz); 73 74 #ifdef __cplusplus 75 } 76 #endif 77 78 #endif // LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_MAGNETOMETER_MAG_SPHERE_FIT_H_ 79