From 8c75d504dc9f1b173454b46e90e1dd737d2aac52 Mon Sep 17 00:00:00 2001 From: Patrick Porlan Date: Mon, 14 Apr 2014 16:56:25 +0200 Subject: [PATCH] STPK-1429 Take into account poll-mode sensors in sampling rate code Poll-mode sensors firing rate is entirely controlled by software, and more precisely by our own poll loop, so be careful when handling the desired sampling rate for these. On the T100, we have both poll mode sensors (such as the AK magnetometer) and regular character-device sensors (accel, gyro) on iio device 0, so also check for poll-mode devices when arbitrating the device level sampling rate. Issue: STPK-1429 Change-Id: I561d25b5afa83fd0360b9197b1dd8b6fd7dffca5 Signed-off-by: Patrick Porlan --- control.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/control.c b/control.c index 6d53187..49ec5a0 100644 --- a/control.c +++ b/control.c @@ -673,6 +673,19 @@ int sensor_set_delay(int s, int64_t ns) return -EINVAL; } + new_sampling_rate = (int) (1000000000L/ns); + + if (!new_sampling_rate) { + ALOGI("Sub-HZ sampling rate requested on on sensor %d\n", s); + new_sampling_rate = 1; + } + + sensor_info[s].sampling_rate = new_sampling_rate; + + /* If we're dealing with a poll-mode sensor, release poll and return */ + if (!sensor_info[s].num_channels) + goto exit; + sprintf(sysfs_path, SENSOR_SAMPLING_PATH, dev_num, prefix); if (sysfs_read_int(sysfs_path, &cur_sampling_rate) != -1) { @@ -694,19 +707,11 @@ int sensor_set_delay(int s, int64_t ns) return -ENOSYS; } - new_sampling_rate = (int) (1000000000L/ns); - - if (!new_sampling_rate) { - ALOGI("Sub-HZ sampling rate requested on on sensor %d\n", s); - new_sampling_rate = 1; - } - - sensor_info[s].sampling_rate = new_sampling_rate; - /* Coordinate with others active sensors on the same device, if any */ if (per_device_sampling_rate) for (n=0; n new_sampling_rate) new_sampling_rate= sensor_info[n].sampling_rate; @@ -770,6 +775,7 @@ int sensor_set_delay(int s, int64_t ns) if (trig_sensors_per_dev[dev_num]) enable_buffer(dev_num, 1); +exit: /* Release the polling loop so an updated timeout value gets used */ write(poll_socket_pair[1], "", 1); -- 2.11.0