From: Adriana Reus Date: Thu, 20 Nov 2014 13:30:26 +0000 (+0200) Subject: Move defines to appropriate c files X-Git-Tag: android-x86-7.1-r1~42^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=222bad1;p=android-x86%2Fhardware-intel-libsensors.git Move defines to appropriate c files Some clean-up Change-Id: I5d04f329d0ee965ba6e9c943baf6682209922060 Signed-off-by: Adriana Reus --- diff --git a/calibration.h b/calibration.h index 8b0d2a5..4fb160d 100644 --- a/calibration.h +++ b/calibration.h @@ -7,22 +7,7 @@ #include "common.h" -/* compass defines */ -#define COMPASS_CALIBRATION_PATH "/data/compass.conf" -#define DS_SIZE 32 -#define EPSILON 0.000000001 - -#define MAGNETIC_LOW 960 /* 31 micro tesla squared */ - -#ifdef DBG_RAW_DATA -#define RAW_DATA_FULL_PATH "/data/raw_compass_data_full_%d.txt" -#define RAW_DATA_SELECTED_PATH "/data/raw_compass_data_selected_%d.txt" -#endif - -/* gyro defines */ -#define GYRO_MAX_ERR 0.05f -#define GYRO_DS_SIZE 100 -#define GYRO_CALIBRATION_PATH "/data/gyro.conf" +#define MAGN_DS_SIZE 32 struct compass_cal { /* hard iron offsets */ @@ -35,7 +20,7 @@ struct compass_cal { double bfield; /* selection data */ - float sample[DS_SIZE][3]; + float sample[MAGN_DS_SIZE][3]; unsigned int sample_count; }; @@ -46,7 +31,7 @@ struct gyro_cal { float max_x, max_y, max_z; }; -typedef double mat_input_t[DS_SIZE][3]; +typedef double mat_input_t[MAGN_DS_SIZE][3]; void calibrate_compass (struct sensors_event_t* event, struct sensor_info_t* info); void compass_read_data (struct sensor_info_t* info); diff --git a/compass-calibration.c b/compass-calibration.c index b6a4917..10ac9d7 100644 --- a/compass-calibration.c +++ b/compass-calibration.c @@ -15,12 +15,19 @@ #ifdef DBG_RAW_DATA #define MAX_RAW_DATA_COUNT 2000 +#define RAW_DATA_FULL_PATH "/data/raw_compass_data_full_%d.txt" +#define RAW_DATA_SELECTED_PATH "/data/raw_compass_data_selected_%d.txt" static FILE *raw_data = NULL; static FILE *raw_data_selected = NULL; static int raw_data_count = 0; int file_no = 0; #endif +/* compass defines */ +#define COMPASS_CALIBRATION_PATH "/data/compass.conf" +#define EPSILON 0.000000001 + +#define MAGNETIC_LOW 960 /* 31 micro tesla squared */ #define CAL_STEPS 5 /* We'll have multiple calibration levels @@ -35,7 +42,7 @@ static void reset_sample (struct compass_cal* data) { int i,j; data->sample_count = 0; - for (i = 0; i < DS_SIZE; i++) + for (i = 0; i < MAGN_DS_SIZE; i++) for (j=0; j < 3; j++) data->sample[i][j] = 0; } @@ -46,7 +53,7 @@ static double calc_square_err (struct compass_cal* data) double raw[3][1], result[3][1], mat_diff[3][1]; int i; - for (i = 0; i < DS_SIZE; i++) { + for (i = 0; i < MAGN_DS_SIZE; i++) { raw[0][0] = data->sample[i][0]; raw[1][0] = data->sample[i][1]; raw[2][0] = data->sample[i][2]; @@ -59,7 +66,7 @@ static double calc_square_err (struct compass_cal* data) err += diff * diff; } - err /= DS_SIZE; + err /= MAGN_DS_SIZE; return err; } @@ -136,11 +143,11 @@ static void calc_evector(double mat[3][3], double eig, double vec[3][1]) static int ellipsoid_fit (mat_input_t m, double offset[3][1], double w_invert[3][3], double* bfield) { int i; - double h[DS_SIZE][9]; - double w[DS_SIZE][1]; - double h_trans[9][DS_SIZE]; + double h[MAGN_DS_SIZE][9]; + double w[MAGN_DS_SIZE][1]; + double h_trans[9][MAGN_DS_SIZE]; double p_temp1[9][9]; - double p_temp2[9][DS_SIZE]; + double p_temp2[9][MAGN_DS_SIZE]; double temp1[3][3], temp[3][3]; double temp1_inv[3][3]; double temp2[3][1]; @@ -149,7 +156,7 @@ static int ellipsoid_fit (mat_input_t m, double offset[3][1], double w_invert[3] double a[3][3], sqrt_evals[3][3], evecs[3][3], evecs_trans[3][3]; double evec1[3][1], evec2[3][1], evec3[3][1]; - for (i = 0; i < DS_SIZE; i++) { + for (i = 0; i < MAGN_DS_SIZE; i++) { w[i][0] = m[i][0] * m[i][0]; h[i][0] = m[i][0]; h[i][1] = m[i][1]; @@ -161,11 +168,11 @@ static int ellipsoid_fit (mat_input_t m, double offset[3][1], double w_invert[3] h[i][7] = -1 * m[i][2] * m[i][2]; h[i][8] = 1; } - transpose (DS_SIZE, 9, h, h_trans); - multiply (9, DS_SIZE, 9, h_trans, h, result); + transpose (MAGN_DS_SIZE, 9, h, h_trans); + multiply (9, MAGN_DS_SIZE, 9, h_trans, h, result); invert (9, result, p_temp1); - multiply (9, 9, DS_SIZE, p_temp1, h_trans, p_temp2); - multiply (9, DS_SIZE, 1, p_temp2, w, p); + multiply (9, 9, MAGN_DS_SIZE, p_temp1, h_trans, p_temp2); + multiply (9, MAGN_DS_SIZE, 1, p_temp2, w, p); temp1[0][0] = 2; temp1[0][1] = p[3][0]; @@ -367,7 +374,7 @@ static int compass_collect (struct sensors_event_t* event, struct sensor_info_t* // For the current point to be accepted, each x/y/z value must be different enough // to the last several collected points - if (cal_data->sample_count > 0 && cal_data->sample_count < DS_SIZE) { + if (cal_data->sample_count > 0 && cal_data->sample_count < MAGN_DS_SIZE) { unsigned int lookback = lookback_count < cal_data->sample_count ? lookback_count : cal_data->sample_count; for (index = 0; index < lookback; index++){ @@ -381,7 +388,7 @@ static int compass_collect (struct sensors_event_t* event, struct sensor_info_t* } } - if (cal_data->sample_count < DS_SIZE) { + if (cal_data->sample_count < MAGN_DS_SIZE) { memcpy(cal_data->sample[cal_data->sample_count], data, sizeof(float) * 3); cal_data->sample_count++; ALOGV("CompassCalibration:point collected [%f,%f,%f], selected_count=%d", @@ -457,13 +464,13 @@ static int compass_ready (struct sensor_info_t* info) int cal_steps = (info->max_cal_level && info->max_cal_level <= CAL_STEPS) ? info->max_cal_level : CAL_STEPS; - if (cal_data->sample_count < DS_SIZE) + if (cal_data->sample_count < MAGN_DS_SIZE) return info->cal_level; max_sqr_err = max_sqr_errs[info->cal_level]; /* enough points have been collected, do the ellipsoid calibration */ - for (i = 0; i < DS_SIZE; i++) { + for (i = 0; i < MAGN_DS_SIZE; i++) { mat[i][0] = cal_data->sample[i][0]; mat[i][1] = cal_data->sample[i][1]; mat[i][2] = cal_data->sample[i][2]; diff --git a/gyro-calibration.c b/gyro-calibration.c index c71ee3b..7120687 100644 --- a/gyro-calibration.c +++ b/gyro-calibration.c @@ -10,6 +10,11 @@ #include "common.h" #include "calibration.h" + /* gyro defines */ +#define GYRO_MAX_ERR 0.05f +#define GYRO_DS_SIZE 100 +#define GYRO_CALIBRATION_PATH "/data/gyro.conf" + static void reset (struct gyro_cal* cal_data) { cal_data->count = 0;