java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.internal.rfid.MFRC522
com.pi4j.crowpi.components.RfidComponent
Implementation of the CrowPi RFID component using SPI with Pi4J
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final long
Default polling period in milliseconds for detecting new cardsprotected static final int
Default GPIO BCM address of reset pin for RFID componentprotected static final int
Default SPI baud rate for the RFID component on the CrowPiprotected static final int
Default SPI channel for the RFID component on the CrowPi -
Constructor Summary
ConstructorDescriptionRfidComponent
(com.pi4j.context.Context pi4j) Creates a new RFID component with the default reset pin, channel and baud rate.RfidComponent
(com.pi4j.context.Context pi4j, int spiChannel, int spiBaud) Creates a new RFID component with a custom channel, baud rate and no reset pin.RfidComponent
(com.pi4j.context.Context pi4j, Integer gpioResetPin, int spiChannel, int spiBaud) Creates a new RFID component with a custom reset pin, channel and baud rate. -
Method Summary
Modifier and TypeMethodDescriptionprotected ScheduledFuture<?>
Returns the internal scheduled future for the poller thread or null if currently stopped.protected com.pi4j.io.gpio.digital.DigitalOutput
Returns the current reset pin for the RFID component.protected com.pi4j.io.spi.Spi
getSpi()
Returns the current SPI instance for the LED matrix.void
onCardDetected
(EventHandler<RfidCard> handler) Sets or disables the handler for any new card which gets in the proximity of the PCD.protected void
startPoller
(long pollerPeriodMs) (Re-)starts the poller with the desired time period in milliseconds.protected void
Stops the poller immediately, therefore causing RFID cards to be no longer detected.void
waitForAnyCard
(EventHandler<RfidCard> handler) Blocks current thread until any card has been detected, then runs the handler and continues.void
waitForNewCard
(EventHandler<RfidCard> handler) Blocks current thread until a new card has been detected, then runs the handler and continues.Methods inherited from class com.pi4j.crowpi.components.internal.rfid.MFRC522
initializeCard, isAnyCardPresent, isNewCardPresent, mifareAuth, mifareRead, mifareStopCrypto1, mifareWrite, reset, select, setAntennaState, uninitializeCard
Methods inherited from class com.pi4j.crowpi.components.Component
sleep, triggerSimpleEvent
-
Field Details
-
DEFAULT_RESET_PIN
protected static final int DEFAULT_RESET_PINDefault GPIO BCM address of reset pin for RFID component- See Also:
-
DEFAULT_SPI_CHANNEL
protected static final int DEFAULT_SPI_CHANNELDefault SPI channel for the RFID component on the CrowPi- See Also:
-
DEFAULT_SPI_BAUD_RATE
protected static final int DEFAULT_SPI_BAUD_RATEDefault SPI baud rate for the RFID component on the CrowPi- See Also:
-
DEFAULT_POLLER_PERIOD_MS
protected static final long DEFAULT_POLLER_PERIOD_MSDefault polling period in milliseconds for detecting new cards- See Also:
-
-
Constructor Details
-
RfidComponent
public RfidComponent(com.pi4j.context.Context pi4j) Creates a new RFID component with the default reset pin, channel and baud rate.- Parameters:
pi4j
- Pi4J context
-
RfidComponent
public RfidComponent(com.pi4j.context.Context pi4j, int spiChannel, int spiBaud) Creates a new RFID component with a custom channel, baud rate and no reset pin.- Parameters:
pi4j
- Pi4J contextspiChannel
- SPI channelspiBaud
- SPI baud rate
-
RfidComponent
public RfidComponent(com.pi4j.context.Context pi4j, Integer gpioResetPin, int spiChannel, int spiBaud) Creates a new RFID component with a custom reset pin, channel and baud rate.- Parameters:
pi4j
- Pi4J contextgpioResetPin
- BCM address of GPIO reset pinspiChannel
- SPI channelspiBaud
- SPI baud rate
-
-
Method Details
-
onCardDetected
Sets or disables the handler for any new card which gets in the proximity of the PCD. Previously written cards are automatically being ignored due to being in the HALT state.- Parameters:
handler
- Event handler to call when new card is approached
-
waitForNewCard
Blocks current thread until a new card has been detected, then runs the handler and continues.- See Also:
-
waitForCard(EventHandler, boolean)
-
waitForAnyCard
Blocks current thread until any card has been detected, then runs the handler and continues.- See Also:
-
waitForCard(EventHandler, boolean)
-
startPoller
protected void startPoller(long pollerPeriodMs) (Re-)starts the poller with the desired time period in milliseconds. If the poller is already running, it will be cancelled and rescheduled with the given time. The first poll happens immediately in a separate thread and does not get delayed.- Parameters:
pollerPeriodMs
- Polling period in milliseconds
-
stopPoller
protected void stopPoller()Stops the poller immediately, therefore causing RFID cards to be no longer detected. If the poller is already stopped, this method will silently return and do nothing. -
getPoller
Returns the internal scheduled future for the poller thread or null if currently stopped.- Returns:
- Active poller instance or null
-
getResetPin
protected com.pi4j.io.gpio.digital.DigitalOutput getResetPin()Returns the current reset pin for the RFID component.- Returns:
- Reset pin as digital output
-
getSpi
protected com.pi4j.io.spi.Spi getSpi()Returns the current SPI instance for the LED matrix.- Returns:
- SPI instance
-