1
0
mirror of https://github.com/AndrewX192/lenovo-sa120-fanspeed-utility synced 2025-12-06 01:23:19 +00:00

Minor cleanup

This commit is contained in:
Andrew Sorensen
2016-04-10 13:45:36 -07:00
parent 650ec84b3e
commit c3fd8166ef

View File

@@ -4,20 +4,27 @@ try:
from StringIO import StringIO
except ImportError:
from io import StringIO
from subprocess import check_output
from subprocess import check_output, Popen, PIPE, STDOUT
def print_speeds():
def print_speeds(device):
for i in range(0, 6):
print("Fan {} speed: {}".format(i, check_output(['sg_ses', '--index=coo,{}'.format(i), '--get=1:2:11', '/dev/sg6']).decode('utf-8').split('\n')[0]))
print("Fan {} speed: {}".format(i, check_output(['sg_ses', '--index=coo,{}'.format(i), '--get=1:2:11', device]).decode('utf-8').split('\n')[0]))
print_speeds()
print("Reading current configuration...")
out = check_output(["sg_ses", "-p", "0x2", "/dev/sg6", "--raw"]).decode('utf-8')
s = out.split()
if len(sys.argv) < 1:
print("python fanspeed.py 1-7")
if len(sys.argv) < 2:
print("python fanspeed.py /dev/sgX 1-7")
sys.exit(-1)
fan = int(sys.argv[1])
device = sys.argv[1]
fan = int(sys.argv[2])
if fan <= 0 or fan > 6:
raise Exception("Fan speed must be between 1 and 7")
print_speeds(device)
print("Reading current configuration...")
out = check_output(["sg_ses", "-p", "0x2", device, "--raw"]).decode('utf-8')
s = out.split()
for i in range(0, 6):
print("Setting fan {} to {}".format(i, fan))
idx = 92 + 4 * i
@@ -30,6 +37,7 @@ output = StringIO()
off = 0
count = 0
line = ''
while True:
output.write(s[off])
off = off + 1
@@ -43,9 +51,10 @@ while True:
output.write(" ")
if off >= len(s):
break
output.write("\n")
from subprocess import Popen, PIPE, STDOUT
p = Popen(['sg_ses', '-p', '0x2', '/dev/sg6', '--control', '--data', '-'], stdout=PIPE, stdin=PIPE, stderr=PIPE)
p = Popen(['sg_ses', '-p', '0x2', device, '--control', '--data', '-'], stdout=PIPE, stdin=PIPE, stderr=PIPE)
print("Set fan speeds... Waiting to get fan speeds (ctrl+c to skip)")
print(p.communicate(input=bytearray(output.getvalue(), 'utf-8'))[0].decode('utf-8'))
time.sleep(10)
print_speeds()
print_speeds(device)