Top Description Fields Constructors Methods
com.studiohartman.jamepad

public final Class ControllerIndex

extends Object
Class Inheritance

This class is the main thing you're gonna need to deal with if you want lots of control over your gamepads or want to avoid lots of ControllerState allocations. A Controller index cannot be made from outside the Jamepad package. You're gonna need to go through a ControllerManager to get your controllers. A ControllerIndex represents the controller at a given index. There may or may not actually be a controller at that index. Exceptions are thrown if the controller is not connected.
Author
William Hartman

Field Summary

Modifier and TypeField and Description
private static final float
private long
private boolean[]
private int
private boolean[]

Constructor Summary

AccessConstructor and Description
pack-priv
ControllerIndex(int
The index of the controller
index
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true of controller can vibrate
canVibrate
()

public void
close()

Close the connection to this controller.

private void
public boolean

Returns:

Whether or not the controller was able to be vibrated (i.e. if haptics are supported)
doVibration
(float
The intensity of the left rumble motor (this should be between 0 and 1)
leftMagnitude
,
float
The intensity of the right rumble motor (this should be between 0 and 1)
rightMagnitude
,
int duration_ms)

Vibrate the controller using the new rumble API Each call to this function cancels any previous rumble effect, and calling it with 0 intensity stops any rumbling.

private void
ensureConnected()

Convenience method to throw an exception if the controller is not connected.

public float

Returns:

The current state of the requested axis.
getAxisState
(ControllerAxis
The ControllerAxis to check the state of
toCheck
)

Returns the current state of a passed axis.

public int

Returns:

The instance ID of the current controller
getDeviceInstanceID
()

Returns the instance ID of the current controller, which uniquely identifies the device from the time it is connected until it is disconnected.

public int

Returns:

The index of the current controller.
getIndex
()

Returns the index of the current controller.

public String

Returns:

The the name of this controller
getName
()

Returns the implementation dependent name of this controller.

public int

Returns:

player index if set and supported, -1 otherwise
getPlayerIndex
()

public ControllerPowerLevel

Returns:

current power level of game controller, see ControllerPowerLevel enum values
getPowerLevel
()

public boolean
isAxisAvailable(ControllerAxis
The ControllerAxis to check
toCheck
)

Returns if passed axis is available on controller.

public boolean
isButtonAvailable(ControllerButton
The ControllerButton to check
toCheck
)

Returns if a given button is available on controller.

public boolean

Returns:

Whether or not the button has just been pressed.
isButtonJustPressed
(ControllerButton
The ControllerButton to check the state of
toCheck
)

Returns whether or not a given button has just been pressed since you last made a query about that button (either through this method, isButtonPressed(), or through the ControllerState side of things).

public boolean

Returns:

Whether or not the button is pressed.
isButtonPressed
(ControllerButton
The ControllerButton to check the state of
toCheck
)

Returns whether or not a given button has been pressed.

public boolean

Returns:

Whether or not the controller is plugged in.
isConnected
()

Return whether or not the controller is currently connected.

private native boolean
nativeAxisAvailable(long controllerPtr, int axisIndex)

private native boolean
nativeButtonAvailable(long controllerPtr, int buttonIndex)

private native boolean
nativeCanVibrate(long controllerPtr)

private native int
nativeCheckAxis(long controllerPtr, int axisIndex)

private native boolean
nativeCheckButton(long controllerPtr, int buttonIndex)

private native void
nativeClose(long controllerPtr)

private native long
private native boolean
nativeDoVibration(long controllerPtr, int leftMagnitude, int rightMagnitude, int duration_ms)

private native int
nativeGetDeviceInstanceID(long controllerPtr)

private native String
nativeGetName(long controllerPtr)

private native int
nativeGetPlayerIndex(long controllerPtr)

private native int
nativeGetPowerLevel(long controllerPtr)

private native boolean
nativeIsConnected(long controllerPtr)

private native void
nativeSetPlayerIndex(long controllerPtr, int index)

public boolean

Returns:

whether or not the controller could successfully reconnect.
reconnectController
()

Close and reconnect to the native gamepad at the index associated with this ControllerIndex object.

public void
setPlayerIndex(int
index to set
index
)

Sets player index.

private void
updateButton(int buttonIndex)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AXIS_MAX_VALback to summary
private static final float AXIS_MAX_VAL
controllerPtrback to summary
private long controllerPtr
heldDownButtonsback to summary
private boolean[] heldDownButtons
indexback to summary
private int index
justPressedButtonsback to summary
private boolean[] justPressedButtons

Constructor Detail

ControllerIndexback to summary
pack-priv ControllerIndex(int index)

Constructor. Builds a controller at the given index and attempts to connect to it. This is only accessible in the Jamepad package, so people can't go trying to make controllers before the native library is loaded or initialized.

Parameters
index:int

The index of the controller

Method Detail

canVibrateback to summary
public boolean canVibrate() throws ControllerUnpluggedException
Returns:boolean

true of controller can vibrate

Exceptions
ControllerUnpluggedException:
If the controller is not connected
closeback to summary
public void close()

Close the connection to this controller.

connectControllerback to summary
private void connectController()
doVibrationback to summary
public boolean doVibration(float leftMagnitude, float rightMagnitude, int duration_ms) throws ControllerUnpluggedException

Vibrate the controller using the new rumble API Each call to this function cancels any previous rumble effect, and calling it with 0 intensity stops any rumbling. This will return false if the controller doesn't support vibration or if SDL was unable to start vibration (maybe the controller doesn't support left/right vibration, maybe it was unplugged in the middle of trying, etc...)

Parameters
leftMagnitude:float

The intensity of the left rumble motor (this should be between 0 and 1)

