blob: d4de9c288b1b069d7fee418f9509d075e598397e [file] [log] [blame]
Naveen Mosesa6d4e652022-04-13 19:27:25 +05301#include "debugHostSelector_button.hpp"
2// add the button iface class to registry
3static ButtonIFRegister<DebugHostSelector> buttonRegister;
4using namespace phosphor::logging;
5
6void DebugHostSelector::simPress()
7{
8 pressed();
9}
10
11void DebugHostSelector::simRelease()
12{
13 released();
14}
15
16void DebugHostSelector::simLongPress()
17{
18 pressedLong();
19}
20
21/**
22 * @brief This method is called from sd-event provided callback function
23 * callbackHandler if platform specific event handling is needed then a
24 * derived class instance with its specific event handling logic along with
25 * init() function can be created to override the default event handling
26 */
27
28void DebugHostSelector::handleEvent(sd_event_source* /* es */, int fd,
29 uint32_t /* revents*/)
30{
31 int n = -1;
32 char buf = '0';
33
34 n = ::lseek(fd, 0, SEEK_SET);
35
36 if (n < 0)
37 {
38 lg2::error("GPIO fd lseek error! : {FORM_FACTOR_TYPE}",
39 "FORM_FACTOR_TYPE", getFormFactorType());
40 return;
41 }
42
43 n = ::read(fd, &buf, sizeof(buf));
44 if (n < 0)
45 {
46 lg2::error("GPIO fd read error! : {FORM_FACTOR_TYPE}",
47 "FORM_FACTOR_TYPE", getFormFactorType());
48 throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
49 IOError();
50 }
51
52 if (buf == '0')
53 {
54 lg2::info("Button pressed : {FORM_FACTOR_TYPE}", "FORM_FACTOR_TYPE",
55 getFormFactorType());
56 // emit pressed signal
57 pressed();
58 }
59 else
60 {
61 lg2::info("Button released{FORM_FACTOR_TYPE}", "FORM_FACTOR_TYPE",
62 getFormFactorType());
63 // emit released signal
64 released();
65 }
Patrick Williams0d038f52023-05-10 07:50:40 -050066}