From 9053916152cf118fa37ad645e48b342c423ae705 Mon Sep 17 00:00:00 2001 From: ColumbusTech Date: Fri, 24 Nov 2017 22:51:49 +0300 Subject: [PATCH] Getting GPU Temperature --- Info.hpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/Info.hpp b/Info.hpp index 6c29c1f..801c9e3 100644 --- a/Info.hpp +++ b/Info.hpp @@ -15,6 +15,7 @@ namespace Columbus float GetCPUTemperature(); unsigned long GetRAMSize(); unsigned long GetRAMFree(); + float GetGPUTemperature(); int GetCPUCount() { @@ -76,7 +77,7 @@ namespace Columbus std::ifstream name2("/sys/class/hwmon/hwmon1/name"); if (name1.is_open() == false || name2.is_open() == false) return 0; std::string tmp; - + name1 >> tmp; if (tmp.find("coretemp") != std::string::npos) hwmon = 0; name2 >> tmp; @@ -133,6 +134,53 @@ namespace Columbus #endif } + float GetGPUTemperature() + { + #ifdef __linux__ + int hwmon = 0; + std::ifstream name1("/sys/class/hwmon/hwmon0/name"); + std::ifstream name2("/sys/class/hwmon/hwmon1/name"); + if (name1.is_open() == false || name2.is_open() == false) return 0; + std::string tmp; + + name1 >> tmp; + if (tmp.find("coretemp") == std::string::npos) hwmon = 0; + name2 >> tmp; + if (tmp.find("coretemp") == std::string::npos) hwmon = 1; + + name1.close(); + name2.close(); + + float t = 0.0; + std::string hw; + if (hwmon == 0) hw = "0"; + if (hwmon == 1) hw = "1"; + + std::ifstream tmp1(("/sys/class/hwmon/hwmon" + hw + "/temp1_input").c_str()); + std::ifstream tmp2(("/sys/class/hwmon/hwmon" + hw + "/temp2_input").c_str()); + std::ifstream tmp3(("/sys/class/hwmon/hwmon" + hw + "/temp3_input").c_str()); + if (tmp1.is_open() != false) + { + tmp1 >> t; + return (t / 1000); + } + + if (tmp2.is_open() != false) + { + tmp2 >> t; + return (t / 1000); + } + + if (tmp3.is_open() != false) + { + tmp1 >> t; + return (t / 1000); + } + return 0.0; + + #endif + } + }