Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: re-enable Mifare Ultralight C support #2214

Merged
merged 8 commits into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion components/rfid-reader/RC522/setup_rc522.sh
Original file line number Diff line number Diff line change
@@ -16,6 +16,13 @@ question() {
printf "Please make sure that the RC522 reader is wired up correctly to the GPIO ports before continuing...\n"
question "Continue"

printf "Use backward-compatible card ID (not suggested for new installations)?\n"
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;;
esac

printf "Installing Python requirements for RC522...\n"
sudo python3 -m pip install --upgrade --force-reinstall -q -r "${JUKEBOX_HOME_DIR}"/components/rfid-reader/RC522/requirements.txt

@@ -29,6 +36,6 @@ sudo chown pi:www-data "${JUKEBOX_HOME_DIR}"/scripts/deviceName.txt
sudo chmod 644 "${JUKEBOX_HOME_DIR}"/scripts/deviceName.txt

printf "Restarting phoniebox-rfid-reader service...\n"
sudo systemctl start phoniebox-rfid-reader.service
sudo systemctl restart phoniebox-rfid-reader.service

printf "Done.\n"
24 changes: 21 additions & 3 deletions scripts/Reader.py.experimental
Original file line number Diff line number Diff line change
@@ -50,11 +50,13 @@ class UsbReader(object):


class Mfrc522Reader(object):
def __init__(self):
def __init__(self, readmode_uid=False):
import pirc522
self.device = pirc522.RFID()
self.readmode_uid = readmode_uid
self.readCard = self.readCard_normal if self.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()
@@ -70,6 +72,17 @@ 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

@staticmethod
def cleanup():
GPIO.cleanup()
@@ -188,9 +201,14 @@ 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()
self.reader = Mfrc522Reader(readmode_uid)
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'}
12 changes: 12 additions & 0 deletions scripts/inc.writeGlobalConfig.sh
Original file line number Diff line number Diff line change
@@ -109,6 +109,16 @@ fi
# 2. then|or read value from file
SECONDSWIPEPAUSECONTROLS=`cat $PATHDATA/../settings/Second_Swipe_Pause_Controls`

##############################################
# RFID reader rc522 readmode UID
# 1. create a default if file does not exist
if [ ! -f $PATHDATA/../settings/Rfidreader_Rc522_Readmode_UID ]; then
echo "OFF" > $PATHDATA/../settings/Rfidreader_Rc522_Readmode_UID
chmod 777 $PATHDATA/../settings/Rfidreader_Rc522_Readmode_UID
fi
# 2. then|or read value from file
RFIDREADERRC522READMODEUID=`cat $PATHDATA/../settings/Rfidreader_Rc522_Readmode_UID`

##############################################
# Audio_iFace_Name
# 1. create a default if file does not exist
@@ -332,6 +342,7 @@ CMDSEEKBACK=`grep 'CMDSEEKBACK' $PATHDATA/../settings/rfid_trigger_play.conf|tai
# SECONDSWIPE
# SECONDSWIPEPAUSE
# SECONDSWIPEPAUSECONTROLS
# RFIDREADERRC522READMODEUID
# AUDIOIFACENAME
# AUDIOIFACEACTIVE
# VOLUMEMANAGER
@@ -369,6 +380,7 @@ echo "SWIPEORPLACE=\"${SWIPEORPLACE}\"" >> "${PATHDATA}/../settings/global.conf"
echo "SECONDSWIPE=\"${SECONDSWIPE}\"" >> "${PATHDATA}/../settings/global.conf"
echo "SECONDSWIPEPAUSE=\"${SECONDSWIPEPAUSE}\"" >> "${PATHDATA}/../settings/global.conf"
echo "SECONDSWIPEPAUSECONTROLS=\"${SECONDSWIPEPAUSECONTROLS}\"" >> "${PATHDATA}/../settings/global.conf"
echo "RFIDREADERRC522READMODEUID=\"${RFIDREADERRC522READMODEUID}\"" >> "${PATHDATA}/../settings/global.conf"
echo "AUDIOIFACENAME=\"${AUDIOIFACENAME}\"" >> "${PATHDATA}/../settings/global.conf"
echo "AUDIOIFACEACTIVE=\"${AUDIOIFACEACTIVE}\"" >> "${PATHDATA}/../settings/global.conf"
echo "VOLUMEMANAGER=\"${VOLUMEMANAGER}\"" >> "${PATHDATA}/../settings/global.conf"
5 changes: 3 additions & 2 deletions scripts/installscripts/tests/run_installation_tests2.sh
Original file line number Diff line number Diff line change
@@ -24,10 +24,11 @@ echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selecti
# y use gpio
# y RFID registration
# 2 use RC522 reader
# yes, reader is connected
# y, reader is connected
# y, use legacy readermode
# n No reboot

./../install-jukebox.sh <<< $'y\nn\n\nn\n\ny\n\nn\n\ny\n\ny\n\ny\n\ny\ny\n2\ny\nn\n'
./../install-jukebox.sh <<< $'y\nn\n\nn\n\ny\n\nn\n\ny\n\ny\n\ny\n\ny\ny\n2\ny\ny\nn\n'
INSTALLATION_EXITCODE=$?

# Test installation