Fix formatting and comments

master
Cole Deck 4 years ago
parent 25af275fb0
commit 78aae1cb6c

@ -2,6 +2,8 @@
import run_cmd import run_cmd
import argparse import argparse
import time import time
# Variables to determine bounds
MAXFAN = 6 MAXFAN = 6
MINSPEED = 35 MINSPEED = 35
MAXSPEED = 100 MAXSPEED = 100
@ -10,35 +12,32 @@ MAXTEMP = 65
parser = argparse.ArgumentParser(description='Read information about and control fans on ASRock boards with IPMI.', prog='asrock-pwm-ipmi') parser = argparse.ArgumentParser(description='Read information about and control fans on ASRock boards with IPMI.', prog='asrock-pwm-ipmi')
parser.add_argument('fanplusspeed', nargs='*', metavar='FAN:SPEED', parser.add_argument('fanplusspeed', nargs='*', metavar='FAN:SPEED',
help='Fan to change the speed of, and the speed, separated by \':\'. Set to 0 for auto.') help='Fan to change the speed of, and the speed, separated by \':\'. Set to 0 for auto.')
#parser.add_argument('SPEED', type=int, nargs='+',
# help='Speed to set FAN to')
parser.add_argument('-i', '--info', action="store_true", default=False, parser.add_argument('-i', '--info', action="store_true", default=False,
help='Read fan information') help='Read fan information')
parser.add_argument('-a', '--auto', action="store_true", default=False, parser.add_argument('-a', '--auto', action="store_true", default=False,
help='Service to control fans based on temperature') help='Service to control fans based on temperature')
parser.add_argument('-q', '--quiet', action="store_true", default=False, parser.add_argument('-q', '--quiet', action="store_true", default=False,
help='Hide output') help='Hide output')
args = parser.parse_args() args = parser.parse_args()
#print(args.info)
#print(args) #print(args)
#print(args.fanplusspeed)
fanChanged = False fanChanged = False
def iterateFans(info): def iterateFans(info):
for fanopt in info: for fanopt in info:
if str(fanopt.split(":"))[2:-2] == fanopt or int(fanopt.split(":")[0]) < 1 or int(fanopt.split(":")[0]) > MAXFAN: if str(fanopt.split(":"))[2:-2] == fanopt or int(fanopt.split(":")[0]) < 1 or int(fanopt.split(":")[0]) > MAXFAN:
print("Improper format!") print("Improper format!")
continue continue
fan, speed = fanopt.split(":") fan, speed = fanopt.split(":")
run_cmd.setSpeed(int(fan), int(speed)) run_cmd.setSpeed(int(fan), int(speed))
fanChanged = True fanChanged = True
if args.quiet is False: if args.quiet is False:
if int(speed) == 0: if int(speed) == 0:
print("Set speed of FAN" + fan + " to Auto.") print("Set speed of FAN" + fan + " to Auto.")
else: else:
print("Set speed of FAN" + fan + " to " + speed + "%.") print("Set speed of FAN" + fan + " to " + speed + "%.")
while args.auto is True: while args.auto is True:
temp = run_cmd.getTemp() temp = run_cmd.getTemp()
@ -48,14 +47,14 @@ while args.auto is True:
speeds.append(str(i) + ":1") speeds.append(str(i) + ":1")
elif temp > MAXTEMP: elif temp > MAXTEMP:
for i in range(2, 7): for i in range(2, 7):
speeds.append(str(i) + ":100") speeds.append(str(i) + ":100")
else: else:
base = temp - MINTEMP base = temp - MINTEMP
max = MAXTEMP - MINTEMP max = MAXTEMP - MINTEMP
scaled = base / max scaled = base / max
speed = int(scaled * (MAXSPEED - MINSPEED) + MINSPEED) speed = int(scaled * (MAXSPEED - MINSPEED) + MINSPEED)
for i in range(2, 7): for i in range(2, 7):
speeds.append(str(i) + ":" + str(speed)) speeds.append(str(i) + ":" + str(speed))
iterateFans(speeds) iterateFans(speeds)
if args.info is False and len(args.fanplusspeed) == 0: if args.info is False and len(args.fanplusspeed) == 0:
@ -69,4 +68,4 @@ if args.info is True:
time.sleep(5) time.sleep(5)
print("\nRetrieving fan speeds...\n") print("\nRetrieving fan speeds...\n")
for line in run_cmd.getFanInfo(): for line in run_cmd.getFanInfo():
print(line) print(line)
Loading…
Cancel
Save