public class Joystick extends Object implements Runnable, JoystickObserver
Responsible for finding any input devices attached. We know about at this writing the Logitech Freedom 2.4 device and the Macally airstick, and have mappings for those devices into command inputs for AVCL.
This implements a singleton pattern. To retrieve a joystick object, use Joystick.getJoystick();
Note that "Controller" is a net.java.games.input object.
To add a new type of joystick: 1) Determine its name, as retrieved by the controller.getName() in jinput 2) add the name to the knownJoystickNames array 3) add a mappings Map object, which matches the button press or joystick tilt axis named to the workbench operation we want to happen; 4) add that mappings object to the stickNameToJoystickEventCommandTypeMappings lookup
Modifier and Type | Field and Description |
---|---|
static Map<String,Map<String,String>> |
componentToDescriptionMappings
Key is the name of the joystick ("Logitech Freedom 2.4"), value is the mappings
hashmap of the user-picked description for the location of the control and control
itself
|
static Map<String,Map<String,Double>> |
componentToScalingMappings |
List<JoystickEventListener> |
joystickEventListenerList
Holds list of objects that receive joystick events
|
static String[] |
knownJoystickNames
The name, as returned by the controller.getName() method, of the joysticks that we have tested and support
|
static String |
selectedJoystickName
The name of the joystick that has been selected from all the possible joysticks;
the first available device that matches a name of the supported joysticks
|
static float |
SIGNIFICANT_JOYSTICK_VALUE
Treat joystick events with values below this as zero
|
static Map<String,Map<String,JoystickEvent.CommandType>> |
stickNameToJoystickEventCommandTypeMappings
Key is the name of the joystick ("Logitech Freedom 2.4"), value is the
mappings hashmap for that joystick, which maps jinput-returned events to our AUV events
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(JoystickEventListener newListener)
JoystickObserver interface implementation.
|
static Joystick |
getJoystick()
If a supported joystick is present it returns a joystick object
object for that.
|
String |
getName() |
boolean |
isFound() |
static boolean |
isJoystickPresent()
Returns true if there is a supported joystick present
|
static void |
listControllers()
Debugging.
|
static void |
main(String[] args) |
void |
removeAllListeners()
Removes all objects that are listening for joystick events
|
void |
removeListener(JoystickEventListener listener)
JoystickObserver interface implementation. removes an object
that is listening for events.
|
void |
run() |
void |
setRunning(boolean status) |
void |
stopPollingThread()
Causes the joystick polling thread to exit
|
public static final String[] knownJoystickNames
public static String selectedJoystickName
public static Map<String,Map<String,JoystickEvent.CommandType>> stickNameToJoystickEventCommandTypeMappings
public static Map<String,Map<String,String>> componentToDescriptionMappings
public final List<JoystickEventListener> joystickEventListenerList
public static final float SIGNIFICANT_JOYSTICK_VALUE
public static void main(String[] args)
public static boolean isJoystickPresent()
Joystick
is connectedpublic static Joystick getJoystick()
Joystick
public String getName()
public boolean isFound()
public static void listControllers()
public void addListener(JoystickEventListener newListener)
addListener
in interface JoystickObserver
newListener
- public void removeListener(JoystickEventListener listener)
removeListener
in interface JoystickObserver
listener
- public void setRunning(boolean status)
public void removeAllListeners()
JoystickObserver
removeAllListeners
in interface JoystickObserver
public void stopPollingThread()
stopPollingThread
in interface JoystickObserver