OSDN Git Service

IRDA-2056: Minor rework to the trigger switching code
authorPatrick Porlan <patrick.porlan@intel.com>
Wed, 15 Oct 2014 12:13:13 +0000 (14:13 +0200)
committerAdriana Reus <adriana.reus@intel.com>
Tue, 21 Oct 2014 13:27:04 +0000 (16:27 +0300)
Isolate the test that we use to switch from the motion trigger to
the continous one (for accelerometer based games that are sensitive
to small motion thresholds) into a function. Also, specifically
deactivate this behaviour for drivers marked as terse: for those it
may make sense to initialize the motion trigger name field with the
same string as the initial trigger name field, so let's check for
the terse flag.

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

index 0afaad2..e1a68e6 100644 (file)
--- a/control.c
+++ b/control.c
@@ -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);