OSDN Git Service

Min/Max delay for Light and Temperature
[android-x86/hardware-intel-libsensors.git] / enumeration.c
index b5464f7..eda8845 100644 (file)
@@ -14,6 +14,7 @@
 #include "description.h"
 #include "control.h"
 #include "calibration.h"
+#include "filtering.h"
 
 /*
  * This table maps syfs entries in scan_elements directories to sensor types,
@@ -332,7 +333,17 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
        */
        sensor_desc[s].requiredPermission = "";
        sensor_desc[s].flags = sensor_get_flags(s);
+       sensor_desc[s].minDelay = sensor_get_min_delay(s);
        sensor_desc[s].maxDelay = sensor_get_max_delay(s);
+       ALOGI("Sensor %d (%s) type(%d) minD(%ld) maxD(%ld) flags(%2.2x)\n",
+               s, sensor_info[s].friendly_name, sensor_desc[s].type,
+               sensor_desc[s].minDelay, sensor_desc[s].maxDelay, sensor_desc[s].flags);
+
+       /* We currently do not implement batching when we'll so
+        * these should be overriden appropriately
+        */
+       sensor_desc[s].fifoReservedEventCount = 0;
+       sensor_desc[s].fifoMaxEventCount = 0;
 
        if (sensor_info[s].internal_name[0] == '\0') {
                /*
@@ -348,6 +359,17 @@ 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;
+               struct filter* f_data = (struct filter*) calloc(1, sizeof(struct filter));
+               f_data->x_buff = (struct circ_buff*) calloc(1, sizeof (struct circ_buff));
+               f_data->y_buff = (struct circ_buff*) calloc(1, sizeof (struct circ_buff));
+               f_data->z_buff = (struct circ_buff*) calloc(1, sizeof (struct circ_buff));
+               f_data->x_buff->buff = (float*)calloc(SAMPLE_SIZE, sizeof(float));
+               f_data->y_buff->buff = (float*)calloc(SAMPLE_SIZE, sizeof(float));
+               f_data->z_buff->buff = (float*)calloc(SAMPLE_SIZE, sizeof(float));
+               f_data->x_buff->size = SAMPLE_SIZE;
+               f_data->y_buff->size = SAMPLE_SIZE;
+               f_data->z_buff->size = SAMPLE_SIZE;
+               sensor_info[s].filter = f_data;
        }
 
        if (sensor_type == SENSOR_TYPE_MAGNETIC_FIELD) {
@@ -499,58 +521,6 @@ static void orientation_sensor_check(void)
                        }
 }
 
-static void uncalibrated_gyro_check (void)
-{
-       unsigned int has_gyr = 0;
-       unsigned int dev_num;
-       int i, c;
-       unsigned int is_poll_sensor;
-
-       int cal_idx = 0;
-       int uncal_idx = 0;
-
-       /* 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)
-               {
-                       has_gyr=1;
-                       dev_num = sensor_info[i].dev_num;
-                       is_poll_sensor = !sensor_info[i].num_channels;
-                       cal_idx = i;
-                       break;
-               }
-
-       /*
-        * If we have a gyro we can add the uncalibrated sensor of the same type and
-        * on the same dev_num. We will save indexes for easy finding and also save the
-        * channel specific information.
-        */
-       if (has_gyr)
-               for (i=0; i<CATALOG_SIZE; i++)
-                       if (sensor_catalog[i].type == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED) {
-                               add_sensor(dev_num, i, is_poll_sensor);
-
-                               uncal_idx = sensor_count - 1; /* Just added uncalibrated sensor */
-
-                               /* Similar to build_sensor_report_maps */
-                               for (c = 0; c < sensor_info[uncal_idx].num_channels; c++)
-                               {
-                                       memcpy( &(sensor_info[uncal_idx].channel[c].type_spec),
-                                               &(sensor_info[cal_idx].channel[c].type_spec),
-                                               sizeof(sensor_info[uncal_idx].channel[c].type_spec));
-                                       sensor_info[uncal_idx].channel[c].type_info = sensor_info[cal_idx].channel[c].type_info;
-                                       sensor_info[uncal_idx].channel[c].offset    = sensor_info[cal_idx].channel[c].offset;
-                                       sensor_info[uncal_idx].channel[c].size      = sensor_info[cal_idx].channel[c].size;
-                               }
-                               strncpy(sensor_info[uncal_idx].trigger_name,
-                                       sensor_info[cal_idx].trigger_name,
-                                       MAX_NAME_SIZE);
-                               sensor_info[uncal_idx].pair_idx = cal_idx;
-                               sensor_info[cal_idx].pair_idx = uncal_idx;
-                               break;
-                       }
-}
-
 static int is_continuous (int s)
 {
        /* Is sensor s of the continous trigger type kind? */
@@ -594,25 +564,19 @@ static void propose_new_trigger (int s, char trigger_name[MAX_NAME_SIZE],
                return;
 
        /*
-        * Anything else is higher priority. However if we already found an
-        * any-motion trigger, don't select anything else.
-        */
-
-       if (!memcmp(sensor_info[s].trigger_name + sensor_name_len + 1,
-                   "any-motion-", 11))
-               return;
-
-       /*
-        * If we're switching to an any-motion trigger, force the sensor to
+        * 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 (!memcmp(suffix, "any-motion-", 11) && is_continuous(s))
-               sensor_info[s].quirks |= QUIRK_TERSE_DRIVER;
+       if (!memcmp(suffix, "any-motion-", 11) && is_continuous(s)) {
+               /* Update the any-motion trigger name to use for this sensor */
+               strcpy(sensor_info[s].motion_trigger_name, trigger_name);
+               return;
+       }
 
-       /* Update the trigger name to use for this sensor */
-       strcpy(sensor_info[s].trigger_name, trigger_name);
+       /* Update the initial trigger name to use for this sensor */
+       strcpy(sensor_info[s].init_trigger_name, trigger_name);
 }
 
 
