at.wisch.joystick
Class Joystick

java.lang.Object
  extended by at.wisch.joystick.AbstractController
      extended by at.wisch.joystick.Joystick
All Implemented Interfaces:
AdvancedController, Controller
Direct Known Subclasses:
FFJoystick

public class Joystick
extends AbstractController

The class Joystick. This is the class that actually represents Joystick objects, which are necessary for recieving input from a Joystick.

Attention: do not instantiate Joystick objects yourself. Aquire Joysticks using JoystickManager.

Author:
Martin Wischenbart

Field Summary
 
Fields inherited from class at.wisch.joystick.AbstractController
AXIS_DEFAULT_DEAD_ZONE, AXIS_MAXIMUM, AXIS_MINIMUM, AXIS_NEUTRAL, DEFAULT_AUTOCENTER_VALUE, DEFAULT_GAIN_VALUE, INFINITE_TIMES, POV_AXIS_NEGATIVE, POV_AXIS_NEUTRAL, POV_AXIS_POSITIVE, POV_CENTERED, POV_DOWN, POV_DOWN_LEFT, POV_DOWN_RIGHT, POV_LEFT, POV_RIGHT, POV_UP, POV_UP_LEFT, POV_UP_RIGHT
 
Method Summary
 int getAxisCount()
          Retrieve the number of axes available on this controller.
 float getAxisValue(int axisIndex)
          Retrieve the value thats currently available on a specified axis.
 int getBallCount()
          Gets the number of trackballs (balls) a device has.
 int[] getBallDelta(int ballIndex)
          Gets the delta for the trackball specified by ballIndex.
 int getButtonCount()
          Retrieve the number of buttons available on this controller.
 float getDeadZone(int axisIndex)
          Get the dead zone for a specified axis.
 java.lang.String getDescription()
          Gets a short description of the joystick's capabilities for input.
 int getIndex()
          Gets the index of this controller in the collection.
 boolean getInvertAxis(int axisIndex)
          Check if an analogue axis is being inverted.
 boolean getInvertBall(int ballIndex, int xORy)
          Check if a trackball's axis is being inverted.
 boolean getInvertPov(int povIndex, int xORy)
          Check if a POV's axis is being inverted.
 java.lang.String getName()
          Gets the name assigned to this controller.
 int getPovCount()
          Gets the device's point-of-view (POV) count.
 int getPovDirection(int povIndex)
          Gets the direction of a POV.
 int getPovX(int povIndex)
          Gets the X coordinate's value of a POV.
 int getPovY(int povIndex)
          Gets the Y coordinate's value of a POV.
 boolean isButtonPressed(int buttonIndex)
          Check if a button is currently pressed
 boolean isFFJoystick()
          Checks if the device supports force feedback (FF).
 void poll()
          Poll the controller for new data.
 void setDeadZone(int axisIndex, float zone)
          Set the dead zone for the specified axis.
 void setInvertAxis(int axisIndex, boolean invert)
          Sets if an analogue axis is to be inverted or not.
 void setInvertBall(int ballIndex, int xORy, boolean invert)
          Sets if a trackball's axis is to be inverted or not.
 void setInvertPov(int povIndex, int xORy, boolean invert)
          Sets if a POV's axis is to be inverted or not.
 java.lang.String toString()
          Gets a string containing the joystick's name and the description of the input capabilities.
 
Methods inherited from class at.wisch.joystick.AbstractController
getAxisName, getBall1Delta, getBall2Delta, getBall3Delta, getBall4Delta, getBallName, getButtonName, getPov1X, getPov1Y, getPov2X, getPov2Y, getPov3X, getPov3Y, getPov4X, getPov4Y, getPovName, getPovX, getPovY, getRXAxisDeadZone, getRXAxisValue, getRYAxisDeadZone, getRYAxisValue, getRZAxisDeadZone, getRZAxisValue, getUAxisDeadZone, getUAxisValue, getVAxisDeadZone, getVAxisValue, getXAxisDeadZone, getXAxisValue, getYAxisDeadZone, getYAxisValue, getZAxisDeadZone, getZAxisValue, setRXAxisDeadZone, setRYAxisDeadZone, setRZAxisDeadZone, setUAxisDeadZone, setVAxisDeadZone, setXAxisDeadZone, setYAxisDeadZone, setZAxisDeadZone
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

