blob: 492531bcc70fae8f9842a4800f8caee23d2b01f1 [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 Tyner0205f3b2020-02-24 10:24:47 -06009int attnDaemon(bool i_breakpoints)
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 Tyner0205f3b2020-02-24 10:24:47 -060034 gpios.push_back(std::make_unique<attn::AttnMonitor>(line, config, io,
35 i_breakpoints));
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