OSDN Git Service

Reinstate monotonic timestamp in data acquisition threads
[android-x86/hardware-intel-libsensors.git] / enumeration.c
index 0db6c8b..c6fd7a3 100644 (file)
@@ -14,7 +14,6 @@
 #include "description.h"
 #include "control.h"
 #include "calibration.h"
-#include "filtering.h"
 
 /*
  * This table maps syfs entries in scan_elements directories to sensor types,
@@ -231,6 +230,7 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
 
        sensor_info[s].dev_num          = dev_num;
        sensor_info[s].catalog_index    = catalog_index;
+       sensor_info[s].type             = sensor_type;
 
         num_channels = sensor_catalog[catalog_index].num_channels;
 
@@ -245,7 +245,7 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
         * receiving the illumination sensor calibration inputs from
         * the Android properties and setting it within sysfs
         */
-       if (sensor_catalog[catalog_index].type == SENSOR_TYPE_LIGHT) {
+       if (sensor_type == SENSOR_TYPE_LIGHT) {
                retval = sensor_get_illumincalib(s);
                 if (retval > 0) {
                        sprintf(sysfs_path, ILLUMINATION_CALIBPATH, dev_num);
@@ -263,6 +263,25 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
        sysfs_read_float(sysfs_path, &sensor_info[s].offset);
 
        sprintf(sysfs_path, SENSOR_SCALE_PATH, dev_num, prefix);
+       if (!sensor_get_fl_prop(s, "scale", &scale)) {
+               /*
+                * There is a chip preferred scale specified,
+                * so try to store it in sensor's scale file
+                */
+               if (sysfs_write_float(sysfs_path, scale) == -1 && errno == ENOENT) {
+                       ALOGE("Failed to store scale[%f] into %s - file is missing", scale, sysfs_path);
+                       /* Store failed, try to store the scale into channel specific file */
+                       for (c = 0; c < num_channels; c++)
+                       {
+                               sprintf(sysfs_path, BASE_PATH "%s", dev_num,
+                                       sensor_catalog[catalog_index].channel[c].scale_path);
+                               if (sysfs_write_float(sysfs_path, scale) == -1)
+                                       ALOGE("Failed to store scale[%f] into %s", scale, sysfs_path);
+                        }
+                }
+       }
+
+       sprintf(sysfs_path, SENSOR_SCALE_PATH, dev_num, prefix);
        if (!sysfs_read_float(sysfs_path, &scale)) {
                 sensor_info[s].scale = scale;
                ALOGI("Scale path:%s scale:%f dev_num:%d\n",
@@ -345,6 +364,9 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
        sensor_desc[s].fifoReservedEventCount = 0;
        sensor_desc[s].fifoMaxEventCount = 0;
 
+       /* Populate the quirks array */
+       sensor_get_quirks(s);
+
        if (sensor_info[s].internal_name[0] == '\0') {
                /*
                 * In case the kernel-mode driver doesn't expose a name for
@@ -359,14 +381,13 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
                sensor_type == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED) {
                struct gyro_cal* calibration_data = calloc(1, sizeof(struct gyro_cal));
                sensor_info[s].cal_data = calibration_data;
-               denoise_median_init(s, 7, 3);
        }
 
        if (sensor_type == SENSOR_TYPE_MAGNETIC_FIELD) {
                struct compass_cal* calibration_data = calloc(1, sizeof(struct compass_cal));
                sensor_info[s].cal_data = calibration_data;
        }
-
+       sensor_info[s].max_cal_level = sensor_get_cal_steps(s);
        /* Select one of the available sensor sample processing styles */
        select_transform(s);
 
@@ -375,8 +396,6 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
        sensor_info[s].thread_data_fd[1]  = -1;
        sensor_info[s].acquisition_thread = -1;
 
-       sensor_info[s].meta_data_pending = 0;
-
        /* Check if we have a special ordering property on this sensor */
        if (sensor_get_order(s, sensor_info[s].order))
                sensor_info[s].quirks |= QUIRK_FIELD_ORDERING;
@@ -486,7 +505,7 @@ static void orientation_sensor_check(void)
        int catalog_size = CATALOG_SIZE;
 
        for (i=0; i<sensor_count; i++)
-               switch (sensor_catalog[sensor_info[i].catalog_index].type) {
+               switch (sensor_info[i].type) {
                        case SENSOR_TYPE_ACCELEROMETER:
                                has_acc = 1;
                                break;
@@ -513,33 +532,6 @@ static void orientation_sensor_check(void)
                        }
 }
 
-static int is_continuous (int s)
-{
-       /* Is sensor s of the continous trigger type kind? */
-
-       int catalog_index = sensor_info[s].catalog_index;
-       int sensor_type = sensor_catalog[catalog_index].type;
-
-       switch (sensor_type) {
-               case SENSOR_TYPE_ACCELEROMETER:
-               case SENSOR_TYPE_MAGNETIC_FIELD:
-               case SENSOR_TYPE_ORIENTATION:
-               case SENSOR_TYPE_GYROSCOPE:
-               case SENSOR_TYPE_PRESSURE:
-               case SENSOR_TYPE_GRAVITY:
-               case SENSOR_TYPE_LINEAR_ACCELERATION:
-               case SENSOR_TYPE_ROTATION_VECTOR:
-               case SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED:
-               case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
-               case SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR:
-                       return 1;
-
-               default:
-                       return 0;
-       }
-}
-
-
 static void propose_new_trigger (int s, char trigger_name[MAX_NAME_SIZE],
                                 int sensor_name_len)
 {
@@ -555,19 +547,18 @@ static void propose_new_trigger (int s, char trigger_name[MAX_NAME_SIZE],
        if (!memcmp(suffix, "dev", 3))
                return;
 
-       /*
-        * If we found any-motion trigger, record it and force the sensor to
-        * automatic intermediate event generation mode, at least if it is of a
-        * continuously firing sensor type.
-        */
+       /* If we found any-motion trigger, record it */
 
-       if (!memcmp(suffix, "any-motion-", 11) && is_continuous(s)) {
-               /* Update the any-motion trigger name to use for this sensor */
+       if (!memcmp(suffix, "any-motion-", 11)) {
                strcpy(sensor_info[s].motion_trigger_name, trigger_name);
                return;
        }
 
-       /* Update the initial trigger name to use for this sensor */
+       /*
+        * It's neither the default "dev" nor an "any-motion" one. Make sure we
+        * use this though, as we may not have any other indication of the name
+        * of the trigger to use with this sensor.
+        */
        strcpy(sensor_info[s].init_trigger_name, trigger_name);
 }
 
@@ -655,13 +646,26 @@ static void setup_trigger_names (void)
                update_sensor_matching_trigger_name(buf);
        }
 
+       /*
+        * Certain drivers expose only motion triggers even though they should
+        * be continous. For these, use the default trigger name as the motion
+        * trigger. The code generating intermediate events is dependent on
+        * motion_trigger_name being set to a non empty string.
+        */
+
+       for (s=0; s<sensor_count; s++)
+               if ((sensor_info[s].quirks & QUIRK_TERSE_DRIVER) &&
+                   sensor_info[s].motion_trigger_name[0] == '\0')
+                       strcpy( sensor_info[s].motion_trigger_name,
+                               sensor_info[s].init_trigger_name);
+
        for (s=0; s<sensor_count; s++)
                if (sensor_info[s].num_channels) {
-                       ALOGI(  "Sensor %d (%s) default trigger: %s\n", s,
+                       ALOGI("Sensor %d (%s) default trigger: %s\n", s,
                                sensor_info[s].friendly_name,
                                sensor_info[s].init_trigger_name);
                        if (sensor_info[s].motion_trigger_name[0])
-                               ALOGI(  "Sensor %d (%s) motion trigger: %s\n",
+                               ALOGI("Sensor %d (%s) motion trigger: %s\n",
                                s, sensor_info[s].friendly_name,
                                sensor_info[s].motion_trigger_name);
                }
@@ -681,8 +685,7 @@ static void uncalibrated_gyro_check (void)
 
        /* Checking to see if we have a gyroscope - we can only have uncal if we have the base sensor */
        for (i=0; i < sensor_count; i++)
-               if(sensor_catalog[sensor_info[i].catalog_index].type == SENSOR_TYPE_GYROSCOPE)
-               {
+               if (sensor_info[i].type == SENSOR_TYPE_GYROSCOPE) {
                        has_gyr=1;
                        dev_num = sensor_info[i].dev_num;
                        is_poll_sensor = !sensor_info[i].num_channels;
@@ -777,16 +780,21 @@ void enumerate_sensors (void)
         * Create the uncalibrated counterpart to the compensated gyroscope.
         * This is is a new sensor type in Android 4.4.
         */
-       uncalibrated_gyro_check();
+
+       /*
+        * Patrick Porlan 11/12/2014 - Disabled for now due to a possible
+        * relation with GMINL-3234 Panorama Drift. I take full responsability
+        * for this.
+        *
+        * uncalibrated_gyro_check(); */
 }
 
 
 void delete_enumeration_data (void)
 {
-
        int i;
        for (i = 0; i < sensor_count; i++)
-       switch (sensor_catalog[sensor_info[i].catalog_index].type) {
+       switch (sensor_info[i].type) {
                case SENSOR_TYPE_MAGNETIC_FIELD:
                        if (sensor_info[i].cal_data != NULL) {
                                free(sensor_info[i].cal_data);
@@ -794,6 +802,7 @@ void delete_enumeration_data (void)
                                sensor_info[i].cal_level = 0;
                        }
                        break;
+
                case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
                case SENSOR_TYPE_GYROSCOPE:
                        if (sensor_info[i].cal_data != NULL) {
@@ -802,9 +811,7 @@ void delete_enumeration_data (void)
                                sensor_info[i].cal_level = 0;
                        }
                        break;
-                       if (sensor_info[i].filter != NULL) {
-                               denoise_median_release(i);
-                       }
+
                default:
                        break;
        }
@@ -813,8 +820,8 @@ void delete_enumeration_data (void)
 }
 
 
-int get_sensors_list struct sensors_module_t* module,
-                       struct sensor_t const** list)
+int get_sensors_list (__attribute__((unused)) struct sensors_module_t* module,
+                     struct sensor_t const** list)
 {
        *list = sensor_desc;
        return sensor_count;