OSDN Git Service

Merge remote-tracking branch 'origin/abt/topic/gmin/l-dev/sensors/master' into gmin...
[android-x86/hardware-intel-libsensors.git] / control.c
index 3e3ae6a..34a8f06 100644 (file)
--- a/control.c
+++ b/control.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Intel Corporation.
+ * Copyright (C) 2014-2015 Intel Corporation.
  */
 
 #include <stdlib.h>
@@ -13,7 +13,7 @@
 #include <sys/socket.h>
 #include <utils/Log.h>
 #include <hardware/sensors.h>
-#include <linux/iio/events.h>
+#include <linux/ioctl.h>
 #include "control.h"
 #include "enumeration.h"
 #include "utils.h"
 #include "description.h"
 #include "filtering.h"
 
+/* Couple of temporary defines until we get a suitable linux/iio/events.h include */
+
+struct iio_event_data {
+         __u64   id;
+         __s64   timestamp;
+};
+
+#define IIO_GET_EVENT_FD_IOCTL _IOR('i', 0x90, int)
+
 /* Currently active sensors count, per device */
 static int poll_sensors_per_dev[MAX_DEVICES];          /* poll-mode sensors                            */
 static int trig_sensors_per_dev[MAX_DEVICES];          /* trigger, event based                         */
@@ -440,6 +449,7 @@ static int get_field_count (int s, size_t *field_size)
                case SENSOR_TYPE_PROXIMITY:             /* centimeters  */
                case SENSOR_TYPE_PRESSURE:              /* hecto-pascal */
                case SENSOR_TYPE_RELATIVE_HUMIDITY:     /* percent */
+               case SENSOR_TYPE_STEP_DETECTOR:         /* event: always 1 */
                        return 1;
 
                case SENSOR_TYPE_ROTATION_VECTOR:
@@ -833,13 +843,17 @@ static int sensor_set_rate (int s, float requested_rate)
                arb_sampling_rate = sensor[s].max_supported_rate;
        }
 
+       /* Record the rate that was agreed upon with the sensor taken in isolation ; this avoid uncontrolled ripple effects between colocated sensor rates */
+       sensor[s].semi_arbitrated_rate = arb_sampling_rate;
+
        /* Coordinate with others active sensors on the same device, if any */
        if (per_device_sampling_rate)
                for (n=0; n<sensor_count; n++)
-                       if (n != s && sensor[n].dev_num == dev_num && sensor[n].num_channels && is_enabled(n) && sensor[n].sampling_rate > arb_sampling_rate) {
+                       if (n != s && sensor[n].dev_num == dev_num && sensor[n].num_channels && is_enabled(n) &&
+                               sensor[n].semi_arbitrated_rate > arb_sampling_rate) {
                                ALOGV("Sampling rate shared between %s and %s, using %g instead of %g\n", sensor[s].friendly_name, sensor[n].friendly_name,
-                                                                                                         sensor[n].sampling_rate, arb_sampling_rate);
-                               arb_sampling_rate = sensor[n].sampling_rate;
+                                                                                                         sensor[n].semi_arbitrated_rate, arb_sampling_rate);
+                               arb_sampling_rate = sensor[n].semi_arbitrated_rate;
                        }
 
        sensor[s].sampling_rate = arb_sampling_rate;
@@ -1276,7 +1290,7 @@ static int integrate_device_report_from_event(int dev_num, int fd)
 
        ts = event.timestamp;
 
-       ALOGV("Read event %ld from fd %d of iio device %d\n", event.id, fd, dev_num);
+       ALOGV("Read event %lld from fd %d of iio device %d\n", event.id, fd, dev_num);
 
        /* Map device report to sensor reports */
        for (s = 0; s < MAX_SENSORS; s++)