@@ -680,8 +644,9 @@ static void setup_trigger_names (void)
 
        /* By default, use the name-dev convention that most drivers use */
        for (s=0; s<sensor_count; s++)
-               snprintf(sensor_info[s].trigger_name, MAX_NAME_SIZE, "%s-dev%d",
-                       sensor_info[s].internal_name, sensor_info[s].dev_num);
+               snprintf(sensor_info[s].init_trigger_name,
+                        MAX_NAME_SIZE, "%s-dev%d",
+                        sensor_info[s].internal_name, sensor_info[s].dev_num);
 
        /* Now have a look to /sys/bus/iio/devices/triggerX entries */
 
@@ -694,17 +659,84 @@ static void setup_trigger_names (void)
                if (ret < 0)
                        break;
 
+               /* Record initial and any-motion triggers names */
                update_sensor_matching_trigger_name(buf);
        }
 
        for (s=0; s<sensor_count; s++)
                if (sensor_info[s].num_channels) {
-                       ALOGI(  "Sensor %d (%s) using iio trigger %s\n", s,
+                       ALOGI(  "Sensor %d (%s) default trigger: %s\n", s,
                                sensor_info[s].friendly_name,
-                               sensor_info[s].trigger_name);
+                               sensor_info[s].init_trigger_name);
+                       if (sensor_info[s].motion_trigger_name[0])
+                               ALOGI(  "Sensor %d (%s) motion trigger: %s\n",
+                               s, sensor_info[s].friendly_name,
+                               sensor_info[s].motion_trigger_name);
                }
 }
 
