From 30552c95285892a81dc4ae704263cc98d07f3208 Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Fri, 25 May 2018 15:36:30 +0930 Subject: physical: Rework commentary for brevity Change-Id: I84341c6418853ad7fb44aa6f02ab298cc70842f6 Signed-off-by: Andrew Jeffery --- physical.cpp | 55 +++++++++++++------------------------------------------ 1 file 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; } -- cgit v1.2.1