java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.TouchSensorComponent
- All Implemented Interfaces:
DigitalEventProvider<TouchSensorComponent.TouchState>
,EventProvider<DigitalEventListener<TouchSensorComponent.TouchState>,
,TouchSensorComponent.TouchState> SimpleEventProvider<TouchSensorComponent.TouchState>
public class TouchSensorComponent
extends Component
implements DigitalEventProvider<TouchSensorComponent.TouchState>
Implementation of the CrowPi touch sensor using GPIO with Pi4J
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
All available states reported by the touch sensor component. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final long
Debounce of input in microsecondsprotected static final int
Default Pin of touch sensorprotected final com.pi4j.io.gpio.digital.DigitalInput
Pi4J digital input instance used by this component -
Constructor Summary
ConstructorDescriptionTouchSensorComponent
(com.pi4j.context.Context pi4j) Creates a new touch sensor component using the default setup.TouchSensorComponent
(com.pi4j.context.Context pi4j, int address, long debounce) Create touch sensor component with custom parameters -
Method Summary
Modifier and TypeMethodDescriptionprotected com.pi4j.io.gpio.digital.DigitalInputConfig
buildDigitalInputConfig
(com.pi4j.context.Context pi4j, int address, long debounce) Configure Digital Inputvoid
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 touch sensorboolean
Method to check if touch sensor is currently touchedmapDigitalState
(com.pi4j.io.gpio.digital.DigitalState digitalState) Maps aDigitalState
to a well-knownTouchSensorComponent.TouchState
void
onRelease
(SimpleEventHandler handler) Sets or disables the handler for the onRelease event.void
onTouch
(SimpleEventHandler handler) Sets or disables the handler for the onTouch 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 Pin of touch sensor- See Also:
-
DEFAULT_DEBOUNCE
protected static final long DEFAULT_DEBOUNCEDebounce of input in microseconds- See Also:
-
-
Constructor Details
-
TouchSensorComponent
public TouchSensorComponent(com.pi4j.context.Context pi4j) Creates a new touch sensor component using the default setup.- Parameters:
pi4j
- Pi4J context
-
TouchSensorComponent
public TouchSensorComponent(com.pi4j.context.Context pi4j, int address, long debounce) Create touch sensor component with custom parameters- Parameters:
pi4j
- Pi4J contextaddress
- GPIO Pin of Raspberrydebounce
- Time in Microseconds to debounce input
-
-
Method Details
-
getState
Returns the current state of the touch sensor- Returns:
- Current touch sensor state
-
mapDigitalState
public TouchSensorComponent.TouchState mapDigitalState(com.pi4j.io.gpio.digital.DigitalState digitalState) Maps aDigitalState
to a well-knownTouchSensorComponent.TouchState
- Specified by:
mapDigitalState
in interfaceDigitalEventProvider<TouchSensorComponent.TouchState>
- Parameters:
digitalState
- Pi4J digital state to map- Returns:
- Mapped touch state
-
isTouched
public boolean isTouched()Method to check if touch sensor is currently touched- Returns:
- True if touch sensor is currently touched
-
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<TouchSensorComponent.TouchState>
- Parameters:
state
- Event value
-
onTouch
Sets or disables the handler for the onTouch event. This event gets triggered whenever the sensor is touched. Only a single event handler can be registered at once.- Parameters:
handler
- Event handler to call or null to disable
-
onRelease
Sets or disables the handler for the onRelease event. This event gets triggered whenever the sensor is no longer touched. 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<TouchSensorComponent.TouchState>
- Returns:
- Pi4J
DigitalInput
instance
-
buildDigitalInputConfig
protected com.pi4j.io.gpio.digital.DigitalInputConfig buildDigitalInputConfig(com.pi4j.context.Context pi4j, int address, long debounce) Configure Digital Input- Parameters:
pi4j
- PI4J Contextaddress
- GPIO Address of touch sensordebounce
- debounce time in microseconds- Returns:
- Return Digital Input configuration
-