Debian Codegraph @

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