Skip to content

Commit

Permalink
iio_attr: Display channel label if present
Browse files Browse the repository at this point in the history
If a IIO channel has a label, display it and support matching
against the label.

Signed-off-by: Dan Nechita <dan.nechita@analog.com>
  • Loading branch information
dNechita committed Jan 20, 2025
1 parent 8cafea1 commit 384d318
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions utils/iio_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,12 @@ static int dump_channel_attributes(const struct iio_device *dev,
iio_channel_get_id(ch),
type_name);
}
if (iio_channel_get_name(ch) && quiet == ATTR_VERBOSE)
printf("id '%s', ", iio_channel_get_name(ch));
if (quiet == ATTR_VERBOSE) {
if (iio_channel_get_name(ch))
printf("id '%s', ", iio_channel_get_name(ch));
if (iio_channel_get_label(ch))
printf("label '%s', ", iio_channel_get_label(ch));
}

if (quiet == ATTR_VERBOSE)
printf("attr '%s', ", iio_attr_get_name(attr));
Expand Down Expand Up @@ -537,7 +541,7 @@ int main(int argc, char **argv)
const char *name = iio_device_get_name(dev);
const char *label_or_name = label ? label : name;
const char *label_or_name_or_id = label_or_name ? label_or_name : dev_id;
const char *ch_name;
const char *ch_name, *ch_label;
struct iio_buffer *buffer;
struct iio_channels_mask *mask;
unsigned int nb_attrs, nb_channels, j;
Expand Down Expand Up @@ -625,10 +629,12 @@ int main(int argc, char **argv)
type_name = "input";

ch_name = iio_channel_get_name(ch);
ch_label = iio_channel_get_label(ch);
if (channel_index &&
!str_match(iio_channel_get_id(ch),
argw[channel_index], ignore_case) &&
(!ch_name || !str_match(ch_name,argw[channel_index], ignore_case)))
(!ch_label || !str_match(ch_label,argw[channel_index], ignore_case) &&
(!ch_name || !str_match(ch_name,argw[channel_index], ignore_case))))
continue;

channel_found = true;
Expand All @@ -642,6 +648,8 @@ int main(int argc, char **argv)

if (ch_name)
printf(", id '%s'", ch_name);
if (ch_label)
printf(", label '%s'", ch_label);

printf(" (%s", type_name);

Expand Down

0 comments on commit 384d318

Please sign in to comment.