From f4fc1e1dc790d0e89ff2a093ba0a8ddd84e4227b Mon Sep 17 00:00:00 2001 From: Drath Date: Mon, 22 Sep 2025 21:10:35 +0200 Subject: [PATCH] clean up, rename cpu sensors struct --- include/cpu.hpp | 11 +++-------- main.cpp | 2 +- src/cpu.cpp | 48 ++---------------------------------------------- 3 files changed, 6 insertions(+), 55 deletions(-) diff --git a/include/cpu.hpp b/include/cpu.hpp index 581c378..5b49adc 100644 --- a/include/cpu.hpp +++ b/include/cpu.hpp @@ -9,14 +9,9 @@ #define N_CPU 16 -// struct cpu_hwmon_t { -// std::string path = ""; -// bool zenpower = false; -// }; - namespace cpu { -struct sensors { +struct cpuSensors { std::string hwmon = ""; bool zenpower = false; @@ -34,8 +29,8 @@ struct sensors { // sensors getCpu(cpu_hwmon_t hw); // cpu_hwmon_t detectCpuHwmon(std::string pci); -void detectHwmon(sensors* target, std::string pci); -void update(sensors* g); +void detectHwmon(cpuSensors* target, std::string pci); +void update(cpuSensors* g); } // namespace cpu diff --git a/main.cpp b/main.cpp index e6ec5a2..e82b0bf 100644 --- a/main.cpp +++ b/main.cpp @@ -35,7 +35,7 @@ struct Sensors { std::string loadavg; sys::Memory ram; sys::Memory home; - cpu::sensors cpu; + cpu::cpuSensors cpu; gpu::sensors gpu; float hass_state = 0.0f; std::mutex mtx; // making sure the struct isnt accessed by multiple threads at once diff --git a/src/cpu.cpp b/src/cpu.cpp index 0177b71..17f9e41 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -2,7 +2,7 @@ namespace cpu { -void detectHwmon(sensors* target, std::string pci) { +void detectHwmon(cpuSensors* target, std::string pci) { std::string path = "/sys/bus/pci/devices/" + pci + "/hwmon"; try { @@ -16,7 +16,7 @@ void detectHwmon(sensors* target, std::string pci) { std::println("[cpu::detectHwmon] Detected module \"{}\" in path \"{}\"", target->zenpower ? "zenpower" : "k10temp", target->hwmon); } -void update(sensors* c) { +void update(cpuSensors* c) { // commented out unused values so its faster if (c->hwmon == "") return; // break if no module if (c->zenpower) { @@ -42,48 +42,4 @@ void update(sensors* c) { c->avg_freq /= N_CPU; } -// cpu_hwmon_t detectCpuHwmon(std::string pci) { -// cpu_hwmon_t hw; -// std::string path = "/sys/bus/pci/devices/" + pci + "/hwmon"; -// try { -// for (const auto& entry : std::filesystem::directory_iterator(path)) -// hw.path = getFirstDir(path); -// } catch (...) { -// std::println("[CpuHwmon] NO CPU HWMON KERNEL MODULE DETECTED"); -// return hw; -// } -// hw.zenpower = readFile((hw.path + "/name"), 128) == "zenpower"; -// std::println("[CpuHwmon] Detected module \"{}\" in path \"{}\"", hw.zenpower ? "zenpower" : "k10temp", hw.path); -// return hw; -// } - -// cpu_t getCpu(cpu_hwmon_t hw) { -// cpu_t cpu; -// // commented out unused values so its faster -// if (hw.path == "") return cpu; // break if no module -// if (hw.zenpower) { -// // cpu.tdie = std::stoi(readFile(hw.path + "/temp1_input", 2)); -// cpu.tctl = std::stoi(readFile(hw.path + "/temp2_input", 2)); -// cpu.tccd1 = std::stoi(readFile(hw.path + "/temp3_input", 2)); -// cpu.pcore = (double)(std::stoi(readFile(hw.path + "/power1_input", 3)) / 100.0); -// cpu.psoc = (double)(std::stoi(readFile(hw.path + "/power2_input", 3)) / 100.0); -// cpu.ptotal = cpu.pcore + cpu.psoc; -// cpu.vcore = (double)(std::stoul(readFile(hw.path + "/in1_input", 4)) / 1000.0); -// // cpu.vsoc = (double)(std::stoul(readFile(hw.path + "/in2_input")) / 1000.0); -// } else { -// cpu.tctl = std::stoi(readFile(hw.path + "/temp1_input", 2)); -// cpu.tccd1 = std::stoi(readFile(hw.path + "/temp3_input", 2)); -// } - -// // lots of reads but still faster than reading /proc/cpuinfo -// char buf[5]; -// for (uint8_t i = 0; i < N_CPU; i++) { -// readFile2("/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq", buf, sizeof(buf)); -// cpu.avg_freq += strtol(buf, NULL, 10); -// } -// cpu.avg_freq /= N_CPU; - -// return cpu; -// } - } // namespace cpu \ No newline at end of file