1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-24 00:48:53 +03:00
Files
libgpiod/dbus/client/detect.c
Bartosz Golaszewski a5ab76da1e dbus: add the D-Bus daemon, command-line client and tests
Add the D-Bus API definition and its implementation in the form of a GPIO
manager daemon and a companion command-line client as well as some
additional configuration and data files (systemd service, example udev
configuration, etc.) and test suites.

Tested-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Link: https://lore.kernel.org/r/20240812-dbus-v5-4-ead288509217@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-08-13 10:45:25 +02:00

54 lines
1.3 KiB
C

// SPDX-License-Identifier: GPL-2.0-or-later
// SPDX-FileCopyrightText: 2022-2023 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
#include <stdlib.h>
#include "common.h"
static void show_chip(gpointer elem, gpointer user_data G_GNUC_UNUSED)
{
GpiodbusObject *chip_obj = elem;
GpiodbusChip *chip;
chip = gpiodbus_object_peek_chip(chip_obj);
g_print("%s [%s] (%u lines)\n",
gpiodbus_chip_get_name(chip),
gpiodbus_chip_get_label(chip),
gpiodbus_chip_get_num_lines(chip));
}
int gpiocli_detect_main(int argc, char **argv)
{
static const gchar *const summary =
"List GPIO chips, print their labels and number of GPIO lines.";
static const gchar *const description =
"Chips may be identified by name or number. e.g. '0' and 'gpiochip0' refer to\n"
"the same chip.\n"
"\n"
"If no chips are specified - display information for all chips in the system.";
g_autolist(GpiodbusObject) chip_objs = NULL;
g_auto(GStrv) chip_names = NULL;
const GOptionEntry opts[] = {
{
.long_name = G_OPTION_REMAINING,
.flags = G_OPTION_FLAG_NONE,
.arg = G_OPTION_ARG_STRING_ARRAY,
.arg_data = &chip_names,
.arg_description = "[chip]...",
},
{ }
};
parse_options(opts, summary, description, &argc, &argv);
check_manager();
chip_objs = get_chip_objs(chip_names);
g_list_foreach(chip_objs, show_chip, NULL);
return EXIT_SUCCESS;
}