Package com.tinkerforge
Class BrickletJoystick
- java.lang.Object
-
- com.tinkerforge.DeviceBase
-
- com.tinkerforge.Device
-
- com.tinkerforge.BrickletJoystick
-
public class BrickletJoystick extends Device
2-axis joystick with push-button
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BrickletJoystick.AnalogValue
class
BrickletJoystick.AnalogValueCallbackThreshold
static interface
BrickletJoystick.AnalogValueListener
This listener is triggered periodically with the period that is set bysetAnalogValueCallbackPeriod(long)
.static interface
BrickletJoystick.AnalogValueReachedListener
This listener is triggered when the threshold as set bysetAnalogValueCallbackThreshold(char, int, int, int, int)
is reached.class
BrickletJoystick.Position
class
BrickletJoystick.PositionCallbackThreshold
static interface
BrickletJoystick.PositionListener
This listener is triggered periodically with the period that is set bysetPositionCallbackPeriod(long)
.static interface
BrickletJoystick.PositionReachedListener
This listener is triggered when the threshold as set bysetPositionCallbackThreshold(char, short, short, short, short)
is reached.static interface
BrickletJoystick.PressedListener
This listener is triggered when the button is pressed.static interface
BrickletJoystick.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_CALIBRATE
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_IDENTITY
static byte
FUNCTION_GET_POSITION
static byte
FUNCTION_GET_POSITION_CALLBACK_PERIOD
static byte
FUNCTION_GET_POSITION_CALLBACK_THRESHOLD
static byte
FUNCTION_IS_PRESSED
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_POSITION_CALLBACK_PERIOD
static byte
FUNCTION_SET_POSITION_CALLBACK_THRESHOLD
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 BrickletJoystick(java.lang.String uid, IPConnection ipcon)
Creates an object with the unique device ID \c uid.
-
Method Summary
-
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_POSITION
public static final byte FUNCTION_GET_POSITION
- See Also:
- Constant Field Values
-
FUNCTION_IS_PRESSED
public static final byte FUNCTION_IS_PRESSED
- See Also:
- Constant Field Values
-
FUNCTION_GET_ANALOG_VALUE
public static final byte FUNCTION_GET_ANALOG_VALUE
- See Also:
- Constant Field Values
-
FUNCTION_CALIBRATE
public static final byte FUNCTION_CALIBRATE
- See Also:
- Constant Field Values
-
FUNCTION_SET_POSITION_CALLBACK_PERIOD
public static final byte FUNCTION_SET_POSITION_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_POSITION_CALLBACK_PERIOD
public static final byte FUNCTION_GET_POSITION_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_POSITION_CALLBACK_THRESHOLD
public static final byte FUNCTION_SET_POSITION_CALLBACK_THRESHOLD
- See Also:
- Constant Field Values
-
FUNCTION_GET_POSITION_CALLBACK_THRESHOLD
public static final byte FUNCTION_GET_POSITION_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
-
BrickletJoystick
public BrickletJoystick(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
-
getPosition
public BrickletJoystick.Position getPosition() throws TinkerforgeException
Returns the position of the joystick. The middle position of the joystick is x=0, y=0. The returned values are averaged and calibrated (seecalibrate()
). If you want to get the position periodically, it is recommended to use theBrickletJoystick.PositionListener
listener and set the period withsetPositionCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
isPressed
public boolean isPressed() throws TinkerforgeException
Returns *true* if the button is pressed and *false* otherwise. It is recommended to use theBrickletJoystick.PressedListener
andBrickletJoystick.ReleasedListener
listeners to handle the button.- Throws:
TinkerforgeException
-
getAnalogValue
public BrickletJoystick.AnalogValue getAnalogValue() throws TinkerforgeException
Returns the values as read by a 12-bit analog-to-digital converter. \note The values returned bygetPosition()
are 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 values periodically, it is recommended to use theBrickletJoystick.AnalogValueListener
listener and set the period withsetAnalogValueCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
calibrate
public void calibrate() throws TinkerforgeException
Calibrates the middle position of the joystick. If your Joystick Bricklet does not return x=0 and y=0 in the middle position, call this function while the joystick is standing still in the middle position. The resulting calibration will be saved on the EEPROM of the Joystick Bricklet, thus you only have to calibrate it once.- Throws:
TinkerforgeException
-
setPositionCallbackPeriod
public void setPositionCallbackPeriod(long period) throws TinkerforgeException
Sets the period with which theBrickletJoystick.PositionListener
listener is triggered periodically. A value of 0 turns the listener off. TheBrickletJoystick.PositionListener
listener is only triggered if the position has changed since the last triggering.- Throws:
TinkerforgeException
-
getPositionCallbackPeriod
public long getPositionCallbackPeriod() throws TinkerforgeException
Returns the period as set bysetPositionCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setAnalogValueCallbackPeriod
public void setAnalogValueCallbackPeriod(long period) throws TinkerforgeException
Sets the period with which theBrickletJoystick.AnalogValueListener
listener is triggered periodically. A value of 0 turns the listener off. TheBrickletJoystick.AnalogValueListener
listener is only triggered if the analog values have changed since the last triggering.- Throws:
TinkerforgeException
-
getAnalogValueCallbackPeriod
public long getAnalogValueCallbackPeriod() throws TinkerforgeException
Returns the period as set bysetAnalogValueCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setPositionCallbackThreshold
public void setPositionCallbackThreshold(char option, short minX, short maxX, short minY, short maxY) throws TinkerforgeException
Sets the thresholds for theBrickletJoystick.PositionReachedListener
listener. The following options are possible: \verbatim "Option", "Description" "'x'", "Listener is turned off" "'o'", "Listener is triggered when the position is *outside* the min and max values" "'i'", "Listener is triggered when the position is *inside* the min and max values" "'<'", "Listener is triggered when the position is smaller than the min values (max is ignored)" "'>'", "Listener is triggered when the position is greater than the min values (max is ignored)" \endverbatim- Throws:
TinkerforgeException
-
getPositionCallbackThreshold
public BrickletJoystick.PositionCallbackThreshold getPositionCallbackThreshold() throws TinkerforgeException
Returns the threshold as set bysetPositionCallbackThreshold(char, short, short, short, short)
.- Throws:
TinkerforgeException
-
setAnalogValueCallbackThreshold
public void setAnalogValueCallbackThreshold(char option, int minX, int maxX, int minY, int maxY) throws TinkerforgeException
Sets the thresholds for theBrickletJoystick.AnalogValueReachedListener
listener. The following options are possible: \verbatim "Option", "Description" "'x'", "Listener is turned off" "'o'", "Listener is triggered when the analog values are *outside* the min and max values" "'i'", "Listener is triggered when the analog values are *inside* the min and max values" "'<'", "Listener is triggered when the analog values are smaller than the min values (max is ignored)" "'>'", "Listener is triggered when the analog values are greater than the min values (max is ignored)" \endverbatim- Throws:
TinkerforgeException
-
getAnalogValueCallbackThreshold
public BrickletJoystick.AnalogValueCallbackThreshold getAnalogValueCallbackThreshold() throws TinkerforgeException
Returns the threshold as set bysetAnalogValueCallbackThreshold(char, int, int, int, int)
.- Throws:
TinkerforgeException
-
setDebouncePeriod
public void setDebouncePeriod(long debounce) throws TinkerforgeException
Sets the period with which the threshold listeners *BrickletJoystick.PositionReachedListener
, *BrickletJoystick.AnalogValueReachedListener
are triggered, if the thresholds *setPositionCallbackThreshold(char, short, short, short, short)
, *setAnalogValueCallbackThreshold(char, int, int, 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
-
addPositionListener
public void addPositionListener(BrickletJoystick.PositionListener listener)
Adds a Position listener.
-
removePositionListener
public void removePositionListener(BrickletJoystick.PositionListener listener)
Removes a Position listener.
-
addAnalogValueListener
public void addAnalogValueListener(BrickletJoystick.AnalogValueListener listener)
Adds a AnalogValue listener.
-
removeAnalogValueListener
public void removeAnalogValueListener(BrickletJoystick.AnalogValueListener listener)
Removes a AnalogValue listener.
-
addPositionReachedListener
public void addPositionReachedListener(BrickletJoystick.PositionReachedListener listener)
Adds a PositionReached listener.
-
removePositionReachedListener
public void removePositionReachedListener(BrickletJoystick.PositionReachedListener listener)
Removes a PositionReached listener.
-
addAnalogValueReachedListener
public void addAnalogValueReachedListener(BrickletJoystick.AnalogValueReachedListener listener)
Adds a AnalogValueReached listener.
-
removeAnalogValueReachedListener
public void removeAnalogValueReachedListener(BrickletJoystick.AnalogValueReachedListener listener)
Removes a AnalogValueReached listener.
-
addPressedListener
public void addPressedListener(BrickletJoystick.PressedListener listener)
Adds a Pressed listener.
-
removePressedListener
public void removePressedListener(BrickletJoystick.PressedListener listener)
Removes a Pressed listener.
-
addReleasedListener
public void addReleasedListener(BrickletJoystick.ReleasedListener listener)
Adds a Released listener.
-
removeReleasedListener
public void removeReleasedListener(BrickletJoystick.ReleasedListener listener)
Removes a Released listener.
-
-