blob: 5a7a90f6b830c25a139723418f6d21e09a70c76a [file] [log] [blame]
Brad Bishop26b815f2017-01-04 13:32:47 -05001#pragma once
Patrick Williams3667cf32015-10-20 22:39:11 -05002
3#include <string>
Patrick Venture09791852018-04-17 17:40:00 -07004#include <tuple>
5
6#include "interface.hpp"
Patrick Williams3667cf32015-10-20 22:39:11 -05007
8namespace hwmon
9{
Brad Bishop6bb97a92016-12-19 13:06:40 -050010namespace entry
11{
Brad Bishop0fcb8b32017-01-04 21:55:04 -050012static constexpr auto cinput = "input";
13static constexpr auto clabel = "label";
Matthew Barthbf7b7b12017-03-07 15:46:59 -060014static constexpr auto ctarget = "target";
Matt Spinler0a8de642017-05-11 10:59:39 -050015static constexpr auto cenable = "enable";
Matthew Barth35819382018-04-18 14:53:01 -050016static constexpr auto cfault = "fault";
Brad Bishop0fcb8b32017-01-04 21:55:04 -050017
18static const std::string input = cinput;
19static const std::string label = clabel;
Matthew Barthbf7b7b12017-03-07 15:46:59 -060020static const std::string target = ctarget;
Matt Spinler0a8de642017-05-11 10:59:39 -050021static const std::string enable = cenable;
Matthew Barth35819382018-04-18 14:53:01 -050022static const std::string fault = cfault;
Matt Spinler0a8de642017-05-11 10:59:39 -050023}
24
Brad Bishop6bb97a92016-12-19 13:06:40 -050025namespace type
26{
Brad Bishop0fcb8b32017-01-04 21:55:04 -050027static constexpr auto cfan = "fan";
28static constexpr auto ctemp = "temp";
29static constexpr auto cvolt = "in";
Jaghathiswari Rankappagounder Natarajane49b6a02017-07-27 16:50:05 -070030static constexpr auto ccurr = "curr";
Brad Bishop5afe21a2017-01-06 20:44:05 -050031static constexpr auto cenergy = "energy";
32static constexpr auto cpower = "power";
Matt Spinler0a8de642017-05-11 10:59:39 -050033static constexpr auto cpwm = "pwm";
34
Brad Bishop0fcb8b32017-01-04 21:55:04 -050035
36static const std::string fan = cfan;
37static const std::string temp = ctemp;
38static const std::string volt = cvolt;
Brad Bishop5afe21a2017-01-06 20:44:05 -050039static const std::string curr = ccurr;
40static const std::string energy = cenergy;
41static const std::string power = cpower;
Matt Spinler0a8de642017-05-11 10:59:39 -050042static const std::string pwm = cpwm;
Brad Bishop6bb97a92016-12-19 13:06:40 -050043}
Patrick Venture09791852018-04-17 17:40:00 -070044
45static constexpr auto typeAttrMap =
46{
47 // 1 - hwmon class
48 // 2 - unit
49 // 3 - sysfs scaling factor
50 // 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"),
81};
82
83inline auto getHwmonType(decltype(typeAttrMap)::const_reference attrs)
84{
85 return std::get<0>(attrs);
Patrick Williams3667cf32015-10-20 22:39:11 -050086}
87
Patrick Venture09791852018-04-17 17:40:00 -070088inline auto getUnit(decltype(typeAttrMap)::const_reference attrs)
89{
90 return std::get<1>(attrs);
91}
92
93inline auto getScale(decltype(typeAttrMap)::const_reference attrs)
94{
95 return std::get<2>(attrs);
96}
97
98inline auto getNamespace(decltype(typeAttrMap)::const_reference attrs)
99{
100 return std::get<3>(attrs);
101}
102
103using AttributeIterator = decltype(*typeAttrMap.begin());
104using Attributes
105 = 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
116} // namespace hwmon
117
Brad Bishop03476f12016-12-19 13:09:12 -0500118// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4