diff --git a/devtimer.py b/devtimer.py index 0d43016..03bca49 100755 --- a/devtimer.py +++ b/devtimer.py @@ -183,6 +183,118 @@ sleep(1) +##### +# Profile Switch Handling +##### + +# 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 monitor_profile_sw(): + + global CURRENT_PROFILE, DIM_BY, temp_led, time_led + + while True: + + 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) + + sleep(1) + + +##### +# Footswitch Handling +##### + +# Callback when footswitch is pressed + +def footsw_pressed(): + global RUNNING + + # Mask interrupts during debounce window + + if time() - footsw_pressed.lastISR >= DEBOUNCE_TIME: + + beep(3, 0.1) # Let user know we're starting/stopping + + # Reflect changed state and current time + + RUNNING = not RUNNING + footsw_pressed.lastISR = time() + + if DEBUG: + print("Running State: %s" % RUNNING) + + +# Check to see if footswitch got pressed + +def footsw_monitor(): + + # We store last interrupt service time as a callback global for debounce + + footsw_pressed.lastISR = 0 + + # Setup the callback + + wiringpi.wiringPiISR(FOOTSW, wiringpi.GPIO.INT_EDGE_FALLING, footsw_pressed) + + # Run the thread forever waiting for footswitch presses + + while True: + sleep(10000) + + +##### +# Utility Subroutines +##### + +# Beep for specified count/length + +def beep(count, delay): + + for repeat in range(count): + wiringpi.digitalWrite(BEEPER, 1) + sleep(delay) + wiringpi.digitalWrite(BEEPER, 0) + sleep(delay) + + if DEBUG: + print("Beep!") + + +# Update the display with elapsed time + +def show_elapsed(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]) + + # Display current temperature # Negative temps are 2 digits, positive temps are 3 digits. # Suppress leading zeros. @@ -229,120 +341,6 @@ ##### -# 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 -##### - -# Beep for specified count/length - -def beep(count, delay): - - for repeat in range(count): - wiringpi.digitalWrite(BEEPER, 1) - sleep(delay) - wiringpi.digitalWrite(BEEPER, 0) - sleep(delay) - - if DEBUG: - print("Beep!") - - -# Callback when footswitch is pressed - -def footsw_pressed(): - global RUNNING - - # Mask interrupts during debounce window - - if time() - footsw_pressed.lastISR >= DEBOUNCE_TIME: - - beep(3, 0.1) # Let user know we're starting/stopping - - # Reflect changed state and current time - - RUNNING = not RUNNING - footsw_pressed.lastISR = time() - - if DEBUG: - print("Running State: %s" % RUNNING) - - -# Check to see if footswitch got pressed - -def footsw_monitor(): - - # We store last interrupt service time as a callback global for debounce - - footsw_pressed.lastISR = 0 - - # Setup the callback - - wiringpi.wiringPiISR(FOOTSW, wiringpi.GPIO.INT_EDGE_FALLING, footsw_pressed) - - # Run the thread forever waiting for footswitch presses - - while True: - sleep(10000) - - -# Update the display with elapsed time - -def show_elapsed(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]) - - -##### # Program entry point #####