diff --git a/devtimer.py b/devtimer.py index 7ad3051..5214741 100755 --- a/devtimer.py +++ b/devtimer.py @@ -17,7 +17,7 @@ from ds18b20 import * from tm1637 import * -from wiringpi import wiringPiSetupGpio +from wiringpi import wiringPiSetupGpio, pinMode, digitalRead, GPIO import globals @@ -26,9 +26,9 @@ # Constants ##### -# Display Hardware Configuration +# GPIO Ports And Other Hardware Constants -TIME_BRIGHT = 0x0a +TIME_BRIGHT = 0x0a # Displays TIME_CLK = 21 TIME_DIO = 20 @@ -38,6 +38,9 @@ DIMMING = 1 # How much to dim display in film mode +FOOTSW = 6 # GPIO port to read footswitch state +RUNNING = False # Whether or not to run the timer + # General Constants DEBUG = True # Debugging switch @@ -79,12 +82,32 @@ (1.445, 1.380, 1.318, 1.259, 1.202, 1.148, 1.096, 1.047, 1.000, 0.955, 0.912, 0.871, 0.832, 0.795, 0.759, 0.725, 0.692, 0.661, 0.631, 0.603, 0.576) ) +##### +# Supporting Subroutines +##### # Beep at the user at fixed intervals def beep(): print("Beep!") +# Check to see if footswitch got pressed + +def monitor_footsw(): + + while True: + if not digitalRead(FOOTSW): # Button push pulls down + Thread(name="ReadFootSW", target=read_footsw).start() + sleep(.2) + +def read_footsw(): + global RUNNING + + sleep(0.10) + if not digitalRead(FOOTSW): + RUNNING = not RUNNING + print(RUNNING) + # Update the display with elapsed time @@ -127,6 +150,7 @@ # Setup the hardware wiringPiSetupGpio() + pinMode(FOOTSW, GPIO.INPUT) # Dim displays in film mode @@ -143,6 +167,10 @@ get_temps.start() sleep(1) # Wait a bit for the 1st temp measurement to complete + # Start monitoring for footswitch presses + + Thread(name="MonitorFootSW", target=monitor_footsw).start() + # Start timing, using the selected profile and measured temperature elapsed_time = 0