-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
174 lines (162 loc) · 5.21 KB
/
code.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from time import sleep
import RPi.GPIO as GPIO
import time
import os
from subprocess import Popen
folder1 = "/media/pi/PRESENT/PRESENTATION/Button1/"
folder2 = "/media/pi/PRESENT/PRESENTATION/Button2/"
folder3 = "/media/pi/PRESENT/PRESENTATION/Button3/"
folder4 = "/media/pi/PRESENT/PRESENTATION/Button4/"
image_file = "/media/pi/PRESENT/PRESENTATION/image.jpg"
video_file = "video.mp4"
def read_folderfile4(folder):
folder_files= os.listdir(folder)
print folder_files
for image_type in (folder_files):
if image_type.endswith(".jpg"):
print image_type
os.system("sudo fbi -T 1 "+folder+"%s"%str(image_type))
#~ time.sleep(2)
elif image_type.endswith("loop.mp4"):
Popen(['omxplayer', '-b', '--loop',folder+"%s"%str(image_type)])
else:
print image_type
Popen(['omxplayer', '-b', folder+"%s"%str(image_type)])
def read_folderfile2(folder):
folder_files= os.listdir(folder)
print folder_files
i=0
while(i!=len(folder_files)):
image_type = folder_files[i]
os.system("sudo fbi -T 1 "+folder2+"%s"%str(image_type))
while(not GPIO.input(26)):
print "pass"
pass
i=i+1
time.sleep(0.3)
omxc = Popen(['killall', 'omxplayer.bin'])
os.system("sudo fbi -T 1 "+image_file)
def read_folderfile1(folder):
folder_files= os.listdir(folder)
print folder_files
for image_type in (folder_files):
if image_type.endswith(".jpg"):
print image_type
#~ os.system("sudo fbi -T 1 /media/pi/44F3-214D/PRESENTATION/Button2/%s"%str(image_type))
Popen(['fbi', '-T', "1",folder+"%s"%str(image_type)])
time.sleep(5)
elif image_type.endswith("loop.mp4"):
Popen(['omxplayer', '-b', '--loop',folder+"%s"%str(image_type)])
else:
print image_type
Popen(['omxplayer', '-b', folder+"%s"%str(image_type)])
def read_folderfile3(folder):
folder_files= os.listdir(folder)
print folder_files
for image_type in (folder_files):
if image_type.endswith(".jpg"):
print image_type
os.system("sudo fbi -T 1 "+folder+"%s"%str(image_type))
#~ time.sleep(2)
elif image_type.endswith("loop.mp4"):
Popen(['omxplayer', '-b', '--loop',folder+"%s"%str(image_type)])
else:
print image_type
Popen(['omxplayer', '-b', folder+"%s"%str(image_type)])
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(24,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(19,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(26,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
last_state1 = True
last_state2 = True
last_state3 = True
last_state4 = True
last_state5 = True
input_state1 = True
input_state2 = True
input_state3 = True
input_state4 = True
input_state5 = True
quit_video = True
player = False
os.system("sudo fbi -T 1 "+image_file)
while True:
#Read states of inputs
input_state1 = GPIO.input(17)
input_state4 = GPIO.input(19)
input_state2 = GPIO.input(24)
input_state3 = GPIO.input(18)
input_state5 = GPIO.input(26)
#If GPIO(17) is shorted to ground
if input_state1 != last_state1:
if (player and not input_state1):
os.system('killall omxplayer.bin')
#~ omxc = os.system("sudo omxplayer -b video.mp4")
#~ omxc = Popen(['omxplayer', '-b', video_file])
omxc = read_folderfile1(folder1)
player = True
elif not input_state1:
#~ os.system("sudo omxplayer -b video.mp4")
omxc = read_folderfile1(folder1)
player = True
print "button 1"
#If GPIO(24) is shorted to ground
elif input_state2 != last_state2:
if (player and not input_state2):
#~ os.system('killall omxplayer.bin')
omxc = Popen(['killall', 'omxplayer.bin'])
os.system("sudo fbi -T 1 "+image_file)
#~ omxc = read_folderfile(folder2)
player = True
elif not input_state2:
omxc = Popen(['killall', 'omxplayer.bin'])
os.system("sudo fbi -T 1 "+image_file)
#~ omxc = read_folderfile(folder2)
player = True
print "button 2"
#If GPIO(19) is shorted to ground
elif input_state4 != last_state4:
if (player and not input_state4):
os.system('killall omxplayer.bin')
#~ omxc = os.system("sudo omxplayer -b video.mp4")
#~ omxc = Popen(['omxplayer', '-b', video_file])
omxc = read_folderfile4(folder4)
player = True
elif not input_state4:
#~ os.system("sudo omxplayer -b video.mp4")
omxc = read_folderfile4(folder4)
player = True
print "button 4"
#If GPIO(18) is shorted to ground
elif input_state3 != last_state3:
if (player and not input_state3):
os.system('killall omxplayer.bin')
#~ omxc = os.system("sudo omxplayer -b video.mp4")
#~ omxc = Popen(['omxplayer', '-b', video_file])
omxc = read_folderfile3(folder3)
player = True
elif not input_state3:
#~ os.system("sudo omxplayer -b video.mp4")
omxc = read_folderfile3(folder3)
player = True
print "button 3"
elif input_state5 != last_state5:
if (player and not input_state5):
os.system('killall omxplayer.bin')
#~ omxc = os.system("sudo omxplayer -b video.mp4")
#~ omxc = Popen(['omxplayer', '-b', video_file])
omxc = read_folderfile2(folder2)
player = True
elif not input_state3:
#~ os.system("sudo omxplayer -b video.mp4")
omxc = read_folderfile2(folder2)
player = True
print "button 5"
#Set last_input states
last_state1 = input_state1
last_state2 = input_state2
last_state3 = input_state3
last_state4 = input_state4
last_state5 = input_state5