From 2b495dd488b0f0cb3e9390e3f028101a0b3bd944 Mon Sep 17 00:00:00 2001 From: Tilman Date: Fri, 30 Nov 2018 13:32:00 +0000 Subject: [PATCH] Update piplayer4.py --- code/piplayer4.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/code/piplayer4.py b/code/piplayer4.py index ca310b9..8dfb906 100644 --- a/code/piplayer4.py +++ b/code/piplayer4.py @@ -1,5 +1,5 @@ -# piplayer3 - AudioLauncher -# http://www.tilman.de/piplayer3 +# piplayer4 - AudioLauncher +# http://www.tilman.de/piplayer4 import RPi.GPIO as GPIO 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.info('Initializing') +logging.info('Initializing TEST') # Configuration MUSIC_BASE_DIRECTORY = "mnt/NAS/" @@ -23,11 +23,8 @@ SOUND_PLAYBACK_ERROR = "~/sounds/error.mp3" QR_SCANNER_TIMEOUT = 3 -pending_play = False -is_paused = True - # photo sensor on PIN 17 -PIN_SENSOR = 17 +PIN_SENSOR = 4 # TEST # IR LED on PIN 22 PIN_IR_LED = 22 @@ -40,11 +37,9 @@ PIN_PREV = 9 PIN_PLAY = 10 PIN_NEXT = 11 -socketIO = SocketIO('127.0.0.1', 3000) - 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.output(PIN_IR_LED, GPIO.LOW) 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) +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): socketIO.emit('clearQueue') @@ -99,14 +99,14 @@ GPIO.add_event_detect(PIN_NEXT, GPIO.FALLING, callback=next_callback, bouncetime try: # play_sound(SOUND_OK) - socketIO.on('pushQueue', on_pushQueue) + #socketIO.on('pushQueue', on_pushQueue) while True: 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') - play_sound(SOUND_SCANNING) + #play_sound(SOUND_SCANNING) # turn LED on GPIO.output(PIN_LED, GPIO.HIGH) @@ -126,8 +126,8 @@ try: if (poll_result): # play confirmation sound - play_sound(SOUND_OK) - socketIO.emit('removeFromQueue', 0) + #play_sound(SOUND_OK) + #socketIO.emit('removeFromQueue', 0) qr_code = zbarcam.stdout.readline().rstrip() qr_code = qr_code.decode("utf-8") # python3 @@ -135,7 +135,7 @@ try: pending_play = True - if (not (qr_code.startswith("http://")): + if (not qr_code.startswith("http://")): # create full path if (qr_code.startswith("/")): qr_code = qr_code[1:] @@ -144,6 +144,8 @@ try: else: socketIO.emit('addToQueue', {'service':'webradio','uri':qr_code}) + socketIO.emit('play') + else: logging.warning('Timeout on zbarcam') play_sound(SOUND_SCAN_FAIL)