Package com.tinkerforge
Class BrickletDistanceIR
- java.lang.Object
-
- com.tinkerforge.DeviceBase
-
- com.tinkerforge.Device
-
- com.tinkerforge.BrickletDistanceIR
-
public class BrickletDistanceIR extends Device
Measures distance up to 150cm with infrared light
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BrickletDistanceIR.AnalogValueCallbackThreshold
static interface
BrickletDistanceIR.AnalogValueListener
This listener is triggered periodically with the period that is set bysetAnalogValueCallbackPeriod(long)
.static interface
BrickletDistanceIR.AnalogValueReachedListener
This listener is triggered when the threshold as set bysetAnalogValueCallbackThreshold(char, int, int)
is reached.class
BrickletDistanceIR.DistanceCallbackThreshold
static interface
BrickletDistanceIR.DistanceListener
This listener is triggered periodically with the period that is set bysetDistanceCallbackPeriod(long)
.static interface
BrickletDistanceIR.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_ANALOG_VALUE
static byte
FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD
static byte
FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD
static byte
FUNCTION_GET_DEBOUNCE_PERIOD
static byte
FUNCTION_GET_DISTANCE
static byte
FUNCTION_GET_DISTANCE_CALLBACK_PERIOD
static byte
FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD
static byte
FUNCTION_GET_IDENTITY
static byte
FUNCTION_GET_SAMPLING_POINT
static byte
FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD
static byte
FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD
static byte
FUNCTION_SET_DEBOUNCE_PERIOD
static byte
FUNCTION_SET_DISTANCE_CALLBACK_PERIOD
static byte
FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD
static byte
FUNCTION_SET_SAMPLING_POINT
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 BrickletDistanceIR(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
addAnalogValueListener(BrickletDistanceIR.AnalogValueListener listener)
Adds a AnalogValue listener.void
addAnalogValueReachedListener(BrickletDistanceIR.AnalogValueReachedListener listener)
Adds a AnalogValueReached listener.void
addDistanceListener(BrickletDistanceIR.DistanceListener listener)
Adds a Distance listener.void
addDistanceReachedListener(BrickletDistanceIR.DistanceReachedListener listener)
Adds a DistanceReached listener.int
getAnalogValue()
Returns the value as read by a 12-bit analog-to-digital converter.long
getAnalogValueCallbackPeriod()
Returns the period as set bysetAnalogValueCallbackPeriod(long)
.BrickletDistanceIR.AnalogValueCallbackThreshold
getAnalogValueCallbackThreshold()
Returns the threshold as set bysetAnalogValueCallbackThreshold(char, int, int)
.long
getDebouncePeriod()
Returns the debounce period as set bysetDebouncePeriod(long)
.int
getDistance()
Returns the distance measured by the sensor.long
getDistanceCallbackPeriod()
Returns the period as set bysetDistanceCallbackPeriod(long)
.BrickletDistanceIR.DistanceCallbackThreshold
getDistanceCallbackThreshold()
Returns the threshold as set bysetDistanceCallbackThreshold(char, int, int)
.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.int
getSamplingPoint(short position)
Returns the distance to a sampling point position as set bysetSamplingPoint(short, int)
.void
removeAnalogValueListener(BrickletDistanceIR.AnalogValueListener listener)
Removes a AnalogValue listener.void
removeAnalogValueReachedListener(BrickletDistanceIR.AnalogValueReachedListener listener)
Removes a AnalogValueReached listener.void
removeDistanceListener(BrickletDistanceIR.DistanceListener listener)
Removes a Distance listener.void
removeDistanceReachedListener(BrickletDistanceIR.DistanceReachedListener listener)
Removes a DistanceReached listener.void
setAnalogValueCallbackPeriod(long period)
Sets the period with which theBrickletDistanceIR.AnalogValueListener
listener is triggered periodically.void
setAnalogValueCallbackThreshold(char option, int min, int max)
Sets the thresholds for theBrickletDistanceIR.AnalogValueReachedListener
listener.void
setDebouncePeriod(long debounce)
Sets the period with which the threshold listeners *BrickletDistanceIR.DistanceReachedListener
, *BrickletDistanceIR.AnalogValueReachedListener
are triggered, if the thresholds *setDistanceCallbackThreshold(char, int, int)
, *setAnalogValueCallbackThreshold(char, int, int)
keep being reached.void
setDistanceCallbackPeriod(long period)
Sets the period with which theBrickletDistanceIR.DistanceListener
listener is triggered periodically.void
setDistanceCallbackThreshold(char option, int min, int max)
Sets the thresholds for theBrickletDistanceIR.DistanceReachedListener
listener.void
setSamplingPoint(short position, int distance)
Sets a sampling point value to a specific position of the lookup table.-
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
public static final byte FUNCTION_GET_DISTANCE
- See Also:
- Constant Field Values
-
FUNCTION_GET_ANALOG_VALUE
public static final byte FUNCTION_GET_ANALOG_VALUE
- See Also:
- Constant Field Values
-
FUNCTION_SET_SAMPLING_POINT
public static final byte FUNCTION_SET_SAMPLING_POINT
- See Also:
- Constant Field Values
-
FUNCTION_GET_SAMPLING_POINT
public static final byte FUNCTION_GET_SAMPLING_POINT
- 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_ANALOG_VALUE_CALLBACK_PERIOD
public static final byte FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD
public static final byte FUNCTION_GET_ANALOG_VALUE_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_ANALOG_VALUE_CALLBACK_THRESHOLD
public static final byte FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD
- See Also:
- Constant Field Values
-
FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD
public static final byte FUNCTION_GET_ANALOG_VALUE_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_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
-
BrickletDistanceIR
public BrickletDistanceIR(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
-
getDistance
public int getDistance() throws TinkerforgeException
Returns the distance measured by the sensor. Possible distance ranges are 40 to 300, 100 to 800 and 200 to 1500, depending on the selected IR sensor. If you want to get the distance periodically, it is recommended to use theBrickletDistanceIR.DistanceListener
listener and set the period withsetDistanceCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
getAnalogValue
public int getAnalogValue() throws TinkerforgeException
Returns the value as read by a 12-bit analog-to-digital converter. \note The value returned bygetDistance()
is averaged over several samples to yield less noise, whilegetAnalogValue()
gives back raw unfiltered analog values. The only reason to usegetAnalogValue()
is, if you need the full resolution of the analog-to-digital converter. If you want the analog value periodically, it is recommended to use theBrickletDistanceIR.AnalogValueListener
listener and set the period withsetAnalogValueCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setSamplingPoint
public void setSamplingPoint(short position, int distance) throws TinkerforgeException
Sets a sampling point value to a specific position of the lookup table. The lookup table comprises 128 equidistant analog values with corresponding distances. If you measure a distance of 50cm at the analog value 2048, you should call this function with (64, 5000). The utilized analog-to-digital converter has a resolution of 12 bit. With 128 sampling points on the whole range, this means that every sampling point has a size of 32 analog values. Thus the analog value 2048 has the corresponding sampling point 64 = 2048/32. Sampling points are saved on the EEPROM of the Distance IR Bricklet and loaded again on startup. \note An easy way to calibrate the sampling points of the Distance IR Bricklet is implemented in the Brick Viewer. If you want to calibrate your Bricklet it is highly recommended to use this implementation.- Throws:
TinkerforgeException
-
getSamplingPoint
public int getSamplingPoint(short position) throws TinkerforgeException
Returns the distance to a sampling point position as set bysetSamplingPoint(short, int)
.- Throws:
TinkerforgeException
-
setDistanceCallbackPeriod
public void setDistanceCallbackPeriod(long period) throws TinkerforgeException
Sets the period with which theBrickletDistanceIR.DistanceListener
listener is triggered periodically. A value of 0 turns the listener off. TheBrickletDistanceIR.DistanceListener
listener is only triggered if the distance has changed since the last triggering.- Throws:
TinkerforgeException
-
getDistanceCallbackPeriod
public long getDistanceCallbackPeriod() throws TinkerforgeException
Returns the period as set bysetDistanceCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setAnalogValueCallbackPeriod
public void setAnalogValueCallbackPeriod(long period) throws TinkerforgeException
Sets the period with which theBrickletDistanceIR.AnalogValueListener
listener is triggered periodically. A value of 0 turns the listener off. TheBrickletDistanceIR.AnalogValueListener
listener is only triggered if the analog value has changed since the last triggering.- Throws:
TinkerforgeException
-
getAnalogValueCallbackPeriod
public long getAnalogValueCallbackPeriod() throws TinkerforgeException
Returns the period as set bysetAnalogValueCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setDistanceCallbackThreshold
public void setDistanceCallbackThreshold(char option, int min, int max) throws TinkerforgeException
Sets the thresholds for theBrickletDistanceIR.DistanceReachedListener
listener. The following options are possible: \verbatim "Option", "Description" "'x'", "Listener is turned off" "'o'", "Listener is triggered when the distance is *outside* the min and max values" "'i'", "Listener is triggered when the distance is *inside* the min and max values" "'<'", "Listener is triggered when the distance is smaller than the min value (max is ignored)" "'>'", "Listener is triggered when the distance is greater than the min value (max is ignored)" \endverbatim- Throws:
TinkerforgeException
-
getDistanceCallbackThreshold
public BrickletDistanceIR.DistanceCallbackThreshold getDistanceCallbackThreshold() throws TinkerforgeException
Returns the threshold as set bysetDistanceCallbackThreshold(char, int, int)
.- Throws:
TinkerforgeException
-
setAnalogValueCallbackThreshold
public void setAnalogValueCallbackThreshold(char option, int min, int max) throws TinkerforgeException
Sets the thresholds for theBrickletDistanceIR.AnalogValueReachedListener
listener. The following options are possible: \verbatim "Option", "Description" "'x'", "Listener is turned off" "'o'", "Listener is triggered when the analog value is *outside* the min and max values" "'i'", "Listener is triggered when the analog value is *inside* the min and max values" "'<'", "Listener is triggered when the analog value is smaller than the min value (max is ignored)" "'>'", "Listener is triggered when the analog value is greater than the min value (max is ignored)" \endverbatim- Throws:
TinkerforgeException
-
getAnalogValueCallbackThreshold
public BrickletDistanceIR.AnalogValueCallbackThreshold getAnalogValueCallbackThreshold() throws TinkerforgeException
Returns the threshold as set bysetAnalogValueCallbackThreshold(char, int, int)
.- Throws:
TinkerforgeException
-
setDebouncePeriod
public void setDebouncePeriod(long debounce) throws TinkerforgeException
Sets the period with which the threshold listeners *BrickletDistanceIR.DistanceReachedListener
, *BrickletDistanceIR.AnalogValueReachedListener
are triggered, if the thresholds *setDistanceCallbackThreshold(char, int, int)
, *setAnalogValueCallbackThreshold(char, int, int)
keep being reached.- Throws:
TinkerforgeException
-
getDebouncePeriod
public long getDebouncePeriod() throws TinkerforgeException
Returns the debounce period as set bysetDebouncePeriod(long)
.- 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(BrickletDistanceIR.DistanceListener listener)
Adds a Distance listener.
-
removeDistanceListener
public void removeDistanceListener(BrickletDistanceIR.DistanceListener listener)
Removes a Distance listener.
-
addAnalogValueListener
public void addAnalogValueListener(BrickletDistanceIR.AnalogValueListener listener)
Adds a AnalogValue listener.
-
removeAnalogValueListener
public void removeAnalogValueListener(BrickletDistanceIR.AnalogValueListener listener)
Removes a AnalogValue listener.
-
addDistanceReachedListener
public void addDistanceReachedListener(BrickletDistanceIR.DistanceReachedListener listener)
Adds a DistanceReached listener.
-
removeDistanceReachedListener
public void removeDistanceReachedListener(BrickletDistanceIR.DistanceReachedListener listener)
Removes a DistanceReached listener.
-
addAnalogValueReachedListener
public void addAnalogValueReachedListener(BrickletDistanceIR.AnalogValueReachedListener listener)
Adds a AnalogValueReached listener.
-
removeAnalogValueReachedListener
public void removeAnalogValueReachedListener(BrickletDistanceIR.AnalogValueReachedListener listener)
Removes a AnalogValueReached listener.
-
-