File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22
3- import subprocess
43import time
54
65from gpiozero import OutputDevice
76
87
9- ON_THRESHOLD = 65 * 1000 # (degrees Celsius) Fan kicks on at this temperature.
10- OFF_THRESHOLD = 55 * 1000 # (degress Celsius) Fan shuts off at this temperature.
8+ ON_THRESHOLD = 65 # (degrees Celsius) Fan kicks on at this temperature.
9+ OFF_THRESHOLD = 55 # (degress Celsius) Fan shuts off at this temperature.
1110SLEEP_INTERVAL = 5 # (seconds) How often we check the core temperature.
1211GPIO_PIN = 17 # Which GPIO pin you're using to control the fan.
1312
@@ -20,10 +19,13 @@ def get_temp():
2019 Returns:
2120 int: The core temperature in thousanths of degrees Celsius.
2221 """
23- with open ("/sys/class/thermal/thermal_zone0/temp" ) as f :
24- temp_data = f .read ()
25-
26- return int (temp_data )
22+ with open ('/sys/class/thermal/thermal_zone0/temp' ) as f :
23+ temp_str = f .read ()
24+
25+ try :
26+ return int (temp_str ) / 1000
27+ except (IndexError , ValueError ,) as e :
28+ raise RuntimeError ('Could not parse temperature output.' ) from e
2729
2830if __name__ == '__main__' :
2931 # Validate the on and off thresholds
You can’t perform that action at this time.
0 commit comments