-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhotoBoothGLPi.py
92 lines (78 loc) · 2.27 KB
/
PhotoBoothGLPi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import pygame
import time
from PhotoBoothGL import PhotoBoothGL
import RPi.GPIO as GPIO
import Queue
class PhotoBoothGLPi(PhotoBoothGL):
last_button = None;
left_button_queue = None
right_button_queue = None
def init(self):
### queue button inputs
self.left_button_queue = Queue.Queue()
self.right_button_queue = Queue.Queue()
self.start()
def button_test(self, but):
return False
if self.last_button != None and (time.time() - self.last_button) < 5:
### clear any events until then
GPIO.event_detected(but)
return False
if GPIO.event_detected(but):
self.last_button = time.time()
#GPIO.remove_event_detect(but)
return True
return False
def clear_button_events(self):
#global last_button
#last_button = time.time()
return
def left_button_pressed(self):
#with self.left_button_queue.mutex:
if self.left_button_queue.qsize() == 0:
self.left_button_queue.put(time.time())
def right_button_pressed(self):
#with self.right_button_queue.mutex:
if self.right_button_queue.qsize() == 0:
self.right_button_queue.put(time.time())
def one_photo_button(self):
if self.left_button_queue.qsize() > 0:
### empty the queue
while self.left_button_queue.qsize() > 0:
self.left_button_queue.get()
return True
return False
def multi_photo_button(self):
if self.right_button_queue.qsize() > 0:
while self.right_button_queue.qsize() > 0:
self.right_button_queue.get()
return True
return False
def exit_button(self):
return False
booth = None
last_button = None
### minimum interval between button presses in seconds
but_int = 1
def button_callback(channel):
global booth, last_button, but_int
if last_button != None and (time.time() - last_button) < but_int:
### ignore
return
last_button = time.time()
if channel == 4:
print "left button"
booth.left_button_pressed()
elif channel == 17:
print "right button"
booth.right_button_pressed()
if __name__ == "__main__":
print "Starting RPi photobooth"
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(4, GPIO.RISING, callback=button_callback)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(17, GPIO.RISING, callback=button_callback)
booth = PhotoBoothGLPi(1280, 1024)
booth.run()