forked from Petingoso/legion-fan-utils-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile_man.py
executable file
·332 lines (248 loc) · 8.9 KB
/
profile_man.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
import os
from os.path import exists
import psutil
import fnmatch
import argparse
class fan_profile:
fan1_rpm = []
fan2_rpm = []
cpu_min_temp= []
cpu_max_temp= []
gpu_min_temp= []
gpu_max_temp= []
ic_min_temp= []
ic_max_temp= []
acceleration = []
deceleration = []
hwmon_dir = ""
profile_mode= ""
def find_hwmondir():
global hwmon_dir
if os.path.exists("/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/hwmon/") == True:
for file in os.listdir("/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/hwmon/"):
if "hwmon" in file:
hwmon_dir = "/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/hwmon/" + file + "/"
print("found hwmon dir at", hwmon_dir)
else:
print("hwmon directory not found, is the module loaded?")
else:
print("Can't find the hwmon path, is everything correct")
def parse_def_config(fan_profile):
#fan1
for i in range(1,11):
file="pwm1_auto_point{}_pwm".format(i)
fan_profile.fan1_rpm.append(valueof(file))
#fan2
for i in range(1,11):
file="pwm2_auto_point{}_pwm".format(i)
fan_profile.fan2_rpm.append(valueof(file))
#cpu_min_temp
for i in range(1,11):
file="pwm1_auto_point{}_temp_hyst".format(i)
fan_profile.cpu_min_temp.append(valueof(file))
#cpu_max_temp
for i in range(1,11):
file="pwm1_auto_point{}_temp".format(i)
fan_profile.cpu_max_temp.append(valueof(file))
#gpu_min_temp
for i in range(1,11):
file="pwm2_auto_point{}_temp_hyst".format(i)
fan_profile.gpu_min_temp.append(valueof(file))
#gpu_max_temp
for i in range(1,11):
file="pwm2_auto_point{}_temp".format(i)
fan_profile.gpu_max_temp.append(valueof(file))
#ic_min_temp
for i in range(1,11):
file="pwm3_auto_point{}_temp_hyst".format(i)
fan_profile.ic_min_temp.append(valueof(file))
#ic_max_temp
for i in range(1,11):
file="pwm3_auto_point{}_temp".format(i)
fan_profile.ic_max_temp.append(valueof(file))
#acceleration
for i in range(1,11):
file="pwm1_auto_point{}_accel".format(i)
fan_profile.acceleration.append(valueof(file))
#deceleration
for i in range(1,11):
file="pwm1_auto_point{}_decel".format(i)
fan_profile.deceleration.append(valueof(file))
print("default profile parsed")
def store_profile(profile,name):
path = "/home/" + os.getlogin() + "/.legion-profile-{}".format(name)
if os.path.exists(path) == False:
print("no file")
print("creating file...")
deffancurve = open(path, "x")
tmplist=[]
for list in dir(profile):
if not list.startswith('__'):
tmplist = getattr(profile,list)
deffancurve.write("#{}\n".format(list))
for element in tmplist:
deffancurve.write(element)
else:
print("File already exists")
def parse_custom_profile(path,profile):
file=open(path,'r')
for line in file:
if line.startswith("#"):
if "Fan" in line or "fan" in line:
print("fan in line")
if "1" in line:
#advance 1 line
for i in range(10):
line = file.readline()
profile.fan1_rpm.append(line)
continue
elif "2" in line:
for i in range(10):
line = file.readline()
profile.fan2_rpm.append(line)
continue
elif "Acc" in line or "acc" in line:
print(line)
for i in range(10):
line = file.readline()
profile.acceleration.append(line)
continue
elif "dec" in line or "Dec" in line:
for i in range(10):
line = file.readline()
profile.deceleration.append(line)
continue
elif "gpu" in line or "GPU" in line or "Gpu" in line:
if "low" in line or "Low" in line or "min" in line or "Min" in line:
for i in range(10):
line = file.readline()
profile.gpu_min_temp.append(line)
continue
elif "Up" in line or "up" in line or "Max" in line or "max" in line:
for i in range(10):
line = file.readline()
profile.gpu_max_temp.append(line)
continue
elif "cpu" in line or "CPU" in line or "Cpu" in line:
if "low" in line or "Low" in line or "min" in line or "Min" in line:
for i in range(10):
line = file.readline()
profile.cpu_min_temp.append(line)
continue
elif "Up" in line or "up" in line or "Max" in line or "max" in line:
for i in range(10):
line = file.readline()
profile.cpu_max_temp.append(line)
continue
elif "ic" in line or "Ic" in line or "IC" in line:
if "low" in line or "Low" in line or "min" in line or "Min" in line:
for i in range(10):
line = file.readline()
profile.ic_min_temp.append(line)
continue
elif "Up" in line or "up" in line or "Max" in line or "max" in line:
for i in range(10):
line = file.readline()
profile.ic_max_temp.append(line)
continue
print("profile parsed")
def is_default_stored():
global profile_mode
f = open("/sys/firmware/acpi/platform_profile","r")
profile_mode = f.readline()[:-1]
path="/home/" + os.getlogin() + "/.legion-profile-default-" + profile_mode
if os.path.exists(path) == False:
print("saving profile {}".format(profile_mode))
return 0
else:
print("profile {} already stored".format(profile_mode))
return 1
def valueof(file):
f = open(hwmon_dir + file, "r")
value = f.read(2048)
return value
def openabs(file):
f = open(hwmon_dir + file, "w")
return f
def apply_profile_default(fan_profile):
apply_profile(default)
def apply_profile(fan_profile):
#traverse fan.rpm
#write first value to pwm1_auto_point{i}_pwm
#advance
i=1
for element in fan_profile.fan1_rpm:
file = openabs("pwm1_auto_point{}_pwm".format(i))
file.write(element)
i=i+1
file.close()
i=1
for element in fan_profile.fan2_rpm:
file = openabs("pwm2_auto_point{}_pwm".format(i))
file.write(element)
i=i+1
file.close()
i=1
for element in fan_profile.cpu_min_temp:
file = openabs("pwm1_auto_point{}_temp_hyst".format(i))
file.write(element)
i=i+1
file.close()
i=1
for element in fan_profile.cpu_max_temp:
file = openabs("pwm1_auto_point{}_temp".format(i))
file.write(element)
i=i+1
file.close()
i=1
for element in fan_profile.gpu_min_temp:
file = openabs("pwm2_auto_point{}_temp_hyst".format(i))
file.write(element)
i=i+1
file.close()
i=1
for element in fan_profile.gpu_max_temp:
file = openabs("pwm2_auto_point{}_temp".format(i))
file.write(element)
i=i+1
file.close()
i=1
for element in fan_profile.ic_min_temp:
file = openabs("pwm3_auto_point{}_temp_hyst".format(i))
file.write(element)
i=i+1
file.close()
i=1
for element in fan_profile.ic_max_temp:
file = openabs("pwm3_auto_point{}_temp".format(i))
file.write(element)
i=i+1
file.close()
i=1
for element in fan_profile.acceleration:
file = openabs("pwm1_auto_point{}_accel".format(i))
file.write(element)
i=i+1
file.close()
i=1
for element in fan_profile.deceleration:
file = openabs("pwm1_auto_point{}_decel".format(i))
file.write(element)
i=i+1
file.close()
print("fan profile applied")
find_hwmondir()
default = fan_profile()
if is_default_stored() == 0:
parse_def_config(default)
name = "default-" + profile_mode
store_profile(default,name)
####
custom=fan_profile()
argParser = argparse.ArgumentParser()
argParser.add_argument("-i", "--input", help="profile to load")
args = argParser.parse_args()
input_abs=os.path.abspath(args.input)
print("parsing " + input_abs)
parse_custom_profile(input_abs, custom)
apply_profile(custom)