physical: Conform to LED class kernel ABI
The kernel says the following about the LED sysfs interface:
> LED handling under Linux
> ========================
>
> In its simplest form, the LED class just allows control of LEDs from
> userspace. LEDs appear in /sys/class/leds/. The maximum brightness of the
> LED is defined in max_brightness file. The brightness file will set the brightness
> of the LED (taking a value 0-max_brightness). Most LEDs don't have hardware
> brightness support so will just be turned on for non-zero brightness settings.
The existing code assumed that max_brightness always held a value of
255 and defined a constant for it. Instead, use a class variable to
cache the max brightness for the associated LED.
Change-Id: I2d8f46de0cddac5f9d8ff5444449518bb4056130
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/physical.cpp b/physical.cpp
index ae9ff1c..e614b99 100644
--- a/physical.cpp
+++ b/physical.cpp
@@ -27,6 +27,7 @@
/** @brief Populates key parameters */
void Physical::setInitialState()
{
+ assert = led.getMaxBrightness();
auto trigger = led.getTrigger();
if (trigger == "timer")
{
@@ -44,7 +45,7 @@
// Cache current LED state
auto brightness = led.getBrightness();
- if (brightness == ASSERT)
+ if (brightness == assert)
{
sdbusplus::xyz::openbmc_project::Led::server::Physical::state(
Action::On);
@@ -89,7 +90,7 @@
void Physical::stableStateOperation(Action action)
{
- auto value = (action == Action::On) ? ASSERT : DEASSERT;
+ auto value = (action == Action::On) ? assert : DEASSERT;
led.setTrigger("none");
led.setBrightness(value);