OSDN Git Service

IRDA-3484: Optionally read window size from filter specification
authorPatrick Porlan <patrick.porlan@intel.com>
Wed, 28 Jan 2015 15:25:24 +0000 (16:25 +0100)
committerPatrick Porlan <patrick.porlan@intel.com>
Wed, 28 Jan 2015 15:30:20 +0000 (16:30 +0100)
I.e. filter=average,10 would supersede the default moving average
window size for a specific sensor.

Change-Id: I6d55f1e7b653a99f5eb4cc2ac4b124131ee876e4
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
Tracked-On: https://jira01.devtools.intel.com/browse/IRDA-3484
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
filtering.c

index 89ab641..ab6f90c 100644 (file)
@@ -2,6 +2,8 @@
  * Copyright (C) 2014 Intel Corporation.
  */
 
+#include <ctype.h>
+#include <stdlib.h>
 #include <hardware/sensors.h>
 #include <utils/Log.h>
 #include "common.h"
@@ -234,6 +236,8 @@ void setup_noise_filtering (int s)
 {
        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;
@@ -267,20 +271,32 @@ void setup_noise_filtering (int s)
        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;
+       }
+
+       /* Check if an integer is part of the string, and use it as window size */
+       if (cursor) {
+               while (*cursor && !isdigit(*cursor))
+                       cursor++;
 
-       if (strstr(filter_buf, "average"))
-               sensor[s].filter_type = FILTER_TYPE_MOVING_AVERAGE;
+               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;
        }
 }