-
Notifications
You must be signed in to change notification settings - Fork 15
/
photo_booth.py
executable file
·56 lines (53 loc) · 1.68 KB
/
photo_booth.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
#!/usr/bin/python
import RPi.GPIO as GPIO, time, os, subprocess
# GPIO setup
GPIO.setmode(GPIO.BCM)
SWITCH = 24
GPIO.setup(SWITCH, GPIO.IN)
RESET = 25
GPIO.setup(RESET, GPIO.IN)
PRINT_LED = 22
POSE_LED = 18
BUTTON_LED = 23
GPIO.setup(POSE_LED, GPIO.OUT)
GPIO.setup(BUTTON_LED, GPIO.OUT)
GPIO.setup(PRINT_LED, GPIO.OUT)
GPIO.output(BUTTON_LED, True)
GPIO.output(PRINT_LED, False)
while True:
if (GPIO.input(SWITCH)):
snap = 0
while snap < 4:
print("pose!")
GPIO.output(BUTTON_LED, False)
GPIO.output(POSE_LED, True)
time.sleep(1.5)
for i in range(5):
GPIO.output(POSE_LED, False)
time.sleep(0.4)
GPIO.output(POSE_LED, True)
time.sleep(0.4)
for i in range(5):
GPIO.output(POSE_LED, False)
time.sleep(0.1)
GPIO.output(POSE_LED, True)
time.sleep(0.1)
GPIO.output(POSE_LED, False)
print("SNAP")
gpout = subprocess.check_output("gphoto2 --capture-image-and-download --filename /home/pi/photobooth_images/photobooth%H%M%S.jpg", stderr=subprocess.STDOUT, shell=True)
print(gpout)
if "ERROR" not in gpout:
snap += 1
GPIO.output(POSE_LED, False)
time.sleep(0.5)
print("please wait while your photos print...")
GPIO.output(PRINT_LED, True)
# build image and send to printer
subprocess.call("sudo /home/pi/scripts/photobooth/assemble_and_print", shell=True)
# TODO: implement a reboot button
# Wait to ensure that print queue doesn't pile up
# TODO: check status of printer instead of using this arbitrary wait time
time.sleep(110)
print("ready for next round")
GPIO.output(PRINT_LED, False)
GPIO.output(BUTTON_LED, True)