Created
December 28, 2018 20:16
-
-
Save michaelneu/3cf5909c6cc6cb96de9e1611234380cd to your computer and use it in GitHub Desktop.
Control the fan in ASUS laptops via ACPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import sys | |
import os | |
def call_acpi(command): | |
with open('/proc/acpi/call', 'w') as acpi_call: | |
acpi_call.write(command) | |
# Response | |
with open('/proc/acpi/call', 'r') as acpi_call: | |
return acpi_call.read() | |
def set_fan(speed, fan=1): | |
if speed < 0: | |
speed = 0 | |
elif speed > 100: | |
speed = 100 | |
raw_speed = round(speed * 2.55) | |
call_acpi('\_SB.PCI0.SBRG.EC0.SFNV %d %s' % (fan, raw_speed)) | |
print 'Set fan speed to %d %%' % speed | |
def get_cpu_temp(): | |
return int(call_acpi('\_SB.PCI0.SBRG.EC0.ECPU')[:4], 16) | |
def cleanup(signal=None, frame=None): | |
call_acpi('\_SB.PCI0.SBRG.EC0.SFNV 0 0') | |
call_acpi('\_SB.ATKD.QMOD 0x02') | |
print 'Reset fan control to automatic. Exiting...' | |
if __name__=='__main__': | |
uid = os.geteuid() | |
if uid == 0: | |
if len(sys.argv) == 2: | |
if sys.argv[1] == "auto": | |
cleanup() | |
else: | |
set_fan(float(sys.argv[1])) | |
else: | |
print "Usage: fan speed|auto" | |
else: | |
os.system("sudo " + " ".join(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment