Skip to content

Commit a58fa7f

Browse files
committed
asus_fanmode: Find Fan Mode sysfs entry.
1 parent d477b68 commit a58fa7f

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

asus_fanmode.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#define FAILCNT_LIMIT 5
1717
#define FILEBUF_SIZE 32
18+
#define FORMATBUF_SIZE 1024
1819

1920
static struct Config {
2021
std::string sCPUTemp;
@@ -38,7 +39,7 @@ static struct Config {
3839
static bool s_bRunning = true;
3940

4041
std::string format(const char* pcFmt, ...) {
41-
char vcBuf[1024];
42+
char vcBuf[FORMATBUF_SIZE];
4243

4344
va_list vaArgs;
4445
va_start(vaArgs, pcFmt);
@@ -107,6 +108,25 @@ bool readUint(File& rfFile, unsigned& rnValue) {
107108
return true;
108109
}
109110

111+
bool searchFanMode() {
112+
const std::string vsPaths[2] = {
113+
"/sys/devices/platform/asus-nb-wmi/fan_boost_mode",
114+
"/sys/devices/platform/asus-nb-wmi/throttle_thermal_policy"
115+
};
116+
117+
for (int n = 0; n < 2; n++) {
118+
File fFanMode(vsPaths[n]);
119+
unsigned nValue;
120+
121+
if (fFanMode.isValid() && readUint(fFanMode, nValue)) {
122+
s_cCfg.sFanMode = vsPaths[n];
123+
return true;
124+
}
125+
}
126+
127+
return false;
128+
}
129+
110130
bool readTemp(unsigned& rnTemp) {
111131
File fTemp(s_cCfg.sCPUTemp);
112132
return readUint(fTemp, rnTemp);
@@ -183,13 +203,22 @@ int main() {
183203

184204
if (s_cCfg.sCPUTemp.empty()) {
185205
if (!searchCPUHwmon()) {
186-
fprintf(stderr, "Cannot find CPU hwmon!\n");
206+
fprintf(stderr, "Cannot find CPU hwmon sysfs entry!\n");
187207
return ENODEV;
188208
}
189209

190210
printf("Found CPU hwmon: %s\n", s_cCfg.sCPUTemp.c_str());
191211
}
192212

213+
if (s_cCfg.sFanMode.empty()) {
214+
if (!searchFanMode()) {
215+
fprintf(stderr, "Cannot find Fan Mode sysfs entry!\n");
216+
return ENODEV;
217+
}
218+
219+
printf("Found Fan Mode: %s\n", s_cCfg.sFanMode.c_str());
220+
}
221+
193222
unsigned nCurrentTemp;
194223
unsigned nCurrentMode;
195224
int nFailCounter = 0;

0 commit comments

Comments
 (0)