Skip to content

Commit 9b75f53

Browse files
osc: fix read sampling frequency
when the sampling freq is a channel specific attribute, the effective sampling freq is calculated depending on the sampling frequencies of each enabled channel this ensures effective timeout calculation Signed-off-by: Cristina Suteu <[email protected]>
1 parent e81ce41 commit 9b75f53

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Diff for: osc.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ static unsigned int max_sample_count_from_plots(struct extra_dev_info *info)
14071407

14081408
static double read_sampling_frequency(const struct iio_device *dev)
14091409
{
1410-
double freq = 400.0;
1410+
double freq = 400.0, freq_sum = 0.0;
14111411
int ret = -1;
14121412
unsigned int i, nb_channels = iio_device_get_channels_count(dev);
14131413
const char *attr;
@@ -1422,8 +1422,11 @@ static double read_sampling_frequency(const struct iio_device *dev)
14221422

14231423
ret = iio_channel_attr_read(ch, "sampling_frequency",
14241424
buf, sizeof(buf));
1425-
if (ret > 0)
1426-
break;
1425+
if (ret > 0 && iio_channel_is_enabled(ch)) {
1426+
sscanf(buf, "%lf", &freq);
1427+
freq_sum += 1 / freq;
1428+
}
1429+
14271430
}
14281431

14291432
if (ret < 0)
@@ -1446,6 +1449,8 @@ static double read_sampling_frequency(const struct iio_device *dev)
14461449

14471450
if (ret > 0)
14481451
sscanf(buf, "%lf", &freq);
1452+
else if (ret > 0 && freq_sum != 0)
1453+
freq = 1 / freq_sum;
14491454

14501455
if (freq < 0)
14511456
freq += 4294967296.0;

0 commit comments

Comments
 (0)