diff --git a/devtimer.py b/devtimer.py index 9dff7e5..ae010ed 100755 --- a/devtimer.py +++ b/devtimer.py @@ -23,29 +23,31 @@ # Constants ##### -DEBUG = True # Debugging switch +DEBUG = True # Debugging switch # GPIO Ports And Other Hardware Constants -TIME_BRIGHT = 0x0a # Displays -TIME_CLK = 21 -TIME_DIO = 20 - -TEMP_BRIGHT = 0x0a +TEMP_BRIGHT = 0x0a # Displays TEMP_CLK = 12 TEMP_DIO = 16 -DIMMING = 1 # How much to dim display in film mode +TIME_BRIGHT = 0x0a +TIME_CLK = 21 +TIME_DIO = 20 -FOOTSW = 6 # GPIO port to read footswitch state -RUNNING = False # Whether or not to run the timer +FOOTSW = 6 # GPIO port to read footswitch state # General Constants -BEEP = 15 # Beep interval -CALIBRATION_OFFSET = 0.003 # Compensate for program overhead in master loop -MINUS = 16 # Index of minus segment table lookup -OUTOFRANGE = False # Flag for compensating profiles when temp is out of range +BEEP = 30 # Beep interval +CALIBRATION_OFFSET = 0.003 # Compensate for program overhead in master loop +MINUS = 16 # Index of minus segment table lookup +TEMP_SENTINEL = 999 # Briefly appears at start, if it stays, temp measurement isn't working + +# Range of compensated timing + +TEMP_LOW=60 +TEMP_HIGH=80 # Timing profiles @@ -53,14 +55,9 @@ PAPER = 1 FILM = 2 -# Range of compensated timing - -TEMP_LOW=60 -TEMP_HIGH=80 - ##### -# Global Variables +# Globals ##### # These get updated by the threads that read the switches and @@ -68,8 +65,14 @@ # unnecessary function calls, so we make these globally RW. # So, shoot me ... -CURRENT_PROFILE = PAPER #REALTIME -CURRENT_TEMP = 68 +CURRENT_PROFILE = REALTIME +CURRENT_TEMP = TEMP_SENTINEL + +# Operating globals + +DIM_BY=0 # How much are we currently dimming +OUTOFRANGE = False # Flag for compensating profiles when temp is out of range +RUNNING = False # Whether or not to run the timer ##### @@ -152,13 +155,21 @@ # values that have changed more than 10 degrees since the last # reading, since that's almost certainly noise. - if abs(temp - CURRENT_TEMP) <= 10: + # At startup we want to suppress this check because we have a + # sentinel value set as default for temperature that will briefly + # display an outrageous temperature. If it stays on, it means + # the temperature measurement process isn't working. + + if CURRENT_TEMP == TEMP_SENTINEL: + CURRENT_TEMP = temp + + elif abs(temp - CURRENT_TEMP) <= 10: CURRENT_TEMP = temp probe.close() -# Update the store temperature every second or so +# Update and store temperature periodically def monitor_temps(): @@ -174,6 +185,42 @@ sleep(1) +# Display current temperature +# Negative temps are 2 digits, positive temps are 3 digits. +# Suppress leading zeros. + +def show_temp(display_temp, temp): + + global OUTOFRANGE + + display_temp.brightness=TIME_BRIGHT-DIM_BY + + if temp < 0: # The leading digit is a minus sign + hun = display_time.digit_to_segment[MINUS] + temp = abs(temp) + else: + hun = temp // 100 + if hun != 0: + hun = display_time.digit_to_segment[hun] + + ten =(temp % 100) // 10 + if ten != 0: + ten = display_time.digit_to_segment[ten] + + one = display_time.digit_to_segment[(temp % 100) % 10] + F = display_time.digit_to_segment[15] + + display_temp.set_segments([hun, ten, one, F]) + sleep(0.5) + + # If we're in a compensating profile and out of + # temperature range, blink the time display + + if OUTOFRANGE: + display_temp.brightness=0 + display_temp.set_segments([hun, ten, one, F]) + + ##### # Utility Subroutines ##### @@ -214,43 +261,13 @@ display_time.set_segments([d0, 0x80 + d1, d2, d3]) - -# Display current temperature -# Negative temps are 2 digits, positive temps are 3 digits - -def show_temp(display_temp, temp): - - global OUTOFRANGE - - display_temp.brightness=TIME_BRIGHT - - if temp < 0: # The leading digit is a minus sign - hun = display_time.digit_to_segment[MINUS] - temp = abs(temp) - else: - hun = display_time.digit_to_segment[temp // 100] - - ten = display_time.digit_to_segment[(temp % 100) // 10] - one = display_time.digit_to_segment[(temp % 100) % 10] - F = display_time.digit_to_segment[15] - display_temp.set_segments([hun, ten, one, F]) - sleep(0.5) - - # If we're in a compensating profile and out of - # temperature range, blink the time display - - if OUTOFRANGE: - display_temp.brightness=0 - display_temp.set_segments([hun, ten, one, F]) - - ##### # Program entry point ##### ''' We start a perpetual thread to read the current temperature - and update the relevant global variable. + and adjust time accordingly Notice that the actual updating of the display gets run on its own thread as well. That's because - on a Pi Zero, at least - it takes @@ -268,7 +285,7 @@ # Dim displays in film mode - DIM_BY=0 + DIM_BY = 0 if CURRENT_PROFILE == FILM: DIM_BY = 2