From c9b1820ef0073884c5db5abea44ae9a098aa0117 Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Tue, 19 May 2015 00:35:27 +0200 Subject: [PATCH] Started preparing GPIO IO --- photobooth.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/photobooth.py b/photobooth.py index 50ab141..aa16004 100755 --- a/photobooth.py +++ b/photobooth.py @@ -11,6 +11,11 @@ import time import pygame +# try: +# import RPi.GPIO as GPIO +# except RuntimeError: +# print("Error importing RPi.GPIO! This is probably because you need superuser privileges. You can achieve this by using 'sudo' to run your script") + ##################### ### Configuration ### ##################### @@ -33,6 +38,9 @@ image_pose = "pose.png" # Image basename image_basename = datetime.datetime.now().strftime("%Y-%m-%d/pic") +# GPIO channel of switch to take pictures +gpio_trigger_channel = 0 #GPIO23 + # Waiting time in seconds for posing pose_time = 5 @@ -217,18 +225,42 @@ def handle_keypress(key): # Take pictures elif key == ord('c'): take_picture() + +# def handle_gpio_event(channel): +# """Implements the actions taken for a GPIO event""" +# if channel == gpio_trigger_channel: +# GPIO.remove_event_detect(gpio_trigger_channel) +# take_picture() +# GPIO.add_event_detect(gpio_trigger_channel, GPIO.RISING, +# callback=handle_gpio_event, bouncetime=200) def handle_exception(msg): + """Displays an error message and returns""" display.clear() - display.show_message("Error: " + msg) + msg = "Error: " + msg + print msg + display.show_message(msg) display.apply() time.sleep(3) +# def setup_gpio(): +# # Display initial information +# print "Your Raspberry Pi is board revision " + str(GPIO.RPI_INFO['P1_REVISION']) +# print "RPi.GPIO version is " + str(GPIO.VERSION) +# # Choose BCM numbering system +# GPIO.setmode(GPIO.BCM) +# # Setup the trigger channel as input and listen for events +# GPIO.setup(gpio_trigger_channel, GPIO.IN, pull_up_down=GPIO.PUD_UP) +# GPIO.add_event_detect(gpio_trigger_channel, GPIO.RISING, +# callback=handle_gpio_event, bouncetime=200) + def teardown(exit_code=0): display.teardown() + # GPIO.cleanup() sys.exit(exit_code) def main(): + # setup_gpio() while True: try: display.mainloop(image_idle)