From 2b9e832ff966ffca2d5b1cdd9084cd01eb8fbe87 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Wed, 30 Sep 2015 10:27:06 +0100 Subject: [PATCH] iio: Simplify API Signed-off-by: Brendan Le Foll --- src/iio/iio.c | 67 ++++++----------------------------------------------------- src/mraa.c | 2 ++ 2 files changed, 8 insertions(+), 61 deletions(-) diff --git a/src/iio/iio.c b/src/iio/iio.c index 3bf100d..d26159f 100644 --- a/src/iio/iio.c +++ b/src/iio/iio.c @@ -36,55 +36,7 @@ mraa_iio_init(int device) return NULL; } - mraa_iio_context dev = &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; + return &plat->iio_devices[device]; } const char* @@ -93,19 +45,11 @@ mraa_iio_get_device_name(mraa_iio_context dev) return dev->name; } -#if 0 mraa_result_t -mraa_iio_get_attr_data(mraa_iio_context dev, mraa_iio_channel* chan) -{ - return MRAA_FEATURE_NOT_IMPLEMENTED; -} -#endif - -mraa_result_t -mraa_iio_read(mraa_iio_context dev, const char* attribute, float* data) +mraa_iio_read(mraa_iio_context dev, const char* attr_chan, float* data) { 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); if (fd != -1) { 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_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; } +#if 0 mraa_result_t mraa_iio_stop(mraa_iio_context dev) { - free(dev); return MRAA_SUCCESS; } +#endif diff --git a/src/mraa.c b/src/mraa.c index 36f7dc6..e0ec89d 100644 --- a/src/mraa.c +++ b/src/mraa.c @@ -176,6 +176,7 @@ mraa_init() if (fd != -1) { len = read(fd, &name, 64); if (len > 1) { + // use strndup device->name = malloc((sizeof(char) * len) + sizeof(char)); strncpy(device->name, name, len); } @@ -775,6 +776,7 @@ mraa_find_iio_device(const char* devicename) int i = 0; for (i; i < plat->iio_device_count; i++) { #if 0 + // compare with devices array if (!strcmp() { } #endif -- 2.7.4