Skip to content

Commit a60b964

Browse files
committed
asus_fanmode: Try to find CPU hwmon if it's not set.
1 parent 79441f6 commit a60b964

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

asus_fanmode.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
# Path to CPU temperature input
3-
cpu_temp = /sys/class/hwmon/hwmon3/temp1_input
3+
# Daemon will try to find it automatically
4+
# If it doesn't uncomment and set proper path
5+
# cpu_temp = /sys/class/hwmon/hwmon3/temp1_input
46
cpu_temp_divider = 1000
57

68
# Path to fan boost mode

asus_fanmode.cpp

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "file.hpp"
1515

1616
#define FAILCNT_LIMIT 5
17-
#define FILEBUF_SIZE 16
17+
#define FILEBUF_SIZE 32
1818

1919
static struct Config {
2020
std::string sCPUTemp;
@@ -37,6 +37,58 @@ static struct Config {
3737

3838
static bool s_bRunning = true;
3939

40+
std::string format(const char* pcFmt, ...) {
41+
char vcBuf[1024];
42+
43+
va_list vaArgs;
44+
va_start(vaArgs, pcFmt);
45+
46+
int nLen = vsprintf(vcBuf, pcFmt, vaArgs);
47+
48+
return std::string(vcBuf, nLen);
49+
}
50+
51+
bool readString(File& rfFile, std::string& rsStr) {
52+
if (!rfFile.isValid()) {
53+
return false;
54+
}
55+
56+
ssize_t nSize;
57+
char vcBuf[FILEBUF_SIZE + 1];
58+
59+
if ((nSize = rfFile.read(vcBuf, FILEBUF_SIZE)) <= 0) {
60+
return false;
61+
}
62+
63+
rsStr = std::string(vcBuf, nSize);
64+
return true;
65+
}
66+
67+
bool searchCPUHwmon() {
68+
int nIndex = 0;
69+
70+
while (true) {
71+
std::string sPath, sName;
72+
sPath = format("/sys/class/hwmon/hwmon%d/", nIndex);
73+
74+
File fName(sPath + "name");
75+
76+
if (!fName.isValid() || !readString(fName, sName)) {
77+
break;
78+
}
79+
80+
if (sName.compare(0, 7, "k10temp") == 0 ||
81+
sName.compare(0, 8, "coretemp") == 0) {
82+
s_cCfg.sCPUTemp = sPath + "temp1_input";
83+
return true;
84+
}
85+
86+
nIndex++;
87+
}
88+
89+
return false;
90+
}
91+
4092
bool readUint(File& rfFile, unsigned& rnValue) {
4193
if (!rfFile.isValid()) {
4294
return false;
@@ -129,6 +181,15 @@ int main() {
129181
return ENOENT;
130182
}
131183

184+
if (s_cCfg.sCPUTemp.empty()) {
185+
if (!searchCPUHwmon()) {
186+
fprintf(stderr, "Cannot find CPU hwmon!\n");
187+
return ENODEV;
188+
}
189+
190+
printf("Found CPU hwmon: %s\n", s_cCfg.sCPUTemp.c_str());
191+
}
192+
132193
unsigned nCurrentTemp;
133194
unsigned nCurrentMode;
134195
int nFailCounter = 0;

0 commit comments

Comments
 (0)