pinhole: move gpio function to utils
The function to read a GPIO is needed elsewhere in later reviews so move
to the utility file.
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I994d4a912c0abe9cae6cb02d22bf5be09581d332
diff --git a/utils.cpp b/utils.cpp
index 6dc7754..8e0e7ed 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -1,5 +1,7 @@
#include "utils.hpp"
+#include <gpiod.h>
+
#include <phosphor-logging/lg2.hpp>
namespace phosphor
@@ -69,6 +71,31 @@
return;
}
+int getGpioValue(const std::string& gpioName)
+{
+
+ int gpioval = -1;
+ gpiod_line* line = gpiod_line_find(gpioName.c_str());
+
+ if (nullptr != line)
+ {
+ // take ownership of gpio
+ if (0 != gpiod_line_request_input(line, "state-manager"))
+ {
+ error("Failed request for {GPIO_NAME} GPIO", "GPIO_NAME", gpioName);
+ }
+ else
+ {
+ // get gpio value
+ gpioval = gpiod_line_get_value(line);
+
+ // release ownership of gpio
+ gpiod_line_close_chip(line);
+ }
+ }
+ return gpioval;
+}
+
} // namespace utils
} // namespace manager
} // namespace state