+static void uncalibrated_gyro_check (void)
+{
+       unsigned int has_gyr = 0;
+       unsigned int dev_num;
+       int i, c;
+       unsigned int is_poll_sensor;
+       char buf[MAX_NAME_SIZE];
+
+       int cal_idx = 0;
+       int uncal_idx = 0;
+       int catalog_size = CATALOG_SIZE; /* Avoid GCC sign comparison warning */
+
+       /* 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)
+               {
+                       has_gyr=1;
+                       dev_num = sensor_info[i].dev_num;
+                       is_poll_sensor = !sensor_info[i].num_channels;
+                       cal_idx = i;
+                       break;
+               }
+
+       /*
+        * If we have a gyro we can add the uncalibrated sensor of the same type and
+        * on the same dev_num. We will save indexes for easy finding and also save the
+        * channel specific information.
+        */
+       if (has_gyr)
+               for (i=0; i<catalog_size; i++)
+                       if (sensor_catalog[i].type == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED) {
+                               add_sensor(dev_num, i, is_poll_sensor);
+
+                               uncal_idx = sensor_count - 1; /* Just added uncalibrated sensor */
+
+                               /* Similar to build_sensor_report_maps */
+                               for (c = 0; c < sensor_info[uncal_idx].num_channels; c++)
+                               {
+                                       memcpy( &(sensor_info[uncal_idx].channel[c].type_spec),
+                                               &(sensor_info[cal_idx].channel[c].type_spec),
+                                               sizeof(sensor_info[uncal_idx].channel[c].type_spec));
+                                       sensor_info[uncal_idx].channel[c].type_info = sensor_info[cal_idx].channel[c].type_info;
+                                       sensor_info[uncal_idx].channel[c].offset    = sensor_info[cal_idx].channel[c].offset;
+                                       sensor_info[uncal_idx].channel[c].size      = sensor_info[cal_idx].channel[c].size;
+                               }
+                               sensor_info[uncal_idx].pair_idx = cal_idx;
+                               sensor_info[cal_idx].pair_idx = uncal_idx;
+                               strncpy(sensor_info[uncal_idx].init_trigger_name,
+                                       sensor_info[cal_idx].init_trigger_name,
+                                       MAX_NAME_SIZE);
+                               strncpy(sensor_info[uncal_idx].motion_trigger_name,
+                                       sensor_info[cal_idx].motion_trigger_name,
+                                       MAX_NAME_SIZE);
+
+                               /* Add "Uncalibrated " prefix to sensor name */
+                               strcpy(buf, sensor_info[cal_idx].friendly_name);
+                               snprintf(sensor_info[uncal_idx].friendly_name,
+                                        MAX_NAME_SIZE,
+                                        "%s %s", "Uncalibrated", buf);
+                               break;
+                       }
+}
 
 void enumerate_sensors (void)
 {
@@ -749,8 +781,10 @@ void enumerate_sensors (void)
        /* Make sure Android fall backs to its own orientation sensor */
        orientation_sensor_check();
 
-       /* Create the uncalibrated counterpart to the compensated gyroscope;
-        * This is is a new sensor type in Android 4.4 */
+       /*
+        * Create the uncalibrated counterpart to the compensated gyroscope.
+        * This is is a new sensor type in Android 4.4.
+        */
        uncalibrated_gyro_check();
 }
 
@@ -762,6 +796,12 @@ void delete_enumeration_data (void)
        for (i = 0; i < sensor_count; i++)
        switch (sensor_catalog[sensor_info[i].catalog_index].type) {
                case SENSOR_TYPE_MAGNETIC_FIELD:
+                       if (sensor_info[i].cal_data != NULL) {
+                               free(sensor_info[i].cal_data);
+                               sensor_info[i].cal_data = NULL;
+                               sensor_info[i].cal_level = 0;
+                       }
+                       break;
                case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
                case SENSOR_TYPE_GYROSCOPE:
                        if (sensor_info[i].cal_data != NULL) {
@@ -770,6 +810,16 @@ void delete_enumeration_data (void)
                                sensor_info[i].cal_level = 0;
                        }
                        break;
+                       if (sensor_info[i].filter != NULL) {
+                               free(((struct filter*)sensor_info[i].filter)->x_buff->buff);
+                               free(((struct filter*)sensor_info[i].filter)->y_buff->buff);
+                               free(((struct filter*)sensor_info[i].filter)->z_buff->buff);
+                               free(((struct filter*)sensor_info[i].filter)->x_buff);
+                               free(((struct filter*)sensor_info[i].filter)->y_buff);
+                               free(((struct filter*)sensor_info[i].filter)->z_buff);
+                               free(sensor_info[i].filter);
+                               sensor_info[i].filter = NULL;
+                       }
                default:
                        break;
        }