Ben Tyner | b797b3e | 2020-06-29 10:12:05 -0500 | [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 | |||||
Ed Tanous | 0577c01 | 2023-03-01 11:18:36 -0800 | [diff] [blame^] | 15 | boost::asio::io_context io; // async io monitoring service |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 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 | ||||
Ben Tyner | 117af99 | 2020-05-22 13:32:11 -0500 | [diff] [blame] | 24 | line = gpiod_line_find("checkstop"); |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 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 | ||||
Ben Tyner | 117af99 | 2020-05-22 13:32:11 -0500 | [diff] [blame] | 38 | |
39 | // done with line, manually close chip (per gpiod api comments) | ||||
40 | gpiod_line_close_chip(line); | ||||
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 41 | } |
42 | |||||
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 43 | return rc; |
44 | } | ||||
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 45 | |
46 | } // namespace attn |