From f20b6deda2053e3fbb8488554de68648452ec93a Mon Sep 17 00:00:00 2001 From: Jussi Kuokkanen Date: Tue, 24 Oct 2023 22:38:16 +0300 Subject: [PATCH] fix fan speed calculation --- src/plugins/AMD.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/plugins/AMD.cpp b/src/plugins/AMD.cpp index 1ab48ae..b740cab 100644 --- a/src/plugins/AMD.cpp +++ b/src/plugins/AMD.cpp @@ -217,21 +217,14 @@ std::vector> getFanSpeedWrite(AMDGPUData data) { } std::vector> getFanSpeedRead(AMDGPUData data) { - // Get delta of min and max fan RPMs char path[96]; - snprintf(path, 96, "%s/fan1_min", data.hwmonPath.c_str()); + + snprintf(path, 96, "%s/fan1_max", data.hwmonPath.c_str()); auto contents = fileContents(path); if (!contents.has_value()) return {}; - int minRPM = std::stoi(*contents); - snprintf(path, 96, "%s/fan1_max", data.hwmonPath.c_str()); - contents = fileContents(path); - if (!contents.has_value()) - return {}; - int maxRPM = std::stoi(*contents); - auto delta = maxRPM - minRPM; snprintf(path, 96, "%s/fan1_input", data.hwmonPath.c_str()); @@ -240,9 +233,9 @@ std::vector> getFanSpeedRead(AMDGPUData data) { if (!string.has_value()) return ReadError::UnknownError; - int curDelta = maxRPM - std::stoi(*string); - double ratio = static_cast(curDelta) / static_cast(delta); - return std::floor(ratio * 100); + int value = std::stoi(*string); + double ratio = static_cast(value) / static_cast(maxRPM); + return std::round(ratio * 100); }; DynamicReadable dr{func, _("%")};