+ if (sensor[s].hrtimer_trigger_name[0])
+ ALOGI("Sensor %d (%s) hrtimer trigger: %s\n", s, sensor[s].friendly_name, sensor[s].hrtimer_trigger_name);
+ }
+}
+
+
+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;
+ }
+}
+
+
+static void swap_sensors (int s1, int s2)
+{
+ struct sensor_t temp_sensor_desc;
+ sensor_info_t temp_sensor;
+
+ /* S1 -> temp */
+ memcpy(&temp_sensor, &sensor[s1], sizeof(sensor_info_t));
+ memcpy(&temp_sensor_desc, &sensor_desc[s1], sizeof(struct sensor_t));
+
+ /* S2 -> S1 */
+ memcpy(&sensor[s1], &sensor[s2], sizeof(sensor_info_t));
+ memcpy(&sensor_desc[s1], &sensor_desc[s2], sizeof(struct sensor_t));
+
+ /* temp -> S2 */
+ memcpy(&sensor[s2], &temp_sensor, sizeof(sensor_info_t));
+ memcpy(&sensor_desc[s2], &temp_sensor_desc, sizeof(struct sensor_t));
+
+ /* Fix-up sensor id mapping, which is stale */
+ sensor_desc[s1].handle = s1;
+ sensor_desc[s2].handle = s2;
+
+ /* Fix up name and vendor buffer pointers, which are potentially stale pointers */
+ sensor_desc[s1].name = sensor_get_name(s1);
+ sensor_desc[s1].vendor = sensor_get_vendor(s1);
+ sensor_desc[s2].name = sensor_get_name(s2);
+ sensor_desc[s2].vendor = sensor_get_vendor(s2);
+}
+
+
+static void reorder_sensors (void)
+{
+ /* Some sensors may be marked as secondary - these need to be listed after other sensors of the same type */
+ int s1, s2;
+
+ for (s1=0; s1<sensor_count-1; s1++)
+ if (sensor[s1].quirks & QUIRK_SECONDARY) {
+ /* Search for subsequent sensors of same type */
+ for (s2 = s1+1; s2<sensor_count; s2++)
+ if (sensor[s2].type == sensor[s1].type && !(sensor[s2].quirks & QUIRK_SECONDARY)) {
+ ALOGI("Sensor S%d has higher priority than S%d, swapping\n", s2, s1);
+ swap_sensors(s1, s2);
+ break;
+ }