mirror of
https://github.com/clockworkpi/DevTerm.git
synced 2025-12-14 19:28:50 +01:00
commit
1649eb7202
@ -10,9 +10,14 @@ cpus = []
|
|||||||
mid_freq = 0
|
mid_freq = 0
|
||||||
max_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
|
ONCE_TIME=30
|
||||||
|
|
||||||
|
lastTemp = {}
|
||||||
|
|
||||||
gpiopath="/sys/class/gpio"
|
gpiopath="/sys/class/gpio"
|
||||||
gpiopin=96
|
gpiopin=96
|
||||||
def init_fan_gpio():
|
def init_fan_gpio():
|
||||||
@ -29,6 +34,9 @@ def fan_off():
|
|||||||
init_fan_gpio()
|
init_fan_gpio()
|
||||||
open("%s/gpio%i/value" % (gpiopath,gpiopin),"w").write("0")
|
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):
|
def isDigit(x):
|
||||||
try:
|
try:
|
||||||
float(x)
|
float(x)
|
||||||
@ -82,23 +90,49 @@ def set_performance(scale):
|
|||||||
#print(_f)
|
#print(_f)
|
||||||
subprocess.run( "echo %s | sudo tee %s" %(freq,_f),shell=True)
|
subprocess.run( "echo %s | sudo tee %s" %(freq,_f),shell=True)
|
||||||
|
|
||||||
|
|
||||||
def fan_loop():
|
def fan_loop():
|
||||||
|
global lastTemp
|
||||||
|
statechange = False
|
||||||
|
hotcount = 0
|
||||||
|
coolcount = 0
|
||||||
while True:
|
while True:
|
||||||
temps = glob.glob('/sys/class/thermal/thermal_zone[0-9]/')
|
temps = glob.glob('/sys/class/thermal/thermal_zone[0-9]/')
|
||||||
temps.sort()
|
temps.sort()
|
||||||
|
hotcount = 0
|
||||||
|
coolcount = 0
|
||||||
for var in temps:
|
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")
|
_f = os.path.join(var,"temp")
|
||||||
#print( open(_f).read().strip("\n") )
|
#print( open(_f).read().strip("\n") )
|
||||||
_t = open(_f).read().strip("\n")
|
_t = open(_f).read().strip("\n")
|
||||||
if isDigit(_t):
|
if isDigit(_t):
|
||||||
if int(_t) > MAX_TEMP:
|
if int(_t) > MAX_TEMP:
|
||||||
|
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()
|
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()
|
fan_off()
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
global cpus
|
global cpus
|
||||||
scale = 'mid'
|
scale = 'mid'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user