From 423c71f547f66e9cc82b9c107694b2874cc1300e Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Fri, 6 Jan 2017 15:56:49 +0100 Subject: [PATCH] core: extend gpiod_simple_get_value() Add the active state argument. Signed-off-by: Bartosz Golaszewski --- core.c | 5 ++++- gpiod.h | 4 +++- gpioget.c | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core.c b/core.c index 25f23f0..50f04e8 100644 --- a/core.c +++ b/core.c @@ -123,7 +123,8 @@ const char * gpiod_strerror(int errnum) return error_descr[errnum - __GPIOD_ERRNO_OFFSET]; } -int gpiod_simple_get_value(const char *device, unsigned int offset) +int gpiod_simple_get_value(const char *device, + unsigned int offset, bool active_low) { struct gpiod_line_request_config config; struct gpiod_chip *chip; @@ -133,6 +134,8 @@ int gpiod_simple_get_value(const char *device, unsigned int offset) memset(&config, 0, sizeof(config)); config.consumer = libgpiod_consumer; config.direction = GPIOD_DIRECTION_INPUT; + config.active_state = active_low ? GPIOD_ACTIVE_STATE_LOW + : GPIOD_ACTIVE_STATE_HIGH; chip = gpiod_chip_open_lookup(device); if (!chip) diff --git a/gpiod.h b/gpiod.h index f6a0106..b0c53df 100644 --- a/gpiod.h +++ b/gpiod.h @@ -109,10 +109,12 @@ const char * gpiod_strerror(int errnum) GPIOD_API; * @brief Read current value from a single GPIO line. * @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 if the operation succeeds. On error this routine returns -1 * and sets the last error number. */ -int gpiod_simple_get_value(const char *device, unsigned int offset) GPIOD_API; +int gpiod_simple_get_value(const char *device, + unsigned int offset, bool active_low) GPIOD_API; /** * @} diff --git a/gpioget.c b/gpioget.c index f8fa21f..c32bc87 100644 --- a/gpioget.c +++ b/gpioget.c @@ -39,7 +39,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - value = gpiod_simple_get_value(device, offset); + value = gpiod_simple_get_value(device, offset, false); if (value < 0) { fprintf(stderr, "%s: error reading GPIO value: %s\n", -- 2.30.2