/*
- * Copyright (C) 2014 Intel Corporation.
+ * Copyright (C) 2014-2015 Intel Corporation.
*/
+#include <ctype.h>
+#include <stdlib.h>
#include <hardware/sensors.h>
#include <utils/Log.h>
#include "common.h"
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;
filter_median_t* f_data = (filter_median_t*) info->filter;
* depending on which is lower.
*/
- int i;
int f;
int sampling_rate = (int) si->sampling_rate;
int history_size;
{
char filter_buf[MAX_NAME_SIZE];
int num_fields;
+ char* cursor;
+ int window_size = 0;
/* By default, don't apply filtering */
sensor[s].filter_type = FILTER_TYPE_NONE;
filter_buf[0] = '\0';
sensor_get_st_prop(s, "filter", filter_buf);
- if (strstr(filter_buf, "median"))
+ cursor = strstr(filter_buf, "median");
+ if (cursor)
sensor[s].filter_type = FILTER_TYPE_MEDIAN;
+ else {
+ cursor = strstr(filter_buf, "average");
+ if (cursor)
+ sensor[s].filter_type = FILTER_TYPE_MOVING_AVERAGE;
+ }
- if (strstr(filter_buf, "average"))
- sensor[s].filter_type = FILTER_TYPE_MOVING_AVERAGE;
+ /* Check if an integer is part of the string, and use it as window size */
+ if (cursor) {
+ while (*cursor && !isdigit(*cursor))
+ cursor++;
+
+ if (*cursor)
+ window_size = atoi(cursor);
+ }
switch (sensor[s].filter_type) {
case FILTER_TYPE_MEDIAN:
- denoise_median_init(s, num_fields, 5);
+ denoise_median_init(s, num_fields, window_size ? window_size : 5);
break;
case FILTER_TYPE_MOVING_AVERAGE:
- denoise_average_init(s, num_fields, 20);
+ denoise_average_init(s, num_fields, window_size ? window_size: 20);
break;
}
}