Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Andrew Jeffery | 42e02d3 | 2018-05-24 13:34:05 +0930 | [diff] [blame] | 3 | #include "sysfs.hpp" |
| 4 | |
Vishwanatha Subbanna | 61675c3 | 2016-11-30 15:52:15 +0530 | [diff] [blame] | 5 | #include <fstream> |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 6 | #include <sdbusplus/bus.hpp> |
| 7 | #include <sdbusplus/server/object.hpp> |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 8 | #include <string> |
Vishwanatha Subbanna | e089173 | 2017-03-10 15:27:23 +0530 | [diff] [blame] | 9 | #include <xyz/openbmc_project/Led/Physical/server.hpp> |
Andrew Jeffery | 42e02d3 | 2018-05-24 13:34:05 +0930 | [diff] [blame] | 10 | |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 11 | namespace phosphor |
| 12 | { |
| 13 | namespace led |
| 14 | { |
Andrew Jeffery | 5b1417b | 2019-03-18 17:20:37 +1030 | [diff] [blame] | 15 | /** @brief De-assert value */ |
Andrew Jeffery | aee9c2c | 2018-05-25 14:05:40 +0930 | [diff] [blame] | 16 | constexpr unsigned long DEASSERT = 0; |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 17 | |
| 18 | /** @class Physical |
| 19 | * @brief Responsible for applying actions on a particular physical LED |
| 20 | */ |
| 21 | class Physical : public sdbusplus::server::object::object< |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 22 | sdbusplus::xyz::openbmc_project::Led::server::Physical> |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 23 | { |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 24 | public: |
| 25 | Physical() = delete; |
| 26 | ~Physical() = default; |
| 27 | Physical(const Physical&) = delete; |
| 28 | Physical& operator=(const Physical&) = delete; |
| 29 | Physical(Physical&&) = delete; |
| 30 | Physical& operator=(Physical&&) = delete; |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 31 | |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 32 | /** @brief Constructs LED object. Argument 'true' says that we hold off |
| 33 | * from sending the signals since we need to do some house keeping and |
| 34 | * only when we finish that, we are considered active and can then |
| 35 | * broadcast the signal. |
| 36 | * |
| 37 | * @param[in] bus - system dbus handler |
| 38 | * @param[in] objPath - The Dbus path that hosts physical LED |
| 39 | * @param[in] ledPath - sysfs path where this LED is exported |
Alexander Soldatov | 97ddb72 | 2019-04-16 09:10:00 +0300 | [diff] [blame] | 40 | * @param[in] color - led color name |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 41 | */ |
| 42 | Physical(sdbusplus::bus::bus& bus, const std::string& objPath, |
Alexander Soldatov | 97ddb72 | 2019-04-16 09:10:00 +0300 | [diff] [blame] | 43 | SysfsLed& led, const std::string& color = "") : |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 44 | |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 45 | sdbusplus::server::object::object< |
| 46 | sdbusplus::xyz::openbmc_project::Led::server::Physical>( |
| 47 | bus, objPath.c_str(), true), |
Andrew Jeffery | 42e02d3 | 2018-05-24 13:34:05 +0930 | [diff] [blame] | 48 | led(led) |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 49 | { |
| 50 | // Suppose this is getting launched as part of BMC reboot, then we |
| 51 | // need to save what the micro-controller currently has. |
| 52 | setInitialState(); |
| 53 | |
Alexander Soldatov | 97ddb72 | 2019-04-16 09:10:00 +0300 | [diff] [blame] | 54 | // Read led color from enviroment and set it in DBus. |
| 55 | setLedColor(color); |
| 56 | |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 57 | // We are now ready. |
| 58 | emit_object_added(); |
| 59 | } |
| 60 | |
| 61 | /** @brief Overloaded State Property Setter function |
| 62 | * |
| 63 | * @param[in] value - One of OFF / ON / BLINK |
| 64 | * @return - Success or exception thrown |
| 65 | */ |
| 66 | Action state(Action value) override; |
| 67 | |
| 68 | private: |
Andrew Jeffery | 42e02d3 | 2018-05-24 13:34:05 +0930 | [diff] [blame] | 69 | /** @brief Associated LED implementation |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 70 | */ |
Andrew Jeffery | 42e02d3 | 2018-05-24 13:34:05 +0930 | [diff] [blame] | 71 | SysfsLed& led; |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 72 | |
Andrew Jeffery | 5b1417b | 2019-03-18 17:20:37 +1030 | [diff] [blame] | 73 | /** @brief The value that will assert the LED */ |
| 74 | unsigned long assert; |
| 75 | |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 76 | /** @brief reads sysfs and then setsup the parameteres accordingly |
| 77 | * |
| 78 | * @return None |
| 79 | */ |
| 80 | void setInitialState(); |
| 81 | |
| 82 | /** @brief Applies the user triggered action on the LED |
| 83 | * by writing to sysfs |
| 84 | * |
| 85 | * @param [in] current - Current state of LED |
| 86 | * @param [in] request - Requested state |
| 87 | * |
| 88 | * @return None |
| 89 | */ |
| 90 | void driveLED(Action current, Action request); |
| 91 | |
| 92 | /** @brief Sets the LED to either ON or OFF state |
| 93 | * |
| 94 | * @param [in] action - Requested action. Could be OFF or ON |
| 95 | * @return None |
| 96 | */ |
| 97 | void stableStateOperation(Action action); |
| 98 | |
| 99 | /** @brief Sets the LED to BLINKING |
| 100 | * |
| 101 | * @return None |
| 102 | */ |
| 103 | void blinkOperation(); |
Alexander Soldatov | 97ddb72 | 2019-04-16 09:10:00 +0300 | [diff] [blame] | 104 | |
| 105 | /** @brief set led color property in DBus |
| 106 | * |
| 107 | * @param[in] color - led color name |
| 108 | */ |
| 109 | void setLedColor(const std::string& color); |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | } // namespace led |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 113 | } // namespace phosphor |