blob: bd3b5c49d50f03d36f3203a6b80f7d99898deb36 [file] [log] [blame]
Ben Tyner0205f3b2020-02-24 10:24:47 -06001#include <../attn/attn_monitor.hpp>
Ben Tyneref320152020-01-09 10:31:23 -06002
Ben Tyner0205f3b2020-02-24 10:24:47 -06003namespace attn
Ben Tyner970fd4f2020-02-19 13:46:42 -06004{
Ben Tyner970fd4f2020-02-19 13:46:42 -06005
Ben Tyneref320152020-01-09 10:31:23 -06006/**
7 * @brief Attention handler application main()
Ben Tyneref320152020-01-09 10:31:23 -06008 */
Ben Tyner3fb52e52020-03-31 10:10:07 -05009int attnDaemon(Config* i_config)
Ben Tyneref320152020-01-09 10:31:23 -060010{
Ben Tyner0205f3b2020-02-24 10:24:47 -060011 int rc = 0; // assume success
Ben Tyneref320152020-01-09 10:31:23 -060012
Ben Tyner73ac3682020-01-09 10:46:47 -060013 gpiod_line* line; // gpio line to monitor
14
15 boost::asio::io_service io; // async io monitoring service
16
Ben Tyner73ac3682020-01-09 10:46:47 -060017 // 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 Tyner117af992020-05-22 13:32:11 -050024 line = gpiod_line_find("checkstop");
Ben Tyner73ac3682020-01-09 10:46:47 -060025
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 Tyner3fb52e52020-03-31 10:10:07 -050034 gpios.push_back(
35 std::make_unique<attn::AttnMonitor>(line, config, io, i_config));
Ben Tyner73ac3682020-01-09 10:46:47 -060036
37 io.run(); // start GPIO monitor
Ben Tyner117af992020-05-22 13:32:11 -050038
39 // done with line, manually close chip (per gpiod api comments)
40 gpiod_line_close_chip(line);
Ben Tyner73ac3682020-01-09 10:46:47 -060041 }
42
Ben Tyneref320152020-01-09 10:31:23 -060043 return rc;
44}
Ben Tyner0205f3b2020-02-24 10:24:47 -060045
46} // namespace attn