blob: ea8d050fed81808c595a1aa59286f06f95256581 [file] [log] [blame]
Ben Tynerb797b3e2020-06-29 10:12:05 -05001#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{
Patrick Williams27dd6362023-05-10 07:51:20 -050011 int rc = 0; // assume success
Ben Tyneref320152020-01-09 10:31:23 -060012
Patrick Williams27dd6362023-05-10 07:51:20 -050013 gpiod_line* line; // gpio line to monitor
Ben Tyner73ac3682020-01-09 10:46:47 -060014
Ed Tanous0577c012023-03-01 11:18:36 -080015 boost::asio::io_context io; // async io monitoring service
Ben Tyner73ac3682020-01-09 10:46:47 -060016
Ben Tyner73ac3682020-01-09 10:46:47 -060017 // GPIO line configuration (falling edge, active low)
Patrick Williamsc7aacfa2024-12-18 11:22:25 -050018 struct gpiod_line_request_config config{
19 "attention", GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE, 0};
Ben Tyner73ac3682020-01-09 10:46:47 -060020
21 // get handle to attention GPIO line
Ben Tyner117af992020-05-22 13:32:11 -050022 line = gpiod_line_find("checkstop");
Ben Tyner73ac3682020-01-09 10:46:47 -060023
24 if (nullptr == line)
25 {
26 rc = 1; // error
27 }
28 else
29 {
30 // Creating a vector of one gpio to monitor
31 std::vector<std::unique_ptr<attn::AttnMonitor>> gpios;
Ben Tyner3fb52e52020-03-31 10:10:07 -050032 gpios.push_back(
33 std::make_unique<attn::AttnMonitor>(line, config, io, i_config));
Ben Tyner73ac3682020-01-09 10:46:47 -060034
35 io.run(); // start GPIO monitor
Ben Tyner117af992020-05-22 13:32:11 -050036
37 // done with line, manually close chip (per gpiod api comments)
38 gpiod_line_close_chip(line);
Ben Tyner73ac3682020-01-09 10:46:47 -060039 }
40
Ben Tyneref320152020-01-09 10:31:23 -060041 return rc;
42}
Ben Tyner0205f3b2020-02-24 10:24:47 -060043
44} // namespace attn