1b797b3e1SBen Tyner #include <attn/attn_monitor.hpp> 2ef320154SBen Tyner 30205f3b3SBen Tyner namespace attn 4970fd4fbSBen Tyner { 5970fd4fbSBen Tyner 6ef320154SBen Tyner /** 7ef320154SBen Tyner * @brief Attention handler application main() 8ef320154SBen Tyner */ attnDaemon(Config * i_config)93fb52e53SBen Tynerint attnDaemon(Config* i_config) 10ef320154SBen Tyner { 110205f3b3SBen Tyner int rc = 0; // assume success 12ef320154SBen Tyner 1373ac368aSBen Tyner gpiod_line* line; // gpio line to monitor 1473ac368aSBen Tyner 15*0577c013SEd Tanous boost::asio::io_context io; // async io monitoring service 1673ac368aSBen Tyner 1773ac368aSBen Tyner // GPIO line configuration (falling edge, active low) 1873ac368aSBen Tyner struct gpiod_line_request_config config 1973ac368aSBen Tyner { 2073ac368aSBen Tyner "attention", GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE, 0 2173ac368aSBen Tyner }; 2273ac368aSBen Tyner 2373ac368aSBen Tyner // get handle to attention GPIO line 24117af99bSBen Tyner line = gpiod_line_find("checkstop"); 2573ac368aSBen Tyner 2673ac368aSBen Tyner if (nullptr == line) 2773ac368aSBen Tyner { 2873ac368aSBen Tyner rc = 1; // error 2973ac368aSBen Tyner } 3073ac368aSBen Tyner else 3173ac368aSBen Tyner { 3273ac368aSBen Tyner // Creating a vector of one gpio to monitor 3373ac368aSBen Tyner std::vector<std::unique_ptr<attn::AttnMonitor>> gpios; 343fb52e53SBen Tyner gpios.push_back( 353fb52e53SBen Tyner std::make_unique<attn::AttnMonitor>(line, config, io, i_config)); 3673ac368aSBen Tyner 3773ac368aSBen Tyner io.run(); // start GPIO monitor 38117af99bSBen Tyner 39117af99bSBen Tyner // done with line, manually close chip (per gpiod api comments) 40117af99bSBen Tyner gpiod_line_close_chip(line); 4173ac368aSBen Tyner } 4273ac368aSBen Tyner 43ef320154SBen Tyner return rc; 44ef320154SBen Tyner } 450205f3b3SBen Tyner 460205f3b3SBen Tyner } // namespace attn 47