OSDN Git Service

GMINL-7944: Ignore ALS intensity if illuminance is available
authorPatrick Porlan <patrick.porlan@intel.com>
Tue, 14 Apr 2015 12:21:58 +0000 (14:21 +0200)
committerAdriana Reus <adriana.reus@intel.com>
Wed, 15 Apr 2015 14:42:25 +0000 (17:42 +0300)
ALS drivers are increasing in sophistication and are now exposing
a variety of values, that we don't want to expose as different
sensors. Add arbitration code that will prioritize illuminance over
intensity.

Change-Id: I52fc3fb3e11be08ec62488a86bab7c04d06946f6
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
control.c
enumeration.c
transform.c

index e260b94..189d499 100644 (file)
--- a/control.c
+++ b/control.c
@@ -536,7 +536,7 @@ static void* acquisition_routine (void* param)
        /* Initialize data fields that will be shared by all sensor reports */
        data.version    = sizeof(sensors_event_t);
        data.sensor     = s;
-       data.type       = sensor[s].type;
+       data.type       = sensor_desc[s].type;
 
        num_fields = get_field_count(s, &field_size);
 
index fa02c28..f0fa564 100644 (file)
@@ -882,6 +882,37 @@ static void setup_trigger_names (void)
                }
 }
 
+
+static int catalog_index_from_sensor_type (int type)
+{
+       /* Return first matching catalog entry index for selected type */
+       unsigned int i;
+
+       for (i=0; i<catalog_size; i++)
+               if (sensor_catalog[i].type == type)
+                       return i;
+
+       return -1;
+}
+
+
+static void post_process_sensor_list (char poll_map[catalog_size], char trig_map[catalog_size], char event_map[catalog_size])
+{
+       int illuminance_cat_index = catalog_index_from_sensor_type(SENSOR_TYPE_INTERNAL_ILLUMINANCE);
+       int intensity_cat_index   = catalog_index_from_sensor_type(SENSOR_TYPE_INTERNAL_INTENSITY);
+       int illuminance_found     = poll_map[illuminance_cat_index] || trig_map[illuminance_cat_index] || event_map[illuminance_cat_index];
+
+       /* If an illumimance sensor has been reported */
+       if (illuminance_found) {
+               /* Hide any intensity sensors we can have for the same iio device */
+               poll_map [intensity_cat_index     ] = 0;
+               trig_map [intensity_cat_index     ] = 0;
+               event_map[intensity_cat_index     ] = 0;
+               return;
+       }
+}
+
+
 void enumerate_sensors (void)
 {
        /*
@@ -903,6 +934,9 @@ void enumerate_sensors (void)
                discover_sensors(dev_num, CHANNEL_PATH, trig_sensors, check_trig_sensors);
                discover_sensors(dev_num, EVENTS_PATH, event_sensors, check_event_sensors);
 
+               /* Hide specific sensor types if appropriate */
+               post_process_sensor_list(poll_sensors, trig_sensors, event_sensors);
+
                for (i=0; i<catalog_size; i++) {
                        /* Try using events interface */
                        if (event_sensors[i] && !add_sensor(dev_num, i, MODE_EVENT))
index 6d20c2c..a5acf6f 100644 (file)
@@ -295,6 +295,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 */
@@ -342,6 +343,8 @@ static int finalize_sample_default (int s, sensors_event_t* data)
                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));