blob: 67a900b04435d82fa8e250805f630cd8dc14dec2 [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 Subbanna61675c32016-11-30 15:52:15 +05305#include <fstream>
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +05306#include <sdbusplus/bus.hpp>
7#include <sdbusplus/server/object.hpp>
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +09308#include <string>
Vishwanatha Subbannae0891732017-03-10 15:27:23 +05309#include <xyz/openbmc_project/Led/Physical/server.hpp>
Andrew Jeffery42e02d32018-05-24 13:34:05 +093010
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053011namespace phosphor
12{
13namespace led
14{
Andrew Jeffery5b1417b2019-03-18 17:20:37 +103015/** @brief De-assert value */
Andrew Jefferyaee9c2c2018-05-25 14:05:40 +093016constexpr unsigned long DEASSERT = 0;
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053017
18/** @class Physical
19 * @brief Responsible for applying actions on a particular physical LED
20 */
21class Physical : public sdbusplus::server::object::object<
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093022 sdbusplus::xyz::openbmc_project::Led::server::Physical>
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053023{
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093024 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 Subbannabda97eb2016-11-30 12:21:25 +053031
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093032 /** @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
40 */
41 Physical(sdbusplus::bus::bus& bus, const std::string& objPath,
Andrew Jeffery42e02d32018-05-24 13:34:05 +093042 SysfsLed& led) :
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053043
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093044 sdbusplus::server::object::object<
45 sdbusplus::xyz::openbmc_project::Led::server::Physical>(
46 bus, objPath.c_str(), true),
Andrew Jeffery42e02d32018-05-24 13:34:05 +093047 led(led)
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093048 {
49 // Suppose this is getting launched as part of BMC reboot, then we
50 // need to save what the micro-controller currently has.
51 setInitialState();
52
53 // We are now ready.
54 emit_object_added();
55 }
56
57 /** @brief Overloaded State Property Setter function
58 *
59 * @param[in] value - One of OFF / ON / BLINK
60 * @return - Success or exception thrown
61 */
62 Action state(Action value) override;
63
64 private:
Andrew Jeffery42e02d32018-05-24 13:34:05 +093065 /** @brief Associated LED implementation
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093066 */
Andrew Jeffery42e02d32018-05-24 13:34:05 +093067 SysfsLed& led;
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093068
Andrew Jeffery5b1417b2019-03-18 17:20:37 +103069 /** @brief The value that will assert the LED */
70 unsigned long assert;
71
Andrew Jefferye5c40fe2018-05-25 15:27:18 +093072 /** @brief The period that the LED will operate on, in milliseconds
73 * Will be removed when periodicity is put into interface
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093074 */
Andrew Jefferye5c40fe2018-05-25 15:27:18 +093075 uint32_t periodMs;
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093076
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093077 /** @brief reads sysfs and then setsup the parameteres accordingly
78 *
79 * @return None
80 */
81 void setInitialState();
82
83 /** @brief Applies the user triggered action on the LED
84 * by writing to sysfs
85 *
86 * @param [in] current - Current state of LED
87 * @param [in] request - Requested state
88 *
89 * @return None
90 */
91 void driveLED(Action current, Action request);
92
93 /** @brief Sets the LED to either ON or OFF state
94 *
95 * @param [in] action - Requested action. Could be OFF or ON
96 * @return None
97 */
98 void stableStateOperation(Action action);
99
100 /** @brief Sets the LED to BLINKING
101 *
102 * @return None
103 */
104 void blinkOperation();
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +0530105};
106
107} // namespace led
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +0930108} // namespace phosphor