summaryrefslogtreecommitdiffstats
path: root/fan_speed.hpp
blob: 7fc303abc4a3e0336653c995aa74521bee6d2ca5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once

#include "interface.hpp"
#include "sysfs.hpp"

namespace hwmon
{

/**
 * @class FanSpeed
 * @brief Target fan speed control implementation
 * @details Derived FanSpeedObject type that writes the target value to sysfs
 * which in turn sets the fan speed to that target value
 */
class FanSpeed : public FanSpeedObject
{
    public:

        /**
         * @brief Constructs FanSpeed Object
         *
         * @param[in] instancePath - The hwmon instance path
         *     (ex. /sys/class/hwmon/hwmon1)
         * @param[in] devPath - The /sys/devices sysfs path
         * @param[in] id - The hwmon id
         * @param[in] bus - Dbus bus object
         * @param[in] objPath - Dbus object path
         * @param[in] defer - Dbus object registration defer
         * @param[in] target - initial target speed value
         */
        FanSpeed(const std::string& instancePath,
                 const std::string& devPath,
                 const std::string& id,
                 sdbusplus::bus::bus& bus,
                 const char* objPath,
                 bool defer,
                 uint64_t target) : FanSpeedObject(bus, objPath, defer),
                    id(id),
                    ioAccess(instancePath),
                    devPath(devPath)
        {
            FanSpeedObject::target(target);
        }

        /**
         * @brief Set the value of target
         *
         * @return Value of target
         */
        uint64_t target(uint64_t value) override;

        /**
         * @brief Writes the pwm_enable sysfs entry if the
         *        env var with the value to write is present
         */
        void enable();

    private:
        /** @brief hwmon type */
        static constexpr auto type = "fan";
        /** @brief hwmon id */
        std::string id;
        /** @brief Hwmon sysfs access. */
        sysfs::hwmonio::HwmonIO ioAccess;
        /** @brief Physical device path. */
        std::string devPath;

};

} // namespace hwmon
OpenPOWER on IntegriCloud