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
Nested ClassesModifier and TypeClassDescriptionstatic enumAll available states reported by the touch sensor component. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final longDebounce of input in microsecondsprotected static final intDefault Pin of touch sensorprotected final com.pi4j.io.gpio.digital.DigitalInputPi4J digital input instance used by this component -
Constructor Summary
ConstructorsConstructorDescriptionTouchSensorComponent(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.DigitalInputConfigbuildDigitalInputConfig(com.pi4j.context.Context pi4j, int address, long debounce) Configure Digital InputvoidAnalyzes 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 touch sensorbooleanMethod to check if touch sensor is currently touchedmapDigitalState(com.pi4j.io.gpio.digital.DigitalState digitalState) Maps aDigitalStateto a well-knownTouchSensorComponent.TouchStatevoidonRelease(SimpleEventHandler handler) Sets or disables the handler for the onRelease event.voidonTouch(SimpleEventHandler handler) Sets or disables the handler for the onTouch 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 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 aDigitalStateto a well-knownTouchSensorComponent.TouchState- Specified by:
mapDigitalStatein 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:
dispatchSimpleEventsin 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 Pi4JDigitalInputassociated with this component.- Specified by:
getDigitalInputin interfaceDigitalEventProvider<TouchSensorComponent.TouchState>- Returns:
- Pi4J
DigitalInputinstance
-
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
-