OSDN Git Service

Clamp high proximity values to 1m
authorAdriana Reus <adriana.reus@intel.com>
Thu, 16 Apr 2015 12:25:14 +0000 (15:25 +0300)
committerAdriana Reus <adriana.reus@intel.com>
Fri, 17 Apr 2015 09:20:55 +0000 (12:20 +0300)
See iio spec for in_proximity* - depending on the device
this value is either in meters either unit-less and cannot
be translated to SI units. Where the translation is not possible
lower values indicate something is close and higher ones indicate distance.

Tracked-On: https://jira01.devtools.intel.com/browse/GMINL-8221
Change-Id: Ic88ff54692c3b0983aa46afe35498c83f7955e3a
Signed-off-by: Adriana Reus <adriana.reus@intel.com>
transform.c

index a5acf6f..eaf0faf 100644 (file)
@@ -57,6 +57,8 @@
 
 #define BIT(x) (1 << (x))
 
+#define PROXIMITY_THRESHOLD 1
+
 inline unsigned int set_bit_range (int start, int end)
 {
        int i;
@@ -340,6 +342,17 @@ static int finalize_sample_default (int s, sensors_event_t* data)
                        clamp_gyro_readings_to_zero(s, data);
                        break;
 
+               case SENSOR_TYPE_PROXIMITY:
+                       /*
+                        * See iio spec for in_proximity* - depending on the device
+                        * this value is either in meters either unit-less and cannot
+                        * be translated to SI units. Where the translation is not possible
+                        * lower values indicate something is close and higher ones indicate distance.
+                        */
+                       if (data->data[0] > PROXIMITY_THRESHOLD)
+                               data->data[0] = PROXIMITY_THRESHOLD;
+
+                       /* ... fall through ... */
                case SENSOR_TYPE_LIGHT:
                case SENSOR_TYPE_AMBIENT_TEMPERATURE:
                case SENSOR_TYPE_TEMPERATURE:
@@ -348,9 +361,6 @@ static int finalize_sample_default (int s, sensors_event_t* data)
                        /* Only keep two decimals for these readings */
                        data->data[0] = 0.01 * ((int) (data->data[0] * 100));
 
-                       /* ... fall through ... */
-
-               case SENSOR_TYPE_PROXIMITY:
                        /* These are on change sensors ; drop the sample if it has the same value as the previously reported one. */
                        if (data->data[0] == sensor[s].prev_val.data)
                                return 0;
@@ -362,6 +372,7 @@ static int finalize_sample_default (int s, sensors_event_t* data)
                                return 0;
                        sensor[s].prev_val.data64 = data->u64.data[0];
                        break;
+
        }
 
        /* If there are active virtual sensors depending on this one - process the event */