diff --git a/devtimer.py b/devtimer.py index a7afd09..b5e28b7 100755 --- a/devtimer.py +++ b/devtimer.py @@ -92,6 +92,7 @@ d3 = display0.digit_to_segment[sec % 10] display0.set_segments([d0, 0x80 + d1, d2, d3]) + ##### # Program entry point ##### @@ -116,8 +117,9 @@ # Start measuring temperature - get_temps = Thread(name="Temperatures", target=read_temp_probe) + get_temps = Thread(name="Temperatures", target=monitor_temps) get_temps.start() + sleep(1) # Wait a bit for the 1st temp measurement to complete # Start timing, using the selected profile and measured temperature @@ -136,8 +138,8 @@ # Update the display on a separate thread - update_thread = Thread(name="Timer", target=show_elapsed, args=(display0, elapsed_time)) - update_thread.start() + display_thread = Thread(name="Timer", target=show_elapsed, args=(display0, elapsed_time)) + display_thread.start() # For temperatures in-range, look up the compensating factor diff --git a/ds18b20.py b/ds18b20.py index e5d08c1..5c4e33b 100755 --- a/ds18b20.py +++ b/ds18b20.py @@ -36,31 +36,30 @@ DS18B20_ID = "28-0416840ac6ff" -# This function is called on it's own thread by __main__ -# so that it runs continuously in background. +# Read the current temp returned by the probe -class read_temp(Thread): +def read_probe(): - def run(self): - probe = open("/sys/bus/w1/devices/%s/w1_slave" % DS18B20_ID) - temp = float(probe.readlines()[-1].split()[-1].split("=")[-1])/1000 # Parse probe output - globals.CURRENT_TEMP = int(round((temp * 9/5) +32)) # Convert C-F and round into an integer - probe.close() + probe = open("/sys/bus/w1/devices/%s/w1_slave" % DS18B20_ID) + temp = float(probe.readlines()[-1].split()[-1].split("=")[-1])/1000 # Parse probe output + globals.CURRENT_TEMP = int(round((temp * 9/5) +32)) # Convert C-F and round into an integer + probe.close() -def read_temp_probe(): +# Update the store temperature every second or so + +def monitor_temps(): while True: - read_temp().start() + update_temp = Thread(name="Update Temp", target=read_probe) + update_temp.start() + sleep(1) if DEBUG: sys.stdout.write("Temp: %sF\n" % globals.CURRENT_TEMP) - sleep(1) - # Run this from the command line - if __name__ == "__main__": DEBUG = True - read_temp_probe() + monitor_temps()