-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_nodetect.py
85 lines (70 loc) · 1.98 KB
/
main_nodetect.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
from detect_presence import PresenceDetector
import gpio
import time
import subprocess
import os
import signal
play_audio = False
switch_on = False
play_video = True
switch_out_pin = 25
record_input_pin = 24
#True for high, False for low
record_switch_pressed_state = 0
is_recording = False
record_process = None
video_process = None
audio_process = None
video_file = 'IMG_0812_VFLIP.MOV'
audio_file = 'IMG_0813.mp3'
x_server = subprocess.Popen('X')
new_env = dict(os.environ, DISPLAY=":0")
while True:
###### Handle record button ######
record_pin_state = gpio.read(record_input_pin)
if record_pin_state == record_switch_pressed_state:
play_audio = True
switch_on = True
else:
play_audio = False
switch_on = False
###### ###### ###### ###### ######
###### Handle Audio Process ######
if play_audio:
if audio_process:
if audio_process.poll() != None:
#Process finished
audio_process = subprocess.Popen(['omxplayer', audio_file], stdin=subprocess.PIPE)
print("Restarting the audio.")
else:
audio_process = subprocess.Popen(['omxplayer', audio_file], stdin=subprocess.PIPE)
print("Starting audio.")
else:
if audio_process:
audio_process.stdin.write('q')
audio_process.stdin.flush()
audio_process.terminate()
audio_process = None
print("Killing audio.")
###### ###### ###### ###### ######
###### Handle Video Process ######
if play_video:
if video_process:
if video_process.poll() != None:
#Process finished
video_process = subprocess.Popen(['omxplayer', video_file], env=new_env)
print("Restarting video.")
else:
video_process = subprocess.Popen(['omxplayer', video_file], env=new_env)
print("Starting video.")
else:
if video_process:
video_process.stdin.write('q')
video_process.stdin.flush()
video_process.terminate()
video_process = None
print("Terminating video.")
###### ###### ###### ###### ######
###### Handle Switch Output ######
gpio.write(switch_out_pin,switch_on)
###### ###### ###### ###### ######