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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumeration which represents all known keycodes for the bundled CrowPi IR remoteprotected final class
Poller manager class which implementsRunnable
and should be ran in a separate thread.protected static interface
Custom interface as an alternative to the Java nativeProcess
interface.protected static interface
Functional interface for a poller process factory which creates newIrReceiverComponent.PollerProcess
instances on demand. -
Field Summary
Modifier and TypeFieldDescriptionprotected IrReceiverComponent.PollerProcessFactory
Default poller process factory, should only be changed during tests for proper mocking. -
Constructor Summary
ConstructorDescriptionCreates a new IR receiver using the default binary and kernel device path.IrReceiverComponent
(String mode2Binary, String devicePath) Creates a new IR receiver using a custom mode2 binary and kernel device path. -
Method Summary
Modifier and TypeMethodDescriptionprotected IrReceiverComponent.PollerManager
Returns the instance of the poller manager or null if currently not running.protected Thread
Returns the instance of the poller manager thread or null if currently not running.void
onKeyPressed
(EventHandler<IrReceiverComponent.Key> handler) Sets or disables the handler for received IR key presses.Methods inherited from class com.pi4j.crowpi.components.Component
sleep, triggerSimpleEvent
-
Field Details
-
pollerProcessFactory
Default poller process factory, should only be changed during tests for proper mocking.
-
-
Constructor Details
-
IrReceiverComponent
public IrReceiverComponent()Creates a new IR receiver using the default binary and kernel device path. -
IrReceiverComponent
Creates a new IR receiver using a custom mode2 binary and kernel device path.- Parameters:
mode2Binary
- Path to `mode2` binary provided by LIRCdevicePath
- Absolute path to kernel device, e.g. /dev/lirc0
-
-
Method Details
-
onKeyPressed
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
Returns the instance of the poller manager or null if currently not running.- Returns:
- Poller manager instance or null
-
getPollerManagerThread
Returns the instance of the poller manager thread or null if currently not running.- Returns:
- Poller manager thread or null
-