toString

public java.lang.String toString()
Gets a string containing the joystick's name and the description of the input capabilities.

Overrides:
toString in class java.lang.Object
Returns:
the joystick's name and a the description of the input capabilities
See Also:
getName(), getDescription()

getIndex

public int getIndex()
Gets the index of this controller in the collection.

Returns:
the index of this controller in the collection
See Also:
getDescription()

getName

public java.lang.String getName()
Gets the name assigned to this controller.

Returns:
the name assigned to this controller
See Also:
toString()

isFFJoystick

public boolean isFFJoystick()
Checks if the device supports force feedback (FF).

If this method returns true, it is safe to cast the Joystick to an FFJoystick. Checks if the device supports force feedback (FF).

If this method returns true, it is safe to cast the AdvancedController to an AdvancedFFController.

Returns:
true, if the controller was recognized as a FF device. false, if the device does not have FF capabilities.
See Also:
FFJoystick

getDescription

public java.lang.String getDescription()
Gets a short description of the joystick's capabilities for input. This includes the joystick index, number of buttons, number of POVs, number of axes and number of trackballs.

Returns:
the String containing the joystick's capabilities for input
See Also:
toString(), getIndex(), getButtonCount(), getPovCount(), getAxisCount(), getBallCount()

poll

public void poll()
Poll the controller for new data. Call this method before you query for inputs from a controller. Note that direcly after initialization polling does not work yet. You have press or move something on the controller first.


getButtonCount

public int getButtonCount()
Retrieve the number of buttons available on this controller.

Returns:
the number of buttons available on this controller
See Also:
AdvancedController.getPovCount(), Controller.getAxisCount(), AdvancedController.getBallCount()

isButtonPressed

public boolean isButtonPressed(int buttonIndex)
Check if a button is currently pressed

Parameters:
buttonIndex - the index of the button to check
Returns:
true if the button is currently pressed, false otherwise

getPovCount

public int getPovCount()
Gets the device's point-of-view (POV) count. POV is also known as "hat". POVs are digital sticks, that can be in the center, up, down, left, right or combinations (up-left, up-right, down-left, down-right).

Returns:
the number of POVs on the device
See Also:
Controller.getButtonCount(), Controller.getAxisCount(), AdvancedController.getBallCount()

getPovX

public int getPovX(int povIndex)
Gets the X coordinate's value of a POV. (X axis of a POV is the left-right-direction)

Parameters:
povIndex - the POV index (POV indices start from 0)
Returns:
the POV's X coordinate: POV_AXIS_NEGATIVE for left, POV_AXIS_NEUTRAL for center, POV_AXIS_POSITIVE for right
See Also:
AdvancedController.getPovDirection(int)

getPovY

public int getPovY(int povIndex)
Gets the Y coordinate's value of a POV. (Y axis of a POV is the up-down-direction)

Parameters:
povIndex - the POV index (POV indices start from 0)
Returns:
the POV's Y coordinate: POV_AXIS_NEGATIVE for up, POV_AXIS_NEUTRAL for center, POV_AXIS_POSITIVE for down
See Also:
AdvancedController.getPovDirection(int)

getPovDirection

public int getPovDirection(int povIndex)
Gets the direction of a POV.

Attention: setInvertPov(int, int, boolean) does not affect the direction, but only the return value of getPovX(int) and getPovY(int)

Parameters:
povIndex - the POV index (POV indices start from 0)
Returns:
the POVs direction: POV_CENTERED for center, or one of the following: POV_DOWN, POV_DOWN_LEFT, POV_DOWN_RIGHT, POV_LEFT, POV_RIGHT, POV_UP, POV_UP_LEFT, POV_UP_RIGHT
See Also:
AdvancedController.getPovX(int), AdvancedController.getPovY(int)

getInvertPov

public boolean getInvertPov(int povIndex,
                            int xORy)
Check if a POV's axis is being inverted.

Parameters:
povIndex - the POV's index
xORy - 0 for X, 1 for Y
Returns:
tells if the device's axis xORy on POV povIndex is set to be inverted or not.
See Also:
setInvertPov(int, int, boolean)

setInvertPov

