Update piplayer4.py
This commit is contained in:
+18
-16
@@ -1,5 +1,5 @@
|
|||||||
# piplayer3 - AudioLauncher
|
# piplayer4 - AudioLauncher
|
||||||
# http://www.tilman.de/piplayer3
|
# http://www.tilman.de/piplayer4
|
||||||
|
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
import logging
|
import logging
|
||||||
@@ -12,7 +12,7 @@ from socketIO_client import SocketIO, LoggingNamespace # https://gist.github.com
|
|||||||
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s - %(message)s')
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s - %(message)s')
|
||||||
logging.info('Initializing')
|
logging.info('Initializing TEST')
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
MUSIC_BASE_DIRECTORY = "mnt/NAS/"
|
MUSIC_BASE_DIRECTORY = "mnt/NAS/"
|
||||||
@@ -23,11 +23,8 @@ SOUND_PLAYBACK_ERROR = "~/sounds/error.mp3"
|
|||||||
QR_SCANNER_TIMEOUT = 3
|
QR_SCANNER_TIMEOUT = 3
|
||||||
|
|
||||||
|
|
||||||
pending_play = False
|
|
||||||
is_paused = True
|
|
||||||
|
|
||||||
# photo sensor on PIN 17
|
# photo sensor on PIN 17
|
||||||
PIN_SENSOR = 17
|
PIN_SENSOR = 4 # TEST
|
||||||
|
|
||||||
# IR LED on PIN 22
|
# IR LED on PIN 22
|
||||||
PIN_IR_LED = 22
|
PIN_IR_LED = 22
|
||||||
@@ -40,11 +37,9 @@ PIN_PREV = 9
|
|||||||
PIN_PLAY = 10
|
PIN_PLAY = 10
|
||||||
PIN_NEXT = 11
|
PIN_NEXT = 11
|
||||||
|
|
||||||
socketIO = SocketIO('127.0.0.1', 3000)
|
|
||||||
|
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
GPIO.setup(PIN_SENSOR, GPIO.IN)
|
GPIO.setup(PIN_SENSOR, GPIO.IN, pull_up_down=GPIO.PUD_UP) # TEST
|
||||||
GPIO.setup(PIN_IR_LED, GPIO.OUT)
|
GPIO.setup(PIN_IR_LED, GPIO.OUT)
|
||||||
GPIO.output(PIN_IR_LED, GPIO.LOW)
|
GPIO.output(PIN_IR_LED, GPIO.LOW)
|
||||||
GPIO.setup(PIN_LED, GPIO.OUT)
|
GPIO.setup(PIN_LED, GPIO.OUT)
|
||||||
@@ -54,6 +49,11 @@ GPIO.setup(PIN_PLAY, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
|||||||
GPIO.setup(PIN_NEXT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
GPIO.setup(PIN_NEXT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
|
|
||||||
|
|
||||||
|
pending_play = False # to determine whether we should send a play command when we receive a pushQueue event
|
||||||
|
is_paused = True # for toggling play/pause
|
||||||
|
|
||||||
|
socketIO = SocketIO('127.0.0.1', 3000)
|
||||||
|
|
||||||
|
|
||||||
def play_sound(filename):
|
def play_sound(filename):
|
||||||
socketIO.emit('clearQueue')
|
socketIO.emit('clearQueue')
|
||||||
@@ -99,14 +99,14 @@ GPIO.add_event_detect(PIN_NEXT, GPIO.FALLING, callback=next_callback, bouncetime
|
|||||||
try:
|
try:
|
||||||
# play_sound(SOUND_OK)
|
# play_sound(SOUND_OK)
|
||||||
|
|
||||||
socketIO.on('pushQueue', on_pushQueue)
|
#socketIO.on('pushQueue', on_pushQueue)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
logging.info('Wait for photo sensor')
|
logging.info('Wait for photo sensor')
|
||||||
GPIO.wait_for_edge(PIN_SENSOR, GPIO.RISING)
|
GPIO.wait_for_edge(PIN_SENSOR, GPIO.FALLING) # TEST
|
||||||
|
|
||||||
logging.info('Photo sensor active, activating light and camera')
|
logging.info('Photo sensor active, activating light and camera')
|
||||||
play_sound(SOUND_SCANNING)
|
#play_sound(SOUND_SCANNING)
|
||||||
|
|
||||||
# turn LED on
|
# turn LED on
|
||||||
GPIO.output(PIN_LED, GPIO.HIGH)
|
GPIO.output(PIN_LED, GPIO.HIGH)
|
||||||
@@ -126,8 +126,8 @@ try:
|
|||||||
if (poll_result):
|
if (poll_result):
|
||||||
|
|
||||||
# play confirmation sound
|
# play confirmation sound
|
||||||
play_sound(SOUND_OK)
|
#play_sound(SOUND_OK)
|
||||||
socketIO.emit('removeFromQueue', 0)
|
#socketIO.emit('removeFromQueue', 0)
|
||||||
|
|
||||||
qr_code = zbarcam.stdout.readline().rstrip()
|
qr_code = zbarcam.stdout.readline().rstrip()
|
||||||
qr_code = qr_code.decode("utf-8") # python3
|
qr_code = qr_code.decode("utf-8") # python3
|
||||||
@@ -135,7 +135,7 @@ try:
|
|||||||
|
|
||||||
pending_play = True
|
pending_play = True
|
||||||
|
|
||||||
if (not (qr_code.startswith("http://")):
|
if (not qr_code.startswith("http://")):
|
||||||
# create full path
|
# create full path
|
||||||
if (qr_code.startswith("/")):
|
if (qr_code.startswith("/")):
|
||||||
qr_code = qr_code[1:]
|
qr_code = qr_code[1:]
|
||||||
@@ -144,6 +144,8 @@ try:
|
|||||||
else:
|
else:
|
||||||
socketIO.emit('addToQueue', {'service':'webradio','uri':qr_code})
|
socketIO.emit('addToQueue', {'service':'webradio','uri':qr_code})
|
||||||
|
|
||||||
|
socketIO.emit('play')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.warning('Timeout on zbarcam')
|
logging.warning('Timeout on zbarcam')
|
||||||
play_sound(SOUND_SCAN_FAIL)
|
play_sound(SOUND_SCAN_FAIL)
|
||||||
|
|||||||
Reference in New Issue
Block a user