summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorgregorypierce <[email protected]>2003-08-05 18:31:29 +0000
committergregorypierce <[email protected]>2003-08-05 18:31:29 +0000
commitbf8dd5ac68b8f85c4420b8b0daa45ab59cbf563a (patch)
tree121bc9cb59537dc63164badffee2e9400850bf99 /plugins
parent386578367ad2e453af4dd898fb5ebda1959e7188 (diff)
Initial update - partial merge with JInput
git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@35 e343933a-64c8-49c5-92b1-88f2ce3e89e8
Diffstat (limited to 'plugins')
-rw-r--r--plugins/OSX/src/java/net/java/games/input/InputController.java220
-rw-r--r--plugins/OSX/src/java/net/java/games/input/InputControllerElement.java183
-rwxr-xr-xplugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java192
-rw-r--r--plugins/OSX/src/java/net/java/games/input/OSXGamepad.java26
-rw-r--r--plugins/OSX/src/java/net/java/games/input/OSXJoystick.java26
-rw-r--r--plugins/OSX/src/java/net/java/games/input/OSXKeyboard.java26
-rw-r--r--plugins/OSX/src/java/net/java/games/input/OSXMouse.java26
7 files changed, 699 insertions, 0 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
new file mode 100644
index 0000000..77dbd5c
--- /dev/null
+++ b/plugins/OSX/src/java/net/java/games/input/InputController.java
@@ -0,0 +1,220 @@
+package net.java.games.input;
+
+import java.util.HashMap;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gpierce
+ * Date: Aug 2, 2003
+ * Time: 2:57:15 PM
+ * To change this template use Options | File Templates.
+ */
+public class 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 );
+ }
+}
diff --git a/plugins/OSX/src/java/net/java/games/input/InputControllerElement.java b/plugins/OSX/src/java/net/java/games/input/InputControllerElement.java
new file mode 100644
index 0000000..af6e2e5
--- /dev/null
+++ b/plugins/OSX/src/java/net/java/games/input/InputControllerElement.java
@@ -0,0 +1,183 @@
+package net.java.games.input;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gpierce
+ * Date: Aug 2, 2003
+ * Time: 2:59:26 PM
+ * To change this template use Options | File Templates.
+ */
+public class InputControllerElement
+{
+ private long hidCookie;
+ private int elementType;
+ private String elementName;
+
+ private int rawMin;
+ private int rawMax;
+ private int scaledMin;
+ private int scaledMax;
+
+ private int dataBitSize;
+
+ private boolean isRelative;
+ private boolean isWrapping;
+ private boolean isNonLinear;
+ private boolean hasPreferredState;
+ private boolean hasNullState;
+
+ public InputControllerElement()
+ {
+ }
+
+ public InputControllerElement(long hidCookie, int elementType, String elementName,
+ int rawMin, int rawMax, int scaledMin, int scaledMax,
+ int dataBitSize, boolean relative, boolean wrapping,
+ boolean nonLinear, boolean hasPreferredState, boolean hasNullState )
+ {
+ this.hidCookie = hidCookie;
+ this.elementType = elementType;
+ this.elementName = elementName;
+ this.rawMin = rawMin;
+ this.rawMax = rawMax;
+ this.scaledMin = scaledMin;
+ this.scaledMax = scaledMax;
+ this.dataBitSize = dataBitSize;
+ isRelative = relative;
+ isWrapping = wrapping;
+ isNonLinear = nonLinear;
+ this.hasPreferredState = hasPreferredState;
+ this.hasNullState = hasNullState;
+ }
+
+ public long getHidCookie()
+ {
+ return hidCookie;
+ }
+
+ public void setHidCookie(long hidCookie)
+ {
+ this.hidCookie = hidCookie;
+ }
+
+ public int getElementType()
+ {
+ return elementType;
+ }
+
+ public void setElementType(int elementType)
+ {
+ this.elementType = elementType;
+ }
+
+ public String getElementName()
+ {
+ return elementName;
+ }
+
+ public void setElementName(String elementName)
+ {
+ this.elementName = elementName;
+ }
+
+ public int getRawMin()
+ {
+ return rawMin;
+ }
+
+ public void setRawMin(int rawMin)
+ {
+ this.rawMin = rawMin;
+ }
+
+ public int getRawMax()
+ {
+ return rawMax;
+ }
+
+ public void setRawMax(int rawMax)
+ {
+ this.rawMax = rawMax;
+ }
+
+ public int getScaledMin()
+ {
+ return scaledMin;
+ }
+
+ public void setScaledMin(int scaledMin)
+ {
+ this.scaledMin = scaledMin;
+ }
+
+ public int getScaledMax()
+ {
+ return scaledMax;
+ }
+
+ public void setScaledMax(int scaledMax)
+ {
+ this.scaledMax = scaledMax;
+ }
+
+ public int getDataBitSize()
+ {
+ return dataBitSize;
+ }
+
+ public void setDataBitSize(int dataBitSize)
+ {
+ this.dataBitSize = dataBitSize;
+ }
+
+ public boolean isRelative()
+ {
+ return isRelative;
+ }
+
+ public void setRelative(boolean relative)
+ {
+ isRelative = relative;
+ }
+
+ public boolean isWrapping()
+ {
+ return isWrapping;
+ }
+
+ public void setWrapping(boolean wrapping)
+ {
+ isWrapping = wrapping;
+ }
+
+ public boolean isNonLinear()
+ {
+ return isNonLinear;
+ }
+
+ public void setNonLinear(boolean nonLinear)
+ {
+ isNonLinear = nonLinear;
+ }
+
+ public boolean isHasPreferredState()
+ {
+ return hasPreferredState;
+ }
+
+ public void setHasPreferredState(boolean hasPreferredState)
+ {
+ this.hasPreferredState = hasPreferredState;
+ }
+
+ public boolean isHasNullState()
+ {
+ return hasNullState;
+ }
+
+ public void setHasNullState(boolean hasNullState)
+ {
+ this.hasNullState = hasNullState;
+ }
+
+}
diff --git a/plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java b/plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java
new file mode 100755
index 0000000..96d4e99
--- /dev/null
+++ b/plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java
@@ -0,0 +1,192 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.security.AccessController;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.HashMap;
+
+import net.java.games.input.Controller;
+import net.java.games.input.ControllerEnvironment;
+import net.java.games.util.plugins.Plugin;
+
+/** OSX HIDManager implementation of controller environment
+* @author gregorypierce
+* @version 1.0
+*/
+public class OSXEnvironmentPlugin extends ControllerEnvironment implements Plugin
+{
+ static
+ {
+ System.loadLibrary("jinput");
+ }
+
+ public native void hidCreate();
+ public native void hidDispose();
+ public native void enumDevices();
+
+ /**
+ * Opens an input device and returns the address of the input queue for that device
+ */
+ public native long openDevice( long lpDevice, int queueDepth );
+ 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;
+
+
+ private HashMap devices = new HashMap();
+
+
+ public OSXEnvironmentPlugin()
+ {
+ System.out.println("net.java.games.input.OSXEnvironmentPlugin instance created");
+ }
+
+ public Controller[] getControllers()
+ {
+ return (Controller[])devices.values().toArray();
+ }
+
+ public InputController 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 );
+ case (HID_DEVICE_JOYSTICK):
+ System.out.println("Found joystick [" + productName + "]");
+ return new OSXJoystick( this, lpDevice, productName, usage );
+ case (HID_DEVICE_GAMEPAD):
+ System.out.println("Found gamepad [" + productName + "]");
+ return new OSXGamepad( this, lpDevice, productName, usage );
+ case (HID_DEVICE_KEYBOARD):
+ System.out.println("Found keyboard [" + productName + "]");
+ return new OSXKeyboard( this, lpDevice, productName, usage );
+ default:
+ System.out.println("Found device of unknown type [" + usage + "],[" + productName + "] - ignoring");
+ return null;
+ }
+ }
+
+ private void addController( long lpDevice,
+ String productName,
+ int usage )
+ {
+ InputController controller = null;
+
+ controller = createController( lpDevice, productName, usage );
+
+ if ( controller != null )
+ {
+ devices.put( productName, controller );
+ }
+ }
+
+ private void addControllerElement( long lpDevice,
+ long hidCookie,
+ int elementType,
+ String elementName,
+ int rawMin,
+ int rawMax,
+ int scaledMin,
+ int scaledMax,
+ int dataBitSize,
+ boolean relative,
+ boolean wrapping,
+ boolean nonLinear,
+ boolean hasPreferredState,
+ boolean hasNullState)
+ {
+ InputControllerElement element = new InputControllerElement( hidCookie, elementType, elementName,
+ rawMin, rawMax, scaledMin, scaledMax,
+ dataBitSize, relative, wrapping, nonLinear,
+ hasPreferredState, hasNullState );
+ }
+
+
+
+ public void testDevice( long lpDevice )
+ {
+ System.out.println("Opening device ");
+ long lpQueue = openDevice( lpDevice, 32 );
+
+ for ( int i = 0; i < 50; i++ )
+ {
+ try
+ {
+ pollDevice( lpQueue );
+ Thread.sleep(10);
+ }
+ catch( Exception e )
+ {
+ System.out.println("Interrupted" + e );
+ }
+ }
+
+ System.out.println("Closing device");
+ closeDevice( lpDevice, lpQueue );
+ }
+
+ public static void main (String args[])
+ {
+ System.out.println("Started net.java.games.input.OSXEnvironmentPlugin");
+ OSXEnvironmentPlugin newjni = new OSXEnvironmentPlugin();
+
+ System.out.println("Creating HID engine");
+ newjni.hidCreate();
+
+ System.out.println("Enumerating devices");
+ newjni.enumDevices();
+
+ System.out.println("Disposing HID engine");
+ newjni.hidDispose();
+
+ System.out.println("Done");
+ }
+
+} \ No newline at end of file
diff --git a/plugins/OSX/src/java/net/java/games/input/OSXGamepad.java b/plugins/OSX/src/java/net/java/games/input/OSXGamepad.java
new file mode 100644
index 0000000..5858122
--- /dev/null
+++ b/plugins/OSX/src/java/net/java/games/input/OSXGamepad.java
@@ -0,0 +1,26 @@
+package net.java.games.input;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gpierce
+ * Date: Aug 2, 2003
+ * Time: 3:59:09 PM
+ * To change this template use Options | File Templates.
+ */
+public class OSXGamepad extends InputController
+{
+ public OSXGamepad( OSXEnvironmentPlugin plugin )
+ {
+ super( plugin );
+ }
+
+ public OSXGamepad( OSXEnvironmentPlugin plugin, long lpDevice, String productName, int usage )
+ {
+ super( plugin, lpDevice, productName, usage );
+ }
+
+ 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)
+ {
+ super( plugin, lpDevice, transportKey, vendorID, productID, version, manufacturer, productName, serialNumber, usbLocationID, usagePage, usage );
+ }
+}
diff --git a/plugins/OSX/src/java/net/java/games/input/OSXJoystick.java b/plugins/OSX/src/java/net/java/games/input/OSXJoystick.java
new file mode 100644
index 0000000..588b1d4
--- /dev/null
+++ b/plugins/OSX/src/java/net/java/games/input/OSXJoystick.java
@@ -0,0 +1,26 @@
+package net.java.games.input;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gpierce
+ * Date: Aug 2, 2003
+ * Time: 3:58:45 PM
+ * To change this template use Options | File Templates.
+ */
+public class OSXJoystick extends InputController
+{
+ public OSXJoystick( OSXEnvironmentPlugin plugin )
+ {
+ super( plugin );
+ }
+
+ public OSXJoystick( OSXEnvironmentPlugin plugin, long lpDevice, String productName, int usage )
+ {
+ super( plugin, lpDevice, productName, usage );
+ }
+
+ 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)
+ {
+ super( plugin, lpDevice, transportKey, vendorID, productID, version, manufacturer, productName, serialNumber, usbLocationID, usagePage, usage );
+ }
+}
diff --git a/plugins/OSX/src/java/net/java/games/input/OSXKeyboard.java b/plugins/OSX/src/java/net/java/games/input/OSXKeyboard.java
new file mode 100644
index 0000000..f745701
--- /dev/null
+++ b/plugins/OSX/src/java/net/java/games/input/OSXKeyboard.java
@@ -0,0 +1,26 @@
+package net.java.games.input;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gpierce
+ * Date: Aug 2, 2003
+ * Time: 3:57:58 PM
+ * To change this template use Options | File Templates.
+ */
+public class OSXKeyboard extends InputController
+{
+ public OSXKeyboard( OSXEnvironmentPlugin plugin )
+ {
+ super( plugin );
+ }
+
+ public OSXKeyboard( OSXEnvironmentPlugin plugin, long lpDevice, String productName, int usage )
+ {
+ super( plugin, lpDevice, productName, usage );
+ }
+
+ 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)
+ {
+ super( plugin, lpDevice, transportKey, vendorID, productID, version, manufacturer, productName, serialNumber, usbLocationID, usagePage, usage );
+ }
+}
diff --git a/plugins/OSX/src/java/net/java/games/input/OSXMouse.java b/plugins/OSX/src/java/net/java/games/input/OSXMouse.java
new file mode 100644
index 0000000..0318a86
--- /dev/null
+++ b/plugins/OSX/src/java/net/java/games/input/OSXMouse.java
@@ -0,0 +1,26 @@
+package net.java.games.input;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gpierce
+ * Date: Aug 2, 2003
+ * Time: 3:57:00 PM
+ * To change this template use Options | File Templates.
+ */
+public class OSXMouse extends InputController
+{
+ public OSXMouse( OSXEnvironmentPlugin plugin )
+ {
+ super( plugin );
+ }
+
+ public OSXMouse( OSXEnvironmentPlugin plugin, long lpDevice, String productName, int usage )
+ {
+ super( plugin, lpDevice, productName, usage );
+ }
+
+ 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)
+ {
+ super( plugin, lpDevice, transportKey, vendorID, productID, version, manufacturer, productName, serialNumber, usbLocationID, usagePage, usage );
+ }
+}