sane makefile, sane structure, lots of updates

This commit is contained in:
Drath
2025-05-01 18:24:01 +02:00
parent fa0cc42f4a
commit 6b9314761d
11 changed files with 568 additions and 99 deletions

44
src/utils.cpp Normal file
View File

@@ -0,0 +1,44 @@
#include <cstdint>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <utils.hpp>
/* SENSOR GETTERS + UTILS*/
std::string readFile(std::string path, uint8_t trim) {
std::string ret;
std::stringstream ss;
std::ifstream fs(path);
if (!fs.good()) {
std::cerr << "Error reading " << path << std::endl;
exit(1);
}
ss << fs.rdbuf();
fs.close();
ret = ss.str();
if (ret.size() < trim) return ret;
return ret.substr(0, ret.size() - trim - 1);
}
int get_val(const std::string &target, const std::string &content) {
int result = -1;
std::size_t start = content.find(target);
if (start != std::string::npos) {
int begin = start + target.length();
std::size_t end = content.find("kB", start);
std::string substr = content.substr(begin, end - begin);
result = std::stoi(substr);
}
return result;
}
std::string findHwmonPath(std::string module) {
uint8_t id = 0;
for (; id < 10; id++)
if (readFile("/sys/class/hwmon/hwmon" + std::to_string(id) + "/name") == module) {
std::cout << ("[Hwmon] Detected " + module + " path is " + "/sys/class/hwmon/hwmon" + std::to_string(id)) << std::endl;
return "/sys/class/hwmon/hwmon" + std::to_string(id);
}
return "";
}