java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.PirMotionSensorComponent
- All Implemented Interfaces:
DigitalEventProvider<PirMotionSensorComponent.MotionState>
,EventProvider<DigitalEventListener<PirMotionSensorComponent.MotionState>,
,PirMotionSensorComponent.MotionState> SimpleEventProvider<PirMotionSensorComponent.MotionState>
public class PirMotionSensorComponent
extends Component
implements DigitalEventProvider<PirMotionSensorComponent.MotionState>
Implementation of the CrowPi PIR motion sensor using GPIO with Pi4J
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
All available states reported by the PIR motion sensor component. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final int
Default BCM pin of PIR motion sensor for CrowPiprotected final com.pi4j.io.gpio.digital.DigitalInput
Pi4J digital input instance used by this component -
Constructor Summary
ConstructorDescriptionPirMotionSensorComponent
(com.pi4j.context.Context pi4j) Creates a new PIR motion sensor component using the default setup.PirMotionSensorComponent
(com.pi4j.context.Context pi4j, int address) Creates a new PIR motion sensor component with custom GPIO address. -
Method Summary
Modifier and TypeMethodDescriptionprotected com.pi4j.io.gpio.digital.DigitalInputConfig
buildDigitalInputConfig
(com.pi4j.context.Context pi4j, int address) Builds a new DigitalInput instance for the PIR motion sensor.void
Analyzes the given value passed by an event and triggers 0-n simple events based on it.com.pi4j.io.gpio.digital.DigitalInput
Returns the Pi4JDigitalInput
associated with this component.getState()
Returns the current state of the PIR motion sensor.boolean
Checks if the PIR motion sensor currently detects movement.boolean
Checks if the PIR motion sensor currently detects stillstand.mapDigitalState
(com.pi4j.io.gpio.digital.DigitalState digitalState) Maps aDigitalState
to a well-knownPirMotionSensorComponent.MotionState
void
onMovement
(SimpleEventHandler handler) Sets or disables the handler for the onMovement event.void
onStillstand
(SimpleEventHandler handler) Sets or disables the handler for the onStillstand event.Methods inherited from class com.pi4j.crowpi.components.Component
sleep, triggerSimpleEvent
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.pi4j.crowpi.components.events.DigitalEventProvider
addListener, removeListener
-
Field Details
-
digitalInput
protected final com.pi4j.io.gpio.digital.DigitalInput digitalInputPi4J digital input instance used by this component -
DEFAULT_PIN
protected static final int DEFAULT_PINDefault BCM pin of PIR motion sensor for CrowPi- See Also:
-
-
Constructor Details
-
PirMotionSensorComponent
public PirMotionSensorComponent(com.pi4j.context.Context pi4j) Creates a new PIR motion sensor component using the default setup.- Parameters:
pi4j
- Pi4J context
-
PirMotionSensorComponent
public PirMotionSensorComponent(com.pi4j.context.Context pi4j, int address) Creates a new PIR motion sensor component with custom GPIO address.- Parameters:
pi4j
- Pi4J contextaddress
- GPIO address of PIR motion sensor
-
-
Method Details
-
getState
Returns the current state of the PIR motion sensor.- Returns:
- Current motion sensor state
-
hasMovement
public boolean hasMovement()Checks if the PIR motion sensor currently detects movement.- Returns:
- True if movement was detected
-
hasStillstand
public boolean hasStillstand()Checks if the PIR motion sensor currently detects stillstand.- Returns:
- True if stillstand was detected
-
dispatchSimpleEvents
Analyzes the given value passed by an event and triggers 0-n simple events based on it. This method allows mapping various value/state changes to simple events. Must be attached usingDigitalEventProvider.addListener(EventHandler)
.- Specified by:
dispatchSimpleEvents
in interfaceSimpleEventProvider<PirMotionSensorComponent.MotionState>
- Parameters:
state
- Event value
-
onMovement
Sets or disables the handler for the onMovement event. This event gets triggered whenever the sensor detects movement. Only a single event handler can be registered at once.- Parameters:
handler
- Event handler to call or null to disable
-
onStillstand
Sets or disables the handler for the onStillstand event. This event gets triggered whenever the sensor detects stillstand. Only a single event handler can be registered at once.- Parameters:
handler
- Event handler to call or null to disable
-
getDigitalInput
public com.pi4j.io.gpio.digital.DigitalInput getDigitalInput()Returns the Pi4JDigitalInput
associated with this component.- Specified by:
getDigitalInput
in interfaceDigitalEventProvider<PirMotionSensorComponent.MotionState>
- Returns:
- Pi4J
DigitalInput
instance
-
mapDigitalState
public PirMotionSensorComponent.MotionState mapDigitalState(com.pi4j.io.gpio.digital.DigitalState digitalState) Maps aDigitalState
to a well-knownPirMotionSensorComponent.MotionState
- Specified by:
mapDigitalState
in interfaceDigitalEventProvider<PirMotionSensorComponent.MotionState>
- Parameters:
digitalState
- Pi4J digital state to map- Returns:
- Mapped motion state
-
buildDigitalInputConfig
protected com.pi4j.io.gpio.digital.DigitalInputConfig buildDigitalInputConfig(com.pi4j.context.Context pi4j, int address) Builds a new DigitalInput instance for the PIR motion sensor.- Parameters:
pi4j
- Pi4J contextaddress
- GPIO address of PIR motion sensor- Returns:
- DigitalInput configuration
-