Package com.tinkerforge
Class BrickletDistanceUS
- java.lang.Object
-
- com.tinkerforge.DeviceBase
-
- com.tinkerforge.Device
-
- com.tinkerforge.BrickletDistanceUS
-
public class BrickletDistanceUS extends Device
Measures distance between 2cm and 400cm with ultrasound
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BrickletDistanceUS.DistanceCallbackThreshold
static interface
BrickletDistanceUS.DistanceListener
This listener is triggered periodically with the period that is set bysetDistanceCallbackPeriod(long)
.static interface
BrickletDistanceUS.DistanceReachedListener
This listener is triggered when the threshold as set bysetDistanceCallbackThreshold(char, int, int)
is reached.-
Nested classes/interfaces inherited from class com.tinkerforge.Device
Device.Identity
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEVICE_DISPLAY_NAME
static int
DEVICE_IDENTIFIER
static byte
FUNCTION_GET_DEBOUNCE_PERIOD
static byte
FUNCTION_GET_DISTANCE_CALLBACK_PERIOD
static byte
FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD
static byte
FUNCTION_GET_DISTANCE_VALUE
static byte
FUNCTION_GET_IDENTITY
static byte
FUNCTION_GET_MOVING_AVERAGE
static byte
FUNCTION_SET_DEBOUNCE_PERIOD
static byte
FUNCTION_SET_DISTANCE_CALLBACK_PERIOD
static byte
FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD
static byte
FUNCTION_SET_MOVING_AVERAGE
static char
THRESHOLD_OPTION_GREATER
static char
THRESHOLD_OPTION_INSIDE
static char
THRESHOLD_OPTION_OFF
static char
THRESHOLD_OPTION_OUTSIDE
static char
THRESHOLD_OPTION_SMALLER
-
Constructor Summary
Constructors Constructor Description BrickletDistanceUS(java.lang.String uid, IPConnection ipcon)
Creates an object with the unique device ID \c uid.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDistanceListener(BrickletDistanceUS.DistanceListener listener)
Adds a Distance listener.void
addDistanceReachedListener(BrickletDistanceUS.DistanceReachedListener listener)
Adds a DistanceReached listener.long
getDebouncePeriod()
Returns the debounce period as set bysetDebouncePeriod(long)
.long
getDistanceCallbackPeriod()
Returns the period as set bysetDistanceCallbackPeriod(long)
.BrickletDistanceUS.DistanceCallbackThreshold
getDistanceCallbackThreshold()
Returns the threshold as set bysetDistanceCallbackThreshold(char, int, int)
.int
getDistanceValue()
Returns the current distance value measured by the sensor.Device.Identity
getIdentity()
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.short
getMovingAverage()
Returns the length moving average as set bysetMovingAverage(short)
.void
removeDistanceListener(BrickletDistanceUS.DistanceListener listener)
Removes a Distance listener.void
removeDistanceReachedListener(BrickletDistanceUS.DistanceReachedListener listener)
Removes a DistanceReached listener.void
setDebouncePeriod(long debounce)
Sets the period with which the threshold listeners *BrickletDistanceUS.DistanceReachedListener
, are triggered, if the thresholds *setDistanceCallbackThreshold(char, int, int)
, keep being reached.void
setDistanceCallbackPeriod(long period)
Sets the period with which theBrickletDistanceUS.DistanceListener
listener is triggered periodically.void
setDistanceCallbackThreshold(char option, int min, int max)
Sets the thresholds for theBrickletDistanceUS.DistanceReachedListener
listener.void
setMovingAverage(short average)
Sets the length of a `moving averaging <https://en.wikipedia.org/wiki/Moving_average>`__ for the distance value.-
Methods inherited from class com.tinkerforge.DeviceBase
getAPIVersion, getResponseExpected, setResponseExpected, setResponseExpectedAll
-
-
-
-
Field Detail
-
DEVICE_IDENTIFIER
public static final int DEVICE_IDENTIFIER
- See Also:
- Constant Field Values
-
DEVICE_DISPLAY_NAME
public static final java.lang.String DEVICE_DISPLAY_NAME
- See Also:
- Constant Field Values
-
FUNCTION_GET_DISTANCE_VALUE
public static final byte FUNCTION_GET_DISTANCE_VALUE
- See Also:
- Constant Field Values
-
FUNCTION_SET_DISTANCE_CALLBACK_PERIOD
public static final byte FUNCTION_SET_DISTANCE_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_DISTANCE_CALLBACK_PERIOD
public static final byte FUNCTION_GET_DISTANCE_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD
public static final byte FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD
- See Also:
- Constant Field Values
-
FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD
public static final byte FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD
- See Also:
- Constant Field Values
-
FUNCTION_SET_DEBOUNCE_PERIOD
public static final byte FUNCTION_SET_DEBOUNCE_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_DEBOUNCE_PERIOD
public static final byte FUNCTION_GET_DEBOUNCE_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_SET_MOVING_AVERAGE
public static final byte FUNCTION_SET_MOVING_AVERAGE
- See Also:
- Constant Field Values
-
FUNCTION_GET_MOVING_AVERAGE
public static final byte FUNCTION_GET_MOVING_AVERAGE
- See Also:
- Constant Field Values
-
FUNCTION_GET_IDENTITY
public static final byte FUNCTION_GET_IDENTITY
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_OFF
public static final char THRESHOLD_OPTION_OFF
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_OUTSIDE
public static final char THRESHOLD_OPTION_OUTSIDE
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_INSIDE
public static final char THRESHOLD_OPTION_INSIDE
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_SMALLER
public static final char THRESHOLD_OPTION_SMALLER
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_GREATER
public static final char THRESHOLD_OPTION_GREATER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BrickletDistanceUS
public BrickletDistanceUS(java.lang.String uid, IPConnection ipcon)
Creates an object with the unique device ID \c uid. and adds it to the IP Connection \c ipcon.
-
-
Method Detail
-
getDistanceValue
public int getDistanceValue() throws TinkerforgeException
Returns the current distance value measured by the sensor. A small value corresponds to a small distance, a big value corresponds to a big distance. The relation between the measured distance value and the actual distance is affected by the 5V supply voltage (deviations in the supply voltage result in deviations in the distance values) and is non-linear (resolution is bigger at close range). If you want to get the distance value periodically, it is recommended to use theBrickletDistanceUS.DistanceListener
listener and set the period withsetDistanceCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setDistanceCallbackPeriod
public void setDistanceCallbackPeriod(long period) throws TinkerforgeException
Sets the period with which theBrickletDistanceUS.DistanceListener
listener is triggered periodically. A value of 0 turns the listener off. DerBrickletDistanceUS.DistanceListener
listener is only triggered if the distance value has changed since the last triggering.- Throws:
TinkerforgeException
-
getDistanceCallbackPeriod
public long getDistanceCallbackPeriod() throws TinkerforgeException
Returns the period as set bysetDistanceCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setDistanceCallbackThreshold
public void setDistanceCallbackThreshold(char option, int min, int max) throws TinkerforgeException
Sets the thresholds for theBrickletDistanceUS.DistanceReachedListener
listener. The following options are possible: \verbatim "Option", "Description" "'x'", "Listener is turned off" "'o'", "Listener is triggered when the distance value is *outside* the min and max values" "'i'", "Listener is triggered when the distance value is *inside* the min and max values" "'<'", "Listener is triggered when the distance value is smaller than the min value (max is ignored)" "'>'", "Listener is triggered when the distance value is greater than the min value (max is ignored)" \endverbatim- Throws:
TinkerforgeException
-
getDistanceCallbackThreshold
public BrickletDistanceUS.DistanceCallbackThreshold getDistanceCallbackThreshold() throws TinkerforgeException
Returns the threshold as set bysetDistanceCallbackThreshold(char, int, int)
.- Throws:
TinkerforgeException
-
setDebouncePeriod
public void setDebouncePeriod(long debounce) throws TinkerforgeException
Sets the period with which the threshold listeners *BrickletDistanceUS.DistanceReachedListener
, are triggered, if the thresholds *setDistanceCallbackThreshold(char, int, int)
, keep being reached.- Throws:
TinkerforgeException
-
getDebouncePeriod
public long getDebouncePeriod() throws TinkerforgeException
Returns the debounce period as set bysetDebouncePeriod(long)
.- Throws:
TinkerforgeException
-
setMovingAverage
public void setMovingAverage(short average) throws TinkerforgeException
Sets the length of a `moving averaging <https://en.wikipedia.org/wiki/Moving_average>`__ for the distance value. Setting the length to 0 will turn the averaging completely off. With less averaging, there is more noise on the data.- Throws:
TinkerforgeException
-
getMovingAverage
public short getMovingAverage() throws TinkerforgeException
Returns the length moving average as set bysetMovingAverage(short)
.- Throws:
TinkerforgeException
-
getIdentity
public Device.Identity getIdentity() throws TinkerforgeException
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier. The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at position 'z'. The device identifier numbers can be found :ref:`here <device_identifier>`. |device_identifier_constant|- Specified by:
getIdentity
in classDevice
- Throws:
TinkerforgeException
-
addDistanceListener
public void addDistanceListener(BrickletDistanceUS.DistanceListener listener)
Adds a Distance listener.
-
removeDistanceListener
public void removeDistanceListener(BrickletDistanceUS.DistanceListener listener)
Removes a Distance listener.
-
addDistanceReachedListener
public void addDistanceReachedListener(BrickletDistanceUS.DistanceReachedListener listener)
Adds a DistanceReached listener.
-
removeDistanceReachedListener
public void removeDistanceReachedListener(BrickletDistanceUS.DistanceReachedListener listener)
Removes a DistanceReached listener.
-
-