2014년 7월 30일 수요일
Raspberry PI MP3 Player Temp Source
from time import sleep
import os
from subprocess import Popen, PIPE
import RPi.GPIO as GPIO
import pyinotify
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN)
GPIO.setup(27, GPIO.IN)
GPIO.setup(25, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(23, GPIO.IN)
GPIO.setup(18, GPIO.IN)
startDelay = 20
sw = [1, 1, 1, 1, 1, 1]
swold = [1, 1, 1, 1, 1, 1]
p = Popen(['mpg321', '-R', 'n', '-g', '100'], stdin=PIPE, stdout=PIPE)
wm = pyinotify.WatchManager()
mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CREATE(self, event):
print "Create: %s" % event.pathname
p.stdin.write('STOP\n')
def process_IN_DELETE(self, event):
print "Remove: %s" % event.pathname
p.stdin.write('STOP\n')
notifier = pyinotify.ThreadedNotifier(wm, EventHandler())
notifier.start()
wdd = wm.add_watch('/media', mask, rec=True)
while True:
sw[0] = GPIO.input(23)
sw[1] = GPIO.input(18)
sw[2] = GPIO.input(27)
sw[3] = GPIO.input(24)
sw[4] = GPIO.input(22)
sw[5] = GPIO.input(25)
#print(GPIO.input(23), GPIO.input(18), GPIO.input(27), GPIO.input(24), GPIO.input(22), GPIO.input(25))
sleep(0.1)
if( startDelay == 0 ):
for x in range(0, 4):
if( (swold[x] == 0) and (sw[x] == 1) ):
printstr = 'clicked' + str(x)
print(printstr)
cmdStr = 'LOAD /home/pi/320/0' + str(x+1) + '.mp3\n'
p.stdin.write(cmdStr)
if( (swold[4] == 0) and (sw[4] == 1) ):
print('clicked5')
p.stdin.write('STOP\n')
if( (swold[5] == 0) and (sw[5] == 1) ):
print('clicked6')
p.stdin.write('QUIT\n')
wm.rm_watch(wdd.values())
notifier.stop()
exit()
else:
startDelay = startDelay - 1
for x in range(0, 6): swold[x] = sw[x]
# /media/2088-0EBF/Disc1/01.\ Yello\ -\ The\ Race.mp3
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기