From fe496e045794a78212ec86b570fc4c3bff4dfd9a Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Tue, 17 Jan 2017 15:50:03 +0100 Subject: [PATCH] core: allow to specify the consumer in simple get value routines Signed-off-by: Bartosz Golaszewski --- include/gpiod.h | 12 ++++++++---- src/lib/core.c | 9 ++++----- src/tools/gpioget.c | 3 ++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/gpiod.h b/include/gpiod.h index 7fb8517..23f36a9 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -121,6 +121,7 @@ const char * gpiod_last_strerror(void) GPIOD_API; /** * @brief Read current values from a set of GPIO lines. + * @param consumer Name of the consumer. * @param device Name, path or number of the gpiochip. * @param offsets An array of offsets of lines whose values should be read. * @param values A buffer in which the values will be stored. @@ -128,23 +129,26 @@ const char * gpiod_last_strerror(void) GPIOD_API; * @param active_low The active state of the lines - true if low. * @return 0 if the operation succeeds, -1 on error. */ -int gpiod_simple_get_value_multiple(const char *device, unsigned int *offsets, - int *values, unsigned int num_lines, +int gpiod_simple_get_value_multiple(const char *consumer, const char *device, + unsigned int *offsets, int *values, + unsigned int num_lines, bool active_low) GPIOD_API; /** * @brief Read current value from a single GPIO line. + * @param consumer Name of the consumer. * @param device Name, path or number of the gpiochip. * @param offset GPIO line offset on the chip. * @param active_low The active state of this line - true if low. * @return 0 or 1 (GPIO value) if the operation succeeds, -1 on error. */ -static inline int gpiod_simple_get_value(const char *device, +static inline int gpiod_simple_get_value(const char *consumer, + const char *device, unsigned int offset, bool active_low) { int value, status; - status = gpiod_simple_get_value_multiple(device, &offset, + status = gpiod_simple_get_value_multiple(consumer, device, &offset, &value, 1, active_low); if (status < 0) return status; diff --git a/src/lib/core.c b/src/lib/core.c index 5a8e6fb..526023e 100644 --- a/src/lib/core.c +++ b/src/lib/core.c @@ -159,9 +159,9 @@ const char * gpiod_last_strerror(void) return gpiod_strerror(gpiod_errno()); } -int gpiod_simple_get_value_multiple(const char *device, unsigned int *offsets, - int *values, unsigned int num_lines, - bool active_low) +int gpiod_simple_get_value_multiple(const char *consumer, const char *device, + unsigned int *offsets, int *values, + unsigned int num_lines, bool active_low) { struct gpiod_line_bulk bulk; struct gpiod_chip *chip; @@ -190,8 +190,7 @@ int gpiod_simple_get_value_multiple(const char *device, unsigned int *offsets, gpiod_line_bulk_add(&bulk, line); } - status = gpiod_line_request_bulk_input(&bulk, - libgpiod_consumer, active_low); + status = gpiod_line_request_bulk_input(&bulk, consumer, active_low); if (status < 0) { gpiod_chip_close(chip); return -1; diff --git a/src/tools/gpioget.c b/src/tools/gpioget.c index ce64030..4ae3e08 100644 --- a/src/tools/gpioget.c +++ b/src/tools/gpioget.c @@ -90,7 +90,8 @@ int main(int argc, char **argv) die("invalid GPIO offset: %s", argv[i + 1]); } - status = gpiod_simple_get_value_multiple(device, offsets, values, + status = gpiod_simple_get_value_multiple("gpioset", device, + offsets, values, num_lines, active_low); if (status < 0) die_perror("error reading GPIO values"); -- 2.30.2