summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2018-05-25 15:36:30 +0930
committerAndrew Jeffery <andrew@aj.id.au>2019-04-08 13:48:50 +0930
commit30552c95285892a81dc4ae704263cc98d07f3208 (patch)
treeef77e4a400b7ad43649eb63bba16853225164880
parente5c40feae02560f56790457be1c2e289ccd0ce6f (diff)
downloadphosphor-led-sysfs-30552c95285892a81dc4ae704263cc98d07f3208.zip
phosphor-led-sysfs-30552c95285892a81dc4ae704263cc98d07f3208.tar.gz
physical: Rework commentary for brevity
Change-Id: I84341c6418853ad7fb44aa6f02ab298cc70842f6 Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
-rw-r--r--physical.cpp55
1 files changed, 13 insertions, 42 deletions
diff --git a/physical.cpp b/physical.cpp
index 0de2a53..2b404b6 100644
--- a/physical.cpp
+++ b/physical.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright © 2016 IBM Corporation
+ * Copyright © 2016,2018 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,86 +26,67 @@ namespace led
/** @brief Populates key parameters */
void Physical::setInitialState()
{
- // 1. read /sys/class/leds/name/trigger
- // 2. If its 'timer', then its blinking.
- // 2.1: On blink, use delay_on and delay_off into dutyOn
- // 3. If its 'none', then read brightness. 255 means, its ON, else OFF.
-
auto trigger = led.getTrigger();
if (trigger == "timer")
{
- // LED is blinking. Get the delay_on and delay_off and compute
- // DutyCycle. sfsfs values are in strings. Need to convert 'em over to
- // integer.
+ // LED is blinking. Get the on and off delays and derive percent duty
auto delayOn = led.getDelayOn();
auto delayOff = led.getDelayOff();
- // Calculate frequency and then percentage ON
+ // Calculate duty from millisecond delay values and derive percentage on
periodMs = delayOn + delayOff;
auto factor = periodMs / 100;
auto dutyOn = delayOn / factor;
- // Update.
this->dutyOn(dutyOn);
}
else
{
- // This is hardcoded for now. This will be changed to this->period()
- // when configurable periodicity is implemented.
- // TODO
+ // TODO: Periodicity is hardcoded for now. This will be changed to
+ // this->period() when configurable periodicity is implemented.
periodMs = 1000;
- // LED is either ON or OFF
+ // Cache current LED state
auto brightness = led.getBrightness();
if (brightness == ASSERT)
{
- // LED is in Solid ON
- sdbusplus::xyz::openbmc_project::Led::server ::Physical::state(
+ sdbusplus::xyz::openbmc_project::Led::server::Physical::state(
Action::On);
}
else
{
- // LED is in OFF state
- sdbusplus::xyz::openbmc_project::Led::server ::Physical::state(
+ sdbusplus::xyz::openbmc_project::Led::server::Physical::state(
Action::Off);
}
}
return;
}
-/** @brief Overloaded State Property Setter function */
auto Physical::state(Action value) -> Action
{
- // Obtain current operation
auto current =
- sdbusplus::xyz::openbmc_project::Led::server ::Physical::state();
+ sdbusplus::xyz::openbmc_project::Led::server::Physical::state();
- // Update requested operation into base class
auto requested =
- sdbusplus::xyz::openbmc_project::Led::server ::Physical::state(value);
+ sdbusplus::xyz::openbmc_project::Led::server::Physical::state(value);
- // Apply the action.
driveLED(current, requested);
return value;
}
-/** @brief apply action on the LED */
void Physical::driveLED(Action current, Action request)
{
if (current == request)
{
- // Best we can do here is ignore.
return;
}
- // Transition TO Blinking state
if (request == Action::Blink)
{
return blinkOperation();
}
- // Transition TO Stable states.
if (request == Action::On || request == Action::Off)
{
return stableStateOperation(request);
@@ -113,35 +94,25 @@ void Physical::driveLED(Action current, Action request)
return;
}
-/** @brief Either TurnON -or- TurnOFF */
void Physical::stableStateOperation(Action action)
{
auto value = (action == Action::On) ? ASSERT : DEASSERT;
- // Write "none" to trigger to clear any previous action
led.setTrigger("none");
-
- // And write the current command
led.setBrightness(value);
return;
}
-/** @brief BLINK the LED */
void Physical::blinkOperation()
{
- // Get the latest dutyOn that the user requested
auto dutyOn = this->dutyOn();
- // Write "timer" to "trigger" file
- led.setTrigger("timer");
-
- // Write DutyON. Value in percentage 1_millisecond.
- // so 50% input becomes 500. Driver wants string input
+ // Convert percent duty to milliseconds for sysfs interface
auto factor = periodMs / 100;
led.setDelayOn(dutyOn * factor);
-
- // Write DutyOFF. Value in milli seconds so 50% input becomes 500.
led.setDelayOff((100 - dutyOn) * factor);
+
+ led.setTrigger("timer");
return;
}
OpenPOWER on IntegriCloud