blob: 5319b694c4725145700fd054fdc6b61b7535da4c [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";
Brad Bishop0fcb8b32017-01-04 21:55:04 -050016
17static const std::string input = cinput;
18static const std::string label = clabel;
Matthew Barthbf7b7b12017-03-07 15:46:59 -060019static const std::string target = ctarget;
Matt Spinler0a8de642017-05-11 10:59:39 -050020static const std::string enable = cenable;
21}
22
Brad Bishop6bb97a92016-12-19 13:06:40 -050023namespace type
24{
Brad Bishop0fcb8b32017-01-04 21:55:04 -050025static constexpr auto cfan = "fan";
26static constexpr auto ctemp = "temp";
27static constexpr auto cvolt = "in";
Jaghathiswari Rankappagounder Natarajane49b6a02017-07-27 16:50:05 -070028static constexpr auto ccurr = "curr";
Brad Bishop5afe21a2017-01-06 20:44:05 -050029static constexpr auto cenergy = "energy";
30static constexpr auto cpower = "power";
Matt Spinler0a8de642017-05-11 10:59:39 -050031static constexpr auto cpwm = "pwm";
32
Brad Bishop0fcb8b32017-01-04 21:55:04 -050033
34static const std::string fan = cfan;
35static const std::string temp = ctemp;
36static const std::string volt = cvolt;
Brad Bishop5afe21a2017-01-06 20:44:05 -050037static const std::string curr = ccurr;
38static const std::string energy = cenergy;
39static const std::string power = cpower;
Matt Spinler0a8de642017-05-11 10:59:39 -050040static const std::string pwm = cpwm;
Brad Bishop6bb97a92016-12-19 13:06:40 -050041}
Patrick Venture09791852018-04-17 17:40:00 -070042
43static constexpr auto typeAttrMap =
44{
45 // 1 - hwmon class
46 // 2 - unit
47 // 3 - sysfs scaling factor
48 // 4 - namespace
49 std::make_tuple(
50 hwmon::type::ctemp,
51 ValueInterface::Unit::DegreesC,
52 -3,
53 "temperature"),
54 std::make_tuple(
55 hwmon::type::cfan,
56 ValueInterface::Unit::RPMS,
57 0,
58 "fan_tach"),
59 std::make_tuple(
60 hwmon::type::cvolt,
61 ValueInterface::Unit::Volts,
62 -3,
63 "voltage"),
64 std::make_tuple(
65 hwmon::type::ccurr,
66 ValueInterface::Unit::Amperes,
67 -3,
68 "current"),
69 std::make_tuple(
70 hwmon::type::cenergy,
71 ValueInterface::Unit::Joules,
72 -6,
73 "energy"),
74 std::make_tuple(
75 hwmon::type::cpower,
76 ValueInterface::Unit::Watts,
77 -6,
78 "power"),
79};
80
81inline auto getHwmonType(decltype(typeAttrMap)::const_reference attrs)
82{
83 return std::get<0>(attrs);
Patrick Williams3667cf32015-10-20 22:39:11 -050084}
85
Patrick Venture09791852018-04-17 17:40:00 -070086inline auto getUnit(decltype(typeAttrMap)::const_reference attrs)
87{
88 return std::get<1>(attrs);
89}
90
91inline auto getScale(decltype(typeAttrMap)::const_reference attrs)
92{
93 return std::get<2>(attrs);
94}
95
96inline auto getNamespace(decltype(typeAttrMap)::const_reference attrs)
97{
98 return std::get<3>(attrs);
99}
100
101using AttributeIterator = decltype(*typeAttrMap.begin());
102using Attributes
103 = std::remove_cv<std::remove_reference<AttributeIterator>::type>::type;
104
105/** @brief Get Attribute tuple for the type
106 *
107 * Given a type, it tries to find the corresponding tuple
108 *
109 * @param[in] type the sensor type
110 * @param[in,out] A pointer to the Attribute tuple
111 */
112bool getAttributes(const std::string& type, Attributes& attributes);
113
114} // namespace hwmon
115
Brad Bishop03476f12016-12-19 13:09:12 -0500116// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4