Add OCP debug card host selector button interface
A new button interface class definition is added for handling OCP
debug card host selector button events.
In case of the button release event, The host selector property is
increased up to the max host position.
Design : https://gerrit.openbmc-project.xyz/c/openbmc/docs/+/45544
Signed-off-by: Naveen Moses <naveen.mosess@hcl.com>
Change-Id: Iec8fabb00d1daa10f587981a9c77df8a62e3c373
diff --git a/src/debugHostSelector_button.cpp b/src/debugHostSelector_button.cpp
new file mode 100644
index 0000000..6f078f2
--- /dev/null
+++ b/src/debugHostSelector_button.cpp
@@ -0,0 +1,66 @@
+#include "debugHostSelector_button.hpp"
+// add the button iface class to registry
+static ButtonIFRegister<DebugHostSelector> buttonRegister;
+using namespace phosphor::logging;
+
+void DebugHostSelector::simPress()
+{
+ pressed();
+}
+
+void DebugHostSelector::simRelease()
+{
+ released();
+}
+
+void DebugHostSelector::simLongPress()
+{
+ pressedLong();
+}
+
+/**
+ * @brief This method is called from sd-event provided callback function
+ * callbackHandler if platform specific event handling is needed then a
+ * derived class instance with its specific event handling logic along with
+ * init() function can be created to override the default event handling
+ */
+
+void DebugHostSelector::handleEvent(sd_event_source* /* es */, int fd,
+ uint32_t /* revents*/)
+{
+ int n = -1;
+ char buf = '0';
+
+ n = ::lseek(fd, 0, SEEK_SET);
+
+ if (n < 0)
+ {
+ lg2::error("GPIO fd lseek error! : {FORM_FACTOR_TYPE}",
+ "FORM_FACTOR_TYPE", getFormFactorType());
+ return;
+ }
+
+ n = ::read(fd, &buf, sizeof(buf));
+ if (n < 0)
+ {
+ lg2::error("GPIO fd read error! : {FORM_FACTOR_TYPE}",
+ "FORM_FACTOR_TYPE", getFormFactorType());
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
+ }
+
+ if (buf == '0')
+ {
+ lg2::info("Button pressed : {FORM_FACTOR_TYPE}", "FORM_FACTOR_TYPE",
+ getFormFactorType());
+ // emit pressed signal
+ pressed();
+ }
+ else
+ {
+ lg2::info("Button released{FORM_FACTOR_TYPE}", "FORM_FACTOR_TYPE",
+ getFormFactorType());
+ // emit released signal
+ released();
+ }
+}
\ No newline at end of file