Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to handle Events and Labels. #1175

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions context.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,8 @@ struct iio_device * iio_context_add_device(struct iio_context *ctx,
devs[ctx->nb_devices++] = dev;
ctx->devices = devs;

ctx_dbg(ctx, "Added device \'%s\' to context \'%s\'\n",
dev->id, ctx->name);
ctx_dbg(ctx, "Added device \'%s\' to context \'%s\' with label \'%s\'\n",
dev->id, ctx->name, dev->label);

iio_sort_devices(ctx);

Expand Down
15 changes: 7 additions & 8 deletions local.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,35 +1099,34 @@ static int add_buffer_attr(void *d, const char *path)

static int add_attr_or_channel_helper(struct iio_device *dev,
const char *path, const char *prefix,
bool dir_is_scan_elements)
bool dir_is_scan_elements, bool is_event)
{
char buf[1024];
const char *name = strrchr(path, '/') + 1;

if (!dir_is_scan_elements && !is_channel(dev, name, true))
return add_attr_to_device(dev, name);

iio_snprintf(buf, sizeof(buf), "%s%s", prefix, name);
if (!is_event && !dir_is_scan_elements && !is_channel(dev, name, true))
return add_attr_to_device(dev, name);

return add_channel(dev, name, buf, dir_is_scan_elements);
}

static int add_attr_or_channel(void *d, const char *path)
{
return add_attr_or_channel_helper((struct iio_device *) d,
path, "", false);
path, "", false, false);
}

static int add_event(void *d, const char *path)
{
return add_attr_or_channel_helper((struct iio_device *) d,
path, "events/", false);
path, "events/", false, true);
}

static int add_scan_element(void *d, const char *path)
{
return add_attr_or_channel_helper((struct iio_device *) d,
path, "scan_elements/", true);
path, "scan_elements/", true, false);
}

static int foreach_in_dir(const struct iio_context *ctx,
Expand Down Expand Up @@ -1251,7 +1250,7 @@ static int create_device(void *d, const char *path)

ret = (int)local_do_read_dev_attr(id, 0, "label", label, sizeof(label),
IIO_ATTR_TYPE_DEVICE);
if (ret < 0)
if (ret > 0)
label_ptr = label;

dev = iio_context_add_device(ctx, id, name_ptr, label_ptr);
Expand Down