Private
Public Access
2
0

iio: Improve iio channel parsing to add enabled channels

scale and other attributes have to be read individually as they vary quite alot
depending on the channel. We only care/take data from scan_elements

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2015-10-05 12:01:00 +01:00
parent 2c97fd5953
commit acfb74f04e
4 changed files with 28 additions and 14 deletions

View File

@@ -105,6 +105,7 @@ mraa_iio_get_channel_data(mraa_iio_context dev)
buf[(strlen(buf)-5)] = '\0';
char* str = strdup(buf);
// grab the type of the buffer
snprintf(buf, MAX_SIZE, "%stype", str);
fd = open(buf, O_RDONLY);
if (fd > 0) {
@@ -119,8 +120,11 @@ mraa_iio_get_channel_data(mraa_iio_context dev)
chan->location = curr_bytes - curr_bytes%chan->bytes + chan->bytes;
}
curr_bytes = chan->location + chan->bytes;
// probably should be 5?
if (ret < 0) {
// probably should be 5?
// cleanup
free(str);
close(fd);
return MRAA_IO_SETUP_FAILURE;
}
chan->signedd = (signchar == 's');
@@ -130,10 +134,21 @@ mraa_iio_get_channel_data(mraa_iio_context dev)
} else {
chan->mask = (1 << chan->bits_used) - 1;
}
close(fd);
}
// todo - read scale & _en attributes
// grab the enable flag of channel
snprintf(buf, MAX_SIZE, "%sen", str);
fd = open(buf, O_RDONLY);
if (fd > 0) {
if (read(fd, readbuf, 2 * sizeof(char)) != 2) {
syslog(LOG_ERR, "iio: Failed to read a sensible value from sysfs");
return -1;
}
chan->enabled = (int) strtol(readbuf, NULL, 10);
close(fd);
}
// clean up str var
free(str);
}
}
}

View File

@@ -173,13 +173,14 @@ mraa_init()
device->num = i;
snprintf(filepath, 64, "/sys/bus/iio/devices/iio:device%d/name", i);
fd = open(filepath, O_RDONLY);
if (fd != -1) {
if (fd > 0) {
len = read(fd, &name, 64);
if (len > 1) {
// use strndup
device->name = malloc((sizeof(char) * len) + sizeof(char));
strncpy(device->name, name, len);
}
close(fd);
}
}