diff --git a/devtimer.py b/devtimer.py index 02116ff..93155f3 100755 --- a/devtimer.py +++ b/devtimer.py @@ -241,18 +241,38 @@ def beep(): print("Beep!") -# Check to see if footswitch got pressed -def monitor_footsw(): +# Callback when footswitch is pressed + +def footsw_pressed(): global RUNNING - while True: - if not wiringpi.digitalRead(FOOTSW): # Button push pulls down - sleep(.030) # Wait for debounce - if not wiringpi.digitalRead(FOOTSW): - RUNNING = not RUNNING + # Process footswitch press accounting for debounce - sleep(.100) + if time() - footsw_pressed.lastISR >= 0.100: + 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(1000) # Update the display with elapsed time @@ -289,6 +309,7 @@ wiringpi.wiringPiSetupGpio() wiringpi.pinMode(FOOTSW, wiringpi.GPIO.INPUT) + wiringpi.pinMode(FOOTSW, wiringpi.GPIO.PUD_UP) # Dim displays in film mode @@ -312,7 +333,7 @@ # Start monitoring for footswitch presses - Thread(name="MonitorFootSW", target=monitor_footsw).start() + Thread(name="MonitorFootSW", target=footsw_monitor).start() # Start timing, using the selected profile and measured temperature @@ -328,7 +349,6 @@ if DEBUG: last = time() - print("Running State: %s" % RUNNING) # If we're not running, don't update elapsed time