From e5c492360969faefd51eb3aa16ddb79ec913342e Mon Sep 17 00:00:00 2001 From: Annika Backstrom Date: Sat, 8 Apr 2017 01:55:34 +0000 Subject: [PATCH] tag-reader: update to pi-rc522 2.1 This version of pi-rc522 gives us a wait_for_tag() method, greatly reducing CPU usage. --- requirements.txt | 8 ++++++-- tag-reader.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1f07111..f8a6d60 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,7 @@ -pi-rc522==1.1.0 +appdirs==1.4.3 +packaging==16.8 +pi-rc522==2.1.0 +pyparsing==2.2.0 RPi.GPIO==0.6.3 -SPI-Py==1.0 +six==1.10.0 +spidev==3.2 diff --git a/tag-reader.py b/tag-reader.py index 74d6dbc..1881ad6 100644 --- a/tag-reader.py +++ b/tag-reader.py @@ -3,11 +3,21 @@ from pirc522 import RFID import RPi.GPIO as GPIO import sys +import signal + GPIO.setwarnings(False) rdr = RFID() +def sigint_handler(signal, frame): + rdr.cleanup() + sys.exit(0) + +signal.signal(signal.SIGINT, sigint_handler) +signal.signal(signal.SIGTERM, sigint_handler) + while True: + rdr.wait_for_tag() (error, tag_type) = rdr.request() if not error: (error, uid) = rdr.anticoll()