Debian Codegraph @

bindings/cxx/examples/get_line_info.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 // SPDX-FileCopyrightText: 2023 Kent Gibson <[email protected]>
3
4 /* Minimal example of reading the info for a line. */
5
6 #include <cstdlib>
7 #include <filesystem>
8 #include <gpiod.hpp>
9 #include <iomanip>
10 #include <iostream>
11
12 namespace {
13
14 /* Example configuration - customize to suit your situation */
15 const ::std::filesystem::path chip_path("/dev/gpiochip0");
16 const ::gpiod::line::offset line_offset = 3;
17
18 } /* namespace */
19
20 int main()
21 {
22 auto chip = ::gpiod::chip(chip_path);
23 auto info = chip.get_line_info(line_offset);
24
25 ::std::cout << "line " << ::std::setw(3) << info.offset() << ": "
26 << ::std::setw(12)
27 << (info.name().empty() ? "unnamed" : info.name()) << " "
28 << ::std::setw(12)
29 << (info.consumer().empty() ? "unused" : info.consumer())
30 << " " << ::std::setw(8)
31 << (info.direction() == ::gpiod::line::direction::INPUT ?
32 "input" :
33 "output")
34 << " " << ::std::setw(10)
35 << (info.active_low() ? "active-low" : "active-high")
36 << ::std::endl;
37
38 return EXIT_SUCCESS;
39 }