public void setInvertPov(int povIndex,
                         int xORy,
                         boolean invert)
Sets if a POV's axis is to be inverted or not.

Attention: Inverting a POV's axis does not affect the return value of getPovDirection(int)

Parameters:
povIndex - the POV's index
xORy - 0 for X, 1 for Y
invert - true for do invert, false for do not invert (default)
See Also:
getInvertPov(int, int)

getAxisCount

public int getAxisCount()
Retrieve the number of axes available on this controller. Axes can are analogue inputs: their values can be anything from AXIS_MINIMUM to AXIS_MAXIMUM (-1f to 1f)

Returns:
the number of axes available on this controller
See Also:
Controller.getButtonCount(), AdvancedController.getPovCount(), AdvancedController.getBallCount()

getAxisValue

public float getAxisValue(int axisIndex)
Retrieve the value thats currently available on a specified axis. If the axis does not exist, AXIS_NEUTRAL (0f) will be returned. It may be useful to get the player to wiggle the joystick from side to side to get the calibration right.

Parameters:
axisIndex - the index of axis to be read (axis indices start with 0)
Returns:
the value from the specified axis: AXIS_NEUTRAL, AXIS_MINIMUM, AXIS_MAXIMUM or anything between AXIS_MINIMUM and AXIS_MAXIMUM (anything from -1f to 1f)

getDeadZone

public float getDeadZone(int axisIndex)
Get the dead zone for a specified axis.

Parameters:
axisIndex - the index of the axis for which to retrieve the dead zone (axis indices start with 0)
Returns:
the dead zone for the specified axis: a value from 0 to AXIS_MAXIMUM (1f)
See Also:
Controller.setDeadZone(int, float)

setDeadZone

public void setDeadZone(int axisIndex,
                        float zone)
Set the dead zone for the specified axis. Analogue joysticks generally don't tend to return exactly to 0 once you stop holding the stick. Therefore it might seem that you are moving the direction stick, while in fact you are not. The dead zone is a "region" around the center where input is ignored. For example if you set the dead zone to 0.1f the values from -0.1f to 0.1f will be ignored (getAxisValue will return values from -1f to -0.1f, 0f or values from 0.1f to 1f).

Parameters:
axisIndex - the index of the axis for which to set the dead zone (axis indices start with 0)
zone - the dead zone to use for the specified axis: a value from 0 to AXIS_MAXIMUM (1f)
See Also:
Controller.getDeadZone(int)

getInvertAxis

public boolean getInvertAxis(int axisIndex)
Check if an analogue axis is being inverted.

Parameters:
axisIndex - the axis' index
Returns:
tells if the device's analogue axis axisIndex is set to be inverted or not.
See Also:
setInvertAxis(int, boolean)

setInvertAxis

public void setInvertAxis(int axisIndex,
                          boolean invert)
Sets if an analogue axis is to be inverted or not.

Parameters:
axisIndex - the axis' index
invert - true for do invert, false for do not invert (default)
See Also:
getInvertAxis(int)

getBallCount

public int getBallCount()
Gets the number of trackballs (balls) a device has.

Returns:
the number of trackballs on the device * @see #getButtonCount()
See Also:
AdvancedController.getPovCount(), Controller.getAxisCount()

getBallDelta

public int[] getBallDelta(int ballIndex)
Gets the delta for the trackball specified by ballIndex. The delta represents the movements in X and Y directions.

Parameters:
ballIndex - the trackball index (ball indices start from 0)
Returns:
the trackball delta: index [0] represents the X movement, index [1] represents the Y movement (the size of the array will always be 2)

getInvertBall

public boolean getInvertBall(int ballIndex,
                             int xORy)
Check if a trackball's axis is being inverted.

Parameters:
ballIndex - the trackball's index
xORy - 0 for X, 1 for Y
Returns:
tells if the device's axis xORy on trackball ballIndex is set to be inverted or not.
See Also:
setInvertBall(int, int, boolean)

setInvertBall

public void setInvertBall(int ballIndex,
                          int xORy,
                          boolean invert)
Sets if a trackball's axis is to be inverted or not.

Parameters:
ballIndex - the trackball's index
xORy - 0 for X, 1 for Y
invert - true for do invert, false for do not invert (default)
See Also:
getInvertBall(int, int)