All these explicit structs ended up being noisy for little benefit.
Change-Id: I0b7ace85ab8a7644d3895e3e45e97ff0e14c5cfc
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
#define MAGN_DS_SIZE 32
-struct compass_cal_t {
+
+typedef struct {
/* hard iron offsets */
double offset[3][1];
float sample[MAGN_DS_SIZE][3];
unsigned int sample_count;
float average[3];
-};
+}
+compass_cal_t;
+
-struct gyro_cal_t {
+typedef struct {
float bias_x, bias_y, bias_z;
int count;
float min_x, min_y, min_z;
float max_x, max_y, max_z;
-};
+}
+gyro_cal_t;
+
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);
-void compass_store_data (struct sensor_info_t* info);
-void calibrate_gyro(struct sensors_event_t* event, struct sensor_info_t* info);
-void gyro_cal_init(struct sensor_info_t* info);
-void gyro_store_data (struct sensor_info_t* info);
+void calibrate_compass (sensors_event_t* event, sensor_info_t* info);
+void compass_read_data (sensor_info_t* info);
+void compass_store_data (sensor_info_t* info);
+
+void calibrate_gyro (sensors_event_t* event, sensor_info_t* info);
+void gyro_cal_init (sensor_info_t* info);
+void gyro_store_data (sensor_info_t* info);
+
#endif
typedef int32_t max_delay_t;
#endif
-struct channel_descriptor_t
+
+typedef struct
{
const char *name; /* channel name ; ex: x */
const char *raw_path; /* _raw sysfs file name */
const char *input_path; /* _input sysfs file name */
const char *scale_path; /* _scale sysfs file name */
-};
+}
+channel_descriptor_t;
+
-struct sensor_catalog_entry_t
+typedef struct
{
const char *tag; /* Prefix such as "accel", "gyro", "temp"... */
const int type; /* Sensor type ; ex: SENSOR_TYPE_ACCELEROMETER */
const int num_channels; /* Expected iio channels for this sensor */
const int is_virtual; /* Is the sensor virtual or not */
- struct channel_descriptor_t channel[MAX_CHANNELS];
-};
+ channel_descriptor_t channel[MAX_CHANNELS];
+}
+sensor_catalog_entry_t;
-struct datum_info_t
+
+typedef struct
{
char sign;
char endianness;
short realbits;
short storagebits;
short shift;
-};
+}
+datum_info_t;
+
-struct channel_info_t
+typedef struct
{
int offset; /* Offset in bytes within the iio character device report */
int size; /* Field size in bytes */
float scale; /* scale for each channel */
char type_spec[MAX_TYPE_SPEC_LEN]; /* From driver; ex: le:u10/16>>0 */
- struct datum_info_t type_info; /* Decoded contents of type spec */
+ datum_info_t type_info; /* Decoded contents of type spec */
float opt_scale; /* Optional correction scale read from a property such
* as iio.accel.x.scale, allowing late compensation of
* problems such as misconfigured axes ; set to 1 by
* default. Applied at the end of the scaling process.
*/
-};
+}
+channel_info_t;
-struct sample_ops_t
+
+typedef struct
{
/* Conversion function called once per channel */
- float (*transform)(int s, int c, unsigned char* sample_data);
+ float (*transform) (int s, int c, unsigned char* sample_data);
/* Function called once per sample */
- int (*finalize)(int s, struct sensors_event_t* data);
-};
+ int (*finalize) (int s, sensors_event_t* data);
+}
+sample_ops_t;
+
/*
* Whenever we have sensor data recorded for a sensor in the associated
#define DATA_SYSFS 2 /* Through polling */
#define DATA_DUPLICATE 3 /* Duplicate of triggered motion sample */
-struct sensor_info_t
+
+typedef struct
{
char friendly_name[MAX_NAME_SIZE]; /* ex: Accelerometer */
char internal_name[MAX_NAME_SIZE]; /* ex: accel_3d */
* should be zero for disabled channels. The type field indicates how a
* specific channel data item is structured.
*/
- struct channel_info_t channel[MAX_CHANNELS];
+ channel_info_t channel[MAX_CHANNELS];
/*
* This flag is set if we acquired data from the sensor but did not
int report_initialized;
/* Channel and sample finalization callbacks for this sensor */
- struct sample_ops_t ops;
+ sample_ops_t ops;
int cal_level; /* 0 means not calibrated */
* keep the data here until it's finally processed. Can be modified for
* more than one at a later time.
*/
- struct sensors_event_t sample;
+ sensors_event_t sample;
/*
* If the QUIRK_FIELD_ORDERING bit is set in quirks, the contents of
* events before filtering kicks in. We can also use it for statistics.
*/
uint64_t event_count;
-};
+}
+sensor_info_t;
+
/* Reference a few commonly used variables... */
-extern int sensor_count;
-extern struct sensor_t sensor_desc[MAX_SENSORS];
-extern struct sensor_info_t sensor[MAX_SENSORS];
-extern struct sensor_catalog_entry_t sensor_catalog[];
+extern int sensor_count;
+extern struct sensor_t sensor_desc[MAX_SENSORS];
+extern sensor_info_t sensor[MAX_SENSORS];
+extern sensor_catalog_entry_t sensor_catalog[];
#endif
static const float max_sqr_errs[CAL_STEPS] = {10.0, 10.0, 8.0, 5.0, 3.5 };
static const unsigned int lookback_counts[CAL_STEPS] = {2, 3, 4, 5, 6 };
-/* reset calibration algorithm */
-static void reset_sample (struct compass_cal_t* data)
+
+/* Reset calibration algorithm */
+static void reset_sample (compass_cal_t* data)
{
int i,j;
data->sample_count = 0;
data->average[0] = data->average[1] = data->average[2] = 0;
}
-static double calc_square_err (struct compass_cal_t* data)
+
+static double calc_square_err (compass_cal_t* data)
{
double err = 0;
double raw[3][1], result[3][1], mat_diff[3][1];
return err;
}
+
/* Given an real symmetric 3x3 matrix A, compute the eigenvalues */
-static void compute_eigenvalues(double mat[3][3], double* eig1, double* eig2, double* eig3)
+static void compute_eigenvalues (double mat[3][3], double* eig1, double* eig2, double* eig3)
{
double p = mat[0][1] * mat[0][1] + mat[0][2] * mat[0][2] + mat[1][2] * mat[1][2];
*eig2 = 3 * q - *eig1 - *eig3;
}
-static void calc_evector(double mat[3][3], double eig, double vec[3][1])
+
+static void calc_evector (double mat[3][3], double eig, double vec[3][1])
{
double h[3][3];
double x_tmp[2][2];
vec[2][0] = temp2 / norm;
}
+
static int ellipsoid_fit (mat_input_t m, double offset[3][1], double w_invert[3][3], double* bfield)
{
int i;
return 1;
}
-static void compass_cal_init (FILE* data_file, struct sensor_info_t* info)
+
+static void compass_cal_init (FILE* data_file, sensor_info_t* info)
{
#ifdef DBG_RAW_DATA
raw_data_count = 0;
#endif
- struct compass_cal_t* cal_data = (struct compass_cal_t*) info->cal_data;
+ compass_cal_t* cal_data = (compass_cal_t*) info->cal_data;
int cal_steps = (info->max_cal_level && info->max_cal_level <= CAL_STEPS) ?
info->max_cal_level : CAL_STEPS;
if (cal_data == NULL)
}
-static void compass_store_result(FILE* data_file, struct sensor_info_t* info)
+
+static void compass_store_result (FILE* data_file, sensor_info_t* info)
{
- struct compass_cal_t* cal_data = (struct compass_cal_t*) info->cal_data;
+ compass_cal_t* cal_data = (compass_cal_t*) info->cal_data;
if (data_file == NULL || cal_data == NULL)
return;
ALOGE ("compass calibration - store data failed!");
}
-static int compass_collect (struct sensors_event_t* event, struct sensor_info_t* info)
+
+static int compass_collect (sensors_event_t* event, sensor_info_t* info)
{
float data[3] = {event->magnetic.x, event->magnetic.y, event->magnetic.z};
unsigned int index,j;
unsigned int lookback_count;
float min_diff;
- struct compass_cal_t* cal_data = (struct compass_cal_t*) info->cal_data;
+ compass_cal_t* cal_data = (compass_cal_t*) info->cal_data;
if (cal_data == NULL)
return -1;
return 1;
}
-static void scale_event (struct sensors_event_t* event)
+
+static void scale_event (sensors_event_t* event)
{
float sqr_norm = 0;
float sanity_norm = 0;
event->magnetic.x = event->magnetic.x * scale;
event->magnetic.y = event->magnetic.y * scale;
event->magnetic.z = event->magnetic.z * scale;
-
}
}
-static void compass_compute_cal (struct sensors_event_t* event, struct sensor_info_t* info)
+
+static void compass_compute_cal (sensors_event_t* event, sensor_info_t* info)
{
- struct compass_cal_t* cal_data = (struct compass_cal_t*) info->cal_data;
+ compass_cal_t* cal_data = (compass_cal_t*) info->cal_data;
double result[3][1], raw[3][1], diff[3][1];
if (!info->cal_level || cal_data == NULL)
}
-static int compass_ready (struct sensor_info_t* info)
+static int compass_ready (sensor_info_t* info)
{
mat_input_t mat;
int i;
float max_sqr_err;
- struct compass_cal_t* cal_data = (struct compass_cal_t*) info->cal_data;
- struct compass_cal_t new_cal_data;
+ compass_cal_t* cal_data = (compass_cal_t*) info->cal_data;
+ compass_cal_t new_cal_data;
/*
* Some sensors take unrealistically long to calibrate at higher levels.
}
-void calibrate_compass (struct sensors_event_t* event, struct sensor_info_t* info)
+void calibrate_compass (sensors_event_t* event, sensor_info_t* info)
{
int cal_level;
}
}
-void compass_read_data (struct sensor_info_t* info)
+void compass_read_data (sensor_info_t* info)
{
FILE* data_file = fopen (COMPASS_CALIBRATION_PATH, "r");
fclose(data_file);
}
-void compass_store_data (struct sensor_info_t* info)
+
+void compass_store_data (sensor_info_t* info)
{
FILE* data_file = fopen (COMPASS_CALIBRATION_PATH, "w");
static int decode_type_spec (const char type_buf[MAX_TYPE_SPEC_LEN],
- struct datum_info_t *type_info)
+ datum_info_t *type_info)
{
/* Return size in bytes for this type specification, or -1 in error */
char sign;
int ch_index;
char* ch_spec;
char spec_buf[MAX_TYPE_SPEC_LEN];
- struct datum_info_t* ch_info;
+ datum_info_t* ch_info;
int size;
char sysfs_path[PATH_MAX];
int known_channels;
int s = (int) (size_t) param;
int num_fields, sample_size;
- struct sensors_event_t data = {0};
+ sensors_event_t data = {0};
int c;
int ret;
struct timespec target_time;
}
-static int propagate_vsensor_report (int s, struct sensors_event_t *data)
+static int propagate_vsensor_report (int s, sensors_event_t *data)
{
/* There's a new report stored in sensor.sample for this sensor; transmit it */
- memcpy(data, &sensor[s].sample, sizeof(struct sensors_event_t));
+ memcpy(data, &sensor[s].sample, sizeof(sensors_event_t));
data->sensor = s;
data->type = sensor[s].type;
}
-static int propagate_sensor_report (int s, struct sensors_event_t *data)
+static int propagate_sensor_report (int s, sensors_event_t *data)
{
/* There's a sensor report pending for this sensor ; transmit it */
}
-int sensor_poll (struct sensors_event_t* data, int count)
+int sensor_poll (sensors_event_t* data, int count)
{
int s;
int i;
* from the same iio device as the base one.
*/
-struct sensor_catalog_entry_t sensor_catalog[] = {
+sensor_catalog_entry_t sensor_catalog[] = {
DECLARE_SENSOR3("accel", SENSOR_TYPE_ACCELEROMETER, "x", "y", "z")
DECLARE_SENSOR3("anglvel", SENSOR_TYPE_GYROSCOPE, "x", "y", "z")
DECLARE_SENSOR3("magn", SENSOR_TYPE_MAGNETIC_FIELD, "x", "y", "z")
/* We equate sensor handles to indices in these tables */
-struct sensor_t sensor_desc[MAX_SENSORS]; /* Android-level descriptors */
-struct sensor_info_t sensor[MAX_SENSORS]; /* Internal descriptors */
-int sensor_count; /* Detected sensors */
+struct sensor_t sensor_desc[MAX_SENSORS]; /* Android-level descriptors */
+sensor_info_t sensor[MAX_SENSORS]; /* Internal descriptors */
+int sensor_count; /* Detected sensors */
static void setup_properties_from_pld (int s, int panel, int rotation,
switch (sensor_type) {
case SENSOR_TYPE_GYROSCOPE:
- sensor[s].cal_data = malloc(sizeof(struct gyro_cal_t));
+ sensor[s].cal_data = malloc(sizeof(gyro_cal_t));
break;
case SENSOR_TYPE_MAGNETIC_FIELD:
- sensor[s].cal_data = malloc(sizeof(struct compass_cal_t));
+ sensor[s].cal_data = malloc(sizeof(compass_cal_t));
break;
}
#include "filtering.h"
-struct filter_median_t
+typedef struct
{
float* buff;
unsigned int idx;
unsigned int count;
unsigned int sample_size;
-};
+}
+filter_median_t;
static unsigned int partition ( float* list, unsigned int left,
static void denoise_median_init(int s, unsigned int num_fields,
unsigned int max_samples)
{
- struct filter_median_t* f_data = (struct filter_median_t*)
- malloc(sizeof(struct filter_median_t));
+ filter_median_t* f_data = (filter_median_t*)
+ malloc(sizeof(filter_median_t));
f_data->buff = (float*) calloc(max_samples, sizeof(float) * num_fields);
f_data->sample_size = max_samples;
}
-static void denoise_median_reset (struct sensor_info_t* info)
+static void denoise_median_reset (sensor_info_t* info)
{
- struct filter_median_t* f_data = (struct filter_median_t*) info->filter;
+ filter_median_t* f_data = (filter_median_t*) info->filter;
if (!f_data)
return;
}
-static void denoise_median ( struct sensor_info_t* info,
- struct sensors_event_t* data,
+static void denoise_median ( sensor_info_t* info,
+ sensors_event_t* data,
unsigned int num_fields)
{
float x, y, z;
float scale;
unsigned int field, offset;
- struct filter_median_t* f_data = (struct filter_median_t*) info->filter;
+ filter_median_t* f_data = (filter_median_t*) info->filter;
if (!f_data)
return;
}
-static void denoise_average ( struct sensor_info_t* si,
- struct sensors_event_t* data,
+static void denoise_average ( sensor_info_t* si,
+ sensors_event_t* data,
int num_fields, int max_samples)
{
/*
}
-void denoise (int s, struct sensors_event_t* data)
+void denoise (int s, sensors_event_t* data)
{
switch (sensor[s].type) {
case SENSOR_TYPE_GYROSCOPE:
/* Delete median filter structures */
if (sensor[s].filter) {
- buff = ((struct filter_median_t*)sensor[s].filter)->buff;
+ buff = ((filter_median_t*) sensor[s].filter)->buff;
if (buff)
free(buff);
#define GLOBAL_HISTORY_SIZE 100
-struct recorded_sample_t
+typedef struct
{
int sensor;
int motion_trigger;
sensors_event_t data;
-};
+}
+recorded_sample_t;
/*
* This is a circular buffer holding the last GLOBAL_HISTORY_SIZE events,
* be a delay between acquisition and insertion into this table.
*/
-static struct recorded_sample_t global_history[GLOBAL_HISTORY_SIZE];
+static recorded_sample_t global_history[GLOBAL_HISTORY_SIZE];
static int initialized_entries; /* How many of these are initialized */
static int insertion_index; /* Index of sample to evict next time */
-void record_sample (int s, const struct sensors_event_t* event)
+void record_sample (int s, const sensors_event_t* event)
{
- struct recorded_sample_t *cell;
+ recorded_sample_t *cell;
int i;
/* Don't record duplicate samples, as they are not useful for filters */
void setup_noise_filtering (int s);
void release_noise_filtering_data (int s);
-void denoise (int s, struct sensors_event_t* event);
+void denoise (int s, sensors_event_t* event);
void record_sample (int s, const sensors_event_t* data);
#endif
#define GYRO_CALIBRATION_PATH "/data/gyro.conf"
-static void reset (struct gyro_cal_t* cal_data)
+static void reset (gyro_cal_t* cal_data)
{
cal_data->count = 0;
}
-void gyro_cal_init (struct sensor_info_t* info)
+void gyro_cal_init (sensor_info_t* info)
{
int ret;
- struct gyro_cal_t* cal_data = (struct gyro_cal_t*) info->cal_data;
+ gyro_cal_t* cal_data = (gyro_cal_t*) info->cal_data;
FILE* data_file;
info->cal_level = 0;
}
-void gyro_store_data (struct sensor_info_t* info)
+void gyro_store_data (sensor_info_t* info)
{
int ret;
- struct gyro_cal_t* cal_data = (struct gyro_cal_t*) info->cal_data;
+ gyro_cal_t* cal_data = (gyro_cal_t*) info->cal_data;
FILE* data_file;
if (cal_data == NULL)
}
-static int gyro_collect (float x, float y, float z, struct gyro_cal_t* cal_data)
+static int gyro_collect (float x, float y, float z, gyro_cal_t* cal_data)
{
/* Analyze gyroscope data */
}
-void calibrate_gyro (struct sensors_event_t* event, struct sensor_info_t* info)
+void calibrate_gyro (sensors_event_t* event, sensor_info_t* info)
{
- struct gyro_cal_t* cal_data = (struct gyro_cal_t*) info->cal_data;
+ gyro_cal_t* cal_data = (gyro_cal_t*) info->cal_data;
if (cal_data == NULL)
return;
/*----------------------------------------------------------------------------*/
-static int64_t sample_as_int64(unsigned char* sample, struct datum_info_t* type)
+
+static int64_t sample_as_int64 (unsigned char* sample, datum_info_t* type)
{
uint64_t u64;
int i;
}
-static void reorder_fields(float* data, unsigned char map[MAX_CHANNELS])
+static void reorder_fields (float* data, unsigned char map[MAX_CHANNELS])
{
int i;
float temp[MAX_CHANNELS];
}
-static void clamp_gyro_readings_to_zero (int s, struct sensors_event_t* data)
+static void clamp_gyro_readings_to_zero (int s, sensors_event_t* data)
{
float x, y, z;
float near_zero;
}
}
-static void process_event_gyro_uncal(int s, int i, struct sensors_event_t* data)
+
+static void process_event_gyro_uncal (int s, int i, sensors_event_t* data)
{
- struct gyro_cal_t* gyro_data;
+ gyro_cal_t* gyro_data;
if (sensor[s].type == SENSOR_TYPE_GYROSCOPE) {
- gyro_data = (struct gyro_cal_t*) sensor[s].cal_data;
+ gyro_data = (gyro_cal_t*) sensor[s].cal_data;
- memcpy(&sensor[i].sample, data, sizeof(struct sensors_event_t));
+ memcpy(&sensor[i].sample, data, sizeof(sensors_event_t));
sensor[i].sample.type = SENSOR_TYPE_GYROSCOPE_UNCALIBRATED;
sensor[i].sample.sensor = s;
}
}
-static void process_event(int s, struct sensors_event_t* data)
+
+static void process_event (int s, sensors_event_t* data)
{
/*
* This gets the real event (post process - calibration, filtering & co.)
}
}
-static int finalize_sample_default (int s, struct sensors_event_t* data)
+
+static int finalize_sample_default (int s, sensors_event_t* data)
{
/* Swap fields if we have a custom channel ordering on this sensor */
if (sensor[s].quirks & QUIRK_FIELD_ORDERING)
static float transform_sample_default(int s, int c, unsigned char* sample_data)
{
- struct datum_info_t* sample_type = &sensor[s].channel[c].type_info;
- int64_t s64 = sample_as_int64(sample_data, sample_type);
+ datum_info_t* sample_type = &sensor[s].channel[c].type_info;
+ int64_t s64 = sample_as_int64(sample_data, sample_type);
float scale = sensor[s].scale ?
sensor[s].scale : sensor[s].channel[c].scale;
}
-static int finalize_sample_ISH (int s, struct sensors_event_t* data)
+static int finalize_sample_ISH (int s, sensors_event_t* data)
{
float pitch, roll, yaw;
static float transform_sample_ISH (int s, int c, unsigned char* sample_data)
{
- struct datum_info_t* sample_type = &sensor[s].channel[c].type_info;
+ datum_info_t* sample_type = &sensor[s].channel[c].type_info;
int val = (int) sample_as_int64(sample_data, sample_type);
float correction;
int data_bytes = (sample_type->realbits)/8;