Enable GPIO polling for fans that dont support GPIO events
This commit will enable the use of GPIO polling for fans that do not
support GPIO events for presence detection.
The configuration should specify the MonitoryType of Polling which will
trigger the polling based presence monitoring.
Preconditions:
Add the configuration of the dual rotor fan in xxx_BaseBoard.json,
for example:
```
{
"Address": "0x52",
"Bus": 6,
"Index": 0,
"MaxReading": 14500,
"Name": "Fan1a_in",
"PowerState": "Always",
"Presence": {
"PinName": "FAN0_PRESENCE_R_N",
"Polarity": "Low",
"MonitorType": "Polling"
},
"Type": "I2CFan"
},
{
"Address": "0x52",
"Bus": 6,
"Index": 1,
"MaxReading": 14500,
"Name": "Fan1b_in",
"PowerState": "Always",
"Presence": {
"PinName": "FAN0_PRESENCE_R_N",
"Polarity": "Low"
"MonitorType": "Polling"
},
"Type": "I2CFan"
},
```
Tested
```
a{sv} 2 "PrettyName" s "" "Present" b true
a{sv} 2 "PrettyName" s "" "Present" b true
(unplug dual rotor fan)
a{sv} 2 "PrettyName" s "" "Present" b false
a{sv} 2 "PrettyName" s "" "Present" b false
(journal)
Feb 27 17:26:17 system1 fansensor[350]: Fan Fan1a_in Removed
Feb 27 17:35:47 system1 fansensor[350]: Fan Fan1a_in Inserted
Signed-off-by: Xiaochao Ma <maxiaochao@ieisystem.com>
Change-Id: I15215e6e919fabc8b362016c9bb8a5bfaea842db
Signed-off-by: Chris Cain <cjcain@us.ibm.com>
diff --git a/src/fan/FanMain.cpp b/src/fan/FanMain.cpp
index 33074b6..a28c0ce 100644
--- a/src/fan/FanMain.cpp
+++ b/src/fan/FanMain.cpp
@@ -469,12 +469,41 @@
}
if (!presenceGpio)
{
+ auto findMonitorType =
+ presenceConfig->second.find("MonitorType");
+ bool polling = false;
+ if (findMonitorType != presenceConfig->second.end())
+ {
+ auto mType = std::get<std::string>(
+ findMonitorType->second);
+ if (mType == "Polling")
+ {
+ polling = true;
+ }
+ else if (mType != "Event")
+ {
+ std::cerr
+ << "Unsupported GPIO MonitorType of "
+ << mType << " for " << sensorName
+ << " (supported types: Polling, Event (default))\n";
+ }
+ }
try
{
- presenceGpio =
- std::make_shared<EventPresenceGpio>(
- "Fan", sensorName, *pinName, inverted,
- io);
+ if (polling)
+ {
+ presenceGpio =
+ std::make_shared<PollingPresenceGpio>(
+ "Fan", sensorName, *pinName,
+ inverted, io);
+ }
+ else
+ {
+ presenceGpio =
+ std::make_shared<EventPresenceGpio>(
+ "Fan", sensorName, *pinName,
+ inverted, io);
+ }
presenceGpios[*pinName] = presenceGpio;
}
catch (const std::system_error& e)