Brad Bishop | 26b815f | 2017-01-04 13:32:47 -0500 | [diff] [blame] | 1 | #pragma once |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 2 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 3 | #include "interface.hpp" |
| 4 | |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 5 | #include <string> |
Patrick Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 6 | #include <tuple> |
| 7 | |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 8 | namespace hwmon |
| 9 | { |
Brad Bishop | 6bb97a9 | 2016-12-19 13:06:40 -0500 | [diff] [blame] | 10 | namespace entry |
| 11 | { |
Brad Bishop | 0fcb8b3 | 2017-01-04 21:55:04 -0500 | [diff] [blame] | 12 | static constexpr auto cinput = "input"; |
| 13 | static constexpr auto clabel = "label"; |
Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame] | 14 | static constexpr auto ctarget = "target"; |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 15 | static constexpr auto cenable = "enable"; |
Matthew Barth | 3581938 | 2018-04-18 14:53:01 -0500 | [diff] [blame] | 16 | static constexpr auto cfault = "fault"; |
Carol Wang | 9bbe602 | 2019-08-01 17:31:30 +0800 | [diff] [blame] | 17 | static constexpr auto caverage = "average"; |
| 18 | static constexpr auto caverage_interval = "average_interval"; |
Brad Bishop | 0fcb8b3 | 2017-01-04 21:55:04 -0500 | [diff] [blame] | 19 | |
| 20 | static const std::string input = cinput; |
| 21 | static const std::string label = clabel; |
Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame] | 22 | static const std::string target = ctarget; |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 23 | static const std::string enable = cenable; |
Matthew Barth | 3581938 | 2018-04-18 14:53:01 -0500 | [diff] [blame] | 24 | static const std::string fault = cfault; |
Carol Wang | 9bbe602 | 2019-08-01 17:31:30 +0800 | [diff] [blame] | 25 | static const std::string average = caverage; |
| 26 | static const std::string average_interval = caverage_interval; |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 27 | } // namespace entry |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 28 | |
Brad Bishop | 6bb97a9 | 2016-12-19 13:06:40 -0500 | [diff] [blame] | 29 | namespace type |
| 30 | { |
Brad Bishop | 0fcb8b3 | 2017-01-04 21:55:04 -0500 | [diff] [blame] | 31 | static constexpr auto cfan = "fan"; |
| 32 | static constexpr auto ctemp = "temp"; |
| 33 | static constexpr auto cvolt = "in"; |
Jaghathiswari Rankappagounder Natarajan | e49b6a0 | 2017-07-27 16:50:05 -0700 | [diff] [blame] | 34 | static constexpr auto ccurr = "curr"; |
Brad Bishop | 5afe21a | 2017-01-06 20:44:05 -0500 | [diff] [blame] | 35 | static constexpr auto cenergy = "energy"; |
| 36 | static constexpr auto cpower = "power"; |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 37 | static constexpr auto cpwm = "pwm"; |
| 38 | |
Brad Bishop | 0fcb8b3 | 2017-01-04 21:55:04 -0500 | [diff] [blame] | 39 | static const std::string fan = cfan; |
| 40 | static const std::string temp = ctemp; |
| 41 | static const std::string volt = cvolt; |
Brad Bishop | 5afe21a | 2017-01-06 20:44:05 -0500 | [diff] [blame] | 42 | static const std::string curr = ccurr; |
| 43 | static const std::string energy = cenergy; |
| 44 | static const std::string power = cpower; |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 45 | static const std::string pwm = cpwm; |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 46 | } // namespace type |
Patrick Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 47 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 48 | static constexpr auto typeAttrMap = { |
Patrick Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 49 | // 1 - hwmon class |
| 50 | // 2 - unit |
| 51 | // 3 - sysfs scaling factor |
| 52 | // 4 - namespace |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 53 | 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 Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | inline auto getHwmonType(decltype(typeAttrMap)::const_reference attrs) |
| 68 | { |
| 69 | return std::get<0>(attrs); |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 70 | } |
| 71 | |
Patrick Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 72 | inline auto getUnit(decltype(typeAttrMap)::const_reference attrs) |
| 73 | { |
| 74 | return std::get<1>(attrs); |
| 75 | } |
| 76 | |
| 77 | inline auto getScale(decltype(typeAttrMap)::const_reference attrs) |
| 78 | { |
| 79 | return std::get<2>(attrs); |
| 80 | } |
| 81 | |
| 82 | inline auto getNamespace(decltype(typeAttrMap)::const_reference attrs) |
| 83 | { |
| 84 | return std::get<3>(attrs); |
| 85 | } |
| 86 | |
| 87 | using AttributeIterator = decltype(*typeAttrMap.begin()); |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 88 | using Attributes = |
| 89 | std::remove_cv<std::remove_reference<AttributeIterator>::type>::type; |
Patrick Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 90 | |
| 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 | */ |
| 98 | bool getAttributes(const std::string& type, Attributes& attributes); |
| 99 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 100 | } // namespace hwmon |
Patrick Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 101 | |
Brad Bishop | 03476f1 | 2016-12-19 13:09:12 -0500 | [diff] [blame] | 102 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |