diff --git a/TODO b/TODO index 0f83ccf..4cb7037 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -- Fix non leading zero suppression - Generate compensation tables at startup based on low/hi range - perhaps limited by times <400ms - Cleanup footswitch handling - Handle start/stop: Ensure rest to all zeros when done diff --git a/devtimer.py b/devtimer.py index 76a5bab..c0ee4cc 100755 --- a/devtimer.py +++ b/devtimer.py @@ -27,11 +27,11 @@ # GPIO Ports And Other Hardware Constants -TEMP_BRIGHT = 0x0a # Displays -TEMP_CLK = 12 +DEFAULT_BRIGHTNESS = 0x0a # Default LED brightness level + +TEMP_CLK = 12 # Display connections TEMP_DIO = 16 -TIME_BRIGHT = 0x0a TIME_CLK = 21 TIME_DIO = 20 @@ -71,6 +71,7 @@ # Operating globals DIM_BY=0 # How much are we currently dimming +FARENHEIGHT=0 # Will be populated with segment pattern for "F" OUTOFRANGE = False # Flag for compensating profiles when temp is out of range RUNNING = False # Whether or not to run the timer @@ -193,24 +194,34 @@ global OUTOFRANGE - temp_led.brightness=TIME_BRIGHT-DIM_BY + minus = hun = ten = one = 0 # Tells display to show nothing + temp_led.brightness=DEFAULT_BRIGHTNESS - DIM_BY if temp < 0: # The leading digit is a minus sign - hun = time_led.digit_to_segment[MINUS] + minus = temp_led.digit_to_segment[MINUS] temp = abs(temp) - else: + + elif temp > 99: # The 100s position is non-zero hun = temp // 100 - if hun != 0: - hun = time_led.digit_to_segment[hun] + hun = temp_led.digit_to_segment[hun] - ten =(temp % 100) // 10 - if ten != 0: - ten = time_led.digit_to_segment[ten] + if temp > 9: # The 10s position is non-zero + ten =(temp % 100) // 10 + ten = temp_led.digit_to_segment[ten] - one = time_led.digit_to_segment[(temp % 100) % 10] - F = time_led.digit_to_segment[15] + one = temp_led.digit_to_segment[(temp % 100) % 10] - temp_led.set_segments([hun, ten, one, F]) + # If temp is negative, display sign next to most significant digit + + if minus: + if not ten: + ten = minus + else: + hun = minus + + # Update the temperature LED + + temp_led.set_segments([hun, ten, one, FARENHEIGHT]) sleep(0.5) # If we're in a compensating profile and out of @@ -289,8 +300,11 @@ if CURRENT_PROFILE == FILM: DIM_BY = 2 - time_led = TM1637(TIME_CLK, TIME_DIO, TIME_BRIGHT-DIM_BY) - temp_led = TM1637(TEMP_CLK, TEMP_DIO, TEMP_BRIGHT-DIM_BY) + time_led = TM1637(TIME_CLK, TIME_DIO, DEFAULT_BRIGHTNESS - DIM_BY) + temp_led = TM1637(TEMP_CLK, TEMP_DIO, DEFAULT_BRIGHTNESS - DIM_BY) + + # Get segment pattern for "F" - only need to do this once, not on every update + FARENHEIGHT = temp_led.digit_to_segment[0x0f] # Start measuring temperature