diff --git a/devtimer.py b/devtimer.py index 2348910..0d43016 100755 --- a/devtimer.py +++ b/devtimer.py @@ -144,43 +144,37 @@ /opt/devtimer/temp_probe ''' -# Read the current temp returned by the probe - -def read_probe(): - - global CURRENT_TEMP - - probe = open("/opt/devtimer/temp_probe/w1_slave") - 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 - # reading, since that's almost certainly noise. - - # 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 and store temperature periodically +# Read current temp from probe and display it def monitor_temps(): global CURRENT_TEMP while True: - update_temp = Thread(name="Update Temp", target=read_probe).start() + + probe = open("/opt/devtimer/temp_probe/w1_slave") + 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 + # reading, since that's almost certainly noise. + + # 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() + + Thread(name="Temp", target=show_temp, args=(temp_led, CURRENT_TEMP)).start() if DEBUG: @@ -188,14 +182,6 @@ sleep(1) -# Read the profile switch selector regularly - -def monitor_profile_sw(): - - while True: - Thread(name="GetProfile", target=read_profile_switch).start() - sleep(1) - # Display current temperature # Negative temps are 2 digits, positive temps are 3 digits. @@ -243,6 +229,51 @@ ##### +# Profile Switch Handling +##### + +# Read the profile switch selector regularly + +def monitor_profile_sw(): + + while True: + Thread(name="GetProfile", target=read_profile_switch).start() + sleep(1) + + +# Read the profile selection switch. +# A pin pulled down means that profile has been selected. +# If neither the film or paper pin is pulled down it means +# we want realtime. + +def read_profile_switch(): + + global CURRENT_PROFILE, DIM_BY, temp_led, time_led + + if not wiringpi.digitalRead(PROFILE_SW_FILM): + CURRENT_PROFILE = FILM + + elif not wiringpi.digitalRead(PROFILE_SW_PAPER): + CURRENT_PROFILE = PAPER + + else: + CURRENT_PROFILE = REALTIME + + # Dim displays in film mode + + DIM_BY = 0 + if CURRENT_PROFILE == FILM: + DIM_BY = 2 + + temp_led.brightness=DEFAULT_BRIGHTNESS - DIM_BY + time_led.brightness=DEFAULT_BRIGHTNESS - DIM_BY + + + if DEBUG: + print("Selected Profile: %s" % CURRENT_PROFILE) + + +##### # Utility Subroutines ##### @@ -298,38 +329,6 @@ sleep(10000) -# Read the profile selection switch. -# A pin pulled down means that profile has been selected. -# If neither the film or paper pin is pulled down it means -# we want realtime. - -def read_profile_switch(): - - global CURRENT_PROFILE, DIM_BY, temp_led, time_led - - if not wiringpi.digitalRead(PROFILE_SW_FILM): - CURRENT_PROFILE = FILM - - elif not wiringpi.digitalRead(PROFILE_SW_PAPER): - CURRENT_PROFILE = PAPER - - else: - CURRENT_PROFILE = REALTIME - - # Dim displays in film mode - - DIM_BY = 0 - if CURRENT_PROFILE == FILM: - DIM_BY = 2 - - temp_led.brightness=DEFAULT_BRIGHTNESS - DIM_BY - time_led.brightness=DEFAULT_BRIGHTNESS - DIM_BY - - - if DEBUG: - print("Selected Profile: %s" % CURRENT_PROFILE) - - # Update the display with elapsed time def show_elapsed(time_led, elapsed):