hostSelector_switch: add support polling mode
Task Description:
Add support for polling mode to periodically sample the group GPIO
selector inputs and update the HostSelector interface’s Position
property on D-Bus.
Motivation:
-Some platforms expose the host-selector via a CPLD as GPIO inputs
without edge interrupts.
-Polling ensures all position changes are detected reliably.
Design:
- Enabled polling through the 'polling_mode' and 'polling_interval_ms'
options in JSON configuration.
- Introduced pollTimerHandler to periodically check GPIO states
and update the internal host selector position.
Tested:
journalctl -xeu xyz.openbmc_project.Chassis.Buttons.service -f
Jul 31 00:06:47 bmc buttons[629]: Start Phosphor buttons service...
Jul 31 00:06:47 bmc buttons[629]: Started polling mode: 2000ms
Jul 31 00:06:49 bmc buttons[629]: Host selector position updated to 0
Jul 31 00:06:53 bmc systemd[1]: Started Phosphor Buttons.
Jul 31 00:13:50 bmc buttons[629]: Host selector position updated to 1
Jul 31 00:13:52 bmc buttons[629]: Host selector position updated to 2
Jul 31 00:13:54 bmc buttons[629]: Host selector position updated to 3
Jul 31 00:14:00 bmc buttons[629]: Host selector position updated to 4
Jul 31 00:14:04 bmc buttons[629]: Host selector position updated to 5
Jul 31 00:14:10 bmc buttons[629]: Host selector position updated to 6
Jul 31 00:14:14 bmc buttons[629]: Host selector position updated to 7
Jul 31 00:14:16 bmc buttons[629]: Host selector position updated to 8
Jul 31 00:14:20 bmc buttons[629]: Host selector position updated to 0
Change-Id: I8b95d773191f1af03b747f9eeb33494da9878bc8
Signed-off-by: Liora Guo <liora.guo.wiwynn@gmail.com>
diff --git a/inc/hostSelector_switch.hpp b/inc/hostSelector_switch.hpp
index 04f80bb..24947ea 100644
--- a/inc/hostSelector_switch.hpp
+++ b/inc/hostSelector_switch.hpp
@@ -11,9 +11,17 @@
#include <nlohmann/json.hpp>
#include <phosphor-logging/elog-errors.hpp>
+#include <sdeventplus/event.hpp>
+#include <sdeventplus/utility/timer.hpp>
+#include <chrono>
#include <fstream>
#include <iostream>
+#include <optional>
+
+using sdeventplus::ClockId;
+using sdeventplus::Event;
+using Timer = sdeventplus::utility::Timer<ClockId::Monotonic>;
static constexpr auto HOST_SELECTOR = "HOST_SELECTOR";
@@ -66,10 +74,15 @@
void setInitialHostSelectorValue(void);
void setHostSelectorValue(int fd, GpioState state);
char getValueFromFd(int fd);
+ void pollGpioState();
+
+ private:
+ std::optional<Timer> pollTimer;
protected:
size_t hostSelectorPosition = 0;
size_t gpioLineCount;
+ size_t previousPos = INVALID_INDEX;
// map of read Host selector switch value and corresponding host number
// value.