Debian Codegraph @

bindings/cxx/examples/get_line_value.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 a single line. */
5
6 #include <cstdlib>
7 #include <filesystem>
8 #include <gpiod.hpp>
9 #include <iostream>
10
11 namespace {
12
13 /* Example configuration - customize to suit your situation */
14 const ::std::filesystem::path chip_path("/dev/gpiochip0");
15 const ::gpiod::line::offset line_offset = 5;
16
17 } /* namespace */
18
19 int main()
20 {
21 auto request = ::gpiod::chip(chip_path)
22 .prepare_request()
23 .set_consumer("get-line-value")
24 .add_line_settings(
25 line_offset,
26 ::gpiod::line_settings().set_direction(
27 ::gpiod::line::direction::INPUT))
28 .do_request();
29
30 ::std::cout << line_offset << "="
31 << (request.get_value(line_offset) ==
32 ::gpiod::line::value::ACTIVE ?
33 "Active" :
34 "Inactive")
35 << ::std::endl;
36
37 return EXIT_SUCCESS;
38 }