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
Nested ClassesModifier and TypeClassDescriptionstatic enumAll available states reported by the PIR motion sensor component. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intDefault BCM pin of PIR motion sensor for CrowPiprotected final com.pi4j.io.gpio.digital.DigitalInputPi4J digital input instance used by this component -
Constructor Summary
ConstructorsConstructorDescriptionPirMotionSensorComponent(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.DigitalInputConfigbuildDigitalInputConfig(com.pi4j.context.Context pi4j, int address) Builds a new DigitalInput instance for the PIR motion sensor.voidAnalyzes the given value passed by an event and triggers 0-n simple events based on it.com.pi4j.io.gpio.digital.DigitalInputReturns the Pi4JDigitalInputassociated with this component.getState()Returns the current state of the PIR motion sensor.booleanChecks if the PIR motion sensor currently detects movement.booleanChecks if the PIR motion sensor currently detects stillstand.mapDigitalState(com.pi4j.io.gpio.digital.DigitalState digitalState) Maps aDigitalStateto a well-knownPirMotionSensorComponent.MotionStatevoidonMovement(SimpleEventHandler handler) Sets or disables the handler for the onMovement event.voidonStillstand(SimpleEventHandler handler) Sets or disables the handler for the onStillstand event.Methods inherited from class com.pi4j.crowpi.components.Component
sleep, triggerSimpleEventMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
dispatchSimpleEventsin 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 Pi4JDigitalInputassociated with this component.- Specified by:
getDigitalInputin interfaceDigitalEventProvider<PirMotionSensorComponent.MotionState>- Returns:
- Pi4J
DigitalInputinstance
-
mapDigitalState
public PirMotionSensorComponent.MotionState mapDigitalState(com.pi4j.io.gpio.digital.DigitalState digitalState) Maps aDigitalStateto a well-knownPirMotionSensorComponent.MotionState- Specified by:
mapDigitalStatein 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
-