Package com.tinkerforge
Class BrickletRotaryEncoder
- java.lang.Object
-
- com.tinkerforge.DeviceBase
-
- com.tinkerforge.Device
-
- com.tinkerforge.BrickletRotaryEncoder
-
public class BrickletRotaryEncoder extends Device
360° rotary encoder with push-button
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BrickletRotaryEncoder.CountCallbackThreshold
static interface
BrickletRotaryEncoder.CountListener
This listener is triggered periodically with the period that is set bysetCountCallbackPeriod(long)
.static interface
BrickletRotaryEncoder.CountReachedListener
This listener is triggered when the threshold as set bysetCountCallbackThreshold(char, int, int)
is reached.static interface
BrickletRotaryEncoder.PressedListener
This listener is triggered when the button is pressed.static interface
BrickletRotaryEncoder.ReleasedListener
This listener is triggered when the button is released.-
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_COUNT
static byte
FUNCTION_GET_COUNT_CALLBACK_PERIOD
static byte
FUNCTION_GET_COUNT_CALLBACK_THRESHOLD
static byte
FUNCTION_GET_DEBOUNCE_PERIOD
static byte
FUNCTION_GET_IDENTITY
static byte
FUNCTION_IS_PRESSED
static byte
FUNCTION_SET_COUNT_CALLBACK_PERIOD
static byte
FUNCTION_SET_COUNT_CALLBACK_THRESHOLD
static byte
FUNCTION_SET_DEBOUNCE_PERIOD
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 BrickletRotaryEncoder(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
addCountListener(BrickletRotaryEncoder.CountListener listener)
Adds a Count listener.void
addCountReachedListener(BrickletRotaryEncoder.CountReachedListener listener)
Adds a CountReached listener.void
addPressedListener(BrickletRotaryEncoder.PressedListener listener)
Adds a Pressed listener.void
addReleasedListener(BrickletRotaryEncoder.ReleasedListener listener)
Adds a Released listener.int
getCount(boolean reset)
Returns the current count of the encoder.long
getCountCallbackPeriod()
Returns the period as set bysetCountCallbackPeriod(long)
.BrickletRotaryEncoder.CountCallbackThreshold
getCountCallbackThreshold()
Returns the threshold as set bysetCountCallbackThreshold(char, int, int)
.long
getDebouncePeriod()
Returns the debounce period as set bysetDebouncePeriod(long)
.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.boolean
isPressed()
Returns *true* if the button is pressed and *false* otherwise.void
removeCountListener(BrickletRotaryEncoder.CountListener listener)
Removes a Count listener.void
removeCountReachedListener(BrickletRotaryEncoder.CountReachedListener listener)
Removes a CountReached listener.void
removePressedListener(BrickletRotaryEncoder.PressedListener listener)
Removes a Pressed listener.void
removeReleasedListener(BrickletRotaryEncoder.ReleasedListener listener)
Removes a Released listener.void
setCountCallbackPeriod(long period)
Sets the period with which theBrickletRotaryEncoder.CountListener
listener is triggered periodically.void
setCountCallbackThreshold(char option, int min, int max)
Sets the thresholds for theBrickletRotaryEncoder.CountReachedListener
listener.void
setDebouncePeriod(long debounce)
Sets the period with which the threshold listener *BrickletRotaryEncoder.CountReachedListener
is triggered, if the thresholds *setCountCallbackThreshold(char, int, int)
keeps being reached.-
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_COUNT
public static final byte FUNCTION_GET_COUNT
- See Also:
- Constant Field Values
-
FUNCTION_SET_COUNT_CALLBACK_PERIOD
public static final byte FUNCTION_SET_COUNT_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_COUNT_CALLBACK_PERIOD
public static final byte FUNCTION_GET_COUNT_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_SET_COUNT_CALLBACK_THRESHOLD
public static final byte FUNCTION_SET_COUNT_CALLBACK_THRESHOLD
- See Also:
- Constant Field Values
-
FUNCTION_GET_COUNT_CALLBACK_THRESHOLD
public static final byte FUNCTION_GET_COUNT_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_IS_PRESSED
public static final byte FUNCTION_IS_PRESSED
- 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
-
BrickletRotaryEncoder
public BrickletRotaryEncoder(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
-
getCount
public int getCount(boolean reset) throws TinkerforgeException
Returns the current count of the encoder. If you set reset to true, the count is set back to 0 directly after the current count is read. The encoder has 24 steps per rotation Turning the encoder to the left decrements the counter, so a negative count is possible.- Throws:
TinkerforgeException
-
setCountCallbackPeriod
public void setCountCallbackPeriod(long period) throws TinkerforgeException
Sets the period with which theBrickletRotaryEncoder.CountListener
listener is triggered periodically. A value of 0 turns the listener off. TheBrickletRotaryEncoder.CountListener
listener is only triggered if the count has changed since the last triggering.- Throws:
TinkerforgeException
-
getCountCallbackPeriod
public long getCountCallbackPeriod() throws TinkerforgeException
Returns the period as set bysetCountCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setCountCallbackThreshold
public void setCountCallbackThreshold(char option, int min, int max) throws TinkerforgeException
Sets the thresholds for theBrickletRotaryEncoder.CountReachedListener
listener. The following options are possible: \verbatim "Option", "Description" "'x'", "Listener is turned off" "'o'", "Listener is triggered when the count is *outside* the min and max values" "'i'", "Listener is triggered when the count is *inside* the min and max values" "'<'", "Listener is triggered when the count is smaller than the min value (max is ignored)" "'>'", "Listener is triggered when the count is greater than the min value (max is ignored)" \endverbatim- Throws:
TinkerforgeException
-
getCountCallbackThreshold
public BrickletRotaryEncoder.CountCallbackThreshold getCountCallbackThreshold() throws TinkerforgeException
Returns the threshold as set bysetCountCallbackThreshold(char, int, int)
.- Throws:
TinkerforgeException
-
setDebouncePeriod
public void setDebouncePeriod(long debounce) throws TinkerforgeException
Sets the period with which the threshold listener *BrickletRotaryEncoder.CountReachedListener
is triggered, if the thresholds *setCountCallbackThreshold(char, int, int)
keeps being reached.- Throws:
TinkerforgeException
-
getDebouncePeriod
public long getDebouncePeriod() throws TinkerforgeException
Returns the debounce period as set bysetDebouncePeriod(long)
.- Throws:
TinkerforgeException
-
isPressed
public boolean isPressed() throws TinkerforgeException
Returns *true* if the button is pressed and *false* otherwise. It is recommended to use theBrickletRotaryEncoder.PressedListener
andBrickletRotaryEncoder.ReleasedListener
listeners to handle the button.- 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
-
addCountListener
public void addCountListener(BrickletRotaryEncoder.CountListener listener)
Adds a Count listener.
-
removeCountListener
public void removeCountListener(BrickletRotaryEncoder.CountListener listener)
Removes a Count listener.
-
addCountReachedListener
public void addCountReachedListener(BrickletRotaryEncoder.CountReachedListener listener)
Adds a CountReached listener.
-
removeCountReachedListener
public void removeCountReachedListener(BrickletRotaryEncoder.CountReachedListener listener)
Removes a CountReached listener.
-
addPressedListener
public void addPressedListener(BrickletRotaryEncoder.PressedListener listener)
Adds a Pressed listener.
-
removePressedListener
public void removePressedListener(BrickletRotaryEncoder.PressedListener listener)
Removes a Pressed listener.
-
addReleasedListener
public void addReleasedListener(BrickletRotaryEncoder.ReleasedListener listener)
Adds a Released listener.
-
removeReleasedListener
public void removeReleasedListener(BrickletRotaryEncoder.ReleasedListener listener)
Removes a Released listener.
-
-