blob: 359249487e5cac6b3c0a0d0f44be46c3a56dd959 [file] [log] [blame]
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +05301#pragma once
2
Andrew Jeffery42e02d32018-05-24 13:34:05 +09303#include "sysfs.hpp"
4
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +05305#include <sdbusplus/bus.hpp>
6#include <sdbusplus/server/object.hpp>
Vishwanatha Subbannae0891732017-03-10 15:27:23 +05307#include <xyz/openbmc_project/Led/Physical/server.hpp>
Andrew Jeffery42e02d32018-05-24 13:34:05 +09308
George Liu61b90632020-06-22 10:55:13 +08009#include <fstream>
10#include <string>
11
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053012namespace phosphor
13{
14namespace led
15{
Andrew Jeffery5b1417b2019-03-18 17:20:37 +103016/** @brief De-assert value */
Andrew Jefferyaee9c2c2018-05-25 14:05:40 +093017constexpr unsigned long DEASSERT = 0;
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053018
Patrick Williams97db22f2022-03-30 15:01:07 -050019namespace
20{
21using PhysicalIfaces = sdbusplus::server::object_t<
22 sdbusplus::xyz::openbmc_project::Led::server::Physical>;
23}
24
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053025/** @class Physical
26 * @brief Responsible for applying actions on a particular physical LED
27 */
Patrick Williams97db22f2022-03-30 15:01:07 -050028class Physical : public PhysicalIfaces
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053029{
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093030 public:
31 Physical() = delete;
32 ~Physical() = default;
33 Physical(const Physical&) = delete;
34 Physical& operator=(const Physical&) = delete;
35 Physical(Physical&&) = delete;
36 Physical& operator=(Physical&&) = delete;
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053037
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093038 /** @brief Constructs LED object. Argument 'true' says that we hold off
39 * from sending the signals since we need to do some house keeping and
40 * only when we finish that, we are considered active and can then
41 * broadcast the signal.
42 *
43 * @param[in] bus - system dbus handler
44 * @param[in] objPath - The Dbus path that hosts physical LED
45 * @param[in] ledPath - sysfs path where this LED is exported
Alexander Soldatov97ddb722019-04-16 09:10:00 +030046 * @param[in] color - led color name
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093047 */
Patrick Williamsff3d5382022-07-22 19:26:55 -050048 Physical(sdbusplus::bus_t& bus, const std::string& objPath, SysfsLed& led,
49 const std::string& color = "") :
Patrick Williams97db22f2022-03-30 15:01:07 -050050 PhysicalIfaces(bus, objPath.c_str(),
51 PhysicalIfaces::action::defer_emit),
Andrew Jeffery42e02d32018-05-24 13:34:05 +093052 led(led)
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093053 {
54 // Suppose this is getting launched as part of BMC reboot, then we
55 // need to save what the micro-controller currently has.
56 setInitialState();
57
Alexander Soldatov97ddb722019-04-16 09:10:00 +030058 // Read led color from enviroment and set it in DBus.
59 setLedColor(color);
60
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093061 // We are now ready.
62 emit_object_added();
63 }
64
65 /** @brief Overloaded State Property Setter function
66 *
67 * @param[in] value - One of OFF / ON / BLINK
68 * @return - Success or exception thrown
69 */
70 Action state(Action value) override;
71
Vishwanatha Subbannadb21bc02021-03-26 00:32:46 -050072 /** @brief Overriden State Property Getter function
73 *
74 * @return - One of OFF / ON / BLINK
75 */
76 Action state() const override;
77
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093078 private:
Andrew Jeffery42e02d32018-05-24 13:34:05 +093079 /** @brief Associated LED implementation
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093080 */
Andrew Jeffery42e02d32018-05-24 13:34:05 +093081 SysfsLed& led;
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093082
Andrew Jeffery5b1417b2019-03-18 17:20:37 +103083 /** @brief The value that will assert the LED */
84 unsigned long assert;
85
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093086 /** @brief reads sysfs and then setsup the parameteres accordingly
87 *
88 * @return None
89 */
90 void setInitialState();
91
92 /** @brief Applies the user triggered action on the LED
93 * by writing to sysfs
94 *
95 * @param [in] current - Current state of LED
96 * @param [in] request - Requested state
97 *
98 * @return None
99 */
100 void driveLED(Action current, Action request);
101
102 /** @brief Sets the LED to either ON or OFF state
103 *
104 * @param [in] action - Requested action. Could be OFF or ON
105 * @return None
106 */
107 void stableStateOperation(Action action);
108
109 /** @brief Sets the LED to BLINKING
110 *
111 * @return None
112 */
113 void blinkOperation();
Alexander Soldatov97ddb722019-04-16 09:10:00 +0300114
115 /** @brief set led color property in DBus
116 *
117 * @param[in] color - led color name
118 */
119 void setLedColor(const std::string& color);
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +0530120};
121
122} // namespace led
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +0930123} // namespace phosphor