Debian Codegraph @

bindings/glib/examples/get_chip_info_glib.c

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 // SPDX-FileCopyrightText: 2023-2024 Bartosz Golaszewski <[email protected]>
3
4 /* Minimal example of reading the info for a chip. */
5
6 #include <glib.h>
7 #include <gpiod-glib.h>
8 #include <stdlib.h>
9
10 int main(void)
11 {
12 /* Example configuration - customize to suit your situation. */
13 static const gchar *const chip_path = "/dev/gpiochip0";
14
15 g_autoptr(GpiodglibChipInfo) info = NULL;
16 g_autoptr(GpiodglibChip) chip = NULL;
17 g_autofree gchar *label = NULL;
18 g_autofree gchar *name = NULL;
19 g_autoptr(GError) err = NULL;
20
21 chip = gpiodglib_chip_new(chip_path, &err);
22 if (err) {
23 g_printerr("Failed to open the GPIO chip at '%s': %s\n",
24 chip_path, err->message);
25 return EXIT_FAILURE;
26 }
27
28 info = gpiodglib_chip_get_info(chip, &err);
29 if (err) {
30 g_printerr("Failed to retrieve GPIO chip info: %s\n",
31 err->message);
32 return EXIT_FAILURE;
33 }
34
35 name = gpiodglib_chip_info_dup_name(info);
36 label = gpiodglib_chip_info_dup_label(info);
37
38 g_print("%s [%s] (%u lines)\n",
39 name, label, gpiodglib_chip_info_get_num_lines(info));
40
41 return EXIT_SUCCESS;
42 }