Last active
August 29, 2015 14:03
-
-
Save ergoithz/62f8f548fa2aabbf0681 to your computer and use it in GitHub Desktop.
Simple ec script for controlling GPU and CPU fans for acer 3820T/3820TG/3820TZ/3820TGZ laptops
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 python | |
# -*- coding: UTF-8 -*- | |
CONTROL_AUTO = 0x04 | |
CONTROL_MANUAL = 0x14 | |
FAN_MAX = 0x00 | |
FAN_MIN = 0xFF | |
READY_TO_WRITE = 0x02 | |
READY_TO_READ = 0x01 | |
SET_WRITE = 0x81 | |
SET_READ = 0x80 | |
class GPU: | |
control = 0x93 | |
set = 0x94 | |
get = 0x95 | |
class CPU: | |
control = 0x96 | |
set = 0x97 | |
get = 0x98 | |
import sys | |
import os | |
import time | |
import struct | |
if 'max' in sys.argv: | |
m = CONTROL_MANUAL | |
v = FAN_MAX | |
elif 'high' in sys.argv: | |
m = CONTROL_MANUAL | |
v = int(FAN_MIN*0.3) | |
elif 'medium' in sys.argv: | |
m = CONTROL_MANUAL | |
v = int(FAN_MIN*0.45) | |
elif 'low' in sys.argv: | |
m = CONTROL_MANUAL | |
v = int(FAN_MIN*0.6) | |
else: | |
m = CONTROL_AUTO | |
v = None | |
char_struct = struct.Struct('B') | |
def char(v): | |
return char_struct.pack(v) | |
def unchar(v): | |
return char_struct.unpack(v)[0] | |
def wait_write(f): | |
os.lseek(f, 0x66, os.SEEK_SET) | |
while unchar(os.read(f, 1)) & READY_TO_WRITE: | |
time.sleep(0.01) | |
os.lseek(f, 0x66, os.SEEK_SET) | |
def write_ec(f, pos, val): | |
wait_write(f) | |
os.lseek(f, 0x66, os.SEEK_SET) | |
os.write(f, char(SET_WRITE)) | |
wait_write(f) | |
os.lseek(f, 0x62, os.SEEK_SET) | |
os.write(f, char(pos)) | |
wait_write(f) | |
os.lseek(f, 0x62, os.SEEK_SET) | |
os.write(f, char(val)) | |
f = os.open('/dev/port', os.O_RDWR) | |
for device in (GPU, CPU): | |
write_ec(f, device.control, m) | |
if not v is None: | |
write_ec(f, device.set, v) | |
os.close(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment