diff --git a/components/rfid-reader/RC522/setup_rc522.sh b/components/rfid-reader/RC522/setup_rc522.sh index 3c0e406ae..43ab60fa6 100644 --- a/components/rfid-reader/RC522/setup_rc522.sh +++ b/components/rfid-reader/RC522/setup_rc522.sh @@ -17,7 +17,7 @@ printf "Please make sure that the RC522 reader is wired up correctly to the GPIO question "Continue" printf "Use backward-compatible card ID (not suggested for new installations)?\n" -read -p "(y/n) " choice +read -p "(y/N) " choice case "$choice" in y|Y ) printf "OFF" > "${JUKEBOX_HOME_DIR}"/settings/Rfidreader_Rc522_Readmode_UID;; * ) printf "ON" > "${JUKEBOX_HOME_DIR}"/settings/Rfidreader_Rc522_Readmode_UID;; diff --git a/scripts/Reader.py b/scripts/Reader.py index 3b583da4b..d3c09f2b6 100755 --- a/scripts/Reader.py +++ b/scripts/Reader.py @@ -29,10 +29,8 @@ def get_devices(): class Reader: - reader = None def __init__(self): - self.reader = self path = os.path.dirname(os.path.realpath(__file__)) self.keys = "X^1234567890XXXXqwertzuiopXXXXasdfghjklXXXXXyxcvbnmXXXXXXXXXXXXXXXXXXXXXXX" if not os.path.isfile(path + '/deviceName.txt'): diff --git a/scripts/Reader.py.Multi b/scripts/Reader.py.Multi index e727d7b5d..5e98b4d0f 100644 --- a/scripts/Reader.py.Multi +++ b/scripts/Reader.py.Multi @@ -29,10 +29,8 @@ def get_devices(): class Reader: - reader = None def __init__(self): - self.reader = self devs = list() path = os.path.dirname(os.path.realpath(__file__)) self.keys = "X^1234567890XXXXqwertzuiopXXXXasdfghjklXXXXXyxcvbnmXXXXXXXXXXXXXXXXXXXXXXX" diff --git a/scripts/Reader.py.experimental b/scripts/Reader.py.experimental index 9e8a32d45..e3854f629 100755 --- a/scripts/Reader.py.experimental +++ b/scripts/Reader.py.experimental @@ -50,15 +50,18 @@ class UsbReader(object): class Mfrc522Reader(object): - def __init__(self, readmode_uid=False): + def __init__(self): import pirc522 self.device = pirc522.RFID() - self.readmode_uid = readmode_uid - self.readCard = self.readCard_normal if self.readmode_uid else self.readCard_legacy + path = os.path.dirname(os.path.realpath(__file__)) + readmode_uid = False + if os.path.isfile(path + '/../settings/Rfidreader_Rc522_Readmode_UID'): + with open(path + '/../settings/Rfidreader_Rc522_Readmode_UID', 'r') as f: + readmode_uid = f.read().rstrip().split(';', 1)[0] == 'ON' + self._read_function = self._readCard_normal if readmode_uid else self._readCard_legacy - def readCard_legacy(self): + def _readCard_legacy(self): # Scan for cards - self.device.wait_for_tag() (error, tag_type) = self.device.request() if not error: @@ -72,7 +75,7 @@ class Mfrc522Reader(object): logger.debug("No Device ID found.") return None - def readCard_normal(self): + def _readCard_normal(self): # Scan for cards uid = self.device.read_id(as_number=True) if not uid: @@ -83,6 +86,11 @@ class Mfrc522Reader(object): logger.info(card_id) return card_id + def readCard(self): + # Scan for cards + self.device.wait_for_tag() + return self._read_function() + @staticmethod def cleanup(): GPIO.cleanup() @@ -201,14 +209,9 @@ class Reader(object): else: with open(path + '/deviceName.txt', 'r') as f: device_name = f.read().rstrip().split(';', 1)[0] - if os.path.isfile(path + '/../settings/Rfidreader_Rc522_Readmode_UID'): - with open(path + '/../settings/Rfidreader_Rc522_Readmode_UID', 'r') as f: - readmode_uid = f.read().rstrip().split(';', 1)[0] == 'ON' - else: - readmode_uid = False if device_name == 'MFRC522': - self.reader = Mfrc522Reader(readmode_uid) + self.reader = Mfrc522Reader() elif device_name == 'RDM6300': # The Rdm6300Reader supports 2 Additional Number Formats which can bee choosen by an optional parameter dictionary: # {'numberformat':'card_id_float'} or {'numberformat':'card_id_dec'} @@ -221,3 +224,6 @@ class Reader(object): self.reader = UsbReader(device) except IndexError: sys.exit('Could not find the device %s.\n Make sure it is connected' % device_name) + + def readCard(self): + return self.reader.readCard() diff --git a/scripts/Reader.py.experimental.Multi b/scripts/Reader.py.experimental.Multi index a4626eb5f..b7c4fcb5f 100644 --- a/scripts/Reader.py.experimental.Multi +++ b/scripts/Reader.py.experimental.Multi @@ -70,11 +70,17 @@ class UsbReader(object): class Mfrc522Reader(object): def __init__(self): + import pirc522 self.device = pirc522.RFID() + path = os.path.dirname(os.path.realpath(__file__)) + readmode_uid = False + if os.path.isfile(path + '/../settings/Rfidreader_Rc522_Readmode_UID'): + with open(path + '/../settings/Rfidreader_Rc522_Readmode_UID', 'r') as f: + readmode_uid = f.read().rstrip().split(';', 1)[0] == 'ON' + self._read_function = self._readCard_normal if readmode_uid else self._readCard_legacy - def readCard(self): + def _readCard_legacy(self): # Scan for cards - self.device.wait_for_tag() (error, tag_type) = self.device.request() if not error: @@ -88,6 +94,22 @@ class Mfrc522Reader(object): logger.debug("No Device ID found.") return None + def _readCard_normal(self): + # Scan for cards + uid = self.device.read_id(as_number=True) + if not uid: + logger.debug("No Device ID found.") + return None + card_id = str(uid) + logger.info("Card detected.") + logger.info(card_id) + return card_id + + def readCard(self): + # Scan for cards + self.device.wait_for_tag() + return self._read_function() + @staticmethod def cleanup(): GPIO.cleanup() @@ -158,7 +180,6 @@ class Pn532Reader: class Reader(object): def __init__(self): - self.reader = self self.devs = list() path = os.path.dirname(os.path.realpath(__file__)) if not os.path.isfile(path + '/deviceName.txt'): diff --git a/scripts/Reader.py.original b/scripts/Reader.py.original index 49f1957bc..80a4fabf3 100755 --- a/scripts/Reader.py.original +++ b/scripts/Reader.py.original @@ -30,11 +30,9 @@ def get_devices(): class Reader: - reader = None def __init__(self): logger.debug('Initialize Reader') - self.reader = self path = os.path.dirname(os.path.realpath(__file__)) self.keys = "X^1234567890XXXXqwertzuiopXXXXasdfghjklXXXXXyxcvbnmXXXXXXXXXXXXXXXXXXXXXXX" deviceNameFile = os.path.join(path, 'deviceName.txt') diff --git a/scripts/Reader.py.pcsc b/scripts/Reader.py.pcsc index e0d2cc374..792b29f01 100644 --- a/scripts/Reader.py.pcsc +++ b/scripts/Reader.py.pcsc @@ -12,10 +12,8 @@ from smartcard.util import * class Reader: - reader = None - def __init__(self): - self.reader = self + pass def readCard(self): diff --git a/scripts/daemon_rfid_reader.py b/scripts/daemon_rfid_reader.py index cc643f26d..b37c96bba 100755 --- a/scripts/daemon_rfid_reader.py +++ b/scripts/daemon_rfid_reader.py @@ -85,14 +85,7 @@ def handler(signum, frame): signal.alarm(1) # reading the card id - # NOTE: it's been reported that KKMOON Reader might need the following line altered. - # Instead of: - # cardid = reader.reader.readCard() - # change the line to: - # cardid = reader.readCard() - # See here for (German ;) details: - # https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/551 - cardid = reader.reader.readCard() + cardid = reader.readCard() # disable the alarm after a successful read signal.alarm(0)