1 #pragma once
2 
3 #include "sysfs.hpp"
4 
5 #include <fstream>
6 #include <sdbusplus/bus.hpp>
7 #include <sdbusplus/server/object.hpp>
8 #include <string>
9 #include <xyz/openbmc_project/Led/Physical/server.hpp>
10 
11 namespace phosphor
12 {
13 namespace led
14 {
15 /** @brief Assert LED by writing 255 */
16 constexpr auto ASSERT = 255;
17 
18 /** @brief De-assert by writing "0" */
19 constexpr auto DEASSERT = 0;
20 
21 /** @class Physical
22  *  @brief Responsible for applying actions on a particular physical LED
23  */
24 class Physical : public sdbusplus::server::object::object<
25                      sdbusplus::xyz::openbmc_project::Led::server::Physical>
26 {
27   public:
28     Physical() = delete;
29     ~Physical() = default;
30     Physical(const Physical&) = delete;
31     Physical& operator=(const Physical&) = delete;
32     Physical(Physical&&) = delete;
33     Physical& operator=(Physical&&) = delete;
34 
35     /** @brief Constructs LED object. Argument 'true' says that we hold off
36      *   from sending the signals since we need to do some house keeping and
37      *   only when we finish that, we are considered active and can then
38      *   broadcast the signal.
39      *
40      * @param[in] bus       - system dbus handler
41      * @param[in] objPath   - The Dbus path that hosts physical LED
42      * @param[in] ledPath   - sysfs path where this LED is exported
43      */
44     Physical(sdbusplus::bus::bus& bus, const std::string& objPath,
45              SysfsLed& led) :
46 
47         sdbusplus::server::object::object<
48             sdbusplus::xyz::openbmc_project::Led::server::Physical>(
49             bus, objPath.c_str(), true),
50         led(led)
51     {
52         // Suppose this is getting launched as part of BMC reboot, then we
53         // need to save what the micro-controller currently has.
54         setInitialState();
55 
56         // We are now ready.
57         emit_object_added();
58     }
59 
60     /** @brief Overloaded State Property Setter function
61      *
62      *  @param[in] value   -  One of OFF / ON / BLINK
63      *  @return            -  Success or exception thrown
64      */
65     Action state(Action value) override;
66 
67   private:
68     /** @brief Associated LED implementation
69      */
70     SysfsLed& led;
71 
72     /** @brief Frequency range that the LED can operate on.
73      *  Will be removed when frequency is put into interface
74      */
75     uint32_t frequency;
76 
77     /** @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();
105 };
106 
107 } // namespace led
108 } // namespace phosphor
109