adcsensor: make BridgeGpio setup time configurable
On some voltage-monitoring lines there may be enough capacitance that
the hard-coded 20ms enable time is insufficient to allow the signal to
fully stabilize (a case in point being the battery voltage line on the
ASRock Rack E3C246D4I), leading to inaccurate readings. It would be
unfortunate to penalize all systems and make them unconditionally wait
longer by simply upping the global enable time, however, so instead we
allow it to be configured as an additional BridgeGpio parameter
"SetupTime", the (float) number of seconds to wait after enabling the
bridge GPIO before sampling the sensor. (The default setup time if
unspecified remains 20ms.)
Tested: with a corresponding entity-manager configuration adjustment to
add a longer SetupTime setting, achieved much more accurate battery
voltage readings on E3C246D4I.
Signed-off-by: Zev Weiss <zweiss@equinix.com>
Change-Id: I17f0ffa603fbbaa3bf929502bbdf02394719b3a4
diff --git a/include/ADCSensor.hpp b/include/ADCSensor.hpp
index 9ba0060..9e58139 100644
--- a/include/ADCSensor.hpp
+++ b/include/ADCSensor.hpp
@@ -15,7 +15,9 @@
class BridgeGpio
{
public:
- BridgeGpio(const std::string& name, const int polarity)
+ BridgeGpio(const std::string& name, const int polarity,
+ const float setupTime) :
+ setupTimeMs(static_cast<unsigned int>(setupTime * 1000))
{
line = gpiod::find_line(name);
if (!line)
@@ -54,6 +56,8 @@
}
}
+ unsigned int setupTimeMs;
+
private:
gpiod::line line;
};