public class SmoothedInputDevice extends WaitableDigitalInputDevice
Represents a generic input device which takes its value from the number of active events over a specific time period.
This class extends WaitableDigitalInputDevice
with a queue which is added to whenever the input device
is active. The number of the active events in the queue is compared to a
threshold which is used to determine the state of the 'active' property.
Any active events over the specified eventAge are removed by a background thread.
This class is intended for use with devices which exhibit "twitchy" behaviour (such as certain motion sensors).
device
activeHigh
gpio
Constructor and Description |
---|
SmoothedInputDevice(GpioDeviceFactoryInterface deviceFactory,
int gpio,
GpioPullUpDown pud,
int threshold,
int eventAge,
int eventDetectPeriod) |
SmoothedInputDevice(int gpio,
GpioPullUpDown pud,
int threshold,
int eventAge,
int eventDetectPeriod) |
Modifier and Type | Method and Description |
---|---|
int |
getEventAge()
The time in milliseconds to keep items in the queue.
|
int |
getEventDetectPeriod()
How frequently (in milliseconds) to check the state of the queue.
|
int |
getThreshold()
If the number of on events younger than eventAge exceeds this amount,
then 'isActive' will return 'True'.
|
void |
setEventAge(int eventAge)
Set the event age (milliseconds).
|
void |
setThreshold(int threshold)
Set the threshold value in terms of number of on events within the
specified time period that will trigger an on event to any listeners.
|
void |
valueChanged(DigitalInputEvent event) |
disableDeviceListener, waitForActive, waitForActive, waitForInactive, waitForInactive, waitForValue
close, getPullUpDown, getTrigger, getValue, isActive, removeListener, setListener
enableDeviceListener, isActiveHigh, whenActivated, whenDeactivated
addListener, removeAllListeners, removeListener
getGpio
public SmoothedInputDevice(int gpio, GpioPullUpDown pud, int threshold, int eventAge, int eventDetectPeriod) throws RuntimeIOException
gpio
- GPIO to which the device is connected.pud
- Pull up/down configuration, values: NONE, PULL_UP, PULL_DOWN.threshold
- The value above which the device will be considered "on".eventAge
- The time in milliseconds to keep active events in the queue.eventDetectPeriod
- How frequently to check for events.RuntimeIOException
- if an I/O error occurspublic SmoothedInputDevice(GpioDeviceFactoryInterface deviceFactory, int gpio, GpioPullUpDown pud, int threshold, int eventAge, int eventDetectPeriod) throws RuntimeIOException
deviceFactory
- Device factory to use to provision this device.gpio
- GPIO to which the device is connected.pud
- Pull up/down configuration, values: NONE, PULL_UP, PULL_DOWN.threshold
- The value above which the device will be considered "on".eventAge
- The time in milliseconds to keep active events in the queue.eventDetectPeriod
- How frequently to check for events.RuntimeIOException
- if an I/O error occurspublic void valueChanged(DigitalInputEvent event)
valueChanged
in interface InputEventListener<DigitalInputEvent>
valueChanged
in class WaitableDigitalInputDevice
public int getThreshold()
public void setThreshold(int threshold)
threshold
- New threshold value.public int getEventAge()
public void setEventAge(int eventAge)
eventAge
- New event age value (milliseconds).public int getEventDetectPeriod()
Copyright © 2016–2018 mattjlewis. All rights reserved.