Private
Public Access
2
0

iio.c: Fix the location mapping in iio

Go through channel array after getting byte mapping to correctly map channel
location. Doing it at the same time as mapping the indexes is unreliable
depending on filename etc...

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2016-05-16 12:31:45 +01:00
parent b15ab84f61
commit 3969af2b24

View File

@@ -83,6 +83,7 @@ mraa_iio_get_channel_data(mraa_iio_context dev)
int padint = 0;
int curr_bytes = 0;
char shortbuf, signchar;
int i = 0;
dev->datasize = 0;
@@ -129,12 +130,6 @@ mraa_iio_get_channel_data(mraa_iio_context dev)
ret = sscanf(readbuf, "%ce:%c%u/%u>>%u", &shortbuf, &signchar, &chan->bits_used,
&padint, &chan->shift);
chan->bytes = padint / 8;
if (curr_bytes % chan->bytes == 0) {
chan->location = curr_bytes;
} else {
chan->location = curr_bytes - curr_bytes % chan->bytes + chan->bytes;
}
curr_bytes = chan->location + chan->bytes;
// probably should be 5?
if (ret < 0) {
// cleanup
@@ -175,6 +170,18 @@ mraa_iio_get_channel_data(mraa_iio_context dev)
}
closedir(dir);
// channel location has to be done in channel index order so do it afetr we
// have grabbed all the correct info
for (i = 0; i < dev->chan_num; i++) {
chan = &dev->channels[i];
if (curr_bytes % chan->bytes == 0) {
chan->location = curr_bytes;
} else {
chan->location = curr_bytes - curr_bytes % chan->bytes + chan->bytes;
}
curr_bytes = chan->location + chan->bytes;
}
return MRAA_SUCCESS;
}