blob: 6931b61b4237bf6d31a0a626337bd0db11558fbf [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";
Carol Wang9bbe6022019-08-01 17:31:30 +080017static constexpr auto caverage = "average";
18static constexpr auto caverage_interval = "average_interval";
Brad Bishop0fcb8b32017-01-04 21:55:04 -050019
20static const std::string input = cinput;
21static const std::string label = clabel;
Matthew Barthbf7b7b12017-03-07 15:46:59 -060022static const std::string target = ctarget;
Matt Spinler0a8de642017-05-11 10:59:39 -050023static const std::string enable = cenable;
Matthew Barth35819382018-04-18 14:53:01 -050024static const std::string fault = cfault;
Carol Wang9bbe6022019-08-01 17:31:30 +080025static const std::string average = caverage;
26static const std::string average_interval = caverage_interval;
Patrick Venture043d3232018-08-31 10:10:53 -070027} // namespace entry
Matt Spinler0a8de642017-05-11 10:59:39 -050028
Brad Bishop6bb97a92016-12-19 13:06:40 -050029namespace type
30{
Brad Bishop0fcb8b32017-01-04 21:55:04 -050031static constexpr auto cfan = "fan";
32static constexpr auto ctemp = "temp";
33static constexpr auto cvolt = "in";
Jaghathiswari Rankappagounder Natarajane49b6a02017-07-27 16:50:05 -070034static constexpr auto ccurr = "curr";
Brad Bishop5afe21a2017-01-06 20:44:05 -050035static constexpr auto cenergy = "energy";
36static constexpr auto cpower = "power";
Matt Spinler0a8de642017-05-11 10:59:39 -050037static constexpr auto cpwm = "pwm";
38
Brad Bishop0fcb8b32017-01-04 21:55:04 -050039static const std::string fan = cfan;
40static const std::string temp = ctemp;
41static const std::string volt = cvolt;
Brad Bishop5afe21a2017-01-06 20:44:05 -050042static const std::string curr = ccurr;
43static const std::string energy = cenergy;
44static const std::string power = cpower;
Matt Spinler0a8de642017-05-11 10:59:39 -050045static const std::string pwm = cpwm;
Patrick Venture043d3232018-08-31 10:10:53 -070046} // namespace type
Patrick Venture09791852018-04-17 17:40:00 -070047
Patrick Venture043d3232018-08-31 10:10:53 -070048static constexpr auto typeAttrMap = {
Patrick Venture09791852018-04-17 17:40:00 -070049 // 1 - hwmon class
50 // 2 - unit
51 // 3 - sysfs scaling factor
52 // 4 - namespace
Patrick Venture043d3232018-08-31 10:10:53 -070053 std::make_tuple(hwmon::type::ctemp, ValueInterface::Unit::DegreesC, -3,
54 "temperature"),
55 std::make_tuple(hwmon::type::cfan, ValueInterface::Unit::RPMS, 0,
56 "fan_tach"),
57 std::make_tuple(hwmon::type::cvolt, ValueInterface::Unit::Volts, -3,
58 "voltage"),
59 std::make_tuple(hwmon::type::ccurr, ValueInterface::Unit::Amperes, -3,
60 "current"),
61 std::make_tuple(hwmon::type::cenergy, ValueInterface::Unit::Joules, -6,
62 "energy"),
63 std::make_tuple(hwmon::type::cpower, ValueInterface::Unit::Watts, -6,
64 "power"),
Patrick Venture09791852018-04-17 17:40:00 -070065};
66
67inline auto getHwmonType(decltype(typeAttrMap)::const_reference attrs)
68{
69 return std::get<0>(attrs);
Patrick Williams3667cf32015-10-20 22:39:11 -050070}
71
Patrick Venture09791852018-04-17 17:40:00 -070072inline auto getUnit(decltype(typeAttrMap)::const_reference attrs)
73{
74 return std::get<1>(attrs);
75}
76
77inline auto getScale(decltype(typeAttrMap)::const_reference attrs)
78{
79 return std::get<2>(attrs);
80}
81
82inline auto getNamespace(decltype(typeAttrMap)::const_reference attrs)
83{
84 return std::get<3>(attrs);
85}
86
87using AttributeIterator = decltype(*typeAttrMap.begin());
Patrick Venture043d3232018-08-31 10:10:53 -070088using Attributes =
89 std::remove_cv<std::remove_reference<AttributeIterator>::type>::type;
Patrick Venture09791852018-04-17 17:40:00 -070090
91/** @brief Get Attribute tuple for the type
92 *
93 * Given a type, it tries to find the corresponding tuple
94 *
95 * @param[in] type the sensor type
96 * @param[in,out] A pointer to the Attribute tuple
97 */
98bool getAttributes(const std::string& type, Attributes& attributes);
99
Patrick Venture043d3232018-08-31 10:10:53 -0700100} // namespace hwmon