Skip to content

Commit

Permalink
Fixed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
powertomato committed Jan 6, 2024
1 parent c122387 commit 319869e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 26 deletions.
21 changes: 7 additions & 14 deletions documentation/developers/rfid/generic_nfcpy.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@ The link above also contains a list of supported devices.
The goal of this module is to handle USB NFC devices, that don't have a HID-keyboard
driver, and thus cannot be used with the [genericusb](genericusb.md) module.

## Installation
> [!NOTE]
> Since nfcpy is a user-space library, it is required to supress the kernel from loading its driver.
> The setup will do this automatically, so make sure the device is connected
> before running the [RFID reader configuration tool](../coreapps.md#RFID-Reader).
Since nfcpy is a user-space library, it is required to supress the kernel from loading its driver:
`echo 'install <DRIVER> /bin/true' > /etc/modprobe.d/disable_<DRIVER>.conf`

Where <DRIVER> is one of the following:
- `pn533_usb` for PN531 PN532 and PN533 based devices connected via USB
- `pn532_uart`\* for PN532 based devices connected via UART (or a UART-to-USB chip)
- `port100`\* for Port100 based devices
- `pn533_usb`\* for RC-S956 based devices

After the driver has been blacklisted. Unplug the device. Then either do `rmmod <DRIVER>`

[!NOTE]
\* Needs to be verified.
# Configuration

By setting `rfid > readers > generic_nfcpy > config > device_path` you can override the
device location. For possible values see the `path` parameter in this [nfcpy documentation](https://nfcpy.readthedocs.io/en/latest/modules/clf.html#nfc.clf.ContactlessFrontend.open)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
""" List of supprted devices https://nfcpy.readthedocs.io/en/latest/overview.html"""
""" List of supported devices https://nfcpy.readthedocs.io/en/latest/overview.html"""
# 40 chars: '========================================'
DESCRIPTION = 'Generic NFCPY NFC Reader Module'
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@
from .description import DESCRIPTION

# Create logger.
# Logging is fully setup. Just replace '.new' with something meaningful and short
logger = logging.getLogger('jb.rfid.new')
logger = logging.getLogger('jb.rfid.nfcpy')
# Get the global handler to the RFID config
cfg = jukebox.cfghandler.get_handler('rfid')




def query_customization() -> dict:
"""
Query the user for reader parameter customization
Expand All @@ -34,19 +31,18 @@ class ReaderClass(ReaderBaseClass):
"""
def __init__(self, reader_cfg_key):
# Create a per-instance logger, just in case the reader will run multiple times in various threads
# Replace '.new' with something meaningful and short
self._logger = logging.getLogger(f'jb.rfid.new({reader_cfg_key})')
self._logger = logging.getLogger(f'jb.rfid.nfcpy({reader_cfg_key})')
# Initialize the super-class. Don't change anything here
super().__init__(reader_cfg_key=reader_cfg_key, description=DESCRIPTION, logger=self._logger)

# Get the configuration from the rfid.yaml:
# Lock config around the access
#with cfg:
# # Get a reference to the actual reader-specific config
# config = cfg.getn('rfid', 'readers', reader_cfg_key, 'config', default=None)
# # No config
with cfg:
# Get a reference to the actual reader-specific config
config = cfg.getn('rfid', 'readers', reader_cfg_key, 'config', default=None)

self.clf = nfc.ContactlessFrontend('usb')
device_path = config.setdefault('device_path', None)
self.clf = nfc.ContactlessFrontend(device_path)

self._keep_running = True

Expand Down
52 changes: 52 additions & 0 deletions src/jukebox/components/rfid/hardware/generic_nfcpy/setup.inc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

usb_devices=$(lsusb | sed -e 's/.*ID \([a-f0-9]\+:[a-f0-9]\+\).*/\1/g')

has_pn533_usb=false
has_port100=false

for dev in $usb_devices; do
if ! $has_pn533_usb && (
[ $dev = "054c:02e1" ] || # Sony RC-S330/S360/S370
[ $dev = "054c:0193" ] || # Sony/NXP PN531 reference board (Sony VID:PID)
[ $dev = "072f:2200" ] || # ACS ACR122U
[ $dev = "04e6:5591" ] || # Identive SCL3711
[ $dev = "04e6:5593" ] || # Identive SCL3712
[ $dev = "04cc:2533" ] || # SensorID StickID
[ $dev = "04cc:0531" ] # Sony/NXP PN531 reference board (NXP VID:PID)
) then
has_pn533_usb=true
log "Found pn53x based device"
elif ! $has_port100 && (
[ $dev = "054c:06c1" ] || # Sony RC-380/S
[ $dev = "054c:06c3" ] # Sony RC-380/P
) then
has_port100=true
log "Found port100 based device"
fi
done

file="/etc/modprobe.d/disable_driver_jukebox_nfcpy.conf"

sh -c "echo > $file"
if $has_pn533_usb; then
rmmod pn533_usb
sudo sh -c "echo 'install pn533_usb /bin/true' >> $file"
fi

if $has_port100; then
rmmod port100
sudo sh -c "echo 'install port100 /bin/true' >> $file"
fi

# The following is not required for functioanlity, but informative to have in the logs
if ! ($has_pn533_usb || $has_port100); then
log "No nfcpy USB devices found, possible UART device"
usb=$(find /dev/ -name 'ttyUSB*')
acm=$(find /dev/ -name 'ttyACM*')
if [ "$usb" = "" ] && [ "$acm" = "" ]; then
log "No nfcpy devices found"
else
log "Possible UART devices: $usb $acm"
fi
fi

0 comments on commit 319869e

Please sign in to comment.