1 #pragma once 2 3 #include "interface.hpp" 4 5 #include <string> 6 #include <tuple> 7 8 namespace hwmon 9 { 10 namespace entry 11 { 12 static constexpr auto cinput = "input"; 13 static constexpr auto clabel = "label"; 14 static constexpr auto ctarget = "target"; 15 static constexpr auto cenable = "enable"; 16 static constexpr auto cfault = "fault"; 17 18 static const std::string input = cinput; 19 static const std::string label = clabel; 20 static const std::string target = ctarget; 21 static const std::string enable = cenable; 22 static const std::string fault = cfault; 23 } // namespace entry 24 25 namespace type 26 { 27 static constexpr auto cfan = "fan"; 28 static constexpr auto ctemp = "temp"; 29 static constexpr auto cvolt = "in"; 30 static constexpr auto ccurr = "curr"; 31 static constexpr auto cenergy = "energy"; 32 static constexpr auto cpower = "power"; 33 static constexpr auto cpwm = "pwm"; 34 35 static const std::string fan = cfan; 36 static const std::string temp = ctemp; 37 static const std::string volt = cvolt; 38 static const std::string curr = ccurr; 39 static const std::string energy = cenergy; 40 static const std::string power = cpower; 41 static const std::string pwm = cpwm; 42 } // namespace type 43 44 static constexpr auto typeAttrMap = { 45 // 1 - hwmon class 46 // 2 - unit 47 // 3 - sysfs scaling factor 48 // 4 - namespace 49 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"), 61 }; 62 63 inline auto getHwmonType(decltype(typeAttrMap)::const_reference attrs) 64 { 65 return std::get<0>(attrs); 66 } 67 68 inline auto getUnit(decltype(typeAttrMap)::const_reference attrs) 69 { 70 return std::get<1>(attrs); 71 } 72 73 inline auto getScale(decltype(typeAttrMap)::const_reference attrs) 74 { 75 return std::get<2>(attrs); 76 } 77 78 inline auto getNamespace(decltype(typeAttrMap)::const_reference attrs) 79 { 80 return std::get<3>(attrs); 81 } 82 83 using AttributeIterator = decltype(*typeAttrMap.begin()); 84 using Attributes = 85 std::remove_cv<std::remove_reference<AttributeIterator>::type>::type; 86 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 */ 94 bool getAttributes(const std::string& type, Attributes& attributes); 95 96 } // namespace hwmon 97 98 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 99