core: allow to specify the consumer in simple get value routines
authorBartosz Golaszewski <bartekgola@gmail.com>
Tue, 17 Jan 2017 14:50:03 +0000 (15:50 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Tue, 17 Jan 2017 14:54:05 +0000 (15:54 +0100)
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
include/gpiod.h
src/lib/core.c
src/tools/gpioget.c

index 7fb85174e061674039f91015d90ade0e2f9b43cb..23f36a93149fcb62b71a827aa9851e6d9c0e81bd 100644 (file)
@@ -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;
index 5a8e6fb0c8111bb5da5a965ebe7bf701f914cd7e..526023eba74dece47c6dc4a7c5e001dc2b5fa67c 100644 (file)
@@ -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;
index ce64030375551b214f668c8117c849755c77245a..4ae3e08f52e899cd93b148c6c1ed4be26b9b1608 100644 (file)
@@ -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");