diff --git a/devtimer.py b/devtimer.py index fa4c276..a2a2022 100755 --- a/devtimer.py +++ b/devtimer.py @@ -38,6 +38,9 @@ BEEPER = 26 # Piezo alarm device FOOTSW = 6 # GPIO port to read footswitch state +PROFILE_SW_FILM = 23 # Profile selector switch pins +PROFILE_SW_PAPER = 24 + # General Constants BEEP_INTERVAL = 30 # Beep interval @@ -259,6 +262,14 @@ if time() - footsw_pressed.lastISR >= DEBOUNCE_TIME: beep(3, 0.1) # Let user know we're starting/stopping + + # If we are about to start running, determine selected profile + + if not RUNNING: + read_profile_switch() + + # Reflect changed state and current time + RUNNING = not RUNNING footsw_pressed.lastISR = time() @@ -284,6 +295,36 @@ 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 + + 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 + + + + if DEBUG: + print("Selected Profile: %s" % CURRENT_PROFILE) + + # Update the display with elapsed time def show_elapsed(time_led, elapsed): @@ -321,12 +362,12 @@ wiringpi.pinMode(BEEPER, wiringpi.GPIO.PUD_DOWN) wiringpi.pinMode(FOOTSW, wiringpi.GPIO.INPUT) wiringpi.pinMode(FOOTSW, wiringpi.GPIO.PUD_UP) + wiringpi.pinMode(PROFILE_SW_FILM, wiringpi.GPIO.PUD_UP) + wiringpi.pinMode(PROFILE_SW_PAPER, wiringpi.GPIO.PUD_UP) - # Dim displays in film mode + # Get initial profile in case we need to dim - DIM_BY = 0 - if CURRENT_PROFILE == FILM: - DIM_BY = 2 + read_profile_switch() time_led = TM1637(TIME_CLK, TIME_DIO, DEFAULT_BRIGHTNESS - DIM_BY) temp_led = TM1637(TEMP_CLK, TEMP_DIO, DEFAULT_BRIGHTNESS - DIM_BY)