blob: 4f4545ce0ef1fa4a0c987133247e4319df78354c [file] [log] [blame]
Brad Bishop26b815f2017-01-04 13:32:47 -05001#pragma once
Patrick Williams3667cf32015-10-20 22:39:11 -05002
Patrick Venture043d3232018-08-31 10:10:53 -07003#include "interface.hpp"
4
Patrick Williams3667cf32015-10-20 22:39:11 -05005#include <string>
Patrick Venture09791852018-04-17 17:40:00 -07006#include <tuple>
7
Patrick Williams3667cf32015-10-20 22:39:11 -05008namespace 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;
Patrick Venture043d3232018-08-31 10:10:53 -070023} // namespace entry
Matt Spinler0a8de642017-05-11 10:59:39 -050024
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 -050035static const std::string fan = cfan;
36static const std::string temp = ctemp;
37static const std::string volt = cvolt;
Brad Bishop5afe21a2017-01-06 20:44:05 -050038static const std::string curr = ccurr;
39static const std::string energy = cenergy;
40static const std::string power = cpower;
Matt Spinler0a8de642017-05-11 10:59:39 -050041static const std::string pwm = cpwm;
Patrick Venture043d3232018-08-31 10:10:53 -070042} // namespace type
Patrick Venture09791852018-04-17 17:40:00 -070043
Patrick Venture043d3232018-08-31 10:10:53 -070044static constexpr auto typeAttrMap = {
Patrick Venture09791852018-04-17 17:40:00 -070045 // 1 - hwmon class
46 // 2 - unit
47 // 3 - sysfs scaling factor
48 // 4 - namespace
Patrick Venture043d3232018-08-31 10:10:53 -070049 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"),
Patrick Venture09791852018-04-17 17:40:00 -070061};
62
63inline auto getHwmonType(decltype(typeAttrMap)::const_reference attrs)
64{
65 return std::get<0>(attrs);
Patrick Williams3667cf32015-10-20 22:39:11 -050066}
67
Patrick Venture09791852018-04-17 17:40:00 -070068inline auto getUnit(decltype(typeAttrMap)::const_reference attrs)
69{
70 return std::get<1>(attrs);
71}
72
73inline auto getScale(decltype(typeAttrMap)::const_reference attrs)
74{
75 return std::get<2>(attrs);
76}
77
78inline auto getNamespace(decltype(typeAttrMap)::const_reference attrs)
79{
80 return std::get<3>(attrs);
81}
82
83using AttributeIterator = decltype(*typeAttrMap.begin());
Patrick Venture043d3232018-08-31 10:10:53 -070084using Attributes =
85 std::remove_cv<std::remove_reference<AttributeIterator>::type>::type;
Patrick Venture09791852018-04-17 17:40:00 -070086
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
Patrick Venture043d3232018-08-31 10:10:53 -070096} // namespace hwmon
Patrick Venture09791852018-04-17 17:40:00 -070097
Brad Bishop03476f12016-12-19 13:09:12 -050098// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4