Skip to content

Commit

Permalink
implementing stop on removal for RC522 (see MiczFlor#1097); implement…
Browse files Browse the repository at this point in the history
…ation proposed by @Toqqi in MiczFlor@786ecf4:

Description from @Toqqi:
I used the signal python library to detect when a RC522 RFID reader stops reading in a card ID for one second.
This then triggers the playerpauseforce action in playout_controls.sh.

I then configured the second swipe action to be "resume playback" to achieve the play/pause effect when moving an RFID card to/from the reader.
  • Loading branch information
s-martin committed Oct 25, 2020
1 parent 1f638fe commit 7d26cfc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions scripts/daemon_rfid_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import subprocess
import time
import re
import signal

from Reader import Reader

Expand Down Expand Up @@ -56,7 +57,27 @@
else:
ids = ""


# handler for RFID reading no cardid
def handler(signum, frame):
logger.info('No RFID Signal detected.')
try:
# force pause the player script
logger.info('Trigger Pause Force')
subprocess.call([dir_path + '/playout_controls.sh -c=playerpauseforce -v=0.1'], shell=True)
except OSError as e:
logger.info('Execution of Pause failed.')


# associate the handler to signal alarm
signal.signal(signal.SIGALRM, handler)

while True:
# slow down the card reading while loop
time.sleep(0.2)
# enable the signal alarm (if no card is present for 1 second)
signal.alarm(1)

# reading the card id
# NOTE: it's been reported that KKMOON Reader might need the following line altered.
# Instead of:
Expand All @@ -66,6 +87,10 @@
# See here for (German ;) details:
# https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/551
cardid = reader.reader.readCard()

# disable the alarm after a successful read
signal.alarm(0)

try:
# start the player script and pass on the cardid (but only if new card or otherwise
# "same_id_delay" seconds have passed)
Expand Down

0 comments on commit 7d26cfc

Please sign in to comment.