From 77fd2f64c5fbccdfd063a004be1df6426fe979bb Mon Sep 17 00:00:00 2001 From: Patrick Porlan Date: Wed, 24 Sep 2014 16:43:08 +0200 Subject: [PATCH] IRDA-1184: Alternate between triggers depending on sampling rate The BMC150 accel driver any-motion trigger is too jerky for certain games such as the "sniper shooter" one, or "doodle jump". Switch back to continuous event generation mode if a sampling rate above 25 is requested, which should keep both the launcher (15 events per second) and games (60 events per second) happy. Issue: IRDA-1184 Change-Id: I16000d57e17506aa7e7c0a4f83ced7739e01dd01 Signed-off-by: Patrick Porlan --- control.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/control.c b/control.c index ce02d69..1bdd333 100644 --- a/control.c +++ b/control.c @@ -650,6 +650,26 @@ int sensor_activate(int s, int enabled) } +static int is_fast_accelerometer (int s) +{ + /* + * Some games don't react well to accelerometers using any-motion + * triggers. Even very low thresholds seem to trip them, and they tend + * to request fairly high event rates. Favor continuous triggers if the + * sensor is an accelerometer and uses a sampling rate of at least 25. + */ + int catalog_index = sensor_info[s].catalog_index; + + if (sensor_catalog[catalog_index].type != SENSOR_TYPE_ACCELEROMETER) + return 0; + + if (sensor_info[s].sampling_rate < 25) + return 0; + + return 1; +} + + static void enable_motion_trigger (int dev_num) { /* @@ -684,7 +704,8 @@ static void enable_motion_trigger (int dev_num) sensor_info[s].enable_count && sensor_info[s].num_channels && (!sensor_info[s].motion_trigger_name[0] || - !sensor_info[s].report_initialized) + !sensor_info[s].report_initialized || + is_fast_accelerometer(s)) ) return; /* Nope */ @@ -1215,6 +1236,11 @@ 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); + if (trig_sensors_per_dev[dev_num]) enable_buffer(dev_num, 1); -- 2.11.0