iio: Simplify API
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -36,55 +36,7 @@ mraa_iio_init(int device)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mraa_iio_context dev = &plat->iio_devices[device];
|
return &plat->iio_devices[device];
|
||||||
|
|
||||||
char* buf;
|
|
||||||
char sep[] = "_";
|
|
||||||
char* splitbuf;
|
|
||||||
DIR* dir;
|
|
||||||
struct dirent *ent;
|
|
||||||
if ((dir = opendir (IIO_SYSFS_DEVICE "0/")) != NULL) {
|
|
||||||
while ((ent = readdir (dir)) != NULL) {
|
|
||||||
if (strlen(ent->d_name) > 3) {
|
|
||||||
if (strncmp(ent->d_name, "in_", 3) == 0) {
|
|
||||||
dev->attrnum++;
|
|
||||||
buf = strndup(&ent->d_name[3], 64);
|
|
||||||
splitbuf = strsep(&buf, sep);
|
|
||||||
if (buf == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
int num = atoi(&splitbuf[strlen(splitbuf)-1]);
|
|
||||||
if (dev->channum < num) {
|
|
||||||
dev->channum = num;
|
|
||||||
}
|
|
||||||
free(splitbuf);
|
|
||||||
}
|
|
||||||
else if (strncmp(ent->d_name, "out_", 4) == 0) {
|
|
||||||
dev->attrnum++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir (dir);
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -1 is the device 'channel'
|
|
||||||
int
|
|
||||||
mraa_iio_get_attr_count(mraa_iio_context dev, int channel)
|
|
||||||
{
|
|
||||||
// search is 0 indexed
|
|
||||||
return dev->attrnum + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
mraa_iio_get_channel_count(mraa_iio_context dev)
|
|
||||||
{
|
|
||||||
// search is 0 indexed
|
|
||||||
return dev->channum + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
@@ -93,19 +45,11 @@ mraa_iio_get_device_name(mraa_iio_context dev)
|
|||||||
return dev->name;
|
return dev->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
mraa_result_t
|
mraa_result_t
|
||||||
mraa_iio_get_attr_data(mraa_iio_context dev, mraa_iio_channel* chan)
|
mraa_iio_read(mraa_iio_context dev, const char* attr_chan, float* data)
|
||||||
{
|
|
||||||
return MRAA_FEATURE_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mraa_result_t
|
|
||||||
mraa_iio_read(mraa_iio_context dev, const char* attribute, float* data)
|
|
||||||
{
|
{
|
||||||
char buf[64];
|
char buf[64];
|
||||||
snprintf(buf, 64, IIO_SYSFS_DEVICE, "%d/%s", dev->num, attribute);
|
snprintf(buf, 64, IIO_SYSFS_DEVICE, "%d/%s", dev->num, attr_chan);
|
||||||
int fd = open(buf, O_RDONLY);
|
int fd = open(buf, O_RDONLY);
|
||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
int len = read(fd, &buf, 64);
|
int len = read(fd, &buf, 64);
|
||||||
@@ -116,15 +60,16 @@ mraa_iio_read(mraa_iio_context dev, const char* attribute, float* data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mraa_result_t
|
mraa_result_t
|
||||||
mraa_iio_write(mraa_iio_context dev, const char* attribute)
|
mraa_iio_write(mraa_iio_context dev, const char* attr_chan)
|
||||||
{
|
{
|
||||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
mraa_result_t
|
mraa_result_t
|
||||||
mraa_iio_stop(mraa_iio_context dev)
|
mraa_iio_stop(mraa_iio_context dev)
|
||||||
{
|
{
|
||||||
free(dev);
|
|
||||||
return MRAA_SUCCESS;
|
return MRAA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ mraa_init()
|
|||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
len = read(fd, &name, 64);
|
len = read(fd, &name, 64);
|
||||||
if (len > 1) {
|
if (len > 1) {
|
||||||
|
// use strndup
|
||||||
device->name = malloc((sizeof(char) * len) + sizeof(char));
|
device->name = malloc((sizeof(char) * len) + sizeof(char));
|
||||||
strncpy(device->name, name, len);
|
strncpy(device->name, name, len);
|
||||||
}
|
}
|
||||||
@@ -775,6 +776,7 @@ mraa_find_iio_device(const char* devicename)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (i; i < plat->iio_device_count; i++) {
|
for (i; i < plat->iio_device_count; i++) {
|
||||||
#if 0
|
#if 0
|
||||||
|
// compare with devices array
|
||||||
if (!strcmp() {
|
if (!strcmp() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user