-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
executable file
·75 lines (64 loc) · 2.03 KB
/
test.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
#!/usr/bin/env python2.7
import RPi.GPIO as GPIO
import signal
import ConfigParser
from pyomxplayer import OMXPlayer
from logbook import Logger
from logbook import SyslogHandler
log = Logger('Door Logger')
error_handler = SyslogHandler('videodoor', level='DEBUG')
with error_handler.applicationbound():
Config = ConfigParser.ConfigParser()
Config.read('/etc/videodoor/videodoor.ini')
SensorPin = Config.getint('hardware','SensorPin')
log.debug('setting up GPIO pin %i...' % SensorPin)
GPIO.setmode(GPIO.BCM)
GPIO.setup(SensorPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
log.debug('done.')
log.debug('Setting up the omxplayer instance...')
File = Config.get('video','File')
Options = Config.get('video','Options')
omx_status = False
log.info('initializing videoplayer with file %s and options %s' % (File, Options))
omx = OMXPlayer(File, Options)
log.debug('done.')
def start_video():
global omx, omx_status
if(omx_status):
log.warn('video already running')
else:
omx.toggle_pause()
omx_status = True
log.info('door opened')
def stop_video():
global omx, omx_status
if(omx_status):
omx.toggle_pause()
omx.previous_chapter()
omx_status = False
log.info('door closed')
else:
log.warn('video not running')
def my_callback2(channel):
global Config
inverse = Config.getboolean('hardware','Inverse')
if GPIO.input(channel) > 0:
if(inverse):
stop_video()
else:
start_video()
else:
if(inverse):
start_video()
else:
stop_video()
GPIO.add_event_detect(23, GPIO.BOTH, callback=my_callback2, bouncetime=100)
try:
log.info('Pausing and waiting for interrupt...')
signal.pause()
log.debug('Something went wrong...')
except KeyboardInterrupt:
GPIO.cleanup()
omx.stop()
GPIO.cleanup()
omx.stop()