Class RfidComponent


public class RfidComponent extends MFRC522
Implementation of the CrowPi RFID component using SPI with Pi4J
  • Field Details

    • DEFAULT_RESET_PIN

      protected static final int DEFAULT_RESET_PIN
      Default GPIO BCM address of reset pin for RFID component
      See Also:
    • DEFAULT_SPI_CHANNEL

      protected static final int DEFAULT_SPI_CHANNEL
      Default SPI channel for the RFID component on the CrowPi
      See Also:
    • DEFAULT_SPI_BAUD_RATE

      protected static final int DEFAULT_SPI_BAUD_RATE
      Default SPI baud rate for the RFID component on the CrowPi
      See Also:
    • DEFAULT_POLLER_PERIOD_MS

      protected static final long DEFAULT_POLLER_PERIOD_MS
      Default 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 context
      spiChannel - SPI channel
      spiBaud - 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 context
      gpioResetPin - BCM address of GPIO reset pin
      spiChannel - SPI channel
      spiBaud - SPI baud rate
  • Method Details

    • onCardDetected

      public void onCardDetected(EventHandler<RfidCard> handler)
      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

      public void waitForNewCard(EventHandler<RfidCard> handler)
      Blocks current thread until a new card has been detected, then runs the handler and continues.
      See Also:
      • waitForCard(EventHandler, boolean)
    • waitForAnyCard

      public void waitForAnyCard(EventHandler<RfidCard> handler)
      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

      protected ScheduledFuture<?> 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