diff options
author | Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com> | 2019-03-25 15:02:39 +0300 |
---|---|---|
committer | Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com> | 2019-03-25 15:02:39 +0300 |
commit | f4d4bfc3296cb27feb17aa5d1d93b3061b56ce10 (patch) | |
tree | dc0d9bf449e60340e4ccd9a2445ddac569886680 /gpiodaemon | |
parent | b708f28e43b85fd51c0f68670e7614dc3d7dbe50 (diff) | |
download | provingground-f4d4bfc3296cb27feb17aa5d1d93b3061b56ce10.tar.xz |
Support: sampled value property in gpio daemon
1. Added property SampledValue, which will reflect the gpio
value status always, will be used when ignore property is true
2. Removed enabled property, as it is not used anymore
3. Fixed bug for Value property which had the inversion first
before comparison.
Tested:
1. Verified the behavior using D-Bus commands
2. Verified Power-up / Gpio Sampling / etc, along with
Buttons & set-passthrough patch.
Change-Id: I30b31d12019c54377d0f279f604aee83c5f63883
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
Diffstat (limited to 'gpiodaemon')
-rw-r--r-- | gpiodaemon/include/gpiodaemon.hpp | 9 | ||||
-rw-r--r-- | gpiodaemon/src/gpiodaemon.cpp | 63 |
2 files changed, 28 insertions, 44 deletions
diff --git a/gpiodaemon/include/gpiodaemon.hpp b/gpiodaemon/include/gpiodaemon.hpp index b3d461e..cbe46ef 100644 --- a/gpiodaemon/include/gpiodaemon.hpp +++ b/gpiodaemon/include/gpiodaemon.hpp @@ -25,9 +25,8 @@ class GpioState { const std::string name; - uint16_t number; + uint64_t number; const bool inverted; - bool enabled; bool value; std::string direction; bool ignore = false; @@ -41,9 +40,9 @@ class GpioState void readValue(void); public: - GpioState(const std::string& name_, const uint16_t number_, - const bool inverted_, const bool enabled_, - const std::string& direction_, boost::asio::io_service& io_, + GpioState(const std::string& name_, const uint64_t& number_, + const bool inverted_, const std::string& direction_, + boost::asio::io_service& io_, std::shared_ptr<sdbusplus::asio::dbus_interface>& iface_); ~GpioState(); Gpio gpio; diff --git a/gpiodaemon/src/gpiodaemon.cpp b/gpiodaemon/src/gpiodaemon.cpp index cd742e2..2d03c54 100644 --- a/gpiodaemon/src/gpiodaemon.cpp +++ b/gpiodaemon/src/gpiodaemon.cpp @@ -92,10 +92,9 @@ void GpioManager::addObject(const std::string& path) server.add_interface(gpioPath + gpioName, gpioInterface); // Monitor gpio value changes - gpioMonitorList.emplace( - gpioName, - std::make_unique<GpioState>(gpioName, index, inverted, - false, direction, io, iface)); + gpioMonitorList.emplace(gpioName, std::make_unique<GpioState>( + gpioName, index, inverted, + direction, io, iface)); } }, entityMgrService, path, propInterface, "GetAll", gpioConfigInterface); @@ -142,15 +141,13 @@ GpioManager::GpioManager(boost::asio::io_service& io_, std::vector<std::string>()); } -GpioState::GpioState(const std::string& name_, const uint16_t number_, - const bool inverted_, const bool enabled_, - const std::string& direction_, +GpioState::GpioState(const std::string& name_, const uint64_t& number_, + const bool inverted_, const std::string& direction_, boost::asio::io_service& io_, std::shared_ptr<sdbusplus::asio::dbus_interface>& iface_) : name(name_), - number(number_), inverted(inverted_), enabled(enabled_), - direction(direction_), inputDev(io_), iface(iface_), - gpio(std::to_string(number_)) + number(number_), inverted(inverted_), direction(direction_), inputDev(io_), + iface(iface_), gpio(std::to_string(number_)) { // Initialize gpio direction as specified by entity-manager @@ -165,8 +162,6 @@ GpioState::GpioState(const std::string& name_, const uint16_t number_, "Ignore", ignore, // Override set [this](const bool& req, bool& propertyValue) { - // If Gpio enabled property is set as true then - // handle the request if (ignore != req) { ignore = req; @@ -181,9 +176,7 @@ GpioState::GpioState(const std::string& name_, const uint16_t number_, "Direction", direction, // Override set [this](const std::string& req, std::string& propertyValue) { - // If Gpio enabled property is set as true then - // handle the request - if (!ignore && enabled && direction != req) + if (!ignore && direction != req) { direction = req; this->gpio.setDirection(req); @@ -202,22 +195,6 @@ GpioState::GpioState(const std::string& name_, const uint16_t number_, return direction; }); - // TODO: Determine whether we require this one? ignore should be fine - // Decide and remove the same - - // Enabled is used to control the set property of Value & direction - iface->register_property( - "Enabled", enabled, - [this](const bool& req, bool& propertyValue) { - if (!ignore && enabled != req) - { - enabled = req; - propertyValue = req; - return 1; - } - return 0; - }, - [this](const bool& propertyValue) { return enabled; }); value = static_cast<bool>(gpio.getValue()); if (inverted) { @@ -227,21 +204,20 @@ GpioState::GpioState(const std::string& name_, const uint16_t number_, "Value", value, // Override set [this](const bool& req, bool& propertyValue) { - if ((!ignore && enabled && this->gpio.getDirection() == "out") || - internalSet) + if ((!ignore && gpio.getDirection() == "out") || internalSet) { bool setVal = req; - if (inverted) - { - setVal = !setVal; - } if (value != setVal) { value = setVal; propertyValue = setVal; if (!internalSet) { - this->gpio.setValue(static_cast<GpioValue>(setVal)); + if (inverted) + { + setVal = !setVal; + } + gpio.setValue(static_cast<GpioValue>(setVal)); } return 1; } @@ -250,6 +226,15 @@ GpioState::GpioState(const std::string& name_, const uint16_t number_, }, // Override get [this](const bool& propertyValue) { return value; }); + iface->register_property( + "SampledValue", value, + // Override set - ignore set + [this](const bool& req, bool& propertyValue) { return 0; }, + // Override get + [this](const bool& propertyValue) { + return (inverted ? !static_cast<bool>(gpio.getValue()) + : static_cast<bool>(gpio.getValue())); + }); iface->initialize(); @@ -323,7 +308,7 @@ void GpioState::readValue(void) bool state = std::stoi(readBuf); internalSet = true; // Update the property value - iface->set_property("Value", state); + iface->set_property("Value", inverted ? !state : state); internalSet = false; } |