diff options
author | cjcdoomed <[email protected]> | 2005-05-20 14:25:24 +0000 |
---|---|---|
committer | cjcdoomed <[email protected]> | 2005-05-20 14:25:24 +0000 |
commit | ee13fe12cf230da1cd9ca9c1dbbe82af9eb428fc (patch) | |
tree | 5e7472f2654834236c171ae2e37335c96095eb39 /plugins/OSX/src | |
parent | 093c179997b7ab42667c9d050d86e83ccad758fe (diff) |
Issue number: Implemented OSXJoystick functionality
Submitted by: Chris Cooper [email protected]
git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@93 e343933a-64c8-49c5-92b1-88f2ce3e89e8
Diffstat (limited to 'plugins/OSX/src')
-rw-r--r-- | plugins/OSX/src/java/net/java/games/input/OSXJoystick.java | 217 |
1 files changed, 207 insertions, 10 deletions
diff --git a/plugins/OSX/src/java/net/java/games/input/OSXJoystick.java b/plugins/OSX/src/java/net/java/games/input/OSXJoystick.java index f200514..f20fb57 100644 --- a/plugins/OSX/src/java/net/java/games/input/OSXJoystick.java +++ b/plugins/OSX/src/java/net/java/games/input/OSXJoystick.java @@ -1,17 +1,34 @@ package net.java.games.input; +import java.util.ArrayList; +import java.util.List; + + /** - * Created by IntelliJ IDEA. - * User: gpierce - * Date: Aug 2, 2003 - * Time: 3:58:45 PM - * To change this template use Options | File Templates. + * Joystick class which recognizes most of the enhanced joystick features + * including: + * x, y, and z axis + * x, y axis rotation + * slider + * hat + * */ public class OSXJoystick extends AbstractController implements InputController { private OSXEnvironmentPlugin plugin; private long lpDevice; private long lpQueue; + private int buttonCount = 0; + private List buttons = new ArrayList(); + + private Axis xAxis = null; + private Axis yAxis = null; + private Axis zAxis = null; + private Axis xAxisRotation = null; + private Axis yAxisRotation = null; + private Axis zAxisRotation = null; + private Axis slider = null; + private Axis hat = null; public OSXJoystick( OSXEnvironmentPlugin plugin, long lpDevice, String productName ) { @@ -22,7 +39,14 @@ public class OSXJoystick extends AbstractController implements InputController openDevice(); } - + + /** + * Returns the type of the Controller. + */ + public Type getType() { + return Type.STICK; + } + public boolean poll() { plugin.pollDevice( lpQueue ); @@ -45,19 +69,99 @@ public class OSXJoystick extends AbstractController implements InputController plugin.pollDevice( this.lpQueue ); } + public Component[] getComponents() { + List cpList = new ArrayList(buttons); + if (xAxis != null) cpList.add(xAxis); + if (yAxis != null) cpList.add(yAxis); + if (zAxis != null) cpList.add(zAxis); + if (xAxisRotation != null) cpList.add(xAxisRotation); + if (yAxisRotation != null) cpList.add(yAxisRotation); + if (zAxisRotation != null) cpList.add(zAxisRotation); + if (slider != null) cpList.add(slider); + if (hat != null) cpList.add(hat); + Component[] ca = new Component[cpList.size()]; + return (Component[]) cpList.toArray(ca); + } + + public void addControllerElement(InputControllerElement element) { + switch ( element.getElementType() ) { - case OSXEnvironmentPlugin.HID_ELEMENTTYPE_INPUT_MISC: - System.out.println("*Adding misc component"); - break; case OSXEnvironmentPlugin.HID_ELEMENTTYPE_INPUT_BUTTON: - System.out.println("*Adding button"); + Button button = null; + switch (buttonCount) { + case 0: + button = new Button(Component.Identifier.Button.TRIGGER, element); + break; + case 1: + button = new Button(Component.Identifier.Button._2, element); + break; + case 2: + button = new Button(Component.Identifier.Button._3, element); + break; + case 3: + button = new Button(Component.Identifier.Button._4, element); + break; + case 4: + button = new Button(Component.Identifier.Button._5, element); + break; + case 5: + button = new Button(Component.Identifier.Button._6, element); + break; + case 6: + button = new Button(Component.Identifier.Button._7, element); + break; + case 7: + button = new Button(Component.Identifier.Button._8, element); + break; + case 8: + button = new Button(Component.Identifier.Button._9, element); + break; + default: + String name = String.valueOf(buttonCount + 1); + button = new Button(new Component.Identifier.Button(name), element); + break; + } + buttons.add(button); + buttonCount++; + System.out.println("Adding button [" + buttonCount + "]"); break; + case OSXEnvironmentPlugin.HID_ELEMENTTYPE_INPUT_MISC: case OSXEnvironmentPlugin.HID_ELEMENTTYPE_INPUT_AXIS: + switch (element.getUsage()) { + case OSXEnvironmentPlugin.HID_USAGE_XAXIS: + xAxis = new Axis(Component.Identifier.Axis.X, element); + break; + case OSXEnvironmentPlugin.HID_USAGE_YAXIS: + yAxis = new Axis(Component.Identifier.Axis.Y, element); + break; + case OSXEnvironmentPlugin.HID_USAGE_ZAXIS: + zAxis = new Axis(Component.Identifier.Axis.Z, element); + break; + case OSXEnvironmentPlugin.HID_USAGE_XAXIS_ROTATION: + xAxisRotation = new Axis(Component.Identifier.Axis.RX, element); + break; + case OSXEnvironmentPlugin.HID_USAGE_YAXIS_ROTATION: + yAxisRotation = new Axis(Component.Identifier.Axis.RY, element); + break; + case OSXEnvironmentPlugin.HID_USAGE_ZAXIS_ROTATION: + zAxisRotation = new Axis(Component.Identifier.Axis.RZ, element); + break; + case OSXEnvironmentPlugin.HID_USAGE_SLIDER: + slider = new Axis(Component.Identifier.Axis.SLIDER, element); + break; + case OSXEnvironmentPlugin.HID_USAGE_HAT: + hat = new Axis(Component.Identifier.Axis.POV, element); + break; + default: + System.out.println("*Unknown axis"); + break; + } + System.out.println("*Adding axis"); break; @@ -80,4 +184,97 @@ public class OSXJoystick extends AbstractController implements InputController } } + + /** + * Mouse button axis implementation + */ + class Button extends AbstractComponent + { + + private long hidCookie; + private boolean isRelative; + + + + /** Public constructor + * @param id An ID of a button to create an obejct to represent. + * + */ + public Button(Component.Identifier.Button id, InputControllerElement element) + { + super(id.getName(), id); + this.hidCookie = element.getHidCookie(); + this.isRelative = element.isRelative(); + } + + /** Returns the data from the last time the control has been polled. + * If this axis is a button, the value returned will be either 0.0f or 1.0f. + * If this axis is normalized, the value returned will be between -1.0f and + * 1.0f. + * @return state of controller. (Note: DX8 mice actually + * queue state so what is returned is the next state, + * not necessarily the most current one.) + */ + public float getPollData() + { + return (float) plugin.pollElement( lpDevice, hidCookie ); + } + + /** Returns <code>true</code> if data returned from <code>poll</code> + * is relative to the last call, or <code>false</code> if data + * is absolute. + * @return true if data is relative, otherwise false. + */ + public boolean isRelative() + { + return isRelative; + } + } + + + /** + * Mouse button axis implementation + */ + class Axis extends AbstractComponent + { + + private long hidCookie; + private boolean isRelative; + + /** Public constructor + * @param id An ID of a button to create an obejct to represent. + * + */ + public Axis(Component.Identifier id, InputControllerElement element) + { + super(id.getName(), id); + this.hidCookie = element.getHidCookie(); + this.isRelative = element.isRelative(); + } + + /** Returns the data from the last time the control has been polled. + * If this axis is a button, the value returned will be either 0.0f or 1.0f. + * If this axis is normalized, the value returned will be between -1.0f and + * 1.0f. + * @return state of controller. (Note: DX8 mice actually + * queue state so what is returned is the next state, + * not necessarily the most current one.) + */ + public float getPollData() + { + return (float) plugin.pollElement( lpDevice, hidCookie ); + } + + /** Returns <code>true</code> if data returned from <code>poll</code> + * is relative to the last call, or <code>false</code> if data + * is absolute. + * @return true if data is relative, otherwise false. + */ + public boolean isRelative() + { + return isRelative; + } + } + + } |