diff --git a/devtimer.py b/devtimer.py index c557ba8..8949f6d 100755 --- a/devtimer.py +++ b/devtimer.py @@ -133,6 +133,8 @@ temp = float(probe.readlines()[-1].split()[-1].split("=")[-1])/1000 # Parse probe output temp = int(round((temp * 9/5) +32)) # Convert C-F and round into an integer + + # 1-wire interfaces (like the DS18B20 uses) can occasionally # return wildly wrong results. For this reason, we throw away # values that have changed more than 10 degrees since the last @@ -152,7 +154,7 @@ probe.close() - Thread(name="Temp", target=show_temp, args=(temp_led, monitor_temps.CURRENT_TEMP)).start() + Thread(name="Temp", target=show_temp, args=[show_temp.LED, monitor_temps.CURRENT_TEMP]).start() if DEBUG: sys.stdout.write("Temp: %sF\n" % monitor_temps.CURRENT_TEMP) @@ -171,8 +173,6 @@ def monitor_profile_sw(): - global temp_led, time_led - while True: if not wiringpi.digitalRead(PROFILE_SW_FILM): @@ -190,8 +190,8 @@ if monitor_profile_sw.CURRENT_PROFILE == FILM: monitor_profile_sw.DIM_BY = 2 - temp_led.brightness=DEFAULT_BRIGHTNESS - monitor_profile_sw.DIM_BY - time_led.brightness=DEFAULT_BRIGHTNESS - monitor_profile_sw.DIM_BY + show_temp.LED.brightness=DEFAULT_BRIGHTNESS - monitor_profile_sw.DIM_BY + show_time.LED.brightness=DEFAULT_BRIGHTNESS - monitor_profile_sw.DIM_BY if DEBUG: print("Selected Profile: %s" % monitor_profile_sw.CURRENT_PROFILE) @@ -260,38 +260,38 @@ # Update the display with elapsed time -def show_elapsed(time_led, elapsed): +def show_time(led, elapsed): min = elapsed // 60 sec = elapsed % 60 - d0 = time_led.digit_to_segment[min // 10] - d1 = time_led.digit_to_segment[min % 10] - d2 = time_led.digit_to_segment[sec // 10] - d3 = time_led.digit_to_segment[sec % 10] - time_led.set_segments([d0, 0x80 + d1, d2, d3]) + d0 = led.digit_to_segment[min // 10] + d1 = led.digit_to_segment[min % 10] + d2 = led.digit_to_segment[sec // 10] + d3 = led.digit_to_segment[sec % 10] + led.set_segments([d0, 0x80 + d1, d2, d3]) # Display current temperature # Negative temps are 2 digits, positive temps are 3 digits. # Suppress leading zeros. -def show_temp(temp_led, temp): +def show_temp(led, temp): minus = hun = ten = one = 0 # Tells display to show nothing if temp < 0: # The leading digit is a minus sign - minus = temp_led.digit_to_segment[MINUS] + minus = led.digit_to_segment[MINUS] temp = abs(temp) elif temp > 99: # The 100s position is non-zero hun = temp // 100 - hun = temp_led.digit_to_segment[hun] + hun = led.digit_to_segment[hun] if temp > 9: # The 10s position is non-zero ten =(temp % 100) // 10 - ten = temp_led.digit_to_segment[ten] + ten = led.digit_to_segment[ten] - one = temp_led.digit_to_segment[(temp % 100) % 10] + one = led.digit_to_segment[(temp % 100) % 10] # If temp is negative, display sign next to most significant digit @@ -303,15 +303,15 @@ # Update the temperature LED - temp_led.set_segments([hun, ten, one, show_temp.farenheight]) + led.set_segments([hun, ten, one, show_temp.farenheight]) sleep(0.3) # If we're in a compensating profile and out of # temperature range, blink the time display if show_temp.OUTOFRANGE: - temp_led.brightness=0 - temp_led.set_segments([hun, ten, one, show_temp.farenheight]) + led.brightness=0 + led.set_segments([hun, ten, one, show_temp.farenheight]) ##### @@ -342,7 +342,7 @@ # Update the time display - Thread(name="Timer", target=show_elapsed, args=(time_led, elapsed_time)).start() + Thread(name="Timer", target=show_time, args=(show_time.LED, elapsed_time)).start() # For temperatures in-range, look up the compensating factor @@ -395,8 +395,8 @@ wiringpi.pinMode(PROFILE_SW_PAPER, wiringpi.GPIO.PUD_UP) monitor_profile_sw.DIM_BY=0 # How much are we currently dimming - time_led = TM1637(TIME_CLK, TIME_DIO, DEFAULT_BRIGHTNESS - monitor_profile_sw.DIM_BY) - temp_led = TM1637(TEMP_CLK, TEMP_DIO, DEFAULT_BRIGHTNESS - monitor_profile_sw.DIM_BY) + show_time.LED = TM1637(TIME_CLK, TIME_DIO, DEFAULT_BRIGHTNESS - monitor_profile_sw.DIM_BY) + show_temp.LED = TM1637(TEMP_CLK, TEMP_DIO, DEFAULT_BRIGHTNESS - monitor_profile_sw.DIM_BY) # Issue audible start alert @@ -409,16 +409,16 @@ Thread(name="MonitorProfileSW", target=monitor_profile_sw).start() # Get segment pattern for "F" - only need to do this once, not on every update - show_temp.farenheight = temp_led.digit_to_segment[0x0f] + show_temp.farenheight = show_temp.LED.digit_to_segment[0x0f] # Initialize the time display - Thread(name="InitTimeDisplay", target=show_elapsed, args=[time_led, 0]).start() + Thread(name="InitTimeDisplay", target=show_time, args=[show_time.LED, 0]).start() # Show the initial temp sentinel show_temp.OUTOFRANGE = False # Flag for compensating profiles when temp is out of range monitor_temps.SENTINEL = monitor_temps.CURRENT_TEMP = 999 - show_temp(temp_led, monitor_temps.CURRENT_TEMP) + show_temp(show_temp.LED, monitor_temps.CURRENT_TEMP) # Start measuring temperature