OSDN Git Service

Add "shorthand" field to sensor_catalog
[android-x86/hardware-intel-libsensors.git] / transform.c
index 25094f6..eaf0faf 100644 (file)
@@ -13,7 +13,7 @@
 #include "transform.h"
 #include "utils.h"
 #include "filtering.h"
-
+#include "enumeration.h"
 
 #define        GYRO_MIN_SAMPLES 5 /* Drop first few gyro samples after enable */
 
@@ -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;
@@ -295,6 +297,7 @@ static int finalize_sample_default (int s, sensors_event_t* data)
                reorder_fields(data->data, sensor[s].order);
 
        sensor[s].event_count++;
+
        switch (sensor[s].type) {
                case SENSOR_TYPE_ACCELEROMETER:
                        /* Always consider the accelerometer accurate */
@@ -305,7 +308,7 @@ static int finalize_sample_default (int s, sensors_event_t* data)
                        break;
 
                case SENSOR_TYPE_MAGNETIC_FIELD:
-                       calibrate_compass (data, &sensor[s]);
+                       calibrate_compass (s, data);
                        denoise(s, data);
                        break;
 
@@ -320,7 +323,7 @@ static int finalize_sample_default (int s, sensors_event_t* data)
                         */
                        if (sensor[s].selected_trigger !=
                                sensor[s].motion_trigger_name)
-                                       calibrate_gyro(data, &sensor[s]);
+                                       calibrate_gyro(s, data);
 
                        /*
                         * For noisy sensors drop a few samples to make sure we have at least GYRO_MIN_SAMPLES events in the
@@ -339,15 +342,25 @@ 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:
+               case SENSOR_TYPE_INTERNAL_ILLUMINANCE:
+               case SENSOR_TYPE_INTERNAL_INTENSITY:
                        /* 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;
@@ -359,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 */
@@ -421,7 +435,7 @@ static float transform_sample_ISH (int s, int c, unsigned char* sample_data)
        /* In case correction has been requested using properties, apply it */
        correction = sensor[s].channel[c].opt_scale;
 
-       switch (sensor[s].type) {
+       switch (sensor_desc[s].type) {
                case SENSOR_TYPE_ACCELEROMETER:
                        switch (c) {
                                case 0: