OSDN Git Service

IRDA-3621: Fix a bug where accel and gyro get stuck at 200 Hz
authorPatrick Porlan <patrick.porlan@intel.com>
Wed, 11 Feb 2015 09:40:36 +0000 (10:40 +0100)
committerGerrit Code Review <gerrit2@irsgerrit001.ir.intel.com>
Wed, 11 Feb 2015 10:27:26 +0000 (10:27 +0000)
This is happening on Malata because the MPU-6050 driver exposes
both the accel and gyro on the same iio device, with a single
frequency knob for both. With the current code the accel would
be bumped up to 200 Hz if the gyro was configured at 200 Hz, but
would not go back when a lower sampling rate was selected because
the accel would appear to require 200 Hz.

Change-Id: Ied0c1c94c278be180a22fd537f8e82f0e8f7adbd
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
common.h
control.c

index 156edac..98aa4c9 100644 (file)
--- a/common.h
+++ b/common.h
@@ -274,6 +274,7 @@ typedef struct
         */
        int needs_enable;
 
+       int semi_arbitrated_rate;       /* Arbitrated sampling rate before we considered other sensors co-located on the same iio device */
 }
 sensor_info_t;
 
index dfd9292..c527a55 100644 (file)
--- a/control.c
+++ b/control.c
@@ -843,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;