OSDN Git Service

IRDA-2056: Minor rework to the trigger switching code
[android-x86/hardware-intel-libsensors.git] / control.c
index 6d07c45..e1a68e6 100644 (file)
--- a/control.c
+++ b/control.c
@@ -920,8 +920,8 @@ static void synthetize_duplicate_samples (void)
                        continue;
 
                /* If the sensor is continuously firing, leave it alone */
-               if (    sensor_info[s].selected_trigger !=
-                       sensor_info[s].motion_trigger_name)
+               if (sensor_info[s].selected_trigger !=
+                   sensor_info[s].motion_trigger_name)
                        continue;
 
                /* If we haven't seen a sample, there's nothing to duplicate */
@@ -983,10 +983,10 @@ static int get_poll_wait_timeout (void)
        int64_t period;
 
        /*
-        * Check if have have to deal with "terse" drivers that only send events
-        * when there is motion, despite the fact that the associated Android
-        * sensor type is continuous rather than on-change. In that case we have
-        * to duplicate events. Check deadline for the nearest upcoming event.
+        * Check if we're dealing with a driver that only send events when
+        * there is motion, despite the fact that the associated Android sensor
+        * type is continuous rather than on-change. In that case we have to
+        * duplicate events. Check deadline for the nearest upcoming event.
         */
        for (s=0; s<sensor_count; s++)
                if (sensor_info[s].enable_count &&
@@ -1127,6 +1127,25 @@ await_event:
 }
 
 
+static void tentative_switch_trigger (int s)
+{
+       /*
+        * Under certain situations it may be beneficial to use an alternate
+        * trigger:
+        *
+        * - for applications using the accelerometer with high sampling rates,
+        *   prefer the continuous trigger over the any-motion one, to avoid
+        *   jumps related to motion thresholds
+        */
+
+       if (is_fast_accelerometer(s) &&
+               !(sensor_info[s].quirks & QUIRK_TERSE_DRIVER) &&
+                       sensor_info[s].selected_trigger ==
+                               sensor_info[s].motion_trigger_name)
+               setup_trigger(s, sensor_info[s].init_trigger_name);
+}
+
+
 int sensor_set_delay(int s, int64_t ns)
 {
        /* Set the rate at which a specific sensor should report events */
@@ -1255,13 +1274,11 @@ int sensor_set_delay(int s, int64_t ns)
                }
        }
 
-
        if (max_supported_rate &&
                new_sampling_rate > max_supported_rate) {
                new_sampling_rate = max_supported_rate;
        }
 
-
        /* If the desired rate is already active we're all set */
        if (new_sampling_rate == cur_sampling_rate)
                return 0;
@@ -1273,10 +1290,8 @@ int sensor_set_delay(int s, int64_t ns)
 
        sysfs_write_float(sysfs_path, new_sampling_rate);
 
-       /* Switch back to continuous sampling for accelerometer based games */
-       if (is_fast_accelerometer(s) && sensor_info[s].selected_trigger !=
-                                       sensor_info[s].init_trigger_name)
-               setup_trigger(s, sensor_info[s].init_trigger_name);
+       /* Check if it makes sense to use an alternate trigger */
+       tentative_switch_trigger(s);
 
        if (trig_sensors_per_dev[dev_num])
                enable_buffer(dev_num, 1);