126b815faSBrad Bishop #pragma once 26292aeedSMatthew Barth 36292aeedSMatthew Barth #include <fstream> 46292aeedSMatthew Barth #include <string> 56292aeedSMatthew Barth 66292aeedSMatthew Barth template <typename T> 76292aeedSMatthew Barth void read_sysfs(const std::string& path, T& val) 86292aeedSMatthew Barth { 96292aeedSMatthew Barth std::ifstream s(path); 106292aeedSMatthew Barth s >> val; 116292aeedSMatthew Barth } 126292aeedSMatthew Barth 136292aeedSMatthew Barth template <typename T> 146292aeedSMatthew Barth void write_sysfs(const std::string& path, const T& val) 156292aeedSMatthew Barth { 166292aeedSMatthew Barth std::ofstream s(path); 176292aeedSMatthew Barth s << val; 186292aeedSMatthew Barth } 196292aeedSMatthew Barth 20cc56cd9eSBrad Bishop inline const std::string make_sysfs_path(const std::string& path, 216292aeedSMatthew Barth const std::string& type, 226292aeedSMatthew Barth const std::string& id, 236292aeedSMatthew Barth const std::string& entry) 246292aeedSMatthew Barth { 256292aeedSMatthew Barth using namespace std::literals; 266292aeedSMatthew Barth 276292aeedSMatthew Barth return path + "/"s + type + id + "_"s + entry; 286292aeedSMatthew Barth } 296292aeedSMatthew Barth 30*613a5b37SBrad Bishop 31*613a5b37SBrad Bishop /** @brief Find hwmon instances 32*613a5b37SBrad Bishop * 33*613a5b37SBrad Bishop * Look for a matching hwmon instance given an 34*613a5b37SBrad Bishop * open firmware device path. 35*613a5b37SBrad Bishop * 36*613a5b37SBrad Bishop * @param[in] ofNode- The open firmware device path. 37*613a5b37SBrad Bishop * 38*613a5b37SBrad Bishop * @returns[in] - The hwmon instance path or an empty 39*613a5b37SBrad Bishop * string if no match is found. 40*613a5b37SBrad Bishop */ 41*613a5b37SBrad Bishop std::string findHwmon(const std::string& ofNode); 42*613a5b37SBrad Bishop 4303476f11SBrad Bishop // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 44