| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <glib.h> |
| 7 |
#include <gpiod-glib.h> |
| 8 |
#include <stdlib.h> |
| 9 |
|
| 10 |
int main(void) |
| 11 |
{ |
| 12 |
|
| 13 |
static const gchar *const chip_path = "/dev/gpiochip1"; |
| 14 |
static const guint line_offsets[] = { 5, 3, 7 }; |
| 15 |
static const gsize num_lines = 3; |
| 16 |
|
| 17 |
g_autoptr(GpiodglibRequestConfig) req_cfg = NULL; |
| 18 |
g_autoptr(GpiodglibLineSettings) settings = NULL; |
| 19 |
g_autoptr(GpiodglibLineRequest) request = NULL; |
| 20 |
g_autoptr(GpiodglibLineConfig) line_cfg = NULL; |
| 21 |
g_autoptr(GpiodglibChip) chip = NULL; |
| 22 |
g_autoptr(GArray) offsets = NULL; |
| 23 |
g_autoptr(GArray) values = NULL; |
| 24 |
g_autoptr(GError) err = NULL; |
| 25 |
gboolean ret; |
| 26 |
guint i, j; |
| 27 |
|
| 28 |
offsets = g_array_new(FALSE, TRUE, sizeof(guint)); |
| 29 |
for (i = 0; i < num_lines; i++) |
| 30 |
g_array_append_val(offsets, line_offsets[i]); |
| 31 |
|
| 32 |
chip = gpiodglib_chip_new(chip_path, &err); |
| 33 |
if (!chip) { |
| 34 |
g_printerr("unable to open %s: %s\n", chip_path, err->message); |
| 35 |
return EXIT_FAILURE; |
| 36 |
} |
| 37 |
|
| 38 |
settings = gpiodglib_line_settings_new("direction", |
| 39 |
GPIODGLIB_LINE_DIRECTION_INPUT, |
| 40 |
NULL); |
| 41 |
|
| 42 |
line_cfg = gpiodglib_line_config_new(); |
| 43 |
ret = gpiodglib_line_config_add_line_settings(line_cfg, offsets, |
| 44 |
settings, &err); |
| 45 |
if (!ret) { |
| 46 |
g_printerr("failed to add line settings to line config: %s\n", |
| 47 |
err->message); |
| 48 |
return EXIT_FAILURE; |
| 49 |
} |
| 50 |
|
| 51 |
req_cfg = gpiodglib_request_config_new("consumer", |
| 52 |
"get-multiple-line-values", |
| 53 |
NULL); |
| 54 |
|
| 55 |
request = gpiodglib_chip_request_lines(chip, req_cfg, line_cfg, &err); |
| 56 |
if (!request) { |
| 57 |
g_printerr("failed to request lines: %s\n", err->message); |
| 58 |
return EXIT_FAILURE; |
| 59 |
} |
| 60 |
|
| 61 |
ret = gpiodglib_line_request_get_values_subset(request, offsets, |
| 62 |
&values, &err); |
| 63 |
if (!ret) { |
| 64 |
g_printerr("failed to read line values: %s\n", err->message); |
| 65 |
return EXIT_FAILURE; |
| 66 |
} |
| 67 |
|
| 68 |
for (j = 0; j < values->len; j++) |
| 69 |
g_print("%d ", g_array_index(values, GpiodglibLineValue, j)); |
| 70 |
g_print("\n"); |
| 71 |
|
| 72 |
return EXIT_SUCCESS; |
| 73 |
} |