java.lang.Object
com.pi4j.crowpi.components.events.FlappingEventProvider<V>
- Type Parameters:
V
- Type of value which gets passed to event handlers.
- All Implemented Interfaces:
EventHandler<V>
Generic event provider to trigger a
SimpleEventHandler
once a value has flapped between two values for a couple times.
The threshold once an event should be dispatched as well as the max idle time can be configured.
Any instance should be registered in a component using EventProvider.addListener(EventHandler)
to actually monitor value changes.-
Constructor Summary
ConstructorDescriptionFlappingEventProvider
(long maxIdleTime, V valueA, V valueB) Initializes a newFlappingEventProvider
with the two given values.FlappingEventProvider
(V valueA, V valueB) Initializes a newFlappingEventProvider
with the two given values. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Implementation ofEventHandler
which must be added as a listener for this event provider to work.void
setOptions
(int threshold, SimpleEventHandler handler) Sets the threshold and event handler for this instance.
-
Constructor Details
-
FlappingEventProvider
Initializes a newFlappingEventProvider
with the two given values. A default maximum idle time between transitions will be used by this method.- Parameters:
valueA
- First value to watch for transitions to second valuevalueB
- Second value to watch for transitions to first value- See Also:
-
FlappingEventProvider
Initializes a newFlappingEventProvider
with the two given values. Whenever the value changes from A to B or vice-versa, an internal counter gets increased. Once a certain threshold has been reached, a user-specified handler will be called.- Parameters:
maxIdleTime
- Maximum idle time between transitions in milliseconds before counter is resetvalueA
- First value to watch for transitions to second valuevalueB
- Second value to watch for transitions to first value
-
-
Method Details
-
setOptions
Sets the threshold and event handler for this instance. These changes will immediately apply and the counter does not get reset.- Parameters:
threshold
- Threshold before event should be firedhandler
- Event handler to call, null to disable
-
handle
Implementation ofEventHandler
which must be added as a listener for this event provider to work. It will track all state changes between value A and B and automatically resets or fires the handler accordingly.- Specified by:
handle
in interfaceEventHandler<V>
- Parameters:
value
- Event value
-