Add ability to set LED colors in DBus
phosphor-led-sysfs parses sysfs LED node names
in the form of "devicename:colour:function" as
described in
https://github.com/torvalds/linux/blob/master/Documentation/leds/leds-class.txt#L46
and then converts the "colour" part into the proper
value of the DBus 'Color' property using the
xyz.openbmc_project.Led.Physical.Palette interface.
In order for the led nodes to have their Color set,
the corresponding led nodes in devicetree must have
correct 'label' properties, e.g.:
leds {
compatible = "gpio-leds";
heartbeat {
label = "bmc:green:hearbeat";
gpios = <&gpio ASPEED_GPIO(R, 4) GPIO_ACTIVE_LOW>;
};
power_red {
label = "system:red:power";
gpios = <&gpio ASPEED_GPIO(N, 1) GPIO_ACTIVE_LOW>;
};
}
Change-Id: I094f0e434bdd262995752576a3c792ccd5dbb3e2
Signed-off-by: Alexander Soldatov <a.soldatov@yadro.com>
Signed-off-by: Alexander Amelkin <a.amelkin@yadro.com>
diff --git a/physical.cpp b/physical.cpp
index e614b99..ac8bb25 100644
--- a/physical.cpp
+++ b/physical.cpp
@@ -17,6 +17,7 @@
#include "physical.hpp"
#include <cassert>
+#include <cstdlib>
#include <iostream>
#include <string>
namespace phosphor
@@ -110,5 +111,26 @@
return;
}
+/** @brief set led color property in DBus*/
+void Physical::setLedColor(const std::string& color)
+{
+ static const std::string prefix =
+ "xyz.openbmc_project.Led.Physical.Palette.";
+ if (!color.length())
+ return;
+ std::string tmp = color;
+ tmp[0] = toupper(tmp[0]);
+ try
+ {
+ auto palette = convertPaletteFromString(prefix + tmp);
+ setPropertyByName("Color", palette);
+ }
+ catch (const sdbusplus::exception::InvalidEnumString&)
+ {
+ // if color var contains invalid color,
+ // Color property will have default value
+ }
+}
+
} // namespace led
} // namespace phosphor