rightMagnitude:float

The intensity of the right rumble motor (this should be between 0 and 1)

Returns:boolean

Whether or not the controller was able to be vibrated (i.e. if haptics are supported)

Exceptions
ControllerUnpluggedException:
If the controller is not connected
ensureConnectedback to summary
private void ensureConnected() throws ControllerUnpluggedException

Convenience method to throw an exception if the controller is not connected.

getAxisStateback to summary
public float getAxisState(ControllerAxis toCheck) throws ControllerUnpluggedException

Returns the current state of a passed axis.

Parameters
toCheck:ControllerAxis

The ControllerAxis to check the state of

Returns:float

The current state of the requested axis.

Exceptions
ControllerUnpluggedException:
If the controller is not connected
getDeviceInstanceIDback to summary
public int getDeviceInstanceID() throws ControllerUnpluggedException

Returns the instance ID of the current controller, which uniquely identifies the device from the time it is connected until it is disconnected.

Returns:int

The instance ID of the current controller

Exceptions
ControllerUnpluggedException:
If the controller is not connected
getIndexback to summary
public int getIndex()

Returns the index of the current controller.

Returns:int

The index of the current controller.

getNameback to summary
public String getName() throws ControllerUnpluggedException

Returns the implementation dependent name of this controller.

Returns:String

The the name of this controller

Exceptions
ControllerUnpluggedException:
If the controller is not connected
getPlayerIndexback to summary
public int getPlayerIndex() throws ControllerUnpluggedException
Returns:int

player index if set and supported, -1 otherwise

getPowerLevelback to summary
public ControllerPowerLevel getPowerLevel() throws ControllerUnpluggedException
Returns:ControllerPowerLevel

current power level of game controller, see ControllerPowerLevel enum values

Exceptions
ControllerUnpluggedException:
If the controller is not connected
isAxisAvailableback to summary
public boolean isAxisAvailable(ControllerAxis toCheck) throws ControllerUnpluggedException

Returns if passed axis is available on controller.

Parameters
toCheck:ControllerAxis

The ControllerAxis to check

Exceptions
ControllerUnpluggedException:
If the controller is not connected
isButtonAvailableback to summary
public boolean isButtonAvailable(ControllerButton toCheck) throws ControllerUnpluggedException

Returns if a given button is available on controller.

Parameters
toCheck:ControllerButton

The ControllerButton to check

Exceptions
ControllerUnpluggedException:
If the controller is not connected
isButtonJustPressedback to summary
public boolean isButtonJustPressed(ControllerButton toCheck) throws ControllerUnpluggedException

Returns whether or not a given button has just been pressed since you last made a query about that button (either through this method, isButtonPressed(), or through the ControllerState side of things). If the button was not pressed the last time you checked but is now, this method will return true.

Parameters
toCheck:ControllerButton

The ControllerButton to check the state of

Returns:boolean

Whether or not the button has just been pressed.

Exceptions
ControllerUnpluggedException:
If the controller is not connected
isButtonPressedback to summary
public boolean isButtonPressed(ControllerButton toCheck) throws ControllerUnpluggedException

Returns whether or not a given button has been pressed.

Parameters
toCheck:ControllerButton

The ControllerButton to check the state of

Returns:boolean

Whether or not the button is pressed.

Exceptions
ControllerUnpluggedException:
If the controller is not connected
isConnectedback to summary
public boolean isConnected()

Return whether or not the controller is currently connected. This first checks that the controller was successfully connected to our SDL backend. Then we check if the controller is currently plugged in.

Returns:boolean

Whether or not the controller is plugged in.

nativeAxisAvailableback to summary
private native boolean nativeAxisAvailable(long controllerPtr, int axisIndex)
nativeButtonAvailableback to summary
private native boolean nativeButtonAvailable(long controllerPtr, int buttonIndex)
nativeCanVibrateback to summary
private native boolean nativeCanVibrate(long controllerPtr)
nativeCheckAxisback to summary
private native int nativeCheckAxis(long controllerPtr, int axisIndex)
nativeCheckButtonback to summary
private native boolean nativeCheckButton(long controllerPtr, int buttonIndex)
nativeCloseback to summary
private native void nativeClose(long controllerPtr)
nativeConnectControllerback to summary
private native long nativeConnectController(int index)
nativeDoVibrationback to summary
private native boolean nativeDoVibration(long controllerPtr, int leftMagnitude, int rightMagnitude, int duration_ms)
nativeGetDeviceInstanceIDback to summary
private native int nativeGetDeviceInstanceID(long controllerPtr)
nativeGetNameback to summary
private native String nativeGetName(long controllerPtr)
nativeGetPlayerIndexback to summary
private native int nativeGetPlayerIndex(long controllerPtr)
nativeGetPowerLevelback to summary
private native int nativeGetPowerLevel(long controllerPtr)
nativeIsConnectedback to summary
private native boolean nativeIsConnected(long controllerPtr)
nativeSetPlayerIndexback to summary
private native void nativeSetPlayerIndex(long controllerPtr, int index)
reconnectControllerback to summary
public boolean reconnectController()

Close and reconnect to the native gamepad at the index associated with this ControllerIndex object. This is will refresh the gamepad represented here. This should be called if something is plugged in or unplugged.

Returns:boolean

whether or not the controller could successfully reconnect.

setPlayerIndexback to summary
public void setPlayerIndex(int index) throws ControllerUnpluggedException

Sets player index. At the time being, this doesn't seem to change the indication lights on a controller on Windows, Linux and Mac, but only an internal representation index.

Parameters
index:int

index to set

updateButtonback to summary
private void updateButton(int buttonIndex) throws ControllerUnpluggedException