Class PirMotionSensorComponent

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
  • Field Details

    • digitalInput

      protected final com.pi4j.io.gpio.digital.DigitalInput digitalInput
      Pi4J digital input instance used by this component
    • DEFAULT_PIN

      protected static final int DEFAULT_PIN
      Default 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 context
      address - 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

      public void dispatchSimpleEvents(PirMotionSensorComponent.MotionState state)
      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 using DigitalEventProvider.addListener(EventHandler).
      Specified by:
      dispatchSimpleEvents in interface SimpleEventProvider<PirMotionSensorComponent.MotionState>
      Parameters:
      state - Event value
    • onMovement

      public void onMovement(SimpleEventHandler handler)
      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

      public void onStillstand(SimpleEventHandler handler)
      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 Pi4J DigitalInput associated with this component.
      Specified by:
      getDigitalInput in interface DigitalEventProvider<PirMotionSensorComponent.MotionState>
      Returns:
      Pi4J DigitalInput instance
    • mapDigitalState

      public PirMotionSensorComponent.MotionState mapDigitalState(com.pi4j.io.gpio.digital.DigitalState digitalState)
      Maps a DigitalState to a well-known PirMotionSensorComponent.MotionState
      Specified by:
      mapDigitalState in interface DigitalEventProvider<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 context
      address - GPIO address of PIR motion sensor
      Returns:
      DigitalInput configuration