hwmon.hpp (358193811e9769851e7f04816c3f5938f5a64f64) hwmon.hpp (043d32306e00484afc446a44789b61869ea14f84)
1#pragma once
2
1#pragma once
2
3#include "interface.hpp"
4
3#include <string>
4#include <tuple>
5
5#include <string>
6#include <tuple>
7
6#include "interface.hpp"
7
8namespace hwmon
9{
10namespace entry
11{
12static constexpr auto cinput = "input";
13static constexpr auto clabel = "label";
14static constexpr auto ctarget = "target";
15static constexpr auto cenable = "enable";
16static constexpr auto cfault = "fault";
17
18static const std::string input = cinput;
19static const std::string label = clabel;
20static const std::string target = ctarget;
21static const std::string enable = cenable;
22static const std::string fault = cfault;
8namespace hwmon
9{
10namespace entry
11{
12static constexpr auto cinput = "input";
13static constexpr auto clabel = "label";
14static constexpr auto ctarget = "target";
15static constexpr auto cenable = "enable";
16static constexpr auto cfault = "fault";
17
18static const std::string input = cinput;
19static const std::string label = clabel;
20static const std::string target = ctarget;
21static const std::string enable = cenable;
22static const std::string fault = cfault;
23}
23} // namespace entry
24
25namespace type
26{
27static constexpr auto cfan = "fan";
28static constexpr auto ctemp = "temp";
29static constexpr auto cvolt = "in";
30static constexpr auto ccurr = "curr";
31static constexpr auto cenergy = "energy";
32static constexpr auto cpower = "power";
33static constexpr auto cpwm = "pwm";
34
24
25namespace type
26{
27static constexpr auto cfan = "fan";
28static constexpr auto ctemp = "temp";
29static constexpr auto cvolt = "in";
30static constexpr auto ccurr = "curr";
31static constexpr auto cenergy = "energy";
32static constexpr auto cpower = "power";
33static constexpr auto cpwm = "pwm";
34
35
36static const std::string fan = cfan;
37static const std::string temp = ctemp;
38static const std::string volt = cvolt;
39static const std::string curr = ccurr;
40static const std::string energy = cenergy;
41static const std::string power = cpower;
42static const std::string pwm = cpwm;
35static const std::string fan = cfan;
36static const std::string temp = ctemp;
37static const std::string volt = cvolt;
38static const std::string curr = ccurr;
39static const std::string energy = cenergy;
40static const std::string power = cpower;
41static const std::string pwm = cpwm;
43}
42} // namespace type
44
43
45static constexpr auto typeAttrMap =
46{
44static constexpr auto typeAttrMap = {
47 // 1 - hwmon class
48 // 2 - unit
49 // 3 - sysfs scaling factor
50 // 4 - namespace
45 // 1 - hwmon class
46 // 2 - unit
47 // 3 - sysfs scaling factor
48 // 4 - namespace
51 std::make_tuple(
52 hwmon::type::ctemp,
53 ValueInterface::Unit::DegreesC,
54 -3,
55 "temperature"),
56 std::make_tuple(
57 hwmon::type::cfan,
58 ValueInterface::Unit::RPMS,
59 0,
60 "fan_tach"),
61 std::make_tuple(
62 hwmon::type::cvolt,
63 ValueInterface::Unit::Volts,
64 -3,
65 "voltage"),
66 std::make_tuple(
67 hwmon::type::ccurr,
68 ValueInterface::Unit::Amperes,
69 -3,
70 "current"),
71 std::make_tuple(
72 hwmon::type::cenergy,
73 ValueInterface::Unit::Joules,
74 -6,
75 "energy"),
76 std::make_tuple(
77 hwmon::type::cpower,
78 ValueInterface::Unit::Watts,
79 -6,
80 "power"),
49 std::make_tuple(hwmon::type::ctemp, ValueInterface::Unit::DegreesC, -3,
50 "temperature"),
51 std::make_tuple(hwmon::type::cfan, ValueInterface::Unit::RPMS, 0,
52 "fan_tach"),
53 std::make_tuple(hwmon::type::cvolt, ValueInterface::Unit::Volts, -3,
54 "voltage"),
55 std::make_tuple(hwmon::type::ccurr, ValueInterface::Unit::Amperes, -3,
56 "current"),
57 std::make_tuple(hwmon::type::cenergy, ValueInterface::Unit::Joules, -6,
58 "energy"),
59 std::make_tuple(hwmon::type::cpower, ValueInterface::Unit::Watts, -6,
60 "power"),
81};
82
83inline auto getHwmonType(decltype(typeAttrMap)::const_reference attrs)
84{
85 return std::get<0>(attrs);
86}
87
88inline auto getUnit(decltype(typeAttrMap)::const_reference attrs)

--- 7 unchanged lines hidden (view full) ---

96}
97
98inline auto getNamespace(decltype(typeAttrMap)::const_reference attrs)
99{
100 return std::get<3>(attrs);
101}
102
103using AttributeIterator = decltype(*typeAttrMap.begin());
61};
62
63inline auto getHwmonType(decltype(typeAttrMap)::const_reference attrs)
64{
65 return std::get<0>(attrs);
66}
67
68inline auto getUnit(decltype(typeAttrMap)::const_reference attrs)

--- 7 unchanged lines hidden (view full) ---

76}
77
78inline auto getNamespace(decltype(typeAttrMap)::const_reference attrs)
79{
80 return std::get<3>(attrs);
81}
82
83using AttributeIterator = decltype(*typeAttrMap.begin());
104using Attributes
105 = std::remove_cv<std::remove_reference<AttributeIterator>::type>::type;
84using Attributes =
85 std::remove_cv<std::remove_reference<AttributeIterator>::type>::type;
106
107/** @brief Get Attribute tuple for the type
108 *
109 * Given a type, it tries to find the corresponding tuple
110 *
111 * @param[in] type the sensor type
112 * @param[in,out] A pointer to the Attribute tuple
113 */
114bool getAttributes(const std::string& type, Attributes& attributes);
115
86
87/** @brief Get Attribute tuple for the type
88 *
89 * Given a type, it tries to find the corresponding tuple
90 *
91 * @param[in] type the sensor type
92 * @param[in,out] A pointer to the Attribute tuple
93 */
94bool getAttributes(const std::string& type, Attributes& attributes);
95
116} // namespace hwmon
96} // namespace hwmon
117
118// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
97
98// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4