Merge pull request #36 from kemenril/main

A06 fan control updates
This commit is contained in:
GNU 2022-06-11 20:40:11 +08:00 committed by GitHub
commit 1649eb7202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,9 +10,14 @@ cpus = []
mid_freq = 0
max_freq = 0
MAX_TEMP=70000
#Start the fan above this temperature
MAX_TEMP=60000
#Cool additionally this far past MAX_TEMP before turning the fan off
TEMP_THRESH=2000
ONCE_TIME=30
lastTemp = {}
gpiopath="/sys/class/gpio"
gpiopin=96
def init_fan_gpio():
@ -29,6 +34,9 @@ def fan_off():
init_fan_gpio()
open("%s/gpio%i/value" % (gpiopath,gpiopin),"w").write("0")
def fan_state():
return int(open("%s/gpio%i/value" % (gpiopath,gpiopin),"r").read()) == 1
def isDigit(x):
try:
float(x)
@ -82,23 +90,49 @@ def set_performance(scale):
#print(_f)
subprocess.run( "echo %s | sudo tee %s" %(freq,_f),shell=True)
def fan_loop():
global lastTemp
statechange = False
hotcount = 0
coolcount = 0
while True:
temps = glob.glob('/sys/class/thermal/thermal_zone[0-9]/')
temps.sort()
hotcount = 0
coolcount = 0
for var in temps:
#Initial check
if not var in lastTemp:
sys.stderr.write("Found zone: " + var + "\n")
lastTemp[var] = 0
_f = os.path.join(var,"temp")
#print( open(_f).read().strip("\n") )
_t = open(_f).read().strip("\n")
if isDigit(_t):
if int(_t) > MAX_TEMP:
fan_on()
fan_off()
if lastTemp[var] <= MAX_TEMP:
sys.stderr.write("Temp(" + var +"): " + _t + "; hot.\n")
hotcount += 1
else:
#Don't turn it off right at the threshold
if (int(_t) + TEMP_THRESH) < MAX_TEMP:
if (lastTemp[var] + TEMP_THRESH) >= MAX_TEMP:
sys.stderr.write("Temp(" + var + ": " + _t + "; cool.\n")
coolcount += 1
lastTemp[var] = int(_t)
if hotcount > 0:
if not fan_state():
#sys.stderr.write("Temps: " + str(lastTemp) +"\n")
sys.stderr.write("Fan on, " + str(hotcount) + " zones hot.\n")
fan_on()
else:
if coolcount > 0:
if fan_state():
#sys.stderr.write("Temps: " + str(lastTemp) +"\n")
sys.stderr.write("Fan off, " + str(hotcount) + " zones hot.\n")
fan_off()
time.sleep(5)
def main(argv):
global cpus
scale = 'mid'