1*6292aeedSMatthew Barth #ifndef __SYSFS_H 2*6292aeedSMatthew Barth #define __SYSFS_H 3*6292aeedSMatthew Barth 4*6292aeedSMatthew Barth #include <fstream> 5*6292aeedSMatthew Barth #include <string> 6*6292aeedSMatthew Barth 7*6292aeedSMatthew Barth template <typename T> 8*6292aeedSMatthew Barth void read_sysfs(const std::string& path, T& val) 9*6292aeedSMatthew Barth { 10*6292aeedSMatthew Barth std::ifstream s(path); 11*6292aeedSMatthew Barth s >> val; 12*6292aeedSMatthew Barth } 13*6292aeedSMatthew Barth 14*6292aeedSMatthew Barth template <typename T> 15*6292aeedSMatthew Barth void write_sysfs(const std::string& path, const T& val) 16*6292aeedSMatthew Barth { 17*6292aeedSMatthew Barth std::ofstream s(path); 18*6292aeedSMatthew Barth s << val; 19*6292aeedSMatthew Barth } 20*6292aeedSMatthew Barth 21*6292aeedSMatthew Barth const std::string make_sysfs_path(const std::string& path, 22*6292aeedSMatthew Barth const std::string& type, 23*6292aeedSMatthew Barth const std::string& id, 24*6292aeedSMatthew Barth const std::string& entry) 25*6292aeedSMatthew Barth { 26*6292aeedSMatthew Barth using namespace std::literals; 27*6292aeedSMatthew Barth 28*6292aeedSMatthew Barth return path + "/"s + type + id + "_"s + entry; 29*6292aeedSMatthew Barth } 30*6292aeedSMatthew Barth 31*6292aeedSMatthew Barth #endif 32