Skip to content

Commit

Permalink
Enhance iio_device_find_channel() to use labels
Browse files Browse the repository at this point in the history
Make iio_device_find_channel() able to search not only by ID and name,
but also by label.

Signed-off-by: Dan Nechita <dan.nechita@analog.com>
  • Loading branch information
dNechita committed Jan 14, 2025
1 parent 2357b08 commit a6c019b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions device.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ struct iio_channel * iio_device_find_channel(const struct iio_device *dev,
continue;

if (!strcmp(chn->id, name) ||
(chn->name && !strcmp(chn->label, name)) ||
(chn->name && !strcmp(chn->name, name)))
return chn;
}
Expand Down
10 changes: 5 additions & 5 deletions include/iio/iio.h
Original file line number Diff line number Diff line change
Expand Up @@ -782,14 +782,14 @@ __api __check_ret __pure const struct iio_attr *
iio_device_get_attr(const struct iio_device *dev, unsigned int index);


/** @brief Try to find a channel structure by its name of ID
/** @brief Try to find a channel structure by its ID, label or name
* @param dev A pointer to an iio_device structure
* @param name A NULL-terminated string corresponding to the name or the ID of
* the channel to search for
* @param name A NULL-terminated string corresponding to ID, label or name
* of the channel to search for
* @param output True if the searched channel is output, False otherwise
* @return On success, a pointer to an iio_channel structure
* @return If the name or ID does not correspond to any known channel of the
* given device, NULL is returned */
* @return If the ID, label or name does not correspond to any known channel of
* the given device, NULL is returned */
__api __check_ret __pure struct iio_channel * iio_device_find_channel(
const struct iio_device *dev, const char *name, bool output);

Expand Down

0 comments on commit a6c019b

Please sign in to comment.