#define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
#define REPORTING_MODE(x) ((x) & 0x06)
+#define FILTER_TYPE_NONE 0
+#define FILTER_TYPE_MOVING_AVERAGE 1
+#define FILTER_TYPE_MEDIAN 2
typedef struct
{
* events before filtering kicks in. We can also use it for statistics.
*/
uint64_t event_count;
+
+ int filter_type; /* FILTER_ specification for this sensor ; default is FILTER_NONE */
}
sensor_info_t;
sensor[s].event_count = 0;
sensor[s].meta_data_pending = 0;
- if (enabled && (sensor[s].quirks & QUIRK_NOISY))
+ if (enabled)
setup_noise_filtering(s); /* Initialize filtering data if required */
if (!sensor[s].is_polling) {
* properties values happen to have its iio device name set to bmg160.
*/
-static int sensor_get_st_prop (int s, const char* sel, char val[MAX_NAME_SIZE])
+int sensor_get_st_prop (int s, const char* sel, char val[MAX_NAME_SIZE])
{
char prop_name[PROP_NAME_MAX];
char prop_val[PROP_VALUE_MAX];
int sensor_get_order (int s,unsigned char map[MAX_CHANNELS]);
int sensor_get_cal_steps (int s);
char* sensor_get_string_type (int s);
+int sensor_get_st_prop (int s, const char* sel, char val[MAX_NAME_SIZE]);
#endif
#include <utils/Log.h>
#include "common.h"
#include "filtering.h"
-
+#include "description.h"
typedef struct
{
void setup_noise_filtering (int s)
{
- switch (sensor[s].type) {
- case SENSOR_TYPE_GYROSCOPE:
+ char filter_buf[MAX_NAME_SIZE];
+
+ /* By default, don't apply filtering */
+ sensor[s].filter_type = FILTER_TYPE_NONE;
+
+ /* If noisy, start with default filter for sensor type */
+ if (sensor[s].quirks & QUIRK_NOISY)
+ switch (sensor[s].type) {
+ case SENSOR_TYPE_GYROSCOPE:
+ sensor[s].filter_type = FILTER_TYPE_MEDIAN;
+ break;
+
+ case SENSOR_TYPE_MAGNETIC_FIELD:
+ sensor[s].filter_type = FILTER_TYPE_MOVING_AVERAGE;
+ break;
+ }
+
+ /* Use whatever was specified if there's an explicit configuration choice for this sensor */
+
+ filter_buf[0] = '\0';
+ sensor_get_st_prop(s, "filter", filter_buf);
+
+ if (strstr(filter_buf, "median"))
+ sensor[s].filter_type = FILTER_TYPE_MEDIAN;
+
+ if (strstr(filter_buf, "average"))
+ sensor[s].filter_type = FILTER_TYPE_MOVING_AVERAGE;
+
+ switch (sensor[s].filter_type) {
+ case FILTER_TYPE_MEDIAN:
denoise_median_init(s, 3, 5);
break;
}
void denoise (int s, sensors_event_t* data)
{
- switch (sensor[s].type) {
- case SENSOR_TYPE_GYROSCOPE:
+ switch (sensor[s].filter_type) {
+ case FILTER_TYPE_MEDIAN:
denoise_median(&sensor[s], data, 3);
break;
- case SENSOR_TYPE_MAGNETIC_FIELD:
+ case FILTER_TYPE_MOVING_AVERAGE:
denoise_average(&sensor[s], data, 3 , 20);
break;
}
case SENSOR_TYPE_ACCELEROMETER:
/* Always consider the accelerometer accurate */
data->acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
- if (sensor[s].quirks & QUIRK_NOISY)
- denoise(s, data);
+ denoise(s, data);
break;
case SENSOR_TYPE_MAGNETIC_FIELD:
calibrate_compass (data, &sensor[s]);
- if (sensor[s].quirks & QUIRK_NOISY)
- denoise(s, data);
+ denoise(s, data);
break;
case SENSOR_TYPE_GYROSCOPE:
* For noisy sensors drop a few samples to make sure we have at least GYRO_MIN_SAMPLES events in the
* filtering queue. This improves mean and std dev.
*/
- if (sensor[s].quirks & QUIRK_NOISY) {
+ if (sensor[s].filter_type) {
if (sensor[s].selected_trigger !=
sensor[s].motion_trigger_name &&
sensor[s].event_count < GYRO_MIN_SAMPLES)