-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKISSS.py
executable file
·156 lines (118 loc) · 4.43 KB
/
KISSS.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/python3
################################################ LIBRARIES ################################################
import RPi.GPIO as GPIO
import time
import os
import subprocess
import sys
import signal
import board
import digitalio
################################################ VARIABLES ################################################
# Folder where folders and pictures will be created
baseFolder = "/home/pi/Desktop/KISSS_Capture/"
# Raspberry pin where you plugged the relay which manage projector remote
relayPin = 17 # pin17
# LCD pin configuration (optional)
lcd = 1 # set to 0 if you don't have LCD
if lcd:
import adafruit_character_lcd.character_lcd as character_lcd
lcd_rs = digitalio.DigitalInOut(board.D25)
lcd_en = digitalio.DigitalInOut(board.D24)
lcd_d7 = digitalio.DigitalInOut(board.D22)
lcd_d6 = digitalio.DigitalInOut(board.D27)
lcd_d5 = digitalio.DigitalInOut(board.D5)
lcd_d4 = digitalio.DigitalInOut(board.D6)
lcd_backlight = digitalio.DigitalInOut(board.D13)
lcd_columns = 16
lcd_rows = 2
################################################ FUNCTIONS ################################################
def setup():
GPIO.setmode(GPIO.BCM)
GPIO.setup(relayPin, GPIO.OUT)
GPIO.output(relayPin, GPIO.HIGH)
def loop():
if lcd:
lcd.clear()
lcd.message = "Calibrate camera\nand press enter..."
input("Calibrate your camera and press Enter when you're ready to start the scanner...")
# Loop over a 50 sliders rack
for x in range(1, 51):
GPIO.output(relayPin, GPIO.HIGH)
time.sleep(2)
# take picture here
if lcd:
lcd.clear()
lcd.message = "Slide #"+str(x)
print("Slide #%d" % (x))
filename = 'DSC_'+boxnbr+'_%03d.JPG'%(x,)
print("destination : "+destFolder+'/'+filename)
os.system('gphoto2 --capture-image-and-download --filename='+destFolder+'/'+filename)
GPIO.output(relayPin, GPIO.LOW)
time.sleep(1)
def destroy():
GPIO.output(relayPin, GPIO.HIGH)
GPIO.cleanup()
def mquit():
print("Exiting ...")
if lcd:
lcd.clear()
lcd.message = "Exiting..."
time.sleep(1)
lcd.clear()
quit()
# Kill the gphoto process that starts whenever we turn on the camera or reboot the raspberry pi
def killGphoto2Process():
p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
out, err = p.communicate()
# Search for the process we want to kill
for line in out.splitlines():
if b'gvfsd-gphoto2' in line:
# Kill that process!
pid = int(line.split(None,1)[0])
os.kill(pid, signal.SIGKILL)
def yes_or_no(question):
reply = str(input(question+' (y/n): ')).lower().strip()
if reply[0] == 'y':
return True
if reply[0] == 'n':
return False
else:
return yes_or_no("Wrong key...")
################################################ MAIN ################################################
if __name__ == '__main__': # Program start from here
if lcd:
lcd = character_lcd.Character_LCD_Mono(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows)
lcd.message = "KISSS\nInitializing..."
# Cow Welcome
print("______________________________________")
print("< KISSS - Keep It Simple Slide Scanner >")
print("--------------------------------------")
print("\ ^__^")
print("\ (oo)\_______")
print(" (__)\ )\/\ ")
print(" ||----w |")
print(" || ||")
print(" ")
# Argument
if len(sys.argv) != 2:
print("Missing box number parameter")
mquit()
boxnbr = str(sys.argv[1])
destFolder = baseFolder+'/'+boxnbr+'/'
# Check if dest folrder already exists
if not os.path.exists(destFolder):
os.makedirs(destFolder)
else:
if not yes_or_no(destFolder+" already exists !!! PHOTOS MAY BE OVERWRITTEN !!!\r\nAre you sure you want to continue with this directory ? "):
mquit()
# Kill gphoto instance to avoid "busy" locks
killGphoto2Process()
# Setup GPIO
setup()
# Main loop
try:
loop()
except KeyboardInterrupt: # Arret 'Ctrl+C'
destroy()
destroy()