core: extend gpiod_simple_get_value()
authorBartosz Golaszewski <bartekgola@gmail.com>
Fri, 6 Jan 2017 14:56:49 +0000 (15:56 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Fri, 6 Jan 2017 14:56:49 +0000 (15:56 +0100)
Add the active state argument.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
core.c
gpiod.h
gpioget.c

diff --git a/core.c b/core.c
index 25f23f0245151acc9c8bf5fcc0afda32f4122a55..50f04e8b96891bb7b369c431833f86bf8ae958c0 100644 (file)
--- 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 f6a010623ddc604c391749e0dd2ac528483df1ab..b0c53df4d95925faf8801c4860c0734a1f8b80f7 100644 (file)
--- 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;
 
 /**
  * @}
index f8fa21fa7631d00c6d4a6aa30cbcacfbfa0b918e..c32bc8703d6b85c4a90ae69ae514cb6ca00d1c6e 100644 (file)
--- 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",