blob: 46455b38a0cb1d30782ce248fb558582b1d7c71d [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
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 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
38 }
39
Ben Tyneref320152020-01-09 10:31:23 -060040 return rc;
41}
Ben Tyner0205f3b2020-02-24 10:24:47 -060042
43} // namespace attn