Class IrReceiverComponent

java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.IrReceiverComponent

public class IrReceiverComponent extends Component
Implementation of the CrowPi IR receiver /not/ using GPIO with Pi4J

Unfortunately the tight timing constraints of the infrared receiver which are in the area of microseconds can not be handled by the JVM. While Pi4J does not drop any event and still processes them reliably, the timing is too far off to be useful for any signal processing. As the bundled IR remote of the CrowPi can be used as a great input device, this class provides an alternative without Pi4J.

The binary `mode2` provided by the LIRC software package is being used to record the pulses of the IR transmitter / remote. This implementation will automatically run `mode2` pointed towards a `lirc` kernel device and parses its output to recognize IR signals. While receiving the pulses is done outside of Java, all the processing and handling is still being covered as part of this class.

  • Field Details

  • Constructor Details

    • IrReceiverComponent

      public IrReceiverComponent()
      Creates a new IR receiver using the default binary and kernel device path.
    • IrReceiverComponent

      public IrReceiverComponent(String mode2Binary, String devicePath)
      Creates a new IR receiver using a custom mode2 binary and kernel device path.
      Parameters:
      mode2Binary - Path to `mode2` binary provided by LIRC
      devicePath - Absolute path to kernel device, e.g. /dev/lirc0
  • Method Details

    • onKeyPressed

      public void onKeyPressed(EventHandler<IrReceiverComponent.Key> handler)
      Sets or disables the handler for received IR key presses. This will automatically start or stop the poller as needed.
      Parameters:
      handler - Event handler to call or null to disable
    • getPollerManager

      protected IrReceiverComponent.PollerManager getPollerManager()
      Returns the instance of the poller manager or null if currently not running.
      Returns:
      Poller manager instance or null
    • getPollerManagerThread

      protected Thread getPollerManagerThread()
      Returns the instance of the poller manager thread or null if currently not running.
      Returns:
      Poller manager thread or null