aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorgregorypierce <[email protected]>2003-08-07 18:28:18 +0000
committergregorypierce <[email protected]>2003-08-07 18:28:18 +0000
commit099f3acc0e35dbc83a5f33f5647fa19aea0bd2bd (patch)
tree2067020a666c8738914e07f367fc5e06528598c1 /plugins
parentf6211c23ed7c742db5ae961ab2c36f1c22edef40 (diff)
no message
git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@40 e343933a-64c8-49c5-92b1-88f2ce3e89e8
Diffstat (limited to 'plugins')
-rw-r--r--plugins/OSX/src/java/net/java/games/input/InputController.java211
-rw-r--r--plugins/OSX/src/java/net/java/games/input/InputControllerElement.java36
-rwxr-xr-xplugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java144
-rw-r--r--plugins/OSX/src/java/net/java/games/input/OSXGamepad.java70
-rw-r--r--plugins/OSX/src/java/net/java/games/input/OSXJoystick.java71
-rw-r--r--plugins/OSX/src/java/net/java/games/input/OSXKeyboard.java83
-rw-r--r--plugins/OSX/src/java/net/java/games/input/OSXMouse.java267
-rw-r--r--plugins/OSX/src/native/jinputjnilib.c144
8 files changed, 680 insertions, 346 deletions
diff --git a/plugins/OSX/src/java/net/java/games/input/InputController.java b/plugins/OSX/src/java/net/java/games/input/InputController.java
index 77dbd5c..2a5442b 100644
--- a/plugins/OSX/src/java/net/java/games/input/InputController.java
+++ b/plugins/OSX/src/java/net/java/games/input/InputController.java
@@ -1,7 +1,5 @@
package net.java.games.input;
-import java.util.HashMap;
-
/**
* Created by IntelliJ IDEA.
* User: gpierce
@@ -9,212 +7,7 @@ import java.util.HashMap;
* Time: 2:57:15 PM
* To change this template use Options | File Templates.
*/
-public class InputController
+public interface InputController
{
- private OSXEnvironmentPlugin plugin;
- private long lpDevice;
- private long lpQueue;
- private int queueDepth;
- private String transportKey;
- private int vendorID;
- private int productID;
- private int version;
- private String manufacturer;
- private String productName;
- private String serialNumber;
- private int usbLocationID;
- private int usagePage;
- private int usage;
-
- private HashMap controllerElements = new HashMap();
-
- public InputController( OSXEnvironmentPlugin plugin )
- {
- this.plugin = plugin;
- }
-
- public InputController(OSXEnvironmentPlugin plugin, long lpDevice, String productName, int usage)
- {
- this.plugin = plugin;
- this.lpDevice = lpDevice;
- this.productName = productName;
- this.usage = usage;
- }
-
- public InputController( OSXEnvironmentPlugin plugin, long lpDevice, String transportKey, int vendorID, int productID, int version, String manufacturer, String productName, String serialNumber, int usbLocationID, int usagePage, int usage)
- {
- this.plugin = plugin;
- this.lpDevice = lpDevice;
- this.transportKey = transportKey;
- this.vendorID = vendorID;
- this.productID = productID;
- this.version = version;
- this.manufacturer = manufacturer;
- this.productName = productName;
- this.serialNumber = serialNumber;
- this.usbLocationID = usbLocationID;
- this.usagePage = usagePage;
- this.usage = usage;
- }
-
- public long getLpQueue()
- {
- return lpQueue;
- }
-
- public void setLpQueue(long lpQueue)
- {
- this.lpQueue = lpQueue;
- }
-
- public int getQueueDepth()
- {
- return queueDepth;
- }
-
- public void setQueueDepth(int queueDepth)
- {
- this.queueDepth = queueDepth;
- }
-
- public long getLpDevice()
- {
- return lpDevice;
- }
-
- public void setLpDevice(long lpDevice)
- {
- this.lpDevice = lpDevice;
- }
-
- public String getTransportKey()
- {
- return transportKey;
- }
-
- public void setTransportKey(String transportKey)
- {
- this.transportKey = transportKey;
- }
-
- public int getVendorID()
- {
- return vendorID;
- }
-
- public void setVendorID(int vendorID)
- {
- this.vendorID = vendorID;
- }
-
- public int getProductID()
- {
- return productID;
- }
-
- public void setProductID(int productID)
- {
- this.productID = productID;
- }
-
- public int getVersion()
- {
- return version;
- }
-
- public void setVersion(int version)
- {
- this.version = version;
- }
-
- public String getManufacturer()
- {
- return manufacturer;
- }
-
- public void setManufacturer(String manufacturer)
- {
- this.manufacturer = manufacturer;
- }
-
- public String getProductName()
- {
- return productName;
- }
-
- public void setProductName(String productName)
- {
- this.productName = productName;
- }
-
- public String getSerialNumber()
- {
- return serialNumber;
- }
-
- public void setSerialNumber(String serialNumber)
- {
- this.serialNumber = serialNumber;
- }
-
- public int getUsbLocationID()
- {
- return usbLocationID;
- }
-
- public void setUsbLocationID(int usbLocationID)
- {
- this.usbLocationID = usbLocationID;
- }
-
- public int getUsagePage()
- {
- return usagePage;
- }
-
- public void setUsagePage(int usagePage)
- {
- this.usagePage = usagePage;
- }
-
- public int getUsage()
- {
- return usage;
- }
-
- public void setUsage(int usage)
- {
- this.usage = usage;
- }
-
- public HashMap getControllerElements()
- {
- return controllerElements;
- }
-
- public void addControllerElement( InputControllerElement controllerElement )
- {
- controllerElements.put( new Long(controllerElement.getHidCookie()), controllerElement );
- }
-
- public InputControllerElement getControllerElement( long hidCookie )
- {
- return (InputControllerElement) controllerElements.get( new Long( hidCookie ) );
- }
-
-
- public void openDevice()
- {
- this.lpQueue = plugin.openDevice( this.lpDevice, 32 );
- }
-
- public void closeDevice()
- {
- plugin.closeDevice( this.lpDevice, this.lpQueue );
- }
-
- public void pollDevice()
- {
- plugin.pollDevice( this.lpQueue );
- }
+ public void addControllerElement( InputControllerElement element );
}
diff --git a/plugins/OSX/src/java/net/java/games/input/InputControllerElement.java b/plugins/OSX/src/java/net/java/games/input/InputControllerElement.java
index af6e2e5..8ba92c3 100644
--- a/plugins/OSX/src/java/net/java/games/input/InputControllerElement.java
+++ b/plugins/OSX/src/java/net/java/games/input/InputControllerElement.java
@@ -11,7 +11,8 @@ public class InputControllerElement
{
private long hidCookie;
private int elementType;
- private String elementName;
+ private int usagePage;
+ private int usage;
private int rawMin;
private int rawMax;
@@ -30,22 +31,23 @@ public class InputControllerElement
{
}
- public InputControllerElement(long hidCookie, int elementType, String elementName,
+ public InputControllerElement(long hidCookie, int elementType, int usage, int usagePage,
int rawMin, int rawMax, int scaledMin, int scaledMax,
- int dataBitSize, boolean relative, boolean wrapping,
- boolean nonLinear, boolean hasPreferredState, boolean hasNullState )
+ int dataBitSize, boolean isRelative, boolean isWrapping,
+ boolean isNonLinear, boolean hasPreferredState, boolean hasNullState )
{
this.hidCookie = hidCookie;
this.elementType = elementType;
- this.elementName = elementName;
+ this.usage = usage;
+ this.usagePage = usagePage;
this.rawMin = rawMin;
this.rawMax = rawMax;
this.scaledMin = scaledMin;
this.scaledMax = scaledMax;
this.dataBitSize = dataBitSize;
- isRelative = relative;
- isWrapping = wrapping;
- isNonLinear = nonLinear;
+ this.isRelative = isRelative;
+ this.isWrapping = isWrapping;
+ this.isNonLinear = isNonLinear;
this.hasPreferredState = hasPreferredState;
this.hasNullState = hasNullState;
}
@@ -70,14 +72,24 @@ public class InputControllerElement
this.elementType = elementType;
}
- public String getElementName()
+ public int getUsagePage()
+ {
+ return usagePage;
+ }
+
+ public void setUsagePage(int usagePage)
+ {
+ this.usagePage = usagePage;
+ }
+
+ public int getUsage()
{
- return elementName;
+ return usage;
}
- public void setElementName(String elementName)
+ public void setUsage(int usage)
{
- this.elementName = elementName;
+ this.usage = usage;
}
public int getRawMin()
diff --git a/plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java b/plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java
index 0fb6d54..8f6e5c8 100755
--- a/plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java
+++ b/plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java
@@ -69,10 +69,60 @@ public class OSXEnvironmentPlugin extends ControllerEnvironment implements Plugi
public native void closeDevice( long lpDevice, long lpInputQueue );
public native void pollDevice( long lpInputQueue );
- private static final int HID_DEVICE_MOUSE = 0x02;
- private static final int HID_DEVICE_JOYSTICK = 0x04;
- private static final int HID_DEVICE_GAMEPAD = 0x05;
- private static final int HID_DEVICE_KEYBOARD = 0x06;
+ public static final int HID_DEVICE_MOUSE = 0x02;
+ public static final int HID_DEVICE_JOYSTICK = 0x04;
+ public static final int HID_DEVICE_GAMEPAD = 0x05;
+ public static final int HID_DEVICE_KEYBOARD = 0x06;
+
+
+ public static final int HID_USAGE_POINTER = 0x01;
+ public static final int HID_USAGE_XAXIS = 0x30;
+ public static final int HID_USAGE_YAXIS = 0x31;
+ public static final int HID_USAGE_ZAXIS = 0x32;
+ public static final int HID_USAGE_XAXIS_ROTATION = 0x33;
+ public static final int HID_USAGE_YAXIS_ROTATION = 0x34;
+ public static final int HID_USAGE_ZAXIS_ROTATION = 0x35;
+ public static final int HID_USAGE_SLIDER = 0x36;
+ public static final int HID_USAGE_DIAL = 0x37;
+ public static final int HID_USAGE_WHEEL = 0x38;
+ public static final int HID_USAGE_HAT = 0x39;
+ public static final int HID_USAGE_DPAD_UP = 0x90;
+ public static final int HID_USAGE_DPAD_DOWN = 0x91;
+ public static final int HID_USAGE_DPAD_LEFT = 0x92;
+ public static final int HID_USAGE_DPAD_RIGHT = 0x93;
+
+ public static final int HID_USAGEPAGE_UNDEFINED = 0x00;
+ public static final int HID_USAGEPAGE_GENERICDESKTOP = 0x01;
+ public static final int HID_USAGEPAGE_SIMULATION = 0x02;
+ public static final int HID_USAGEPAGE_VR = 0x03;
+ public static final int HID_USAGEPAGE_SPORT = 0x04;
+ public static final int HID_USAGEPAGE_GAME = 0x05;
+ public static final int HID_USAGEPAGE_KEYBOARD = 0x07; /* USB Device Class Definition for Human Interface Devices (HID). Note: the usage type for all key codes is Selector (Sel). */
+ public static final int HID_USAGEPAGE_LED = 0x08;
+ public static final int HID_USAGEPAGE_BUTTON = 0x09;
+ public static final int HID_USAGEPAGE_ORDINAL = 0x0A;
+ public static final int HID_USAGEPAGE_TELEPHONY = 0x0B;
+ public static final int HID_USAGEPAGE_CONSUMER = 0x0C;
+ public static final int HID_USAGEPAGE_DIGITIZER = 0x0D;
+ public static final int HID_USAGEPAGE_PID = 0x0F; /* USB Physical Interface Device definitions for force feedback and related devices. */
+ public static final int HID_USAGEPAGE_UNICODE = 0x10;
+ public static final int HID_USAGEPAGE_ALPHANUMERIC_DISPLAY = 0x14;
+ public static final int HID_USAGEPAGE_POWERDEVICE = 0x84; /* Power Device Page */
+ public static final int HID_USAGEPAGE_BATTERY_SYSTEM = 0x85; /* Battery System Page */
+ public static final int HID_USAGEPAGE_BARCODE_SCANNER = 0x8C; /* (Point of Sale) USB Device Class Definition for Bar Code Scanner Devices */
+ public static final int HID_USAGEPAGE_SCALE = 0x8D; /* (Point of Sale) USB Device Class Definition for Scale Devices */
+ public static final int HID_USAGEPAGE_CAMERA_CONTROL = 0x90; /* USB Device Class Definition for Image Class Devices */
+ public static final int HID_USAGEPAGE_ARCADE = 0x91; /* OAAF Definitions for arcade and coinop related Devices */
+ public static final int HID_USAGEPAGE_VENDOR_DEFINED_START = 0xFF00;
+
+
+ public static final int HID_ELEMENTTYPE_INPUT_MISC = 1;
+ public static final int HID_ELEMENTTYPE_INPUT_BUTTON = 2;
+ public static final int HID_ELEMENTTYPE_INPUT_AXIS = 3;
+ public static final int HID_ELEMENTTYPE_INPUT_SCANCODES = 4;
+ public static final int HID_ELEMENTTYPE_OUTPUT = 129;
+ public static final int HID_ELEMENTTYPE_FEATURE = 257;
+ public static final int HID_ELEMENTTYPE_COLLECTION = 513;
private HashMap devices = new HashMap();
@@ -88,66 +138,90 @@ public class OSXEnvironmentPlugin extends ControllerEnvironment implements Plugi
return (Controller[])devices.values().toArray();
}
- public InputController createController( long lpDevice,
- String productName,
- int usage )
+ public Controller createController( long lpDevice, String productName, int usage )
{
switch (usage)
{
case (HID_DEVICE_MOUSE):
- System.out.println("Found mouse [" + productName + "]");
- return new OSXMouse( this, lpDevice, productName, usage );
+ System.out.println("Found mouse [" + productName + "] device address [" + lpDevice + "]");
+ return new OSXMouse( this, lpDevice, productName );
case (HID_DEVICE_JOYSTICK):
- System.out.println("Found joystick [" + productName + "]");
- return new OSXJoystick( this, lpDevice, productName, usage );
+ System.out.println("Found joystick [" + productName + "] device address [" + lpDevice + "]");
+ return new OSXJoystick( this, lpDevice, productName );
case (HID_DEVICE_GAMEPAD):
- System.out.println("Found gamepad [" + productName + "]");
- return new OSXGamepad( this, lpDevice, productName, usage );
+ System.out.println("Found gamepad [" + productName + "] device address [" + lpDevice + "]");
+ return new OSXGamepad( this, lpDevice, productName );
case (HID_DEVICE_KEYBOARD):
- System.out.println("Found keyboard [" + productName + "]");
- return new OSXKeyboard( this, lpDevice, productName, usage );
+ System.out.println("Found keyboard [" + productName + "] device address [" + lpDevice + "]");
+ return new OSXKeyboard( this, lpDevice, productName );
+
default:
- System.out.println("Found device of unknown type [" + usage + "],[" + productName + "] - ignoring");
+ System.out.println("Found device of unknown or unsupported type. Usage[" + usage + "], ProductName[" + productName + "] - ignoring");
return null;
}
}
- private void addController( long lpDevice,
- String productName,
- int usage )
+ /**
+ * Add a controller to the device list
+ * @param lpDevice
+ * @param productName
+ * @param usage
+ */
+ private void addController( long lpDevice, String productName, int usage )
{
- InputController controller = null;
+ Controller controller = null;
controller = createController( lpDevice, productName, usage );
if ( controller != null )
{
- devices.put( productName, controller );
+ devices.put( new Long(lpDevice), controller );
}
}
+ /**
+ * Adds an InputControllerElement to a device. This method is invoked from native code.
+ * @param lpDevice
+ * @param elementCookie
+ * @param elementType
+ * @param usage
+ * @param usagePage
+ * @param rawMin
+ * @param rawMax
+ * @param scaledMin
+ * @param scaledMax
+ * @param dataBitSize
+ * @param isRelative
+ * @param isWrapping
+ * @param isNonLinear
+ * @param hasPreferredState
+ * @param hasNullState
+ */
private void addControllerElement( long lpDevice,
- long hidCookie,
+ long elementCookie,
int elementType,
- String elementName,
+ int usage,
+ int usagePage,
int rawMin,
int rawMax,
- int scaledMin,
- int scaledMax,
- int dataBitSize,
- boolean relative,
- boolean wrapping,
- boolean nonLinear,
- boolean hasPreferredState,
- boolean hasNullState)
+ int scaledMin,
+ int scaledMax,
+ int dataBitSize,
+ boolean isRelative,
+ boolean isWrapping,
+ boolean isNonLinear,
+ boolean hasPreferredState,
+ boolean hasNullState)
{
-
- System.out.println("Added new element [" + hidCookie + "] to controller [" + lpDevice + "]");
- InputControllerElement element = new InputControllerElement( hidCookie, elementType, elementName,
+ InputControllerElement element = new InputControllerElement( elementCookie, usagePage, usage, usagePage,
rawMin, rawMax, scaledMin, scaledMax,
- dataBitSize, relative, wrapping, nonLinear,
+ dataBitSize, isRelative, isWrapping, isNonLinear,
hasPreferredState, hasNullState );
+
+
+ InputController inputController = (InputController)devices.get( new Long( lpDevice) );
+ inputController.addControllerElement( element );
}
diff --git a/plugins/OSX/src/java/net/java/games/input/OSXGamepad.java b/plugins/OSX/src/java/net/java/games/input/OSXGamepad.java
index 5858122..d739b6c 100644
--- a/plugins/OSX/src/java/net/java/games/input/OSXGamepad.java
+++ b/plugins/OSX/src/java/net/java/games/input/OSXGamepad.java
@@ -7,20 +7,76 @@ package net.java.games.input;
* Time: 3:59:09 PM
* To change this template use Options | File Templates.
*/
-public class OSXGamepad extends InputController
+public class OSXGamepad extends AbstractController implements InputController
{
- public OSXGamepad( OSXEnvironmentPlugin plugin )
+ private OSXEnvironmentPlugin plugin;
+ private long lpDevice;
+ private long lpQueue;
+
+ public OSXGamepad( OSXEnvironmentPlugin plugin, long lpDevice, String productName )
+ {
+ super( productName );
+
+ this.plugin = plugin;
+ this.lpDevice = lpDevice;
+
+ openDevice();
+ }
+ public boolean poll()
+ {
+ plugin.pollDevice( lpQueue );
+
+ return true;
+ }
+
+ public void openDevice()
+ {
+ this.lpQueue = plugin.openDevice( this.lpDevice, 32 );
+ }
+
+ public void closeDevice()
{
- super( plugin );
+ plugin.closeDevice( this.lpDevice, this.lpQueue );
}
- public OSXGamepad( OSXEnvironmentPlugin plugin, long lpDevice, String productName, int usage )
+ public void pollDevice()
{
- super( plugin, lpDevice, productName, usage );
+ plugin.pollDevice( this.lpQueue );
}
- public OSXGamepad( OSXEnvironmentPlugin plugin, long lpDevice, String transportKey, int vendorID, int productID, int version, String manufacturer, String productName, String serialNumber, int usbLocationID, int usagePage, int usage)
+ public void addControllerElement(InputControllerElement element)
{
- super( plugin, lpDevice, transportKey, vendorID, productID, version, manufacturer, productName, serialNumber, usbLocationID, usagePage, usage );
+ 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");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_INPUT_AXIS:
+ System.out.println("*Adding axis");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_INPUT_SCANCODES:
+ System.out.println("*Adding scancode");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_OUTPUT:
+ System.out.println("*Adding forcefeedback");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_FEATURE:
+
+ System.out.println("*Adding feature");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_COLLECTION:
+ System.out.println("*Adding collection");
+ break;
+
+ }
}
}
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 588b1d4..f200514 100644
--- a/plugins/OSX/src/java/net/java/games/input/OSXJoystick.java
+++ b/plugins/OSX/src/java/net/java/games/input/OSXJoystick.java
@@ -7,20 +7,77 @@ package net.java.games.input;
* Time: 3:58:45 PM
* To change this template use Options | File Templates.
*/
-public class OSXJoystick extends InputController
+public class OSXJoystick extends AbstractController implements InputController
{
- public OSXJoystick( OSXEnvironmentPlugin plugin )
+ private OSXEnvironmentPlugin plugin;
+ private long lpDevice;
+ private long lpQueue;
+
+ public OSXJoystick( OSXEnvironmentPlugin plugin, long lpDevice, String productName )
{
- super( plugin );
+ super( productName );
+
+ this.plugin = plugin;
+ this.lpDevice = lpDevice;
+
+ openDevice();
}
- public OSXJoystick( OSXEnvironmentPlugin plugin, long lpDevice, String productName, int usage )
+ public boolean poll()
{
- super( plugin, lpDevice, productName, usage );
+ plugin.pollDevice( lpQueue );
+
+ return true;
}
- public OSXJoystick( OSXEnvironmentPlugin plugin, long lpDevice, String transportKey, int vendorID, int productID, int version, String manufacturer, String productName, String serialNumber, int usbLocationID, int usagePage, int usage)
+ public void openDevice()
{
- super( plugin, lpDevice, transportKey, vendorID, productID, version, manufacturer, productName, serialNumber, usbLocationID, usagePage, usage );
+ this.lpQueue = plugin.openDevice( this.lpDevice, 32 );
+ }
+
+ public void closeDevice()
+ {
+ plugin.closeDevice( this.lpDevice, this.lpQueue );
+ }
+
+ public void pollDevice()
+ {
+ plugin.pollDevice( this.lpQueue );
+ }
+
+ 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");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_INPUT_AXIS:
+ System.out.println("*Adding axis");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_INPUT_SCANCODES:
+ System.out.println("*Adding scancode");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_OUTPUT:
+ System.out.println("*Adding forcefeedback");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_FEATURE:
+
+ System.out.println("*Adding feature");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_COLLECTION:
+ System.out.println("*Adding collection");
+ break;
+
+ }
}
}
diff --git a/plugins/OSX/src/java/net/java/games/input/OSXKeyboard.java b/plugins/OSX/src/java/net/java/games/input/OSXKeyboard.java
index f745701..fa48a56 100644
--- a/plugins/OSX/src/java/net/java/games/input/OSXKeyboard.java
+++ b/plugins/OSX/src/java/net/java/games/input/OSXKeyboard.java
@@ -7,20 +7,89 @@ package net.java.games.input;
* Time: 3:57:58 PM
* To change this template use Options | File Templates.
*/
-public class OSXKeyboard extends InputController
+public class OSXKeyboard extends StandardKeyboard implements InputController
{
- public OSXKeyboard( OSXEnvironmentPlugin plugin )
+ private OSXEnvironmentPlugin plugin;
+ private long lpDevice;
+ private long lpQueue;
+
+ public OSXKeyboard( OSXEnvironmentPlugin plugin, long lpDevice, String productName )
+ {
+ super( productName );
+
+ this.plugin = plugin;
+ this.lpDevice = lpDevice;
+
+ openDevice();
+ }
+
+ public void openDevice()
+ {
+ this.lpQueue = plugin.openDevice( this.lpDevice, 32 );
+ }
+
+ public void closeDevice()
+ {
+ plugin.closeDevice( this.lpDevice, this.lpQueue );
+ }
+
+ public void pollDevice()
+ {
+ plugin.pollDevice( this.lpQueue );
+ }
+
+ public void addControllerElement(InputControllerElement element)
{
- super( plugin );
+/*
+ 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");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_INPUT_AXIS:
+ System.out.println("*Adding axis");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_INPUT_SCANCODES:
+ System.out.println("*Adding scancode");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_OUTPUT:
+ System.out.println("*Adding forcefeedback");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_FEATURE:
+
+ System.out.println("*Adding feature");
+ break;
+
+ case OSXEnvironmentPlugin.HID_ELEMENTTYPE_COLLECTION:
+ System.out.println("*Adding collection");
+ break;
+
+ default:
+ break;
+ }
+
+ System.out.println("Cookie [" + element.getHidCookie() + "]");
+*/
}
- public OSXKeyboard( OSXEnvironmentPlugin plugin, long lpDevice, String productName, int usage )
+ public boolean poll()
{
- super( plugin, lpDevice, productName, usage );
+ plugin.pollDevice( lpQueue );
+
+
+ return true;
}
- public OSXKeyboard( OSXEnvironmentPlugin plugin, long lpDevice, String transportKey, int vendorID, int productID, int version, String manufacturer, String productName, String serialNumber, int usbLocationID, int usagePage, int usage)
+ protected boolean isKeyPressed(Keyboard.Key key)
{
- super( plugin, lpDevice, transportKey, vendorID, productID, version, manufacturer, productName, serialNumber, usbLocationID, usagePage, usage );
+ return false;
}
}
diff --git a/plugins/OSX/src/java/net/java/games/input/OSXMouse.java b/plugins/OSX/src/java/net/java/games/input/OSXMouse.java
index 0318a86..0c1fe1a 100644
--- a/plugins/OSX/src/java/net/java/games/input/OSXMouse.java
+++ b/plugins/OSX/src/java/net/java/games/input/OSXMouse.java
@@ -7,20 +7,273 @@ package net.java.games.input;
* Time: 3:57:00 PM
* To change this template use Options | File Templates.
*/
-public class OSXMouse extends InputController
+public class OSXMouse extends Mouse implements InputController
{
- public OSXMouse( OSXEnvironmentPlugin plugin )
+ private OSXEnvironmentPlugin plugin;
+ private long lpDevice;
+ private long lpQueue;
+ private int buttonCount = 0;
+
+
+ public OSXMouse( OSXEnvironmentPlugin plugin, long lpDevice, String productName )
+ {
+ super( productName );
+
+ this.plugin = plugin;
+ this.lpDevice = lpDevice;
+
+ openDevice();
+
+ buttons = new ButtonsImpl();
+ ball = new BallImpl();
+ }
+
+ public void openDevice()
{
- super( plugin );
+ this.lpQueue = plugin.openDevice( this.lpDevice, 32 );
}
- public OSXMouse( OSXEnvironmentPlugin plugin, long lpDevice, String productName, int usage )
+ public void closeDevice()
{
- super( plugin, lpDevice, productName, usage );
+ plugin.closeDevice( this.lpDevice, this.lpQueue );
}
- public OSXMouse( OSXEnvironmentPlugin plugin, long lpDevice, String transportKey, int vendorID, int productID, int version, String manufacturer, String productName, String serialNumber, int usbLocationID, int usagePage, int usage)
+ public boolean poll()
{
- super( plugin, lpDevice, transportKey, vendorID, productID, version, manufacturer, productName, serialNumber, usbLocationID, usagePage, usage );
+ plugin.pollDevice( this.lpQueue );
+
+ return true;
+ }
+
+ public void addControllerElement(InputControllerElement element)
+ {
+
+ switch ( element.getUsagePage() )
+ {
+ case OSXEnvironmentPlugin.HID_USAGEPAGE_BUTTON:
+ buttonCount ++;
+ System.out.println("Adding button [" + buttonCount + "]");
+ ((ButtonsImpl)buttons).addButton(element);
+ break;
+
+
+ case OSXEnvironmentPlugin.HID_USAGEPAGE_GENERICDESKTOP:
+ switch( element.getUsage() )
+ {
+ case OSXEnvironmentPlugin.HID_USAGE_POINTER:
+ System.out.println("Adding pointer - this will contain axis");
+ break;
+
+ case OSXEnvironmentPlugin.HID_USAGE_XAXIS:
+ ((BallImpl)ball).addXAxis(element);
+ System.out.println("Adding X Axis") ;
+ break;
+
+ case OSXEnvironmentPlugin.HID_USAGE_YAXIS:
+ ((BallImpl)ball).addYAxis(element);
+ System.out.println("Adding Y Axis");
+ break;
+
+ case OSXEnvironmentPlugin.HID_USAGE_WHEEL:
+ ((BallImpl)ball).addWheelAxis(element);
+ System.out.println("Adding wheel");
+ break;
+
+ default:
+
+ }
+ break;
+
+
+ default:
+
+ }
}
+
+ /**
+ * Implementation class representing the mouse ball
+ */
+ class BallImpl extends Ball
+ {
+ /**
+ * Public constructor
+ */
+ public BallImpl()
+ {
+ super(OSXMouse.this.getName() + " ball");
+ }
+
+ public void addXAxis( InputControllerElement element )
+ {
+ x = new BallAxis( Axis.Identifier.X, element );
+ }
+
+ public void addYAxis( InputControllerElement element )
+ {
+ y = new BallAxis( Axis.Identifier.Y, element );
+ }
+
+ public void addWheelAxis( InputControllerElement element )
+ {
+ wheel = new BallAxis( Axis.Identifier.SLIDER, element );
+ }
+ }
+
+
+ /**
+ * Implementation class representing the mouse buttons
+ */
+ class ButtonsImpl extends Buttons
+ {
+ /**
+ * Public constructor
+ */
+ public ButtonsImpl()
+ {
+ super(OSXMouse.this.getName() + " buttons");
+ }
+
+ public void addButton( InputControllerElement element )
+ {
+ if ( left == null )
+ {
+ left = new ButtonImpl( ButtonID.LEFT, element );
+ }
+ else if ( right == null )
+ {
+ right = new ButtonImpl( ButtonID.RIGHT, element );
+ }
+ else if ( middle == null )
+ {
+ middle = new ButtonImpl( ButtonID.MIDDLE, element );
+ }
+ }
+ }
+
+ /**
+ * Mouse button axis implementation
+ */
+ class ButtonImpl extends Button
+ {
+
+ private long hidCookie;
+ private boolean isRelative;
+
+
+ /** Public constructor
+ * @param id An ID of a button to create an obejct to represent.
+ *
+ */
+ public ButtonImpl(ButtonID 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()
+ {
+/* // Mouse button
+ byte data = mouseData[index];
+ if ((data & 0x80) != 0)
+ {
+ return 1.0f;
+ }
+ else
+ {
+ return 0.0f;
+ }*/
+
+ return 0.0f;
+ }
+
+ /** 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 ball axis implementation
+ */
+ class BallAxis extends AbstractAxis
+ {
+
+ private long hidCookie;
+ private boolean isRelative;
+
+ /** Public constructor
+ * @param id An ID for a mouse axis to create an object to represent.
+ */
+ public BallAxis(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 data. (Note that mice queue state in DX8 so what
+ * is returned is the next stae in the queue, not
+ * necessarily the most current one.)
+ */
+ public float getPollData()
+ {
+/* int data = ((int) mouseData[index] << 12) |
+ ((int) mouseData[index + 1] << 8) |
+ ((int) mouseData[index + 2] << 4) |
+ ((int) mouseData[index + 3]);
+ if (data == -1)
+ {
+ return -1.0f;
+ }
+ else if (data >= 1)
+ {
+ return 1.0f;
+ }
+ else
+ {
+ return 0.0f;
+ }*/
+
+ return 0.0f;
+ }
+
+ /** 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 relative, otherwise false.
+ */
+ public boolean isRelative()
+ {
+ return isRelative;
+ }
+
+ /** Returns whether or not the axis is analog, or false if it is digital.
+ * @return true if analog, false if digital
+ */
+ public boolean isAnalog()
+ {
+ return true;
+ }
+ }
+
}
diff --git a/plugins/OSX/src/native/jinputjnilib.c b/plugins/OSX/src/native/jinputjnilib.c
index 148eee0..b711f10 100644
--- a/plugins/OSX/src/native/jinputjnilib.c
+++ b/plugins/OSX/src/native/jinputjnilib.c
@@ -74,10 +74,11 @@ jmethodID MID_AddController = NULL;
jmethodID MID_AddControllerElement = NULL;
mach_port_t masterPort = NULL;
io_iterator_t hidObjectIterator;
-int gElementIndex;
long elementCookie;
-long collectionType;
+long elementType;
+long usage;
+long usagePage;
long min;
long max;
long scaledMin;
@@ -91,6 +92,7 @@ jboolean isNonLinear;
JNIEnv * lpEnv;
jlong lpDevice;
jobject lpObj;
+jboolean completeElement = JNI_FALSE;
@@ -141,16 +143,10 @@ void CFObjectShow( CFTypeRef value )
CFTypeID type = CFGetTypeID(value);
if (type == CFArrayGetTypeID())
{
-
- printf("Array Type\n");
CFRange range = {0, CFArrayGetCount (value)};
- CFIndex savedIndex = gElementIndex;
//Show an element array containing one or more element dictionaries
- gElementIndex = 0; //Reset index to zero
CFArrayApplyFunction (value, range, showCFArray, 0);
-
- gElementIndex = savedIndex;
}
else if (type == CFBooleanGetTypeID())
{
@@ -239,7 +235,7 @@ Boolean init(JNIEnv* env)
return FALSE;
}
- MID_AddControllerElement = (*env)->GetMethodID(env, CLASS_JNIWrapper, "addControllerElement", "(JJILjava/lang/String;IIIIIZZZZZ)V");
+ MID_AddControllerElement = (*env)->GetMethodID(env, CLASS_JNIWrapper, "addControllerElement", "(JJIIIIIIIIZZZZZ)V");
if (MID_AddControllerElement == NULL)
{
printf("Method addControllerElement not found... \n");
@@ -362,19 +358,14 @@ void CFObjectSend( CFTypeRef value )
CFTypeID type = CFGetTypeID(value);
if (type == CFArrayGetTypeID())
{
- printf("Array Type\n");
CFRange range = {0, CFArrayGetCount (value)};
- CFIndex savedIndex = gElementIndex;
//Show an element array containing one or more element dictionaries
- gElementIndex = 0; //Reset index to zero
CFArrayApplyFunction (value, range, sendCFArray, 0);
-
- gElementIndex = savedIndex;
}
else if (type == CFDictionaryGetTypeID())
{
- printf("Sending Map\n");
+// printf("Sending Map\n");
CFTypeRef val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementCookieKey) );
@@ -384,91 +375,128 @@ void CFObjectSend( CFTypeRef value )
printf("ElementCookie - 0x%lx (%ld) \n", elementCookie, elementCookie);
}
- val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementCollectionTypeKey) );
+ val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementTypeKey) );
+ if ( val )
+ {
+ CFNumberGetValue ( val, kCFNumberLongType, &elementType);
+ printf("element Type - 0x%lx (%ld) \n", elementType, elementType);
+ }
+
+ val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementUsageKey) );
if ( val )
{
- CFNumberGetValue ( val, kCFNumberLongType, &collectionType);
- printf("collection Type - 0x%lx (%ld) \n", collectionType, collectionType);
+ CFNumberGetValue ( val, kCFNumberLongType, &usage);
+ printf("usage - 0x%lx (%ld) \n", usage, usage);
+ }
+
+ val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementUsagePageKey) );
+ if ( val )
+ {
+ CFNumberGetValue ( val, kCFNumberLongType, &usagePage);
+ printf("usage page- 0x%lx (%ld) \n", usagePage, usagePage);
}
val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementMinKey) );
if ( val )
{
CFNumberGetValue ( val, kCFNumberLongType, &min);
- printf("min - 0x%lx (%ld) \n", min, min);
+ //printf("min - 0x%lx (%ld) \n", min, min);
}
val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementMaxKey) );
if ( val )
{
CFNumberGetValue ( val, kCFNumberLongType, &max);
- printf("max - 0x%lx (%ld) \n", max, max);
+ //printf("max - 0x%lx (%ld) \n", max, max);
}
val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementScaledMinKey) );
if ( val )
{
CFNumberGetValue ( val, kCFNumberLongType, &scaledMin);
- printf("scaledMin - 0x%lx (%ld) \n", scaledMin, scaledMin);
+ //printf("scaledMin - 0x%lx (%ld) \n", scaledMin, scaledMin);
}
val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementScaledMaxKey) );
if ( val )
{
CFNumberGetValue ( val, kCFNumberLongType, &scaledMax);
- printf("scaledMax - 0x%lx (%ld) \n", scaledMax, scaledMax);
+ //printf("scaledMax - 0x%lx (%ld) \n", scaledMax, scaledMax);
}
val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementSizeKey) );
if ( val )
{
CFNumberGetValue ( val, kCFNumberLongType, &size);
- printf("Size - 0x%lx (%ld) \n", size, size);
+ //printf("Size - 0x%lx (%ld) \n", size, size);
+ }
+
+ jboolean isRelative = JNI_FALSE;
+ val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementIsRelativeKey) );
+ if ( val )
+ {
+ isRelative = (CFBooleanGetValue(val) ? JNI_TRUE : JNI_FALSE);
+ }
+
+
+ jboolean isWrapping = JNI_FALSE;
+ val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementIsWrappingKey) );
+ if ( val )
+ {
+ isWrapping = (CFBooleanGetValue(val) ? JNI_TRUE : JNI_FALSE);
}
- isRelative = JNI_FALSE;
- isWrapping = JNI_FALSE;
- isNonLinear = JNI_FALSE;
+
+ jboolean isNonLinear = JNI_FALSE;
+ val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementIsNonLinearKey) );
+ if ( val )
+ {
+ isNonLinear = (CFBooleanGetValue(val) ? JNI_TRUE : JNI_FALSE);
+ }
+
+
jboolean hasPreferredState = JNI_FALSE;
+#ifdef kIOHIDElementHasPreferredStateKey
+ val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementHasPreferredStateKey) );
+ if ( val )
+ {
+ hasPreferredState = (CFBooleanGetValue(val) ? JNI_TRUE : JNI_FALSE);
+ }
+#else
+ val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementHasPreferedStateKey) );
+ if ( val )
+ {
+ hasPreferredState = (CFBooleanGetValue(val) ? JNI_TRUE : JNI_FALSE);
+ }
+#endif
+
jboolean hasNullState = JNI_FALSE;
+ val = CFDictionaryGetValue( value, CFSTR(kIOHIDElementHasNullStateKey) );
+ if ( val )
+ {
+ hasNullState = (CFBooleanGetValue(val) ? JNI_TRUE : JNI_FALSE);
+ }
- (*lpEnv)->CallVoidMethod(lpEnv, lpObj, MID_AddControllerElement,
- lpDevice,
+ (*lpEnv)->CallVoidMethod(lpEnv, lpObj, MID_AddControllerElement,
+ (jlong)(long)lpDevice,
(jlong)(long)elementCookie,
- (jlong)(long)collectionType,
- (jlong)(long)min,
- (jlong)(long)max,
- (jlong)(long)scaledMin,
- (jlong)(long)scaledMax,
- (jlong)(long)size,
+ (jint)(long)elementType,
+ (jint)(long)usage,
+ (jint)(long)usagePage,
+ (jint)(long)min,
+ (jint)(long)max,
+ (jint)(long)scaledMin,
+ (jint)(long)scaledMax,
+ (jint)(long)size,
(jboolean)isRelative,
(jboolean)isWrapping,
(jboolean)isNonLinear,
(jboolean)hasPreferredState,
(jboolean)hasNullState);
- printf("End of element definition \n");
-
-/*
-
- jboolean isRelative;
- isRelative = (CFBooleanGetValue(value) ? JNI_TRUE : JNI_FALSE);
+// printf("End of element definition \n");
- jboolean isWrapping;
- isWrapping = (CFBooleanGetValue(value) ? JNI_TRUE : JNI_FALSE);
-
- jboolean isNonLinear;
- isNonLinear = (CFBooleanGetValue(value) ? JNI_TRUE : JNI_FALSE);
-*/
-#ifdef kIOHIDElementHasPreferredStateKey
- //showDictionaryElement (value, CFSTR(kIOHIDElementHasPreferredStateKey));
-#else
- //showDictionaryElement (value, CFSTR(kIOHIDElementHasPreferedStateKey));
-#endif
- //showDictionaryElement (value, CFSTR(kIOHIDElementHasNullStateKey));
- showDictionaryElement (value, CFSTR(kIOHIDElementVendorSpecificKey));
- //showDictionaryElement (value, CFSTR(kIOHIDElementKey));
CFTypeRef object = CFDictionaryGetValue (value, CFSTR(kIOHIDElementKey));
if (object)
@@ -487,16 +515,8 @@ void addControllerElements( CFMutableDictionaryRef dictionary, CFStringRef key )
CFTypeRef value = CFDictionaryGetValue (dictionary, key);
if (value)
{
- CFTypeID type = CFGetTypeID(value);
-
CFRange range = {0, CFArrayGetCount (value)};
- CFIndex savedIndex = gElementIndex;
-
- //Show an element array containing one or more element dictionaries
- gElementIndex = 0; //Reset index to zero
CFArrayApplyFunction (value, range, sendCFArray, 0);
-
- gElementIndex = savedIndex;
}
}