Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 1 | #include <../attn/attn_monitor.hpp> |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 2 | |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 3 | namespace attn |
Ben Tyner | 970fd4f | 2020-02-19 13:46:42 -0600 | [diff] [blame] | 4 | { |
Ben Tyner | 970fd4f | 2020-02-19 13:46:42 -0600 | [diff] [blame] | 5 | |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 6 | /** |
| 7 | * @brief Attention handler application main() |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 8 | */ |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 9 | int attnDaemon(Config* i_config) |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 10 | { |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 11 | int rc = 0; // assume success |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 12 | |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 13 | gpiod_line* line; // gpio line to monitor |
| 14 | |
| 15 | boost::asio::io_service io; // async io monitoring service |
| 16 | |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 17 | // GPIO line configuration (falling edge, active low) |
| 18 | struct gpiod_line_request_config config |
| 19 | { |
| 20 | "attention", GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE, 0 |
| 21 | }; |
| 22 | |
| 23 | // get handle to attention GPIO line |
| 24 | line = gpiod_line_get("gpiochip0", 74); |
| 25 | |
| 26 | if (nullptr == line) |
| 27 | { |
| 28 | rc = 1; // error |
| 29 | } |
| 30 | else |
| 31 | { |
| 32 | // Creating a vector of one gpio to monitor |
| 33 | std::vector<std::unique_ptr<attn::AttnMonitor>> gpios; |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 34 | gpios.push_back( |
| 35 | std::make_unique<attn::AttnMonitor>(line, config, io, i_config)); |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 36 | |
| 37 | io.run(); // start GPIO monitor |
| 38 | } |
| 39 | |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 40 | return rc; |
| 41 | } |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 42 | |
| 43 | } // namespace attn |