Make version 2 the main jinput version

This commit is contained in:
endolf 2006-04-29 22:29:27 +00:00
parent 4c91a4eb44
commit 559c008a02
149 changed files with 13218 additions and 10800 deletions

View file

@ -1,32 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="all" name="Linux Plugin">
<target name="init">
<property name="hello" value="world"/>
<mkdir dir="classes"/>
<mkdir dir="bin"/>
<condition property="linux" >
<!--<os family="unix" />-->
<os name="Linux" />
</condition>
</target>
<target depends="init" name="compile">
<!-- <ant dir="src/native" target="createNativeDefinitions.java"/>-->
<javac debug="true" deprecation="true" destdir="classes" source="1.4" target="1.4" srcdir="src/java">
<classpath>
<pathelement location="../../coreAPI/bin/jinput.jar"/>
<pathelement location="../../coreAPI/lib/jutils.jar"/>
<pathelement location="../../coreAPI/bin/jinput-core.jar"/>
<pathelement location="../../lib/jutils.jar"/>
</classpath>
</javac>
</target>
<target depends="init,compile" name="jar">
<jar jarfile="bin/linux.jar" compress="true" basedir="classes">
<exclude name="**/*.java"/>
<exclude name="linux.jar"/>
<exclude name="apidoc"/>
<include name="**/*.class"/>
</jar>
<copy file="bin/linux.jar" todir="../../coreAPI/src/tests/controller" />
</target>
<target depends="compileNativeJinputLib,jar" description="Build everything." name="all">
<echo message="Application built. Hello ${hello}!"/>
<target depends="jar,compileNativeJinputLib" description="Build everything." name="all">
</target>
<target name="javadoc" depends="init" description="Javadoc for Linux plugin for JInput.">
@ -39,43 +39,31 @@
<pathelement location="src/java"/>
</sourcepath>
<classpath>
<pathelement location="../../coreAPI/bin/jinput.jar"/>
<pathelement location="../../coreAPI/bin/jinput-core.jar"/>
<pathelement location="../../coreAPI/lib/jutils.jar"/>
</classpath>
</javadoc>
</target>
<target description="Clean all build products." name="clean">
<delete failonerror="no">
<fileset dir="classes">
<include name="**/*.class"/>
</fileset>
</delete>
<delete file="bin/linux.jar" failonerror="no"/>
<delete file="src/native/libjinput-linux.so" failonerror="no"/>
<delete file="../../coreAPI/src/tests/controller/linux.jar" failonerror="no" />
<delete file="../../coreAPI/src/tests/controller/libjinput-linux.so" failonerror="no"/>
<delete file="apidoc" failonerror="no"/>
<delete dir="classes" failonerror="no"/>
<delete dir="bin" failonerror="no"/>
<delete dir="apidocs" failonerror="no"/>
<ant inheritAll="false" antfile="src/native/build.xml" target="clean"/>
</target>
<target depends="init,compile" name="createJNIHeaders">
<javah destdir="src/native">
<javah destdir="src/native">
<classpath>
<pathelement location="../../coreAPI/bin/jinput.jar"/>
<pathelement location="bin/linux.jar"/>
<pathelement location="classes"/>
</classpath>
<class name="net.java.games.input.JInputLibrary"/>
</javah>
<class name="net.java.games.input.LinuxEventDevice"/>
<class name="net.java.games.input.LinuxJoystickDevice"/>
</javah>
</target>
<target depends="init" name="createNativeDefinitions.java">
<exec dir="." executable="./getDefinitions" os="linux" output="src/java/net/java/games/input/NativeDefinitions.java">
<arg line="/usr/include/linux/input.h"/>
</exec>
</target>
<target depends="init" name="compileNativeJinputLib">
<target depends="init,createJNIHeaders" name="compileNativeJinputLib" if="linux">
<ant dir="src/native" target="compileNativeJinputLib"/>
<copy file="src/native/libjinput-linux.so" todir="../../coreAPI/src/tests/controller" />
<copy file="src/native/libjinput-linux.so" todir="bin" />
</target>
</project>

View file

@ -1,244 +0,0 @@
package net.java.games.input;
public class JInputLibrary {
static {
if(isSupported()) {
System.loadLibrary("jinput-linux");
}
}
private static boolean inited = false;
private static Object workerThreadMonitor = new Object();
private static boolean shutdown = false;
private static Object shutdownThreadMonitor = new Object();
private static boolean cleanupDone = false;
private static int rumbler = -1;
private static float force;
public static boolean isSupported() {
System.out.println("OS name is: " + System.getProperty("os.name"));
if(System.getProperty("os.name").indexOf("Linux")!=-1) {
System.out.println("Linux plugin is supported");
return true;
}
System.out.println("Linux plugin is not supported");
return false;
}
public static void init() {
if(!inited) {
System.out.println("Initing JInputLibrary");
Thread initShutdownThread = new Thread() {
public void run() {
nativeInit();
inited=true;
synchronized (workerThreadMonitor) {
workerThreadMonitor.notify();
}
synchronized(workerThreadMonitor) {
while(!shutdown) {
System.out.println("Waiting on monitor");
System.out.flush();
try {
workerThreadMonitor.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(rumbler>=0) {
nativeRumble(rumbler,force);
rumbler =-1;
}
}
}
System.out.println("Cleaning up from shutdown thread");
realCleanup();
cleanupDone = true;
synchronized (shutdownThreadMonitor) {
System.out.println("Notifying on shutdownThreadMonitor after shutdown");
System.out.flush();
shutdownThreadMonitor.notifyAll();
System.out.println("Notified on shutdownThreadMonitor after shutdown");
System.out.flush();
}
}
};
initShutdownThread.setDaemon(true);
initShutdownThread.start();
System.out.println("Shutdown thread created and run");
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
cleanup();
}
});
synchronized (workerThreadMonitor) {
while(!inited) {
try {
workerThreadMonitor.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
private static void realCleanup() {
//Give the rumblers chance to cleanup
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Environment cleanup");
for(int i=0;i<JInputLibrary.getNumberOfDevices();i++) {
if(JInputLibrary.getFFEnabled(i)) {
JInputLibrary.nativeRumble(i, 0f);
}
JInputLibrary.nativeCleanup(i);
}
}
public static void rumble(int rumblerNo, float forceValue) {
rumbler = rumblerNo;
force = forceValue;
synchronized (workerThreadMonitor) {
System.out.println("Notifying clean up thread");
System.out.flush();
workerThreadMonitor.notify();
}
}
private static void cleanup() {
shutdown = true;
System.out.println("Trying to notify for cleanup");
System.out.flush();
synchronized (workerThreadMonitor) {
System.out.println("Notifying clean up thread");
System.out.flush();
workerThreadMonitor.notify();
}
while(!cleanupDone) {
synchronized (shutdownThreadMonitor) {
try {
System.out.println("cleanup waiting on shutdownThreadMonitor");
System.out.flush();
shutdownThreadMonitor.wait();
System.out.println("cleanup done waiting on shutdownThreadMonitor");
System.out.flush();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/** Call to poll the device at the native library
* @param deviceID The native device ID
* @param buttonData Array to populate with button values
* @param relAxesData Array to populate with relative axes values
* @param absAxesData Array to populate with absolute axes values
* @return the number of events read
*/
public static int safePoll(int deviceID, int buttonData[], int relAxesData[], int absAxesData[]) {
if(!shutdown) {
return poll(deviceID, buttonData, relAxesData, absAxesData);
}
return 0;
}
/** Get the name of a device from the native library
* @param deviceID The device id
* @return The devices name
*/
public static native String getDeviceName(int deviceID);
/** Get the number of absolute axes for the requested device
* @param deviceID The device ID
* @return The number of abs axes
*/
public static native int getNumAbsAxes(int deviceID);
/** Get the nmber or relative axes from the native library
* @param deviceID The native device ID
* @return The number of raltive axes for the device
*/
public static native int getNumRelAxes(int deviceID);
/** Gets the number of buttons for the requested devce from the native library
* @param deviceID The device ID
* @return The number of buttons
*/
public static native int getNumButtons(int deviceID);
/** Initialises the native library
* @return <0 if something went wrong
*/
private static native int nativeInit();
/** Gets the number of devices the native library found
* @return Th number of devices
*/
public static native int getNumberOfDevices();
/** Native call to get the supported absolute axes for a device
* @param deviceID The native device number
* @param supportedAbsAxes aray to populate
*/
public static native void getSupportedAbsAxes(int deviceID, int supportedAbsAxes[]);
/** Native call to get the supported relative axes for a device
* @param deviceID The native device number
* @param supportedRelAxes aray to populate
*/
public static native void getSupportedRelAxes(int deviceID, int supportedRelAxes[]);
/** Native call to get the supported buttons for a device
* @param deviceID The native device ID
* @param supportedButtons The array to populate
*/
public static native void getSupportedButtons(int deviceID, int supportedButtons[]);
/** Call to poll the device at the native library
* @param deviceID The native device ID
* @param buttonData Array to populate with button values
* @param relAxesData Array to populate with relative axes values
* @param absAxesData Array to populate with absolute axes values
* @return the number of events read
*/
public static native int poll(int deviceID, int buttonData[], int relAxesData[], int absAxesData[]);
/** Returns the fuzz of an axis fro mthe native lib
* @param deviceID The native device id
* @param axisID The native axis ID
* @return The fuzz
*/
public static native int getAbsAxisFuzz(int deviceID, int axisID);
/** Gets the maximum value for an absloute axis fr omthe native library
* @param deviceID The native device ID
* @param axisID The native axis ID
* @return The Max value
*/
public static native int getAbsAxisMaximum(int deviceID, int axisID);
/** Gets the minimum value for an absloute axis from the native library
* @param deviceID The native device ID
* @param axisID The native axis number
* @return The min value
*/
public static native int getAbsAxisMinimum(int deviceID, int axisID);
/** Gets the port type from the native lib
* @param deviceID The device to get the port type for
* @return The port type
*/
public static native int getNativePortType(int deviceID);
public static native boolean getFFEnabled(int deviceID);
private static native void nativeRumble(int deviceID, float intensity);
private static native void nativeCleanup(int deviceID);
}

View file

@ -23,48 +23,47 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
#ifndef JoystickDevice_h
#define JoystickDevice_h
/**
* @author elias
*/
final class LinuxAbsInfo {
private int value;
private int minimum;
private int maximum;
private int fuzz;
private int flat;
#include <stdint.h>
#include <linux/input.h>
#include "eventInterfaceTypes.h"
#include "Device.h"
public final void set(int value, int min, int max, int fuzz, int flat) {
this.value = value;
this.minimum = min;
this.maximum = max;
this.fuzz = fuzz;
this.flat = flat;
}
class JoystickDevice : public Device {
public final String toString() {
return "AbsInfo: value = " + value + " | min = " + minimum + " | max = " + maximum + " | fuzz = " + fuzz + " | flat = " + flat;
}
private:
int fd;
int inited;
char *name;
int numButtons;
int *absAxesData;
uint8_t *buttonData;
int numAbsAxes;
public final int getValue() {
return value;
}
public:
JoystickDevice(char *deviceFilename);
int getNumberRelAxes();
int getNumberAbsAxes();
int getNumberButtons();
const char *getName();
int getBusType();
int getVendorID();
int getProductID();
int getVersion();
void getSupportedRelAxes(int supportedAxis[]);
void getSupportedAbsAxes(int supportedAxis[]);
void getSupportedButtons(int supportedButtons[]);
int poll();
void getPolledData(int relAxesData[], int absAxesData[], int buttonData[]);
int getAbsAxisMinimum(int axisNumber);
int getAbsAxisMaximum(int axisNumber);
int getAbsAxisFuzz(int axisNumber);
int isValidDevice();
bool getFFEnabled();
void rumble(float force);
void cleanup();
};
final int getMax() {
return maximum;
}
#endif //eventInterface_eventDevice_h
final int getMin() {
return minimum;
}
final int getFlat() {
return flat;
}
final int getFuzz() {
return fuzz;
}
}

View file

@ -0,0 +1,74 @@
/*
* %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.io.IOException;
/** Represents a Linux controller
* @author elias
* @version 1.0
*/
final class LinuxAbstractController extends AbstractController {
private final PortType port;
private final LinuxEventDevice device;
private final Type type;
protected LinuxAbstractController(LinuxEventDevice device, Component[] components, Controller[] children, Rumbler[] rumblers, Type type) throws IOException {
super(device.getName(), components, children, rumblers);
this.device = device;
this.port = device.getPortType();
this.type = type;
}
public final PortType getPortType() {
return port;
}
public final void pollDevice() throws IOException {
device.pollKeyStates();
}
protected final boolean getNextDeviceEvent(Event event) throws IOException {
return LinuxControllers.getNextDeviceEvent(event, device);
}
public Type getType() {
return type;
}
}

View file

@ -1,192 +0,0 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
import net.java.games.input.AbstractComponent;
import net.java.games.input.LinuxDevice;
/** Represents an Axis absolute or relative
*
* @author Jeremy Booth (jeremy@newdawnsoftware.com)
*/
public class LinuxAxis extends AbstractComponent {
/** The controller this axis is part of */
private LinuxDevice controller;
/** The native ID of this axis */
private int axisID;
/** The null zone, defaulted to 0 */
private float nullZone = 0.0f;
/** Is this axis analog */
private boolean isAnalog = true;
/** Are the values returned by getPollData normalised */
private boolean isNormalized = false;
/** Is this a relative axis */
private boolean isRelative = false;
/** Should we normalise the value before returning it in getPollData */
private boolean needsNormalising = false;
/** The minimum possible axis value (not always used) */
private float minAxisValue;
/** The maximum possibe axis value (not always used */
private float maxAxisValue;
/** The current value of the axis */
private float value = 0.0f;
/**
* Creates a new instance of LinuxAxis
* @param controller The parent Controller
* @param axisID The native ID of this axis
* @param name The name of this axis
* @param id The Axis.Identifier of this axis
* @param deadzone The deadzone (null zone) of this axis
* @param isAnalog Is this axis analog
* @param isNormalized Is this axis normalised
* @param isRelative Is this axis relative
*/
public LinuxAxis(LinuxDevice controller, int axisID, String name, Identifier id, float deadzone, boolean isAnalog, boolean isNormalized, boolean isRelative) {
super(name, id);
this.controller = controller;
this.axisID = axisID;
this.nullZone = deadzone;
this.isAnalog = isAnalog;
this.isNormalized = isNormalized;
this.isRelative = isRelative;
}
/** Creates a new instance of LinuxAxis, it will auto normalise the data based on
* the minimum and maximum values provided
* @param controller The parent Controller
* @param axisID The native ID of this axis
* @param name The name of this axis
* @param id The Axis.Identifier of this axis
* @param deadzone The deadzone (null zone) of this axis
* @param isAnalog Is this axis analog
* @param isRelative Is this axis relative
* @param minAxisValue Minimum value that the native library will return for this axis
* @param maxAxisValue Maximum value that the native library will return for this axis
*/
public LinuxAxis(LinuxDevice controller, int axisID, String name, Identifier id, float deadzone, boolean isAnalog, boolean isRelative, float minAxisValue, float maxAxisValue) {
super(name, id);
this.controller = controller;
this.axisID = axisID;
this.nullZone = deadzone;
this.isAnalog = isAnalog;
this.isNormalized = false;
this.isRelative = isRelative;
this.needsNormalising = true;
this.minAxisValue = minAxisValue;
this.maxAxisValue = maxAxisValue;
}
/** 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 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.
*/
public boolean isRelative() {
return isRelative;
}
/** Returns the suggested dead zone for this axis. Dead zone is the
* amount polled data can vary before considered a significant change
* in value. An application can safely ignore changes less than this
* value in the positive or negative direction.
* @return 0.0f by default, can be overridden
*/
public float getDeadZone() {
return nullZone;
}
/** Returns whether or not the axis is analog, or false if it is digital.
* @return false by default, can be overridden
*/
public boolean isAnalog() {
return isAnalog;
}
/** 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 0.0f by default, can be overridden
*/
public float getPollData() {
if(isPolling()) {
updateValue();
}
return value;
}
/** Update this axis data from the latest native poll value
*/
private void updateValue() {
if(isAnalog) {
float tempVal;
if(isRelative) {
tempVal = (float)controller.getRelAxisValue(axisID);
} else {
tempVal = (float)controller.getAbsAxisValue(axisID);
}
if(needsNormalising) {
if(isRelative) {
if(tempVal>1) {
tempVal = 1;
} else if(tempVal<-1) {
tempVal = -1;
}
value = tempVal;
} else {
//float center = (minAxisValue + maxAxisValue) / 2;
//value = (tempVal - center) / center;
float center = ((maxAxisValue - minAxisValue)/2);
value = (((tempVal - minAxisValue) - center) / center);
//System.out.println("tempVal: " + tempVal + " minAxisValue: " + minAxisValue + " maxAxisValue: " + maxAxisValue + " center: " + center + " value: " + value);
//System.out.flush();
}
} else {
value = tempVal;
}
} else {
value = (float)controller.getButtonValue(axisID);
}
}
/** Returns whether or not data polled from this axis is normalized
* between the values of -1.0f and 1.0f.
* @return true by default, can be overridden
*/
public boolean isNormalized() {
return (isNormalized || needsNormalising);
}
}

View file

@ -23,48 +23,40 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
#ifndef MixedDevice_h
#define MixedDevice_h
/**
* @author elias
*/
final class LinuxAxisDescriptor {
private int type;
private int code;
#include <stdint.h>
#include <linux/input.h>
#include "eventInterfaceTypes.h"
#include "Device.h"
#include "EventDevice.h"
#include "JoystickDevice.h"
#include "MixedDevice.h"
public final void set(int type, int code) {
this.type = type;
this.code = code;
}
class MixedDevice : public Device {
public final int getType() {
return type;
}
private:
JoystickDevice *joystickDevice;
EventDevice *eventDevice;
public final int getCode() {
return code;
}
public:
MixedDevice(JoystickDevice *joystickDevice, EventDevice *eventDevice);
int getNumberRelAxes();
int getNumberAbsAxes();
int getNumberButtons();
const char *getName();
int getBusType();
int getVendorID();
int getProductID();
int getVersion();
void getSupportedRelAxes(int supportedAxis[]);
void getSupportedAbsAxes(int supportedAxis[]);
void getSupportedButtons(int supportedButtons[]);
void getSupportedRelAxes(short supportedAxis[]);
void getSupportedAbsAxes(short supportedAxis[]);
void getSupportedButtons(short supportedButtons[]);
int poll();
void getPolledData(int relAxesData[], int absAxesData[], int buttonData[]);
int getAbsAxisMinimum(int axisNumber);
int getAbsAxisMaximum(int axisNumber);
int getAbsAxisFuzz(int axisNumber);
bool getFFEnabled();
void rumble(float force);
void cleanup();
};
public final int hashCode() {
return type ^ code;
}
#endif //eventInterface_eventDevice_h
public final boolean equals(Object other) {
if (!(other instanceof LinuxAxisDescriptor))
return false;
LinuxAxisDescriptor descriptor = (LinuxAxisDescriptor)other;
return descriptor.type == type && descriptor.code == code;
}
public final String toString() {
return "LinuxAxis: type = 0x" + Integer.toHexString(type) + ", code = 0x" + Integer.toHexString(code);
}
}

View file

@ -0,0 +1,78 @@
/*
* %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.io.IOException;
/** Represents a linux Axis
* @author elias
* @version 1.0
*/
class LinuxComponent extends AbstractComponent {
private final LinuxEventComponent component;
public LinuxComponent(LinuxEventComponent component) {
super(component.getIdentifier().getName(), component.getIdentifier());
this.component = component;
}
public final boolean isRelative() {
return component.isRelative();
}
public final boolean isAnalog() {
return component.isAnalog();
}
protected float poll() throws IOException {
return convertValue(LinuxControllers.poll(component), component.getDescriptor());
}
float convertValue(float value, LinuxAxisDescriptor descriptor) {
return getComponent().convertValue(value);
}
public final float getDeadZone() {
return component.getDeadZone();
}
public final LinuxEventComponent getComponent() {
return component;
}
}

View file

@ -23,15 +23,20 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
#if !defined(eventInterface_h)
#define eventInterface_h
import java.io.IOException;
#include "Device.h"
/**
* @author elias
*/
final class LinuxConstantFF extends LinuxForceFeedbackEffect {
public LinuxConstantFF(LinuxEventDevice device) throws IOException {
super(device);
}
int evGetEventInterfaceVersionNumber();
int evInit();
int evGetNumberDevices();
void evGetDevices(Device **deviceList);
#endif //eventInterface_h
protected final int upload(int id, float intensity) throws IOException {
int scaled_intensity = Math.round(intensity*0x7fff);
return getDevice().uploadConstantEffect(id, 0, 0, 0, 0, 0, scaled_intensity, 0, 0, 0, 0);
}
}

View file

@ -0,0 +1,81 @@
/*
* %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.io.IOException;
/** helper methods for Linux specific Controllers
* @author elias
* @version 1.0
*/
final class LinuxControllers {
private final static LinuxEvent linux_event = new LinuxEvent();
/* Declared synchronized to protect linux_event */
public final static synchronized boolean getNextDeviceEvent(Event event, LinuxEventDevice device) throws IOException {
while (device.getNextEvent(linux_event)) {
LinuxAxisDescriptor descriptor = linux_event.getDescriptor();
LinuxComponent component = device.mapDescriptor(descriptor);
if (component != null) {
float value = component.convertValue(linux_event.getValue(), descriptor);
event.set(component, value, linux_event.getNanos());
return true;
}
}
return false;
}
private final static LinuxAbsInfo abs_info = new LinuxAbsInfo();
/* Declared synchronized to protect abs_info */
public final static synchronized float poll(LinuxEventComponent event_component) throws IOException {
int native_type = event_component.getDescriptor().getType();
switch (native_type) {
case NativeDefinitions.EV_KEY:
int native_code = event_component.getDescriptor().getCode();
float state = event_component.getDevice().isKeySet(native_code) ? 1f : 0f;
return state;
case NativeDefinitions.EV_ABS:
event_component.getAbsInfo(abs_info);
return abs_info.getValue();
default:
throw new RuntimeException("Unkown native_type: " + native_type);
}
}
}

View file

@ -25,680 +25,15 @@
*/
package net.java.games.input;
import java.io.IOException;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
/**
* Represents a device that is not a keyboard or mouse.
* @author Jeremy Booth (jeremy@newdawnsoftware.com)
* @author elias
*/
public class LinuxDevice extends AbstractController {
/** The name of the device
*/
private String name;
/** The native ID of the device
*/
private int nativeID;
/** The port type the device is attached to.
*/
private PortType portType;
/** List of buttons the device has
*/
private LinuxAxis[] buttons;
/** List of relative axes the device has
*/
private LinuxAxis[] relAxes;
/** List of absolute axes the device has
*/
private LinuxAxis[] absAxes;
/** List of coolie hats the device has
*/
private LinuxHat[] hats;
/** The id's of the coolie hat axes
*/
private int hatAxisIDs[] = new int[8];
/** The number of buttons the device has
*/
private int numButtons;
/** The number of relative axes the device has
*/
private int numRelAxes;
/** The number of absolute axes the device has
*/
private int numAbsAxes;
/** The number of coolie hats the device has
*/
private int numHats=0;
/** The native button values.
*/
private int[] buttonData;
/** The native relative axes values
*/
private int[] relAxesData;
/** The native absolute axis values
*/
private int[] absAxesData;
/** A guess at the device type.
*/
private Type typeGuess = Type.UNKNOWN;
/** An array of the list of axes this device has
*/
private ArrayList axesArray = new ArrayList();
/** Creates a new instance of LinuxDevice
* @param nativeID The native ID of this device
* @param name The name of this device
* @param numButtons The number of buttons the devices has
* @param numRelAxes The number of raltive axes this device has
* @param numAbsAxes The number of absolute axes this device has
*/
public LinuxDevice(int nativeID, String name, int numButtons, int numRelAxes, int numAbsAxes, Controller.Type type) {
this(nativeID, name, numButtons, numRelAxes, numAbsAxes);
typeGuess = type;
}
/** Creates a new instance of LinuxDevice
* @param nativeID The native ID of this device
* @param name The name of this device
* @param numButtons The number of buttons the devices has
* @param numRelAxes The number of raltive axes this device has
* @param numAbsAxes The number of absolute axes this device has
*/
public LinuxDevice(int nativeID, String name, int numButtons, int numRelAxes, int numAbsAxes) {
super(name);
children = NO_CONTROLLERS;
rumblers = NO_RUMBLERS;
this.nativeID = nativeID;
portType = LinuxNativeTypesMap.getPortType(JInputLibrary.getNativePortType(nativeID));
for(int i=0;i<8;i++) {
hatAxisIDs[i] = -1;
}
this.numButtons = numButtons;
this.numRelAxes = numRelAxes;
this.numAbsAxes = numAbsAxes;
this.numHats = 0;
buttonData = new int[numButtons];
relAxesData = new int[numRelAxes];
absAxesData = new int[numAbsAxes];
createButtons(numButtons);
createRelAxes(numRelAxes);
createAbsAxes(numAbsAxes);
createHats();
/*ArrayList tempAxes = new ArrayList();
for(int i=0;i<numButtons;i++) {
Axis tempAxis = buttons[i];
if(tempAxis!=null) {
tempAxes.add(tempAxis);
}
}
for(int i=0;i<numRelAxes;i++) {
Axis tempAxis = relAxes[i];
if(tempAxis!=null) {
tempAxes.add(tempAxis);
}
}
for(int i=0;i<numAbsAxes;i++) {
Axis tempAxis = absAxes[i];
if(tempAxis!=null) {
tempAxes.add(tempAxis);
}
}
axes = (Axis[]) tempAxes.toArray(axes);*/
for(int i=0;i<numAbsAxes;i++) {
if(absAxes[i]!=null) {
axesArray.add(absAxes[i]);
}
}
for(int i=0;i<numRelAxes;i++) {
if(relAxes[i]!=null) {
axesArray.add(relAxes[i]);
}
}
for(int i=0;i<numHats;i++) {
if(hats[i]!=null) {
axesArray.add(hats[i]);
}
}
for(int i=0;i<numButtons;i++) {
if(buttons[i]!=null) {
axesArray.add(buttons[i]);
}
}
components = (Component[]) axesArray.toArray(components);
guessType();
if(getFFEnabled()) {
System.out.println("Java code thinks FF is enabled for device " + name);
Rumbler[] tempRumblers = rumblers;
rumblers = new Rumbler[rumblers.length+1];
System.arraycopy(tempRumblers,0,rumblers,0,tempRumblers.length);
rumblers[rumblers.length-1] = new LinuxDeviceRumbler(nativeID);
System.out.println("rumblers.length: " + rumblers.length);
System.out.println("getRumblers().length: " + getRumblers().length);
} else {
System.out.println("Java code thinks FF is disabled for device " + name);
}
}
/*public Axis[] getAxes(){
Axis retval[] = new Axis[0];
retval = (Axis []) axesArray.toArray(retval);
return retval;
}*/
/**
* Returns the port type that this device is connected to.
* @return The port type
*/
public PortType getPortType() {
return portType;
}
/**
* Returns the type of the Controller.
* @return The controller type.
*/
public Type getType() {
return typeGuess;
}
/** Create the buttons for the device
* @param numButtons The number of buttons the device has
*/
private void createButtons(int numButtons) {
int supportedButtons[] = new int[numButtons];
buttons = new LinuxAxis[numButtons];
if(numButtons>0) {
getSupportedButtons(supportedButtons);
for(int i=0;i<numButtons;i++) {
buttons[i] = createButton(i, supportedButtons[i]);
//axesArray.add(buttons[i]);
}
}
}
/** Create the relative axes for the device
* @param numRelAxes The number of relative axes the device has
*/
private void createRelAxes(int numRelAxes) {
int supportedRelAxes[] = new int[numRelAxes];
getSupportedRelAxes(supportedRelAxes);
relAxes = new LinuxAxis[numRelAxes];
for(int i=0;i<numRelAxes;i++) {
relAxes[i] = createRelAxis(i, supportedRelAxes[i]);
//axesArray.add(relAxes[i]);
}
}
/** Create the absolute axes for the device
* @param numAbsAxes The number of absolute axes the device has
*/
private void createAbsAxes(int numAbsAxes) {
int supportedAbsAxes[] = new int[numAbsAxes];
getSupportedAbsAxes(supportedAbsAxes);
absAxes = new LinuxAxis[numAbsAxes];
for(int i=0;i<numAbsAxes;i++) {
// Nasy code here
// Hats underlinux are 2 axis, combine them
if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT0X) {
hatAxisIDs[0] = i;
} else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT0Y) {
hatAxisIDs[1] = i;
} else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT1X) {
hatAxisIDs[2] = i;
} else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT1Y) {
hatAxisIDs[3] = i;
} else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT2X) {
hatAxisIDs[4] = i;
} else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT2Y) {
hatAxisIDs[5] = i;
} else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT3X) {
hatAxisIDs[6] = i;
} else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT3Y) {
hatAxisIDs[7] = i;
} else {
absAxes[i] = createAbsAxis(i, supportedAbsAxes[i]);
//axesArray.add(absAxes[i]);
}
}
}
/** Create the coolie hats for the device
*/
private void createHats() {
LinuxHat tempHats[] = new LinuxHat[4];
for(int i=0;i<4;i++) {
int x = i*2;
int y= x+1;
//Check we have at least one hat axis (can hats have just one axis?
if((hatAxisIDs[x]!=-1) || (hatAxisIDs[y]!=-1)) {
String hatName = "Hat " + i;
tempHats[numHats] = createHat(hatName, hatAxisIDs[x], hatAxisIDs[y]);
numHats++;
}
}
hats = new LinuxHat[numHats];
for(int i=0;i<numHats;i++) {
hats[i] = tempHats[i];
//axesArray.add(hats[i]);
}
}
/** Take a guess at the device type.
*/
private void guessType() {
int joystickCharacteristic=0;
int digitiserCharacteristic=0;
int gamepadCharacteristic=0;
int miscCharacteristic=0;
int mouseCharacteristic=0;
int supportedButtons[] = new int[numButtons];
getSupportedButtons(supportedButtons);
for(int i=0;i<numButtons;i++) {
switch (supportedButtons[i]) {
case NativeDefinitions.BTN_TRIGGER :
case NativeDefinitions.BTN_THUMB :
case NativeDefinitions.BTN_THUMB2 :
case NativeDefinitions.BTN_TOP :
case NativeDefinitions.BTN_TOP2 :
case NativeDefinitions.BTN_PINKIE :
case NativeDefinitions.BTN_BASE :
case NativeDefinitions.BTN_BASE2 :
case NativeDefinitions.BTN_BASE3 :
case NativeDefinitions.BTN_BASE4 :
case NativeDefinitions.BTN_BASE5 :
case NativeDefinitions.BTN_BASE6 :
case NativeDefinitions.BTN_DEAD :
joystickCharacteristic++;
break;
case NativeDefinitions.BTN_A :
case NativeDefinitions.BTN_B :
case NativeDefinitions.BTN_C :
case NativeDefinitions.BTN_X :
case NativeDefinitions.BTN_Y :
case NativeDefinitions.BTN_Z :
case NativeDefinitions.BTN_TL :
case NativeDefinitions.BTN_TR :
case NativeDefinitions.BTN_TL2 :
case NativeDefinitions.BTN_TR2 :
case NativeDefinitions.BTN_SELECT :
case NativeDefinitions.BTN_MODE :
case NativeDefinitions.BTN_THUMBL :
case NativeDefinitions.BTN_THUMBR :
gamepadCharacteristic++;
break;
case NativeDefinitions.BTN_0 :
case NativeDefinitions.BTN_1 :
case NativeDefinitions.BTN_2 :
case NativeDefinitions.BTN_3 :
case NativeDefinitions.BTN_4 :
case NativeDefinitions.BTN_5 :
case NativeDefinitions.BTN_6 :
case NativeDefinitions.BTN_7 :
case NativeDefinitions.BTN_8 :
case NativeDefinitions.BTN_9 :
miscCharacteristic++;
break;
case NativeDefinitions.BTN_LEFT :
case NativeDefinitions.BTN_RIGHT :
case NativeDefinitions.BTN_MIDDLE :
case NativeDefinitions.BTN_SIDE :
case NativeDefinitions.BTN_EXTRA :
case NativeDefinitions.BTN_FORWARD :
case NativeDefinitions.BTN_BACK :
mouseCharacteristic++;
break;
case NativeDefinitions.BTN_TOOL_PEN :
case NativeDefinitions.BTN_TOOL_RUBBER :
case NativeDefinitions.BTN_TOOL_BRUSH :
case NativeDefinitions.BTN_TOOL_PENCIL :
case NativeDefinitions.BTN_TOOL_AIRBRUSH :
case NativeDefinitions.BTN_TOOL_FINGER :
case NativeDefinitions.BTN_TOOL_MOUSE :
case NativeDefinitions.BTN_TOOL_LENS :
case NativeDefinitions.BTN_TOUCH :
case NativeDefinitions.BTN_STYLUS :
case NativeDefinitions.BTN_STYLUS2 :
digitiserCharacteristic++;
break;
default:
// no sweat, it's non of the above, erg
}
}
if((joystickCharacteristic > 0) &&
(joystickCharacteristic >= digitiserCharacteristic) &&
(joystickCharacteristic >= gamepadCharacteristic) &&
(joystickCharacteristic >= miscCharacteristic) &&
(joystickCharacteristic >= mouseCharacteristic)) {
typeGuess = Type.STICK;
} else if((gamepadCharacteristic > 0) &&
(gamepadCharacteristic >= digitiserCharacteristic) &&
(gamepadCharacteristic >= joystickCharacteristic) &&
(gamepadCharacteristic >= miscCharacteristic) &&
(gamepadCharacteristic >= mouseCharacteristic)) {
typeGuess = Type.GAMEPAD;
} else if((digitiserCharacteristic > 0) &&
(digitiserCharacteristic >= gamepadCharacteristic) &&
(digitiserCharacteristic >= joystickCharacteristic) &&
(digitiserCharacteristic >= miscCharacteristic) &&
(digitiserCharacteristic >= mouseCharacteristic)) {
typeGuess = Type.TRACKPAD;
} else if((miscCharacteristic > 0) &&
(miscCharacteristic >= gamepadCharacteristic) &&
(miscCharacteristic >= joystickCharacteristic) &&
(miscCharacteristic >= miscCharacteristic) &&
(miscCharacteristic >= mouseCharacteristic)) {
// I'm not sure what one of these would be, but it has axis other
// wise a LinuxKeyboard would have been constructed, so assume its
// some kind of stick;
typeGuess = Type.STICK;
} else if((mouseCharacteristic > 0) &&
(mouseCharacteristic >= digitiserCharacteristic) &&
(mouseCharacteristic >= joystickCharacteristic) &&
(mouseCharacteristic >= miscCharacteristic) &&
(mouseCharacteristic >= gamepadCharacteristic)) {
// We shouldn't ever get here, as a mouse should have constructed
// a LinuxMouse object, but you never know
typeGuess = Type.MOUSE;
}
if(typeGuess == Type.STICK) {
String tempName = getName().toLowerCase();
if((tempName.indexOf("gamepad") > -1) || (tempName.indexOf("game pad") > -1)) {
typeGuess = Type.GAMEPAD;
}
}
}
/** Create an button for the device
* @param buttonNumber The button number
* @param nativeButtonType The type of button
* @return The new button
*/
private LinuxAxis createButton(int buttonNumber, int nativeButtonType) {
Component.Identifier id = LinuxNativeTypesMap.getButtonID(nativeButtonType);
String name = LinuxNativeTypesMap.getButtonName(nativeButtonType);
if(name == null) {
name = "Uknown button";
id = Component.Identifier.Button.UNKNOWN;
}
return new LinuxAxis(this, buttonNumber, name, id, 0, false, true, false);
}
/** Create a relative axis for the device
* @param axisNumber The native axis id
* @param nativeType The native type
* @return The new axis
*/
private LinuxAxis createRelAxis(int axisNumber, int nativeType) {
Component.Identifier id = LinuxNativeTypesMap.getRelAxisID(nativeType);
String name = LinuxNativeTypesMap.getRelAxisName(nativeType);
// This is done to be like the windows version
// return new LinuxAxis(this, axisNumber, name, id, 0, true, true, 0, 0);
// this is what should be done
return new LinuxAxis(this, axisNumber, name, id, 0, true, false, true);
}
/** Create an absolute axis for the device
* @param axisNumber The native axis number
* @param nativeType The native tpye
* @return The new axis
*/
private LinuxAxis createAbsAxis(int axisNumber, int nativeType) {
Component.Identifier id = LinuxNativeTypesMap.getAbsAxisID(nativeType);
String name = LinuxNativeTypesMap.getAbsAxisName(nativeType);
// Work around for a kernel level (I think) bug that incorrectly reports
// the third axis as a rudder not a throttle on analog (gameport) 3 axis
// 4 button sticks
if((getName().equals("Analog 3-axis 4-button joystick")) && (portType == Controller.PortType.GAME)) {
if((id == Component.Identifier.Axis.RZ) && (name.equals("Rudder"))) {
id = Component.Identifier.Axis.SLIDER;
name = "Throttle";
}
}
return new LinuxAxis(this, axisNumber, name, id, getAbsAxisFuzz(axisNumber), true, false, getAbsAxisMinimum(axisNumber), getAbsAxisMaximum(axisNumber));
//return new LinuxAxis(this, axisNumber, name, id, getAbsAxisFuzz(axisNumber), true, false, false);
}
/** Create a hat for the device
* @param name The name of the hat to create
* @param xAxisID The axis that is the hats X axis
* @param yAxisID The axis that is the hats Y axis
* @return The new hat
*/
private LinuxHat createHat(String name, int xAxisID, int yAxisID) {
return new LinuxHat(this, name, xAxisID, yAxisID);
}
/** Polls axes for data. Returns false if the controller is no longer valid.
* Polling reflects the current state of the device when polled.
* @return false if the controller is no longer valid.
*/
public boolean poll() {
int retval = JInputLibrary.safePoll(nativeID, buttonData, relAxesData, absAxesData);
if(retval>=0) return true;
return false;
}
/**
* Retursn the value of a particular button or key
* @param buttonID The button/key to check
* @return The value fo the button/key
*/
public float getButtonValue(int buttonID) {
if(buttonData[buttonID]>0) return 1.0f;
return 0.0f;
}
/**
* Returns the value of a particular absolute axis
* @param axisID The axis id
* @return The axis value
*/
public float getAbsAxisValue(int axisID) {
return (float) absAxesData[axisID];
}
/**
* Returns the value of the requested relative axis.
* @param axisID The native axis ID.
* @return The value of the axis
*/
public float getRelAxisValue(int axisID) {
return (float) relAxesData[axisID];
}
/**
* Gets the axis fuzz, used for nullzone information
* @param axisID The axis to get the fuzz for
* @return The axis fuzz.
*/
public float getAbsAxisFuzz(int axisID) {
return (float) JInputLibrary.getAbsAxisFuzz(nativeID, axisID);
}
/**
* Returns the maximum value for the requested axis
* @param axisID The native ID of the axis to check
* @return The maximum value
*/
public float getAbsAxisMaximum(int axisID) {
return (float) JInputLibrary.getAbsAxisMaximum(nativeID, axisID);
}
/**
* The minimum value the requested axis can have
* @param axisID The native axis ID
* @return The minimum axis value
*/
public float getAbsAxisMinimum(int axisID) {
return (float) JInputLibrary.getAbsAxisMinimum(nativeID, axisID);
}
/** Return the enumeration of supported button types for this device
* @param supportedButtons Array to populate
*/
private void getSupportedButtons(int supportedButtons[]) {
if(supportedButtons.length==0) {
return;
}
JInputLibrary.getSupportedButtons(nativeID, supportedButtons);
}
/** Return the enumeration of supported absolute axis types for this device
* @param suportedAbsAxes The array to populate
*/
private void getSupportedAbsAxes(int suportedAbsAxes[]) {
JInputLibrary.getSupportedAbsAxes(nativeID, suportedAbsAxes);
}
/** Return the enumeration of supported relative axis types for this device
* @param supportedRelAxes The array to populate
*/
private void getSupportedRelAxes(int supportedRelAxes[]) {
JInputLibrary.getSupportedRelAxes(nativeID, supportedRelAxes);
}
/** Returns the status of FF support for this device
*
*/
private boolean getFFEnabled() {
return JInputLibrary.getFFEnabled(nativeID);
}
/**
* A device that represents a joystick coolie hat.
* @author Jeremy Booth (jeremy@newdawnsoftware.com)
*/
public static class LinuxHat extends AbstractComponent {
/** The parent controller
*/
private LinuxDevice controller;
/** The xAxis for this hat
*/
private int xAxisID;
/** The y axis for this hat
*/
private int yAxisID;
/** The last polled value of this hat
*/
private float value;
/**
* Creates a new instance of LinuxHat, coolie hats under linux are reported as
* two independant axis, this class is responsible for combining the axis values
* and returning a value appropriate for a coolie hat.
* @param controller The parent controller
* @param name The name of this hat
* @param xAxisID The X axis native axis ID
* @param yAxisID The Y axis native axis ID
*/
public LinuxHat(LinuxDevice controller, String name, int xAxisID, int yAxisID) {
super(name, Component.Identifier.Axis.POV);
System.out.println("Creating a Hat for device " + controller.getName() + " named " + name + " from axis " + xAxisID + " and " + yAxisID);
this.controller = controller;
this.xAxisID = xAxisID;
this.yAxisID = yAxisID;
//System.err.println("New hat: " + name + " created");
//System.err.flush();
}
/** 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 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.
*/
public boolean isRelative() {
return false;
}
/** Returns true if this axis is analog
* @return Always retursn true as coolie hats are analog under linux
*/
public boolean isAnalog() {
return false;
}
/**
* Retursn true if this axis is normalised
* @return Always returns true as linux hats are normalised
*/
public boolean isNormalised() {
return true;
}
/**
* Returns the current value of this axis
* @return The current axis value
*/
public float getPollData() {
//System.err.println("getPollData called, isPolling: " + isPolling());
//System.err.flush();
if(isPolling()) { updateData(); };
return value;
}
/** Gets the data fro mthe native level and combines it to the hats value
*/
private void updateData() {
//System.err.println("updateData called");
//System.err.flush();
int newXAxisValue = (int)controller.getAbsAxisValue(xAxisID);
int newYAxisValue = (int)controller.getAbsAxisValue(yAxisID);
//System.err.println("newXAxisValue: " + newXAxisValue + " newYAxisValue: " + newYAxisValue);
if((newXAxisValue == 0) && (newYAxisValue == 0)) {
value = POV.OFF;
} else if((newXAxisValue > 0) && (newYAxisValue < 0)) {
value = POV.UP_RIGHT;
} else if((newXAxisValue > 0) && (newYAxisValue == 0)) {
value = POV.RIGHT;
} else if((newXAxisValue > 0) && (newYAxisValue > 0)) {
value = POV.DOWN_RIGHT;
} else if((newXAxisValue == 0) && (newYAxisValue > 0)) {
value = POV.DOWN;
} else if((newXAxisValue < 0) && (newYAxisValue > 0)) {
value = POV.DOWN_LEFT;
} else if((newXAxisValue < 0) && (newYAxisValue == 0)) {
value = POV.LEFT;
} else if((newXAxisValue < 0) && (newYAxisValue < 0)) {
value = POV.UP_LEFT;
} else if((newXAxisValue == 0) && (newYAxisValue < 0)) {
value = POV.UP;
}
//System.err.println("new value: " + value);
//System.err.flush();
}
}
interface LinuxDevice {
void close() throws IOException;
}

View file

@ -1,28 +0,0 @@
package net.java.games.input;
import net.java.games.input.Component.Identifier;
public class LinuxDeviceRumbler implements Rumbler {
private int deviceID;
public LinuxDeviceRumbler(int deviceID) {
this.deviceID = deviceID;
}
public void rumble(float intensity) {
// TODO Auto-generated method stub
JInputLibrary.rumble(deviceID, intensity);
}
public String getAxisName() {
// TODO Auto-generated method stub
return null;
}
public Identifier getAxisIdentifier() {
// TODO Auto-generated method stub
return null;
}
}

View file

@ -0,0 +1,62 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
import java.io.IOException;
abstract class LinuxDeviceTask {
public final static int INPROGRESS = 1;
public final static int COMPLETED = 2;
public final static int FAILED = 3;
private Object result;
private IOException exception;
private int state = INPROGRESS;
public final void doExecute() {
try {
result = execute();
state = COMPLETED;
} catch (IOException e) {
exception = e;
state = FAILED;
}
}
public final IOException getException() {
return exception;
}
public final Object getResult() {
return result;
}
public final int getState() {
return state;
}
protected abstract Object execute() throws IOException;
}

View file

@ -0,0 +1,91 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
/**
* Linux doesn't have proper support for force feedback
* from different threads since it relies on PIDs
* to determine ownership of a particular effect slot.
* Therefore we have to hack around this by
* making sure everything related to FF
* (including the final device close that performs
* and implicit deletion of all the process' effects)
* is run on a single thread.
*/
final class LinuxDeviceThread extends Thread {
private final List tasks = new ArrayList();
public LinuxDeviceThread() {
setDaemon(true);
start();
}
public synchronized final void run() {
while (true) {
if (!tasks.isEmpty()) {
LinuxDeviceTask task = (LinuxDeviceTask)tasks.remove(0);
task.doExecute();
synchronized (task) {
task.notify();
}
} else {
try {
wait();
} catch (InterruptedException e) {
// ignore
}
}
}
}
public final Object execute(LinuxDeviceTask task) throws IOException {
synchronized (this) {
tasks.add(task);
notify();
}
synchronized (task) {
while (task.getState() == LinuxDeviceTask.INPROGRESS) {
try {
task.wait();
} catch (InterruptedException e) {
// ignore
}
}
}
switch (task.getState()) {
case LinuxDeviceTask.COMPLETED:
return task.getResult();
case LinuxDeviceTask.FAILED:
throw task.getException();
default:
throw new RuntimeException("Invalid task state: " + task.getState());
}
}
}

View file

@ -26,27 +26,47 @@
package net.java.games.input;
import net.java.games.util.plugins.Plugin;
import java.util.List;
import java.util.ArrayList;
import java.io.IOException;
import java.io.File;
import java.io.FilenameFilter;
import java.security.AccessController;
import java.security.PrivilegedAction;
/** Environment plugin for linux
* @author elias
* @author Jeremy Booth (jeremy@newdawnsoftware.com)
*/
public class LinuxEnvironmentPlugin extends ControllerEnvironment implements Plugin {
public final class LinuxEnvironmentPlugin extends ControllerEnvironment implements Plugin {
private final Controller[] controllers;
private final List devices = new ArrayList();
private final static LinuxDeviceThread device_thread = new LinuxDeviceThread();
/** List of controllers
*/
private Controller[] controllers;
/** Creates a new instance of LinuxEnvironmentPlugin */
static {
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
System.loadLibrary("jinput-linux");
return null;
}
});
}
public final static Object execute(LinuxDeviceTask task) throws IOException {
return device_thread.execute(task);
}
public LinuxEnvironmentPlugin() {
if(JInputLibrary.isSupported()) {
LinuxNativeTypesMap.init();
JInputLibrary.init();
createControllers();
} else {
controllers = new Controller[0];
}
this.controllers = enumerateControllers();
System.out.println("Linux plugin claims to have found " + controllers.length + " controllers");
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
return null;
}
});
}
/** Returns a list of all controllers available to this environment,
@ -54,91 +74,283 @@ public class LinuxEnvironmentPlugin extends ControllerEnvironment implements Plu
* @return Returns a list of all controllers available to this environment,
* or an empty array if there are no controllers in this environment.
*/
public Controller[] getControllers() {
public final Controller[] getControllers() {
return controllers;
}
/** Create the controllers
*/
private void createControllers() {
int numDevices = JInputLibrary.getNumberOfDevices();
Controller[] tempControllers = new Controller[numDevices];
int numRealDevices = 0;
Controller tempController;
for(int i=0;i<numDevices;i++) {
tempController = createDevice(i);
if(tempController!=null) {
if(tempController.getComponents().length>0 || tempController.getControllers().length>0) {
tempControllers[numRealDevices] = tempController;
numRealDevices++;
}
}
}
controllers = new Controller[numRealDevices];
for(int i=0;i<numRealDevices;i++) {
controllers[i] = tempControllers[i];
}
private final static Component[] createComponents(List event_components, LinuxEventDevice device) {
LinuxEventComponent[][] povs = new LinuxEventComponent[4][2];
List components = new ArrayList();
for (int i = 0; i < event_components.size(); i++) {
LinuxEventComponent event_component = (LinuxEventComponent)event_components.get(i);
Component.Identifier identifier = event_component.getIdentifier();
if (identifier == Component.Identifier.Axis.POV) {
int native_code = event_component.getDescriptor().getCode();
switch (native_code) {
case NativeDefinitions.ABS_HAT0X:
povs[0][0] = event_component;
break;
case NativeDefinitions.ABS_HAT0Y:
povs[0][1] = event_component;
break;
case NativeDefinitions.ABS_HAT1X:
povs[1][0] = event_component;
break;
case NativeDefinitions.ABS_HAT1Y:
povs[1][1] = event_component;
break;
case NativeDefinitions.ABS_HAT2X:
povs[2][0] = event_component;
break;
case NativeDefinitions.ABS_HAT2Y:
povs[2][1] = event_component;
break;
case NativeDefinitions.ABS_HAT3X:
povs[3][0] = event_component;
break;
case NativeDefinitions.ABS_HAT3Y:
povs[3][1] = event_component;
break;
default:
ControllerEnvironment.logln("Unknown POV instance: " + native_code);
break;
}
} else if (identifier != null) {
LinuxComponent component = new LinuxComponent(event_component);
components.add(component);
device.registerComponent(event_component.getDescriptor(), component);
}
}
for (int i = 0; i < povs.length; i++) {
LinuxEventComponent x = povs[i][0];
LinuxEventComponent y = povs[i][1];
if (x != null && y != null) {
LinuxComponent controller_component = new LinuxPOV(x, y);
components.add(controller_component);
device.registerComponent(x.getDescriptor(), controller_component);
device.registerComponent(y.getDescriptor(), controller_component);
}
}
Component[] components_array = new Component[components.size()];
components.toArray(components_array);
return components_array;
}
private final static Mouse createMouseFromDevice(LinuxEventDevice device, Component[] components) throws IOException {
Mouse mouse = new LinuxMouse(device, components, new Controller[]{}, device.getRumblers());
if (mouse.getX() != null && mouse.getY() != null && mouse.getLeft() != null)
return mouse;
else
return null;
}
private final static Keyboard createKeyboardFromDevice(LinuxEventDevice device, Component[] components) throws IOException {
Keyboard keyboard = new LinuxKeyboard(device, components, new Controller[]{}, device.getRumblers());
return keyboard;
}
private final static Controller createJoystickFromDevice(LinuxEventDevice device, Component[] components, Controller.Type type) throws IOException {
Controller joystick = new LinuxAbstractController(device, components, new Controller[]{}, device.getRumblers(), type);
return joystick;
}
private final static Controller createControllerFromDevice(LinuxEventDevice device) throws IOException {
List event_components = device.getComponents();
Component[] components = createComponents(event_components, device);
Controller.Type type = device.getType();
if (type == Controller.Type.MOUSE) {
return createMouseFromDevice(device, components);
} else if (type == Controller.Type.KEYBOARD) {
return createKeyboardFromDevice(device, components);
} else if (type == Controller.Type.STICK || type == Controller.Type.GAMEPAD) {
return createJoystickFromDevice(device, components, type);
} else
return null;
}
private final Controller[] enumerateControllers() {
List controllers = new ArrayList();
enumerateEventControllers(controllers);
if (controllers.size() == 0) {
/* Some linux distros, even modern ones, can't figure out
* how to give event devices proper access rights, so we'll have
* to fallback to the legacy joystick interface.
*/
enumerateJoystickControllers(controllers);
}
Controller[] controllers_array = new Controller[controllers.size()];
controllers.toArray(controllers_array);
return controllers_array;
}
private final static Component.Identifier.Button getButtonIdentifier(int index) {
switch (index) {
case 0:
return Component.Identifier.Button._0;
case 1:
return Component.Identifier.Button._1;
case 2:
return Component.Identifier.Button._2;
case 3:
return Component.Identifier.Button._3;
case 4:
return Component.Identifier.Button._4;
case 5:
return Component.Identifier.Button._5;
case 6:
return Component.Identifier.Button._6;
case 7:
return Component.Identifier.Button._7;
case 8:
return Component.Identifier.Button._8;
case 9:
return Component.Identifier.Button._9;
case 10:
return Component.Identifier.Button._10;
case 11:
return Component.Identifier.Button._11;
case 12:
return Component.Identifier.Button._12;
case 13:
return Component.Identifier.Button._13;
case 14:
return Component.Identifier.Button._14;
case 15:
return Component.Identifier.Button._15;
case 16:
return Component.Identifier.Button._16;
case 17:
return Component.Identifier.Button._17;
case 18:
return Component.Identifier.Button._18;
case 19:
return Component.Identifier.Button._19;
case 20:
return Component.Identifier.Button._20;
case 21:
return Component.Identifier.Button._21;
case 22:
return Component.Identifier.Button._22;
case 23:
return Component.Identifier.Button._23;
case 24:
return Component.Identifier.Button._24;
case 25:
return Component.Identifier.Button._25;
case 26:
return Component.Identifier.Button._26;
case 27:
return Component.Identifier.Button._27;
case 28:
return Component.Identifier.Button._28;
case 29:
return Component.Identifier.Button._29;
case 30:
return Component.Identifier.Button._30;
case 31:
return Component.Identifier.Button._31;
default:
return null;
}
}
private final static Controller createJoystickFromJoystickDevice(LinuxJoystickDevice device) {
List components = new ArrayList();
for (int i = 0; i < device.getNumButtons(); i++) {
Component.Identifier.Button button_id = getButtonIdentifier(i);
if (button_id != null) {
LinuxJoystickButton button = new LinuxJoystickButton(button_id);
device.registerButton(i, button);
components.add(button);
}
}
for (int i = 0; i < device.getNumAxes(); i++) {
Component.Identifier.Axis axis_id;
if ((i % 2) == 0)
axis_id = Component.Identifier.Axis.X;
else
axis_id = Component.Identifier.Axis.Y;
LinuxJoystickAxis axis = new LinuxJoystickAxis(axis_id);
device.registerAxis(i, axis);
components.add(axis);
}
return new LinuxJoystickAbstractController(device, (Component[])components.toArray(new Component[]{}), new Controller[]{}, new Rumbler[]{});
}
private final void enumerateJoystickControllers(List controllers) {
File[] joystick_device_files = enumerateJoystickDeviceFiles("/dev/input");
if (joystick_device_files == null || joystick_device_files.length == 0) {
joystick_device_files = enumerateJoystickDeviceFiles("/dev");
if (joystick_device_files == null)
return;
}
for (int i = 0; i < joystick_device_files.length; i++) {
File event_file = joystick_device_files[i];
try {
LinuxJoystickDevice device = new LinuxJoystickDevice(event_file.getAbsolutePath());
Controller controller = createJoystickFromJoystickDevice(device);
if (controller != null) {
controllers.add(controller);
devices.add(device);
} else
device.close();
} catch (IOException e) {
ControllerEnvironment.logln("Failed to open device (" + event_file + "): " + e.getMessage());
}
}
}
private final static File[] enumerateJoystickDeviceFiles(String dev_path) {
File dev = new File(dev_path);
return dev.listFiles(new FilenameFilter() {
public final boolean accept(File dir, String name) {
return name.startsWith("js");
}
});
}
private final void enumerateEventControllers(List controllers) {
File dev = new File("/dev/input");
File[] event_device_files = dev.listFiles(new FilenameFilter() {
public final boolean accept(File dir, String name) {
return name.startsWith("event");
}
});
if (event_device_files == null)
return;
for (int i = 0; i < event_device_files.length; i++) {
File event_file = event_device_files[i];
try {
LinuxEventDevice device = new LinuxEventDevice(event_file.getAbsolutePath());
try {
Controller controller = createControllerFromDevice(device);
if (controller != null) {
controllers.add(controller);
devices.add(device);
} else
device.close();
} catch (IOException e) {
ControllerEnvironment.logln("Failed to create Controller: " + e.getMessage());
device.close();
}
} catch (IOException e) {
ControllerEnvironment.logln("Failed to open device (" + event_file + "): " + e.getMessage());
}
}
}
/** Create a particular device
* @param deviceNumber The device ID
* @return The new device
*/
private Controller createDevice(int deviceNumber) {
String name = JInputLibrary.getDeviceName(deviceNumber);
int numAbsAxes = JInputLibrary.getNumAbsAxes(deviceNumber);
int numRelAxes = JInputLibrary.getNumRelAxes(deviceNumber);
int numButtons = JInputLibrary.getNumButtons(deviceNumber);
Controller device = null;
System.out.println("Java working on device " + name);
int mouseCharacteristic = 0;
int keyboardCharacteristic = 0;
int joystickCharacteristic = 0;
// we are going to try and guess what type of controller it is now
if(name.toLowerCase().indexOf("mouse")>=0) {
mouseCharacteristic++;
}
if(name.toLowerCase().indexOf("keyboard")>=0) {
keyboardCharacteristic++;
}
if(name.toLowerCase().indexOf("joystick")>=0) {
joystickCharacteristic++;
}
if(numRelAxes>=2) {
mouseCharacteristic++;
} else {
mouseCharacteristic--;
}
if(numAbsAxes>=2) {
joystickCharacteristic++;
} else {
joystickCharacteristic--;
}
if(numButtons>64) {
keyboardCharacteristic++;
} else {
keyboardCharacteristic--;
}
if((mouseCharacteristic > keyboardCharacteristic) && (mouseCharacteristic > joystickCharacteristic)) {
device = new LinuxMouse(new LinuxDevice(deviceNumber, name, numButtons, numRelAxes, numAbsAxes));
} else if((keyboardCharacteristic > mouseCharacteristic) && (keyboardCharacteristic > joystickCharacteristic)) {
device = new LinuxDevice(deviceNumber, name, numButtons, numRelAxes, numAbsAxes, Controller.Type.KEYBOARD);
} else if((joystickCharacteristic > keyboardCharacteristic) && (joystickCharacteristic > mouseCharacteristic)) {
device = new LinuxDevice(deviceNumber, name, numButtons, numRelAxes, numAbsAxes);
} else {
//Dunno what this is, but try it anyway
device = new LinuxDevice(deviceNumber, name, numButtons, numRelAxes, numAbsAxes);
}
return device;
}
private final class ShutdownHook extends Thread {
public final void run() {
for (int i = 0; i < devices.size(); i++) {
try {
LinuxDevice device = (LinuxDevice)devices.get(i);
device.close();
} catch (IOException e) {
ControllerEnvironment.logln("Failed to close device: " + e.getMessage());
}
}
}
}
}

View file

@ -0,0 +1,53 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
/**
* @author elias
*/
final class LinuxEvent {
private long nanos;
private final LinuxAxisDescriptor descriptor = new LinuxAxisDescriptor();
private int value;
public final void set(long seconds, long microseconds, int type, int code, int value) {
this.nanos = (seconds*1000000 + microseconds)*1000;
this.descriptor.set(type, code);
this.value = value;
}
public final int getValue() {
return value;
}
public final LinuxAxisDescriptor getDescriptor() {
return descriptor;
}
public final long getNanos() {
return nanos;
}
}

View file

@ -0,0 +1,115 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
import java.io.IOException;
/**
* @author elias
* @author Jeremy Booth (jeremy@newdawnsoftware.com)
*/
final class LinuxEventComponent {
private final LinuxEventDevice device;
private final Component.Identifier identifier;
private final Controller.Type button_trait;
private final boolean is_relative;
private final LinuxAxisDescriptor descriptor;
private final int min;
private final int max;
private final int flat;
public LinuxEventComponent(LinuxEventDevice device, Component.Identifier identifier, boolean is_relative, int native_type, int native_code) throws IOException {
this.device = device;
this.identifier = identifier;
if (native_type == NativeDefinitions.EV_KEY)
this.button_trait = LinuxNativeTypesMap.guessButtonTrait(native_code);
else
this.button_trait = Controller.Type.UNKNOWN;
this.is_relative = is_relative;
this.descriptor = new LinuxAxisDescriptor();
descriptor.set(native_type, native_code);
if (native_type == NativeDefinitions.EV_ABS) {
LinuxAbsInfo abs_info = new LinuxAbsInfo();
getAbsInfo(abs_info);
this.min = abs_info.getMin();
this.max = abs_info.getMax();
this.flat = abs_info.getFlat();
} else {
this.min = Integer.MIN_VALUE;
this.max = Integer.MAX_VALUE;
this.flat = 0;
}
}
public final LinuxEventDevice getDevice() {
return device;
}
public final void getAbsInfo(LinuxAbsInfo abs_info) throws IOException {
assert descriptor.getType() == NativeDefinitions.EV_ABS;
device.getAbsInfo(descriptor.getCode(), abs_info);
}
public final Controller.Type getButtonTrait() {
return button_trait;
}
public final Component.Identifier getIdentifier() {
return identifier;
}
public final LinuxAxisDescriptor getDescriptor() {
return descriptor;
}
public final boolean isRelative() {
return is_relative;
}
public final boolean isAnalog() {
return identifier instanceof Component.Identifier.Axis && identifier != Component.Identifier.Axis.POV;
}
final float convertValue(float value) {
if (identifier instanceof Component.Identifier.Axis && !is_relative) {
// Some axes have min = max = 0
if (min == max)
return 0;
if (value > max)
value = max;
else if (value < min)
value = min;
return 2*(value - min)/(max - min) - 1;
} else {
return value;
}
}
final float getDeadZone() {
return flat/(2f*(max - min));
}
}

View file

@ -0,0 +1,393 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
import java.io.IOException;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
/**
* @author elias
*/
final class LinuxEventDevice implements LinuxDevice {
private final Map component_map = new HashMap();
private final Rumbler[] rumblers;
private final long fd;
private final String name;
private final LinuxInputID input_id;
private final List components;
private final Controller.Type type;
/* Closed state variable that protects the validity of the file descriptor.
* Access to the closed state must be synchronized
*/
private boolean closed;
/* Access the the key_states array could be synchronized, but
* it doesn't hurt to have multiple threads read/write from/to it
*/
private final byte[] key_states = new byte[NativeDefinitions.KEY_MAX/8 + 1];
public LinuxEventDevice(String filename) throws IOException {
long fd;
try {
fd = nOpen(filename, true);
} catch (IOException e) {
ControllerEnvironment.logln("Failed to open device R/W: " + e.getMessage());
fd = nOpen(filename, false);
}
this.fd = fd;
try {
this.name = getDeviceName();
this.input_id = getDeviceInputID();
this.components = getDeviceComponents();
this.rumblers = enumerateRumblers();
this.type = guessType();
} catch (IOException e) {
close();
throw e;
}
}
private final static native long nOpen(String filename, boolean rw) throws IOException;
public final Controller.Type getType() {
return type;
}
private final static int countComponents(List components, Class id_type, boolean relative) {
int count = 0;
for (int i = 0; i < components.size(); i++) {
LinuxEventComponent component = (LinuxEventComponent)components.get(i);
if (id_type.isInstance(component.getIdentifier()) && relative == component.isRelative())
count++;
}
return count;
}
private final Controller.Type guessType() throws IOException {
Controller.Type type_from_usages = guessTypeFromUsages();
if (type_from_usages == Controller.Type.UNKNOWN)
return guessTypeFromComponents();
else
return type_from_usages;
}
private final Controller.Type guessTypeFromUsages() throws IOException {
byte[] usage_bits = getDeviceUsageBits();
if (isBitSet(usage_bits, NativeDefinitions.USAGE_MOUSE))
return Controller.Type.MOUSE;
else if (isBitSet(usage_bits, NativeDefinitions.USAGE_KEYBOARD))
return Controller.Type.KEYBOARD;
else if (isBitSet(usage_bits, NativeDefinitions.USAGE_GAMEPAD))
return Controller.Type.GAMEPAD;
else if (isBitSet(usage_bits, NativeDefinitions.USAGE_JOYSTICK))
return Controller.Type.STICK;
else
return Controller.Type.UNKNOWN;
}
private final Controller.Type guessTypeFromComponents() throws IOException {
List components = getComponents();
if (components.size() == 0)
return Controller.Type.UNKNOWN;
int num_rel_axes = countComponents(components, Component.Identifier.Axis.class, true);
int num_abs_axes = countComponents(components, Component.Identifier.Axis.class, false);
int num_keys = countComponents(components, Component.Identifier.Key.class, false);
int mouse_traits = 0;
int keyboard_traits = 0;
int joystick_traits = 0;
int gamepad_traits = 0;
if (name.toLowerCase().indexOf("mouse") != -1)
mouse_traits++;
if (name.toLowerCase().indexOf("keyboard") != -1)
keyboard_traits++;
if (name.toLowerCase().indexOf("joystick") != -1)
joystick_traits++;
if (name.toLowerCase().indexOf("gamepad") != -1)
gamepad_traits++;
int num_keyboard_button_traits = 0;
int num_mouse_button_traits = 0;
int num_joystick_button_traits = 0;
int num_gamepad_button_traits = 0;
// count button traits
for (int i = 0; i < components.size(); i++) {
LinuxEventComponent component = (LinuxEventComponent)components.get(i);
if (component.getButtonTrait() == Controller.Type.MOUSE)
num_mouse_button_traits++;
else if (component.getButtonTrait() == Controller.Type.KEYBOARD)
num_keyboard_button_traits++;
else if (component.getButtonTrait() == Controller.Type.GAMEPAD)
num_gamepad_button_traits++;
else if (component.getButtonTrait() == Controller.Type.STICK)
num_joystick_button_traits++;
}
if ((num_mouse_button_traits >= num_keyboard_button_traits) && (num_mouse_button_traits >= num_joystick_button_traits) && (num_mouse_button_traits >= num_gamepad_button_traits)) {
mouse_traits++;
} else if ((num_keyboard_button_traits >= num_mouse_button_traits) && (num_keyboard_button_traits >= num_joystick_button_traits) && (num_keyboard_button_traits >= num_gamepad_button_traits)) {
keyboard_traits++;
} else if ((num_joystick_button_traits >= num_keyboard_button_traits) && (num_joystick_button_traits >= num_mouse_button_traits) && (num_joystick_button_traits >= num_gamepad_button_traits)) {
joystick_traits++;
} else if ((num_gamepad_button_traits >= num_keyboard_button_traits) && (num_gamepad_button_traits >= num_mouse_button_traits) && (num_gamepad_button_traits >= num_joystick_button_traits)) {
gamepad_traits++;
}
if (num_rel_axes >= 2) {
mouse_traits++;
}
if (num_abs_axes >= 2) {
joystick_traits++;
gamepad_traits++;
}
if ((mouse_traits >= keyboard_traits) && (mouse_traits >= joystick_traits) && (mouse_traits >= gamepad_traits)) {
return Controller.Type.MOUSE;
} else if ((keyboard_traits >= mouse_traits) && (keyboard_traits >= joystick_traits) && (keyboard_traits >= gamepad_traits)) {
return Controller.Type.KEYBOARD;
} else if ((joystick_traits >= mouse_traits) && (joystick_traits >= keyboard_traits) && (joystick_traits >= gamepad_traits)) {
return Controller.Type.STICK;
} else if ((gamepad_traits >= mouse_traits) && (gamepad_traits >= keyboard_traits) && (gamepad_traits >= joystick_traits)) {
return Controller.Type.GAMEPAD;
} else
return null;
}
private final Rumbler[] enumerateRumblers() {
List rumblers = new ArrayList();
try {
int num_effects = getNumEffects();
if (num_effects <= 0)
return (Rumbler[])rumblers.toArray(new Rumbler[]{});
byte[] ff_bits = getForceFeedbackBits();
if (isBitSet(ff_bits, NativeDefinitions.FF_RUMBLE) && num_effects > rumblers.size()) {
rumblers.add(new LinuxRumbleFF(this));
}
} catch (IOException e) {
ControllerEnvironment.logln("Failed to enumerate rumblers: " + e.getMessage());
}
return (Rumbler[])rumblers.toArray(new Rumbler[]{});
}
public final Rumbler[] getRumblers() {
return rumblers;
}
public final synchronized int uploadRumbleEffect(int id, int trigger_button, int direction, int trigger_interval, int replay_length, int replay_delay, int strong_magnitude, int weak_magnitude) throws IOException {
checkClosed();
return nUploadRumbleEffect(fd, id, direction, trigger_button, trigger_interval, replay_length, replay_delay, strong_magnitude, weak_magnitude);
}
private final static native int nUploadRumbleEffect(long fd, int id, int direction, int trigger_button, int trigger_interval, int replay_length, int replay_delay, int strong_magnitude, int weak_magnitude) throws IOException;
public final synchronized int uploadConstantEffect(int id, int trigger_button, int direction, int trigger_interval, int replay_length, int replay_delay, int constant_level, int constant_env_attack_length, int constant_env_attack_level, int constant_env_fade_length, int constant_env_fade_level) throws IOException {
checkClosed();
return nUploadConstantEffect(fd, id, direction, trigger_button, trigger_interval, replay_length, replay_delay, constant_level, constant_env_attack_length, constant_env_attack_level, constant_env_fade_length, constant_env_fade_level);
}
private final static native int nUploadConstantEffect(long fd, int id, int direction, int trigger_button, int trigger_interval, int replay_length, int replay_delay, int constant_level, int constant_env_attack_length, int constant_env_attack_level, int constant_env_fade_length, int constant_env_fade_level) throws IOException;
final void eraseEffect(int id) throws IOException {
nEraseEffect(fd, id);
}
private final static native void nEraseEffect(long fd, int ff_id) throws IOException;
public final synchronized void writeEvent(int type, int code, int value) throws IOException {
checkClosed();
nWriteEvent(fd, type, code, value);
}
private final static native void nWriteEvent(long fd, int type, int code, int value) throws IOException;
public final void registerComponent(LinuxAxisDescriptor desc, LinuxComponent component) {
component_map.put(desc, component);
}
public final LinuxComponent mapDescriptor(LinuxAxisDescriptor desc) {
return (LinuxComponent)component_map.get(desc);
}
public final Controller.PortType getPortType() throws IOException {
return input_id.getPortType();
}
public final LinuxInputID getInputID() {
return input_id;
}
private final LinuxInputID getDeviceInputID() throws IOException {
return nGetInputID(fd);
}
private final static native LinuxInputID nGetInputID(long fd) throws IOException;
public final int getNumEffects() throws IOException {
return nGetNumEffects(fd);
}
private final static native int nGetNumEffects(long fd) throws IOException;
private final int getVersion() throws IOException {
return nGetVersion(fd);
}
private final static native int nGetVersion(long fd) throws IOException;
public final synchronized boolean getNextEvent(LinuxEvent linux_event) throws IOException {
checkClosed();
return nGetNextEvent(fd, linux_event);
}
private final static native boolean nGetNextEvent(long fd, LinuxEvent linux_event) throws IOException;
public final synchronized void getAbsInfo(int abs_axis, LinuxAbsInfo abs_info) throws IOException {
checkClosed();
nGetAbsInfo(fd, abs_axis, abs_info);
}
private final static native void nGetAbsInfo(long fd, int abs_axis, LinuxAbsInfo abs_info) throws IOException;
private final void addKeys(List components) throws IOException {
byte[] bits = getKeysBits();
for (int i = 0; i < bits.length*8; i++) {
if (isBitSet(bits, i)) {
Component.Identifier id = LinuxNativeTypesMap.getButtonID(i);
components.add(new LinuxEventComponent(this, id, false, NativeDefinitions.EV_KEY, i));
}
}
}
private final void addAbsoluteAxes(List components) throws IOException {
byte[] bits = getAbsoluteAxesBits();
for (int i = 0; i < bits.length*8; i++) {
if (isBitSet(bits, i)) {
Component.Identifier id = LinuxNativeTypesMap.getAbsAxisID(i);
components.add(new LinuxEventComponent(this, id, false, NativeDefinitions.EV_ABS, i));
}
}
}
private final void addRelativeAxes(List components) throws IOException {
byte[] bits = getRelativeAxesBits();
for (int i = 0; i < bits.length*8; i++) {
if (isBitSet(bits, i)) {
Component.Identifier id = LinuxNativeTypesMap.getRelAxisID(i);
components.add(new LinuxEventComponent(this, id, true, NativeDefinitions.EV_REL, i));
}
}
}
public final List getComponents() {
return components;
}
private final List getDeviceComponents() throws IOException {
List components = new ArrayList();
byte[] evtype_bits = getEventTypeBits();
if (isBitSet(evtype_bits, NativeDefinitions.EV_KEY))
addKeys(components);
if (isBitSet(evtype_bits, NativeDefinitions.EV_ABS))
addAbsoluteAxes(components);
if (isBitSet(evtype_bits, NativeDefinitions.EV_REL))
addRelativeAxes(components);
return components;
}
private final byte[] getForceFeedbackBits() throws IOException {
byte[] bits = new byte[NativeDefinitions.FF_MAX/8 + 1];
nGetBits(fd, NativeDefinitions.EV_FF, bits);
return bits;
}
private final byte[] getKeysBits() throws IOException {
byte[] bits = new byte[NativeDefinitions.KEY_MAX/8 + 1];
nGetBits(fd, NativeDefinitions.EV_KEY, bits);
return bits;
}
private final byte[] getAbsoluteAxesBits() throws IOException {
byte[] bits = new byte[NativeDefinitions.ABS_MAX/8 + 1];
nGetBits(fd, NativeDefinitions.EV_ABS, bits);
return bits;
}
private final byte[] getRelativeAxesBits() throws IOException {
byte[] bits = new byte[NativeDefinitions.REL_MAX/8 + 1];
nGetBits(fd, NativeDefinitions.EV_REL, bits);
return bits;
}
private final byte[] getEventTypeBits() throws IOException {
byte[] bits = new byte[NativeDefinitions.EV_MAX/8 + 1];
nGetBits(fd, 0, bits);
return bits;
}
private final static native void nGetBits(long fd, int ev_type, byte[] evtype_bits) throws IOException;
private final byte[] getDeviceUsageBits() throws IOException {
byte[] bits = new byte[NativeDefinitions.USAGE_MAX/8 + 1];
if (getVersion() >= 0x010001) {
nGetDeviceUsageBits(fd, bits);
}
return bits;
}
private final static native void nGetDeviceUsageBits(long fd, byte[] type_bits) throws IOException;
public final synchronized void pollKeyStates() throws IOException {
nGetKeyStates(fd, key_states);
}
private final static native void nGetKeyStates(long fd, byte[] states) throws IOException;
public final boolean isKeySet(int bit) {
return isBitSet(key_states, bit);
}
public final static boolean isBitSet(byte[] bits, int bit) {
return (bits[bit/8] & (1<<(bit%8))) != 0;
}
public final String getName() {
return name;
}
private final String getDeviceName() throws IOException {
return nGetName(fd);
}
private final static native String nGetName(long fd) throws IOException;
public synchronized final void close() throws IOException {
if (closed)
return;
closed = true;
LinuxEnvironmentPlugin.execute(new LinuxDeviceTask() {
protected final Object execute() throws IOException {
nClose(fd);
return null;
}
});
}
private final static native void nClose(long fd) throws IOException;
private final void checkClosed() throws IOException {
if (closed)
throw new IOException("Device is closed");
}
protected void finalize() throws IOException {
close();
}
}

View file

@ -0,0 +1,110 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
import java.io.IOException;
/**
* @author elias
*/
abstract class LinuxForceFeedbackEffect implements Rumbler {
private final LinuxEventDevice device;
private final int ff_id;
private final WriteTask write_task = new WriteTask();
private final UploadTask upload_task = new UploadTask();
public LinuxForceFeedbackEffect(LinuxEventDevice device) throws IOException {
this.device = device;
this.ff_id = upload_task.doUpload(-1, 0);
}
protected abstract int upload(int id, float intensity) throws IOException;
protected final LinuxEventDevice getDevice() {
return device;
}
public synchronized final void rumble(float intensity) {
try {
if (intensity > 0) {
upload_task.doUpload(ff_id, intensity);
write_task.write(1);
} else {
write_task.write(0);
}
} catch (IOException e) {
ControllerEnvironment.logln("Failed to rumble: " + e);
}
}
/*
* Erase doesn't seem to be implemented on Logitech joysticks,
* so we'll rely on the kernel cleaning up on device close
*/
/*
public final void erase() throws IOException {
device.eraseEffect(ff_id);
}
*/
public final String getAxisName() {
return null;
}
public final Component.Identifier getAxisIdentifier() {
return null;
}
private final class UploadTask extends LinuxDeviceTask {
private int id;
private float intensity;
public final int doUpload(int id, float intensity) throws IOException {
this.id = id;
this.intensity = intensity;
LinuxEnvironmentPlugin.execute(this);
return this.id;
}
protected final Object execute() throws IOException {
this.id = upload(id, intensity);
return null;
}
}
private final class WriteTask extends LinuxDeviceTask {
private int value;
public final void write(int value) throws IOException {
this.value = value;
LinuxEnvironmentPlugin.execute(this);
}
protected final Object execute() throws IOException {
device.writeEvent(NativeDefinitions.EV_FF, ff_id, value);
return null;
}
}
}

View file

@ -0,0 +1,52 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
/**
* @author elias
*/
final class LinuxInputID {
private final int bustype;
private final int vendor;
private final int product;
private final int version;
public LinuxInputID(int bustype, int vendor, int product, int version) {
this.bustype = bustype;
this.vendor = vendor;
this.product = product;
this.version = version;
}
public final Controller.PortType getPortType() {
return LinuxNativeTypesMap.getPortType(bustype);
}
public final String toString() {
return "LinuxInputID: bustype = 0x" + Integer.toHexString(bustype) + " | vendor = 0x" + Integer.toHexString(vendor) +
" | product = 0x" + Integer.toHexString(product) + " | version = 0x" + Integer.toHexString(version);
}
}

View file

@ -0,0 +1,70 @@
/*
* %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.io.IOException;
/** Represents a Linux controller
* @author elias
* @version 1.0
*/
final class LinuxJoystickAbstractController extends AbstractController {
private final LinuxJoystickDevice device;
protected LinuxJoystickAbstractController(LinuxJoystickDevice device, Component[] components, Controller[] children, Rumbler[] rumblers) {
super(device.getName(), components, children, rumblers);
this.device = device;
}
protected final void setDeviceEventQueueSize(int size) throws IOException {
device.setBufferSize(size);
}
public final void pollDevice() throws IOException {
device.poll();
}
protected final boolean getNextDeviceEvent(Event event) throws IOException {
return false;
}
public Type getType() {
return Controller.Type.STICK;
}
}

View file

@ -0,0 +1,69 @@
/*
* %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.io.IOException;
/** Represents a linux Axis
* @author elias
* @version 1.0
*/
class LinuxJoystickAxis extends AbstractComponent {
private float value;
public LinuxJoystickAxis(Component.Identifier.Axis axis_id) {
super(axis_id.getName(), axis_id);
}
public final boolean isRelative() {
return false;
}
public final boolean isAnalog() {
return true;
}
final void setValue(float value) {
this.value = value;
}
protected final float poll() throws IOException {
return value;
}
}

View file

@ -0,0 +1,65 @@
/*
* %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.io.IOException;
/** Represents a linux button from the joystick interface
* @author elias
* @version 1.0
*/
final class LinuxJoystickButton extends AbstractComponent {
private float value;
public LinuxJoystickButton(Component.Identifier.Button button_id) {
super(button_id.getName(), button_id);
}
public final boolean isRelative() {
return false;
}
final void setValue(float value) {
this.value = value;
}
protected final float poll() throws IOException {
return value;
}
}

View file

@ -0,0 +1,185 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
import java.io.IOException;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
/**
* @author elias
*/
final class LinuxJoystickDevice implements LinuxDevice {
public final static int JS_EVENT_BUTTON = 0x01; /* button pressed/released */
public final static int JS_EVENT_AXIS = 0x02; /* joystick moved */
public final static int JS_EVENT_INIT = 0x80; /* initial state of device */
public final static int AXIS_MAX_VALUE = 32767;
private final long fd;
private final String name;
private final LinuxJoystickEvent joystick_event = new LinuxJoystickEvent();
private final Event event = new Event();
private final LinuxJoystickButton[] buttons;
private final LinuxJoystickAxis[] axes;
private EventQueue event_queue;
/* Closed state variable that protects the validity of the file descriptor.
* Access to the closed state must be synchronized
*/
private boolean closed;
public LinuxJoystickDevice(String filename) throws IOException {
this.fd = nOpen(filename);
try {
this.name = getDeviceName();
setBufferSize(AbstractController.EVENT_QUEUE_DEPTH);
buttons = new LinuxJoystickButton[getNumDeviceButtons()];
axes = new LinuxJoystickAxis[getNumDeviceAxes()];
} catch (IOException e) {
close();
throw e;
}
}
private final static native long nOpen(String filename) throws IOException;
public final synchronized void setBufferSize(int size) {
event_queue = new EventQueue(size);
}
private final void processEvent(LinuxJoystickEvent joystick_event) {
int index = joystick_event.getNumber();
// Filter synthetic init event flag
int type = joystick_event.getType() & ~JS_EVENT_INIT;
switch (type) {
case JS_EVENT_BUTTON:
if (index < getNumButtons()) {
LinuxJoystickButton button = buttons[index];
if (button != null) {
float value = joystick_event.getValue();
button.setValue(value);
event.set(button, value, joystick_event.getNanos());
break;
}
}
return;
case JS_EVENT_AXIS:
if (index < getNumAxes()) {
LinuxJoystickAxis axis = axes[index];
if (axis != null) {
float value = (float)joystick_event.getValue()/AXIS_MAX_VALUE;
axis.setValue(value);
event.set(axis, value, joystick_event.getNanos());
break;
}
}
return;
default:
// Unknown component type
return;
}
if (!event_queue.isFull()) {
event_queue.add(event);
}
}
public final void registerAxis(int index, LinuxJoystickAxis axis) {
axes[index] = axis;
}
public final void registerButton(int index, LinuxJoystickButton button) {
buttons[index] = button;
}
public final synchronized boolean getNextEvent(Event event) throws IOException {
return event_queue.getNextEvent(event);
}
public final synchronized void poll() throws IOException {
checkClosed();
while (getNextDeviceEvent(joystick_event)) {
processEvent(joystick_event);
}
}
private final boolean getNextDeviceEvent(LinuxJoystickEvent joystick_event) throws IOException {
return nGetNextEvent(fd, joystick_event);
}
private final static native boolean nGetNextEvent(long fd, LinuxJoystickEvent joystick_event) throws IOException;
public final int getNumAxes() {
return axes.length;
}
public final int getNumButtons() {
return buttons.length;
}
private final int getNumDeviceButtons() throws IOException {
return nGetNumButtons(fd);
}
private final static native int nGetNumButtons(long fd) throws IOException;
private final int getNumDeviceAxes() throws IOException {
return nGetNumAxes(fd);
}
private final static native int nGetNumAxes(long fd) throws IOException;
private final int getVersion() throws IOException {
return nGetVersion(fd);
}
private final static native int nGetVersion(long fd) throws IOException;
public final String getName() {
return name;
}
private final String getDeviceName() throws IOException {
return nGetName(fd);
}
private final static native String nGetName(long fd) throws IOException;
public final synchronized void close() throws IOException {
if (!closed) {
closed = true;
nClose(fd);
}
}
private final static native void nClose(long fd) throws IOException;
private final void checkClosed() throws IOException {
if (closed)
throw new IOException("Device is closed");
}
protected void finalize() throws IOException {
close();
}
}

View file

@ -23,15 +23,37 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
#if !defined(joystickInterface_h)
#define joystickInterface_h
/**
* @author elias
*/
final class LinuxJoystickEvent {
private long nanos;
private int value;
private int type;
private int number;
#include "Device.h"
public final void set(long millis, int value, int type, int number) {
this.nanos = millis*1000000;
this.value = value;
this.type = type;
this.number = number;
}
int jsGetJoystickInterfaceVersionNumber();
int jsInit();
int jsGetNumberDevices();
void jsGetDevices(Device **deviceList);
public final int getValue() {
return value;
}
#endif //joystickInterface_h
public final int getType() {
return type;
}
public final int getNumber() {
return number;
}
public final long getNanos() {
return nanos;
}
}

View file

@ -1,175 +1,68 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
/*
* %W% %E%
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
* 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;
/** Class that represents a keyboard under linux
* @author Jeremy Booth (jeremy@newdawnsoftware.com)
*/
public class LinuxKeyboard extends StandardKeyboard {
/** Values for the keys
*/
private int keyData[];
/** Needed for the polling methods
*/
private int dummyRelAxesData[];
/** Needed for the polling methods
*/
private int dummyAbsAxesData[];
/** Map of native key numbers from jinput key id key indexes.
*/
private int keyMap[];
/** List of keys this keyboard supports
*/
private int supportedKeys[];
/** Number of keys this keyboard has
*/
private int numKeys;
/** Port type that this keyboard is connected to.
*/
private PortType portType;
/** The native device id
*/
private int nativeID;
/** Creates a new instance of LinuxKeyboard
* @param nativeID Native device id
* @param name Name of this keybaord
* @param numButtons Number of keys
* @param numRelAxes Number of relative axes (you never know)
* @param numAbsAxes Number of absolute axes (you never know)
*/
public LinuxKeyboard(int nativeID, String name, int numButtons, int numRelAxes, int numAbsAxes) {
super(name);
throw new RuntimeException("Error, should not get here");
/*children = NO_CONTROLLERS;
rumblers = NO_RUMBLERS;
this.nativeID = nativeID;
portType = LinuxNativeTypesMap.getPortType(getNativePortType(nativeID));
dummyRelAxesData = new int[numRelAxes];
dummyAbsAxesData = new int[numAbsAxes];
this.numKeys = numButtons;
keyData = new int[numButtons+1];
supportedKeys = new int[numButtons+1];
keyMap = new int[KeyID.LAST.getKeyIndex()];
getSupportedButtons(supportedKeys);
supportedKeys[numKeys] = NativeDefinitions.KEY_UNKNOWN;
setupKeyMap();
renameKeys();*/
}
/** Returns whether or not the given key has been pressed since the last
* call to poll. This is called from a key's getPollData method.
* @param key The key to check
* @return the value fo the key
*/
protected boolean isKeyPressed(Key key) {
/*if(((Keyboard.KeyID) key.getIdentifier()).getKeyIndex() == StandardKeyboard.KeyID.ESCAPE.getKeyIndex()) {
System.out.println("Asked if key " + key + " was pressed");
System.out.println("key id " + key.getIdentifier());
System.out.println("keyIndex " + ((Keyboard.KeyID) key.getIdentifier()).getKeyIndex());
System.out.println("keyMap for index is " + keyMap[((Keyboard.KeyID) key.getIdentifier()).getKeyIndex()]);
System.out.println("name for supportedKeys index is " + LinuxNativeTypesMap.getButtonName(supportedKeys[keyMap[((Keyboard.KeyID) key.getIdentifier()).getKeyIndex()]]));
System.out.println("id for supportedKeys index is " + LinuxNativeTypesMap.getButtonID(supportedKeys[keyMap[((Keyboard.KeyID) key.getIdentifier()).getKeyIndex()]]));
System.out.flush();
}*/
if(keyData[keyMap[((Component.Identifier.Key) key.getIdentifier()).getKeyIndex()]] > 0) {
return true;
}
return false;
}
/** Polls axes for data. Returns false if the controller is no longer valid.
* Polling reflects the current state of the device when polled.
* @return False if this device is invalid.
*/
public boolean poll() {
int retval = JInputLibrary.safePoll(nativeID, keyData, dummyRelAxesData, dummyAbsAxesData);
if(retval>=0) return true;
return false;
}
/** Goes through every key to initialise the key map
*/
private void setupKeyMap() {
for(int i=0;i<Component.Identifier.Key.LAST.getKeyIndex();i++) {
keyMap[i] = numKeys;
}
for(int i=0;i<numKeys;i++) {
int tempNativeID = supportedKeys[i];
Component.Identifier.Key tempKeyID = Component.Identifier.Key.VOID;
try {
tempKeyID = (Component.Identifier.Key)LinuxNativeTypesMap.getButtonID(tempNativeID);
} catch (ClassCastException e) {
System.out.println("LinuxNativeTypesMap.getButtonID() returned " + LinuxNativeTypesMap.getButtonID(tempNativeID).getClass().toString());
}
if(tempKeyID.getKeyIndex() < keyMap.length) {
keyMap[tempKeyID.getKeyIndex()] = i;
//System.out.println("keyMap[" + (tempKeyID.getKeyIndex()) + "] (" + tempKeyID + ") set to index " + i + " (" + LinuxNativeTypesMap.getButtonName(supportedKeys[i]) + ")");
} else {
//System.out.println("Linux key " + LinuxNativeTypesMap.getButtonName(tempNativeID) + " isn't supported by jinput");
}
}
}
/** Renames all the keys based on what information we have about them (number/name)
*/
private void renameKeys() {
Component tempAxes[] = getComponents();
// Do this one by hand as it's a special case
//((AbstractAxis)tempAxes[0]).setName("Unknown");
for(int i=0;i<tempAxes.length;i++) {
Component tempAxis = tempAxes[i];
int nativeKeyID = supportedKeys[keyMap[((Component.Identifier.Key) tempAxis.getIdentifier()).getKeyIndex()]];
//System.out.println("key " + tempAxis + " map: " + nativeKeyID);
if(nativeKeyID != NativeDefinitions.KEY_UNKNOWN) {
String tempName = LinuxNativeTypesMap.getButtonName(nativeKeyID);
((AbstractComponent)tempAxis).setName(tempName);
import java.io.IOException;
/*System.out.println("axis id is " + (Keyboard.KeyID) tempAxis.getIdentifier());
System.out.println("keyMap[id] is " + keyMap[((Keyboard.KeyID) tempAxis.getIdentifier()).getKeyIndex()]);
System.out.println("nativeKeyID is: " + nativeKeyID);
System.out.println("Set name of key " + ((Keyboard.KeyID) tempAxis.getIdentifier()).getKeyIndex() + " to " + tempName);*/
}
}
}
/** Gets all the supported keys for this device
* @param supportedButtons The array if key types to populate
*/
private void getSupportedButtons(int supportedButtons[]) {
JInputLibrary.getSupportedButtons(nativeID, supportedButtons);
}
/** Represents an OSX Keyboard
* @author elias
* @version 1.0
*/
final class LinuxKeyboard extends Keyboard {
private final PortType port;
private final LinuxEventDevice device;
protected LinuxKeyboard(LinuxEventDevice device, Component[] components, Controller[] children, Rumbler[] rumblers) throws IOException {
super(device.getName(), components, children, rumblers);
this.device = device;
this.port = device.getPortType();
}
public final PortType getPortType() {
return port;
}
protected final boolean getNextDeviceEvent(Event event) throws IOException {
return LinuxControllers.getNextDeviceEvent(event, device);
}
public final void pollDevice() throws IOException {
device.pollKeyStates();
}
}

View file

@ -1,168 +1,68 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
/*
* %W% %E%
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
* 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;
/** Class that represents a mouse under linux.
*
* @author Jeremy Booth (jeremy@newdawnsoftware.com)
*/
public class LinuxMouse extends Mouse {
/** The parent linux device
*/
private LinuxDevice device;
/** Creates a new instance of LinuxMouse
* @param device The parent device
*/
public LinuxMouse(LinuxDevice device) {
super(device.getName());
this.device = device;
Component[] components = device.getComponents();
Component x = null;
Component y = null;
Component wheel = null;
Button left = null;
Button right = null;
Button middle = null;
Button side = null;
Button extra = null;
Button forward = null;
Button back = null;
// start from the back, that way the first one is it
for(int i = (components.length -1);i>=0;i--) {
Component tempAxis = components[i];
if(tempAxis.isRelative()) {
if(tempAxis.getIdentifier() == Component.Identifier.Axis.X) {
x = tempAxis;
} else if(tempAxis.getIdentifier() == Component.Identifier.Axis.Y) {
y = tempAxis;
} else if(tempAxis.getIdentifier() == Component.Identifier.Axis.SLIDER) {
wheel = tempAxis;
}
} else if(!(tempAxis.isAnalog())) {
if(tempAxis.getIdentifier() == Component.Identifier.Button.LEFT) {
left = new LinuxMouseButton(tempAxis);
} else if(tempAxis.getIdentifier() == Component.Identifier.Button.RIGHT) {
right = new LinuxMouseButton(tempAxis);
} else if(tempAxis.getIdentifier() == Component.Identifier.Button.MIDDLE) {
middle = new LinuxMouseButton(tempAxis);
} else if(tempAxis.getIdentifier() == Component.Identifier.Button.SIDE) {
side = new LinuxMouseButton(tempAxis);
} else if(tempAxis.getIdentifier() == Component.Identifier.Button.EXTRA) {
extra = new LinuxMouseButton(tempAxis);
} else if(tempAxis.getIdentifier() == Component.Identifier.Button.FORWARD) {
forward = new LinuxMouseButton(tempAxis);
} else if(tempAxis.getIdentifier() == Component.Identifier.Button.BACK) {
back = new LinuxMouseButton(tempAxis);
}
}
}
ball = new LinuxMouseBall(x,y,wheel);
buttons = new LinuxMouseButtons(left, right, middle, side, extra, forward, back);
}
/** Polls axes for data. Returns false if the controller is no longer valid.
* Polling reflects the current state of the device when polled.
* @return Returns false if the controller is no longer valid.
*/
public boolean poll() {
return device.poll();
}
/** Mouse ball under linux
*/
private class LinuxMouseBall extends Ball {
/** Constructs the new mouse ball
* @param x The x axis
* @param y The y axis
* @param wheel The mouse wheel axis
*/
public LinuxMouseBall(Component x, Component y, Component wheel) {
super(LinuxMouse.this.getName() + " ball");
this.x = x;
this.y = y;
this.wheel = wheel;
}
}
/** Mouse buttons under linux
*/
private class LinuxMouseButtons extends Buttons {
/** Creates the new mouse's buttons
* @param left Left mouse button
* @param right Right mouse button
* @param middle Middle mouse button
* @param side Side mouse button
* @param extra Extra mouse button
* @param forward Forward mouse button
* @param back Back mouse button
*/
public LinuxMouseButtons(Button left, Button right, Button middle, Button side, Button extra, Button forward, Button back) {
super(LinuxMouse.this.getName() + " buttons");
this.left = left;
this.right = right;
this.middle = middle;
this.side = side;
this.extra = extra;
this.forward = forward;
this.back = back;
}
}
/** Linux specific mouse buttons
*/
private class LinuxMouseButton extends Mouse.Button {
/** The real Axis
*/
private Component realAxis;
/** Construct a linux mouse button fro mthe given axis
* @param axis The axis that holds the data
*/
public LinuxMouseButton(Component axis) {
super(axis.getName(), (Component.Identifier.Button)axis.getIdentifier());
this.realAxis = axis;
}
/** Returns true f this axis is relative
* @return Always returns false for a mouse button
*/
public boolean isRelative() {
return false;
}
/** Returns the data for this mouse button
* @return Retursn this mouse buttons value
*/
public float getPollData(){
return realAxis.getPollData();
}
}
import java.io.IOException;
/** Represents an OSX Mouse
* @author elias
* @version 1.0
*/
final class LinuxMouse extends Mouse {
private final PortType port;
private final LinuxEventDevice device;
protected LinuxMouse(LinuxEventDevice device, Component[] components, Controller[] children, Rumbler[] rumblers) throws IOException {
super(device.getName(), components, children, rumblers);
this.device = device;
this.port = device.getPortType();
}
public final PortType getPortType() {
return port;
}
public final void pollDevice() throws IOException {
device.pollKeyStates();
}
protected final boolean getNextDeviceEvent(Event event) throws IOException {
return LinuxControllers.getNextDeviceEvent(event, device);
}
}

View file

@ -30,315 +30,25 @@ package net.java.games.input;
* Key.Identifiers
* @author Jeremy Booth (jeremy@newdawnsoftware.com)
*/
public class LinuxNativeTypesMap {
/** Instance of they key map
*/
class LinuxNativeTypesMap {
private static LinuxNativeTypesMap INSTANCE = new LinuxNativeTypesMap();
/** Indexed array of key names
*/
private String keyNames[];
/** Inexed array of relative axes names
*/
private String relAxesNames[];
/** Indexed array of absolute axis names
*/
private String absAxesNames[];
/** Indexed array of relative axis ID's
*/
private Component.Identifier relAxesIDs[];
/** Indexed array of absoulte axis ID's
*/
private Component.Identifier absAxesIDs[];
/** Indexed array of button axis ID's
*/
private Component.Identifier buttonIDs[];
private final Component.Identifier relAxesIDs[];
private final Component.Identifier absAxesIDs[];
private final Component.Identifier buttonIDs[];
/** create an empty, uninitialsed map
*/
private LinuxNativeTypesMap() {
keyNames = new String[NativeDefinitions.KEY_MAX];
buttonIDs = new Component.Identifier[NativeDefinitions.KEY_MAX];
relAxesIDs = new Component.Identifier[NativeDefinitions.REL_MAX];
absAxesIDs = new Component.Identifier[NativeDefinitions.ABS_MAX];
reInit();
}
/** Initialise the map, has to be done like this because the map references staic
* classes, as this would otherwise be done in a static class initialiser the whole
* thing blew up as the static classes this class references refer to this class
* this meant that the other classes could not be initialsed until this one was,
* but this class couldn't be loaded until the others were, all went horibly wrong
* and INSTANCE was null whilst initialising the class, ouch.
*/
public static void init() {
INSTANCE.reInit();
}
/** Do the work.
*/
private void reInit() {
keyNames[NativeDefinitions.KEY_ESC] = "Escape";
keyNames[NativeDefinitions.KEY_1] = "1";
keyNames[NativeDefinitions.KEY_2] = "2";
keyNames[NativeDefinitions.KEY_3] = "3";
keyNames[NativeDefinitions.KEY_4] = "4";
keyNames[NativeDefinitions.KEY_5] = "5";
keyNames[NativeDefinitions.KEY_6] = "6";
keyNames[NativeDefinitions.KEY_7] = "7";
keyNames[NativeDefinitions.KEY_8] = "8";
keyNames[NativeDefinitions.KEY_9] = "9";
keyNames[NativeDefinitions.KEY_0] = "0";
keyNames[NativeDefinitions.KEY_MINUS] = "-";
keyNames[NativeDefinitions.KEY_EQUAL] = "=";
keyNames[NativeDefinitions.KEY_BACKSPACE] = "Backspace";
keyNames[NativeDefinitions.KEY_TAB] = "Tab";
keyNames[NativeDefinitions.KEY_Q] = "Q";
keyNames[NativeDefinitions.KEY_W] = "W";
keyNames[NativeDefinitions.KEY_E] = "E";
keyNames[NativeDefinitions.KEY_R] = "R";
keyNames[NativeDefinitions.KEY_T] = "T";
keyNames[NativeDefinitions.KEY_Y] = "Y";
keyNames[NativeDefinitions.KEY_U] = "U";
keyNames[NativeDefinitions.KEY_I] = "I";
keyNames[NativeDefinitions.KEY_O] = "O";
keyNames[NativeDefinitions.KEY_P] = "P";
keyNames[NativeDefinitions.KEY_LEFTBRACE] = "[";
keyNames[NativeDefinitions.KEY_RIGHTBRACE] = "]";
keyNames[NativeDefinitions.KEY_ENTER] = "Enter";
keyNames[NativeDefinitions.KEY_LEFTCTRL] = "LH Control";
keyNames[NativeDefinitions.KEY_A] = "A";
keyNames[NativeDefinitions.KEY_S] = "S";
keyNames[NativeDefinitions.KEY_D] = "D";
keyNames[NativeDefinitions.KEY_F] = "F";
keyNames[NativeDefinitions.KEY_G] = "G";
keyNames[NativeDefinitions.KEY_H] = "H";
keyNames[NativeDefinitions.KEY_J] = "J";
keyNames[NativeDefinitions.KEY_K] = "K";
keyNames[NativeDefinitions.KEY_L] = "L";
keyNames[NativeDefinitions.KEY_SEMICOLON] = ";";
keyNames[NativeDefinitions.KEY_APOSTROPHE] = "'";
keyNames[NativeDefinitions.KEY_GRAVE] = "`";
keyNames[NativeDefinitions.KEY_LEFTSHIFT] = "LH Shift";
keyNames[NativeDefinitions.KEY_BACKSLASH] = "\\";
keyNames[NativeDefinitions.KEY_Z] = "Z";
keyNames[NativeDefinitions.KEY_X] = "X";
keyNames[NativeDefinitions.KEY_C] = "C";
keyNames[NativeDefinitions.KEY_V] = "V";
keyNames[NativeDefinitions.KEY_B] = "B";
keyNames[NativeDefinitions.KEY_N] = "N";
keyNames[NativeDefinitions.KEY_M] = "M";
keyNames[NativeDefinitions.KEY_COMMA] = ",";
keyNames[NativeDefinitions.KEY_DOT] = ".";
keyNames[NativeDefinitions.KEY_SLASH] = "/";
keyNames[NativeDefinitions.KEY_RIGHTSHIFT] = "RH Shift";
keyNames[NativeDefinitions.KEY_KPASTERISK] = "*";
keyNames[NativeDefinitions.KEY_LEFTALT] = "LH Alt";
keyNames[NativeDefinitions.KEY_SPACE] = "Space";
keyNames[NativeDefinitions.KEY_CAPSLOCK] = "CapsLock";
keyNames[NativeDefinitions.KEY_F1] = "F1";
keyNames[NativeDefinitions.KEY_F2] = "F2";
keyNames[NativeDefinitions.KEY_F3] = "F3";
keyNames[NativeDefinitions.KEY_F4] = "F4";
keyNames[NativeDefinitions.KEY_F5] = "F5";
keyNames[NativeDefinitions.KEY_F6] = "F6";
keyNames[NativeDefinitions.KEY_F7] = "F7";
keyNames[NativeDefinitions.KEY_F8] = "F8";
keyNames[NativeDefinitions.KEY_F9] = "F9";
keyNames[NativeDefinitions.KEY_F10] = "F10";
keyNames[NativeDefinitions.KEY_NUMLOCK] = "NumLock";
keyNames[NativeDefinitions.KEY_SCROLLLOCK] = "ScrollLock";
keyNames[NativeDefinitions.KEY_KP7] = "KeyPad 7";
keyNames[NativeDefinitions.KEY_KP8] = "KeyPad 8";
keyNames[NativeDefinitions.KEY_KP9] = "Keypad 9";
keyNames[NativeDefinitions.KEY_KPMINUS] = "KeyPad Minus";
keyNames[NativeDefinitions.KEY_KP4] = "KeyPad 4";
keyNames[NativeDefinitions.KEY_KP5] = "KeyPad 5";
keyNames[NativeDefinitions.KEY_KP6] = "KeyPad 6";
keyNames[NativeDefinitions.KEY_KPPLUS] = "KeyPad Plus";
keyNames[NativeDefinitions.KEY_KP1] = "KeyPad 1";
keyNames[NativeDefinitions.KEY_KP2] = "KeyPad 2";
keyNames[NativeDefinitions.KEY_KP3] = "KeyPad 3";
keyNames[NativeDefinitions.KEY_KP0] = "KeyPad 0";
keyNames[NativeDefinitions.KEY_KPDOT] = "KeyPad decimal point";
keyNames[NativeDefinitions.KEY_103RD] = "Huh?";
keyNames[NativeDefinitions.KEY_F13] = "F13";
keyNames[NativeDefinitions.KEY_102ND] = "Beats me...";
keyNames[NativeDefinitions.KEY_F11] = "F11";
keyNames[NativeDefinitions.KEY_F12] = "F12";
keyNames[NativeDefinitions.KEY_F14] = "F14";
keyNames[NativeDefinitions.KEY_F15] = "F15";
keyNames[NativeDefinitions.KEY_F16] = "F16";
keyNames[NativeDefinitions.KEY_F17] = "F17";
keyNames[NativeDefinitions.KEY_F18] = "F18";
keyNames[NativeDefinitions.KEY_F19] = "F19";
keyNames[NativeDefinitions.KEY_F20] = "F20";
keyNames[NativeDefinitions.KEY_KPENTER] = "Keypad Enter";
keyNames[NativeDefinitions.KEY_RIGHTCTRL] = "RH Control";
keyNames[NativeDefinitions.KEY_KPSLASH] = "KeyPad Forward Slash";
keyNames[NativeDefinitions.KEY_SYSRQ] = "System Request";
keyNames[NativeDefinitions.KEY_RIGHTALT] = "RH Alternate";
keyNames[NativeDefinitions.KEY_LINEFEED] = "Line Feed";
keyNames[NativeDefinitions.KEY_HOME] = "Home";
keyNames[NativeDefinitions.KEY_UP] = "Up";
keyNames[NativeDefinitions.KEY_PAGEUP] = "Page Up";
keyNames[NativeDefinitions.KEY_LEFT] = "Left";
keyNames[NativeDefinitions.KEY_RIGHT] = "Right";
keyNames[NativeDefinitions.KEY_END] = "End";
keyNames[NativeDefinitions.KEY_DOWN] = "Down";
keyNames[NativeDefinitions.KEY_PAGEDOWN] = "Page Down";
keyNames[NativeDefinitions.KEY_INSERT] = "Insert";
keyNames[NativeDefinitions.KEY_DELETE] = "Delete";
keyNames[NativeDefinitions.KEY_MACRO] = "Macro";
keyNames[NativeDefinitions.KEY_MUTE] = "Mute";
keyNames[NativeDefinitions.KEY_VOLUMEDOWN] = "Volume Down";
keyNames[NativeDefinitions.KEY_VOLUMEUP] = "Volume Up";
keyNames[NativeDefinitions.KEY_POWER] = "Power";
keyNames[NativeDefinitions.KEY_KPEQUAL] = "KeyPad Equal";
keyNames[NativeDefinitions.KEY_KPPLUSMINUS] = "KeyPad +/-";
keyNames[NativeDefinitions.KEY_PAUSE] = "Pause";
keyNames[NativeDefinitions.KEY_F21] = "F21";
keyNames[NativeDefinitions.KEY_F22] = "F22";
keyNames[NativeDefinitions.KEY_F23] = "F23";
keyNames[NativeDefinitions.KEY_F24] = "F24";
keyNames[NativeDefinitions.KEY_KPCOMMA] = "KeyPad comma";
keyNames[NativeDefinitions.KEY_LEFTMETA] = "LH Meta";
keyNames[NativeDefinitions.KEY_RIGHTMETA] = "RH Meta";
keyNames[NativeDefinitions.KEY_COMPOSE] = "Compose";
keyNames[NativeDefinitions.KEY_STOP] = "Stop";
keyNames[NativeDefinitions.KEY_AGAIN] = "Again";
keyNames[NativeDefinitions.KEY_PROPS] = "Properties";
keyNames[NativeDefinitions.KEY_UNDO] = "Undo";
keyNames[NativeDefinitions.KEY_FRONT] = "Front";
keyNames[NativeDefinitions.KEY_COPY] = "Copy";
keyNames[NativeDefinitions.KEY_OPEN] = "Open";
keyNames[NativeDefinitions.KEY_PASTE] = "Paste";
keyNames[NativeDefinitions.KEY_FIND] = "Find";
keyNames[NativeDefinitions.KEY_CUT] = "Cut";
keyNames[NativeDefinitions.KEY_HELP] = "Help";
keyNames[NativeDefinitions.KEY_MENU] = "Menu";
keyNames[NativeDefinitions.KEY_CALC] = "Calculator";
keyNames[NativeDefinitions.KEY_SETUP] = "Setup";
keyNames[NativeDefinitions.KEY_SLEEP] = "Sleep";
keyNames[NativeDefinitions.KEY_WAKEUP] = "Wakeup";
keyNames[NativeDefinitions.KEY_FILE] = "File";
keyNames[NativeDefinitions.KEY_SENDFILE] = "Send File";
keyNames[NativeDefinitions.KEY_DELETEFILE] = "Delete File";
keyNames[NativeDefinitions.KEY_XFER] = "Transfer";
keyNames[NativeDefinitions.KEY_PROG1] = "Program 1";
keyNames[NativeDefinitions.KEY_PROG2] = "Program 2";
keyNames[NativeDefinitions.KEY_WWW] = "Web Browser";
keyNames[NativeDefinitions.KEY_MSDOS] = "DOS mode";
keyNames[NativeDefinitions.KEY_COFFEE] = "Coffee";
keyNames[NativeDefinitions.KEY_DIRECTION] = "Direction";
keyNames[NativeDefinitions.KEY_CYCLEWINDOWS] = "Window cycle";
keyNames[NativeDefinitions.KEY_MAIL] = "Mail";
keyNames[NativeDefinitions.KEY_BOOKMARKS] = "Book Marks";
keyNames[NativeDefinitions.KEY_COMPUTER] = "Computer";
keyNames[NativeDefinitions.KEY_BACK] = "Back";
keyNames[NativeDefinitions.KEY_FORWARD] = "Forward";
keyNames[NativeDefinitions.KEY_CLOSECD] = "Close CD";
keyNames[NativeDefinitions.KEY_EJECTCD] = "Eject CD";
keyNames[NativeDefinitions.KEY_EJECTCLOSECD] = "Eject / Close CD";
keyNames[NativeDefinitions.KEY_NEXTSONG] = "Next Song";
keyNames[NativeDefinitions.KEY_PLAYPAUSE] = "Play and Pause";
keyNames[NativeDefinitions.KEY_PREVIOUSSONG] = "Previous Song";
keyNames[NativeDefinitions.KEY_STOPCD] = "Stop CD";
keyNames[NativeDefinitions.KEY_RECORD] = "Record";
keyNames[NativeDefinitions.KEY_REWIND] = "Rewind";
keyNames[NativeDefinitions.KEY_PHONE] = "Phone";
keyNames[NativeDefinitions.KEY_ISO] = "ISO";
keyNames[NativeDefinitions.KEY_CONFIG] = "Config";
keyNames[NativeDefinitions.KEY_HOMEPAGE] = "Home";
keyNames[NativeDefinitions.KEY_REFRESH] = "Refresh";
keyNames[NativeDefinitions.KEY_EXIT] = "Exit";
keyNames[NativeDefinitions.KEY_MOVE] = "Move";
keyNames[NativeDefinitions.KEY_EDIT] = "Edit";
keyNames[NativeDefinitions.KEY_SCROLLUP] = "Scroll Up";
keyNames[NativeDefinitions.KEY_SCROLLDOWN] = "Scroll Down";
keyNames[NativeDefinitions.KEY_KPLEFTPAREN] = "KeyPad LH parenthesis";
keyNames[NativeDefinitions.KEY_KPRIGHTPAREN] = "KeyPad RH parenthesis";
keyNames[NativeDefinitions.KEY_INTL1] = "Intl 1";
keyNames[NativeDefinitions.KEY_INTL2] = "Intl 2";
keyNames[NativeDefinitions.KEY_INTL3] = "Intl 3";
keyNames[NativeDefinitions.KEY_INTL4] = "Intl 4";
keyNames[NativeDefinitions.KEY_INTL5] = "Intl 5";
keyNames[NativeDefinitions.KEY_INTL6] = "Intl 6";
keyNames[NativeDefinitions.KEY_INTL7] = "Intl 7";
keyNames[NativeDefinitions.KEY_INTL8] = "Intl 8";
keyNames[NativeDefinitions.KEY_INTL9] = "Intl 9";
keyNames[NativeDefinitions.KEY_LANG1] = "Language 1";
keyNames[NativeDefinitions.KEY_LANG2] = "Language 2";
keyNames[NativeDefinitions.KEY_LANG3] = "Language 3";
keyNames[NativeDefinitions.KEY_LANG4] = "Language 4";
keyNames[NativeDefinitions.KEY_LANG5] = "Language 5";
keyNames[NativeDefinitions.KEY_LANG6] = "Language 6";
keyNames[NativeDefinitions.KEY_LANG7] = "Language 7";
keyNames[NativeDefinitions.KEY_LANG8] = "Language 8";
keyNames[NativeDefinitions.KEY_LANG9] = "Language 9";
keyNames[NativeDefinitions.KEY_PLAYCD] = "Play CD";
keyNames[NativeDefinitions.KEY_PAUSECD] = "Pause CD";
keyNames[NativeDefinitions.KEY_PROG3] = "Program 3";
keyNames[NativeDefinitions.KEY_PROG4] = "Program 4";
keyNames[NativeDefinitions.KEY_SUSPEND] = "Suspend";
keyNames[NativeDefinitions.KEY_CLOSE] = "Close";
keyNames[NativeDefinitions.KEY_UNKNOWN] = "Specifically unknown";
keyNames[NativeDefinitions.KEY_BRIGHTNESSDOWN] = "Brightness Down";
keyNames[NativeDefinitions.KEY_BRIGHTNESSUP] = "Brightness Up";
keyNames[NativeDefinitions.BTN_0] = "Button 0";
keyNames[NativeDefinitions.BTN_1] = "Button 1";
keyNames[NativeDefinitions.BTN_2] = "Button 2";
keyNames[NativeDefinitions.BTN_3] = "Button 3";
keyNames[NativeDefinitions.BTN_4] = "Button 4";
keyNames[NativeDefinitions.BTN_5] = "Button 5";
keyNames[NativeDefinitions.BTN_6] = "Button 6";
keyNames[NativeDefinitions.BTN_7] = "Button 7";
keyNames[NativeDefinitions.BTN_8] = "Button 8";
keyNames[NativeDefinitions.BTN_9] = "Button 9";
keyNames[NativeDefinitions.BTN_LEFT] = "Left Button";
keyNames[NativeDefinitions.BTN_RIGHT] = "Right Button";
keyNames[NativeDefinitions.BTN_MIDDLE] = "Middle Button";
keyNames[NativeDefinitions.BTN_SIDE] = "Side Button";
keyNames[NativeDefinitions.BTN_EXTRA] = "Extra Button";
keyNames[NativeDefinitions.BTN_FORWARD] = "Forward Button";
keyNames[NativeDefinitions.BTN_BACK] = "Back Button";
keyNames[NativeDefinitions.BTN_TRIGGER] = "Trigger Button";
keyNames[NativeDefinitions.BTN_THUMB] = "Thumb Button";
keyNames[NativeDefinitions.BTN_THUMB2] = "Second Thumb Button";
keyNames[NativeDefinitions.BTN_TOP] = "Top Button";
keyNames[NativeDefinitions.BTN_TOP2] = "Second Top Button";
keyNames[NativeDefinitions.BTN_PINKIE] = "Pinkie Button";
keyNames[NativeDefinitions.BTN_BASE] = "Base Button";
keyNames[NativeDefinitions.BTN_BASE2] = "Second Base Button";
keyNames[NativeDefinitions.BTN_BASE3] = "Third Base Button";
keyNames[NativeDefinitions.BTN_BASE4] = "Fourth Base Button";
keyNames[NativeDefinitions.BTN_BASE5] = "Fifth Base Button";
keyNames[NativeDefinitions.BTN_BASE6] = "Sixth Base Button";
keyNames[NativeDefinitions.BTN_DEAD] = "Dead Button";
keyNames[NativeDefinitions.BTN_A] = "Button A";
keyNames[NativeDefinitions.BTN_B] = "Button B";
keyNames[NativeDefinitions.BTN_C] = "Button C";
keyNames[NativeDefinitions.BTN_X] = "Button X";
keyNames[NativeDefinitions.BTN_Y] = "Button Y";
keyNames[NativeDefinitions.BTN_Z] = "Button Z";
keyNames[NativeDefinitions.BTN_TL] = "Thumb Left Button";
keyNames[NativeDefinitions.BTN_TR] = "Thumb Right Button ";
keyNames[NativeDefinitions.BTN_TL2] = "Second Thumb Left Button";
keyNames[NativeDefinitions.BTN_TR2] = "Second Thumb Right Button ";
keyNames[NativeDefinitions.BTN_SELECT] = "Select Button";
keyNames[NativeDefinitions.BTN_MODE] = "Mode Button";
keyNames[NativeDefinitions.BTN_THUMBL] = "Another Left Thumb Button ";
keyNames[NativeDefinitions.BTN_THUMBR] = "Another Right Thumb Button ";
keyNames[NativeDefinitions.BTN_TOOL_PEN] = "Digitiser Pen Tool";
keyNames[NativeDefinitions.BTN_TOOL_RUBBER] = "Digitiser Rubber Tool";
keyNames[NativeDefinitions.BTN_TOOL_BRUSH] = "Digitiser Brush Tool";
keyNames[NativeDefinitions.BTN_TOOL_PENCIL] = "Digitiser Pencil Tool";
keyNames[NativeDefinitions.BTN_TOOL_AIRBRUSH] = "Digitiser Airbrush Tool";
keyNames[NativeDefinitions.BTN_TOOL_FINGER] = "Digitiser Finger Tool";
keyNames[NativeDefinitions.BTN_TOOL_MOUSE] = "Digitiser Mouse Tool";
keyNames[NativeDefinitions.BTN_TOOL_LENS] = "Digitiser Lens Tool";
keyNames[NativeDefinitions.BTN_TOUCH] = "Digitiser Touch Button ";
keyNames[NativeDefinitions.BTN_STYLUS] = "Digitiser Stylus Button ";
keyNames[NativeDefinitions.BTN_STYLUS2] = "Second Digitiser Stylus Button ";
buttonIDs = new Component.Identifier[NativeDefinitions.KEY_MAX];
buttonIDs[NativeDefinitions.KEY_ESC] = Component.Identifier.Key.ESCAPE;
buttonIDs[NativeDefinitions.KEY_1] = Component.Identifier.Key._1;
buttonIDs[NativeDefinitions.KEY_2] = Component.Identifier.Key._2;
@ -422,7 +132,7 @@ public class LinuxNativeTypesMap {
buttonIDs[NativeDefinitions.KEY_KP3] = Component.Identifier.Key.NUMPAD3;
buttonIDs[NativeDefinitions.KEY_KP0] = Component.Identifier.Key.NUMPAD0;
buttonIDs[NativeDefinitions.KEY_KPDOT] = Component.Identifier.Key.DECIMAL;
buttonIDs[NativeDefinitions.KEY_103RD] = null;
// buttonIDs[NativeDefinitions.KEY_103RD] = null;
buttonIDs[NativeDefinitions.KEY_F13] = Component.Identifier.Key.F13;
buttonIDs[NativeDefinitions.KEY_102ND] = null;
buttonIDs[NativeDefinitions.KEY_F11] = Component.Identifier.Key.F11;
@ -547,7 +257,7 @@ public class LinuxNativeTypesMap {
/*buttonIDs[NativeDefinitions.KEY_BRIGHTNESSDOWN] = "Brightness Down";
buttonIDs[NativeDefinitions.KEY_BRIGHTNESSUP] = "Brightness Up";*/
//Msic keys
//Misc keys
buttonIDs[NativeDefinitions.BTN_0] = Component.Identifier.Button._0;
buttonIDs[NativeDefinitions.BTN_1] = Component.Identifier.Button._1;
buttonIDs[NativeDefinitions.BTN_2] = Component.Identifier.Button._2;
@ -612,53 +322,15 @@ public class LinuxNativeTypesMap {
buttonIDs[NativeDefinitions.BTN_STYLUS] = Component.Identifier.Button.STYLUS;
buttonIDs[NativeDefinitions.BTN_STYLUS2] = Component.Identifier.Button.STYLUS2;
relAxesNames = new String[NativeDefinitions.REL_MAX];
relAxesNames[NativeDefinitions.REL_X] = "X axis";
relAxesNames[NativeDefinitions.REL_Y] = "Y axis";
relAxesNames[NativeDefinitions.REL_Z] = "Z axis";
relAxesNames[NativeDefinitions.REL_HWHEEL] ="Horizontal wheel";
relAxesNames[NativeDefinitions.REL_DIAL] = "Dial";
relAxesNames[NativeDefinitions.REL_WHEEL] = "Vertical wheel";
relAxesNames[NativeDefinitions.REL_MISC] = "Miscellaneous";
relAxesIDs = new Component.Identifier[NativeDefinitions.REL_MAX];
relAxesIDs[NativeDefinitions.REL_X] = Component.Identifier.Axis.X;
relAxesIDs[NativeDefinitions.REL_Y] = Component.Identifier.Axis.Y;
relAxesIDs[NativeDefinitions.REL_Z] = Component.Identifier.Axis.Z;
relAxesIDs[NativeDefinitions.REL_WHEEL] = Component.Identifier.Axis.SLIDER;
relAxesIDs[NativeDefinitions.REL_WHEEL] = Component.Identifier.Axis.Z;
// There are guesses as I have no idea what they would be used for
relAxesIDs[NativeDefinitions.REL_HWHEEL] = Component.Identifier.Axis.SLIDER;
relAxesIDs[NativeDefinitions.REL_DIAL] = Component.Identifier.Axis.SLIDER;
relAxesIDs[NativeDefinitions.REL_MISC] = Component.Identifier.Axis.SLIDER;
absAxesNames = new String[NativeDefinitions.ABS_MAX];
absAxesNames[NativeDefinitions.ABS_X] = "X axis";
absAxesNames[NativeDefinitions.ABS_Y] = "Y axis";
absAxesNames[NativeDefinitions.ABS_Z] = "Z axis";
absAxesNames[NativeDefinitions.ABS_RX] = "X rate axis";
absAxesNames[NativeDefinitions.ABS_RY] = "Y rate axis";
absAxesNames[NativeDefinitions.ABS_RZ] = "Z rate axis";
absAxesNames[NativeDefinitions.ABS_THROTTLE] = "Throttle";
absAxesNames[NativeDefinitions.ABS_RUDDER] = "Rudder";
absAxesNames[NativeDefinitions.ABS_WHEEL] = "Wheel";
absAxesNames[NativeDefinitions.ABS_GAS] = "Accelerator";
absAxesNames[NativeDefinitions.ABS_BRAKE] = "Brake";
// Hats are done this way as they are mapped from two axis down to one
absAxesNames[NativeDefinitions.ABS_HAT0X] = "Hat 1";
absAxesNames[NativeDefinitions.ABS_HAT0Y] = "Hat 1";
absAxesNames[NativeDefinitions.ABS_HAT1X] = "Hat 2";
absAxesNames[NativeDefinitions.ABS_HAT1Y] = "Hat 2";
absAxesNames[NativeDefinitions.ABS_HAT2X] = "Hat 3";
absAxesNames[NativeDefinitions.ABS_HAT2Y] = "Hat 3";
absAxesNames[NativeDefinitions.ABS_HAT3X] = "Hat 4";
absAxesNames[NativeDefinitions.ABS_HAT3Y] = "Hat 4";
absAxesNames[NativeDefinitions.ABS_PRESSURE] = "Pressure";
absAxesNames[NativeDefinitions.ABS_DISTANCE] = "Distance";
absAxesNames[NativeDefinitions.ABS_TILT_X] = "X axis tilt";
absAxesNames[NativeDefinitions.ABS_TILT_Y] = "Y axis tilt";
absAxesNames[NativeDefinitions.ABS_MISC] = "Miscellaneous";
absAxesIDs = new Component.Identifier[NativeDefinitions.ABS_MAX];
absAxesIDs[NativeDefinitions.ABS_X] = Component.Identifier.Axis.X;
absAxesIDs[NativeDefinitions.ABS_Y] = Component.Identifier.Axis.Y;
absAxesIDs[NativeDefinitions.ABS_Z] = Component.Identifier.Axis.Z;
@ -685,9 +357,373 @@ public class LinuxNativeTypesMap {
absAxesIDs[NativeDefinitions.ABS_TILT_X] = null;
absAxesIDs[NativeDefinitions.ABS_TILT_Y] = null;
absAxesIDs[NativeDefinitions.ABS_MISC] = null;
}
public final static Controller.Type guessButtonTrait(int button_code) {
switch (button_code) {
case NativeDefinitions.BTN_TRIGGER :
case NativeDefinitions.BTN_THUMB :
case NativeDefinitions.BTN_THUMB2 :
case NativeDefinitions.BTN_TOP :
case NativeDefinitions.BTN_TOP2 :
case NativeDefinitions.BTN_PINKIE :
case NativeDefinitions.BTN_BASE :
case NativeDefinitions.BTN_BASE2 :
case NativeDefinitions.BTN_BASE3 :
case NativeDefinitions.BTN_BASE4 :
case NativeDefinitions.BTN_BASE5 :
case NativeDefinitions.BTN_BASE6 :
case NativeDefinitions.BTN_DEAD :
return Controller.Type.STICK;
case NativeDefinitions.BTN_A :
case NativeDefinitions.BTN_B :
case NativeDefinitions.BTN_C :
case NativeDefinitions.BTN_X :
case NativeDefinitions.BTN_Y :
case NativeDefinitions.BTN_Z :
case NativeDefinitions.BTN_TL :
case NativeDefinitions.BTN_TR :
case NativeDefinitions.BTN_TL2 :
case NativeDefinitions.BTN_TR2 :
case NativeDefinitions.BTN_SELECT :
case NativeDefinitions.BTN_MODE :
case NativeDefinitions.BTN_THUMBL :
case NativeDefinitions.BTN_THUMBR :
return Controller.Type.GAMEPAD;
case NativeDefinitions.BTN_0 :
case NativeDefinitions.BTN_1 :
case NativeDefinitions.BTN_2 :
case NativeDefinitions.BTN_3 :
case NativeDefinitions.BTN_4 :
case NativeDefinitions.BTN_5 :
case NativeDefinitions.BTN_6 :
case NativeDefinitions.BTN_7 :
case NativeDefinitions.BTN_8 :
case NativeDefinitions.BTN_9 :
return Controller.Type.UNKNOWN;
case NativeDefinitions.BTN_LEFT :
case NativeDefinitions.BTN_RIGHT :
case NativeDefinitions.BTN_MIDDLE :
case NativeDefinitions.BTN_SIDE :
case NativeDefinitions.BTN_EXTRA :
return Controller.Type.MOUSE;
// case NativeDefinitions.KEY_RESERVED:
case NativeDefinitions.KEY_ESC:
case NativeDefinitions.KEY_1:
case NativeDefinitions.KEY_2:
case NativeDefinitions.KEY_3:
case NativeDefinitions.KEY_4:
case NativeDefinitions.KEY_5:
case NativeDefinitions.KEY_6:
case NativeDefinitions.KEY_7:
case NativeDefinitions.KEY_8:
case NativeDefinitions.KEY_9:
case NativeDefinitions.KEY_0:
case NativeDefinitions.KEY_MINUS:
case NativeDefinitions.KEY_EQUAL:
case NativeDefinitions.KEY_BACKSPACE:
case NativeDefinitions.KEY_TAB:
case NativeDefinitions.KEY_Q:
case NativeDefinitions.KEY_W:
case NativeDefinitions.KEY_E:
case NativeDefinitions.KEY_R:
case NativeDefinitions.KEY_T:
case NativeDefinitions.KEY_Y:
case NativeDefinitions.KEY_U:
case NativeDefinitions.KEY_I:
case NativeDefinitions.KEY_O:
case NativeDefinitions.KEY_P:
case NativeDefinitions.KEY_LEFTBRACE:
case NativeDefinitions.KEY_RIGHTBRACE:
case NativeDefinitions.KEY_ENTER:
case NativeDefinitions.KEY_LEFTCTRL:
case NativeDefinitions.KEY_A:
case NativeDefinitions.KEY_S:
case NativeDefinitions.KEY_D:
case NativeDefinitions.KEY_F:
case NativeDefinitions.KEY_G:
case NativeDefinitions.KEY_H:
case NativeDefinitions.KEY_J:
case NativeDefinitions.KEY_K:
case NativeDefinitions.KEY_L:
case NativeDefinitions.KEY_SEMICOLON:
case NativeDefinitions.KEY_APOSTROPHE:
case NativeDefinitions.KEY_GRAVE:
case NativeDefinitions.KEY_LEFTSHIFT:
case NativeDefinitions.KEY_BACKSLASH:
case NativeDefinitions.KEY_Z:
case NativeDefinitions.KEY_X:
case NativeDefinitions.KEY_C:
case NativeDefinitions.KEY_V:
case NativeDefinitions.KEY_B:
case NativeDefinitions.KEY_N:
case NativeDefinitions.KEY_M:
case NativeDefinitions.KEY_COMMA:
case NativeDefinitions.KEY_DOT:
case NativeDefinitions.KEY_SLASH:
case NativeDefinitions.KEY_RIGHTSHIFT:
case NativeDefinitions.KEY_KPASTERISK:
case NativeDefinitions.KEY_LEFTALT:
case NativeDefinitions.KEY_SPACE:
case NativeDefinitions.KEY_CAPSLOCK:
case NativeDefinitions.KEY_F1:
case NativeDefinitions.KEY_F2:
case NativeDefinitions.KEY_F3:
case NativeDefinitions.KEY_F4:
case NativeDefinitions.KEY_F5:
case NativeDefinitions.KEY_F6:
case NativeDefinitions.KEY_F7:
case NativeDefinitions.KEY_F8:
case NativeDefinitions.KEY_F9:
case NativeDefinitions.KEY_F10:
case NativeDefinitions.KEY_NUMLOCK:
case NativeDefinitions.KEY_SCROLLLOCK:
case NativeDefinitions.KEY_KP7:
case NativeDefinitions.KEY_KP8:
case NativeDefinitions.KEY_KP9:
case NativeDefinitions.KEY_KPMINUS:
case NativeDefinitions.KEY_KP4:
case NativeDefinitions.KEY_KP5:
case NativeDefinitions.KEY_KP6:
case NativeDefinitions.KEY_KPPLUS:
case NativeDefinitions.KEY_KP1:
case NativeDefinitions.KEY_KP2:
case NativeDefinitions.KEY_KP3:
case NativeDefinitions.KEY_KP0:
case NativeDefinitions.KEY_KPDOT:
case NativeDefinitions.KEY_ZENKAKUHANKAKU:
case NativeDefinitions.KEY_102ND:
case NativeDefinitions.KEY_F11:
case NativeDefinitions.KEY_F12:
case NativeDefinitions.KEY_RO:
case NativeDefinitions.KEY_KATAKANA:
case NativeDefinitions.KEY_HIRAGANA:
case NativeDefinitions.KEY_HENKAN:
case NativeDefinitions.KEY_KATAKANAHIRAGANA:
case NativeDefinitions.KEY_MUHENKAN:
case NativeDefinitions.KEY_KPJPCOMMA:
case NativeDefinitions.KEY_KPENTER:
case NativeDefinitions.KEY_RIGHTCTRL:
case NativeDefinitions.KEY_KPSLASH:
case NativeDefinitions.KEY_SYSRQ:
case NativeDefinitions.KEY_RIGHTALT:
case NativeDefinitions.KEY_LINEFEED:
case NativeDefinitions.KEY_HOME:
case NativeDefinitions.KEY_UP:
case NativeDefinitions.KEY_PAGEUP:
case NativeDefinitions.KEY_LEFT:
case NativeDefinitions.KEY_RIGHT:
case NativeDefinitions.KEY_END:
case NativeDefinitions.KEY_DOWN:
case NativeDefinitions.KEY_PAGEDOWN:
case NativeDefinitions.KEY_INSERT:
case NativeDefinitions.KEY_DELETE:
case NativeDefinitions.KEY_MACRO:
case NativeDefinitions.KEY_MUTE:
case NativeDefinitions.KEY_VOLUMEDOWN:
case NativeDefinitions.KEY_VOLUMEUP:
case NativeDefinitions.KEY_POWER:
case NativeDefinitions.KEY_KPEQUAL:
case NativeDefinitions.KEY_KPPLUSMINUS:
case NativeDefinitions.KEY_PAUSE:
case NativeDefinitions.KEY_KPCOMMA:
case NativeDefinitions.KEY_HANGUEL:
case NativeDefinitions.KEY_HANJA:
case NativeDefinitions.KEY_YEN:
case NativeDefinitions.KEY_LEFTMETA:
case NativeDefinitions.KEY_RIGHTMETA:
case NativeDefinitions.KEY_COMPOSE:
case NativeDefinitions.KEY_STOP:
case NativeDefinitions.KEY_AGAIN:
case NativeDefinitions.KEY_PROPS:
case NativeDefinitions.KEY_UNDO:
case NativeDefinitions.KEY_FRONT:
case NativeDefinitions.KEY_COPY:
case NativeDefinitions.KEY_OPEN:
case NativeDefinitions.KEY_PASTE:
case NativeDefinitions.KEY_FIND:
case NativeDefinitions.KEY_CUT:
case NativeDefinitions.KEY_HELP:
case NativeDefinitions.KEY_MENU:
case NativeDefinitions.KEY_CALC:
case NativeDefinitions.KEY_SETUP:
case NativeDefinitions.KEY_SLEEP:
case NativeDefinitions.KEY_WAKEUP:
case NativeDefinitions.KEY_FILE:
case NativeDefinitions.KEY_SENDFILE:
case NativeDefinitions.KEY_DELETEFILE:
case NativeDefinitions.KEY_XFER:
case NativeDefinitions.KEY_PROG1:
case NativeDefinitions.KEY_PROG2:
case NativeDefinitions.KEY_WWW:
case NativeDefinitions.KEY_MSDOS:
case NativeDefinitions.KEY_COFFEE:
case NativeDefinitions.KEY_DIRECTION:
case NativeDefinitions.KEY_CYCLEWINDOWS:
case NativeDefinitions.KEY_MAIL:
case NativeDefinitions.KEY_BOOKMARKS:
case NativeDefinitions.KEY_COMPUTER:
case NativeDefinitions.KEY_BACK:
case NativeDefinitions.KEY_FORWARD:
case NativeDefinitions.KEY_CLOSECD:
case NativeDefinitions.KEY_EJECTCD:
case NativeDefinitions.KEY_EJECTCLOSECD:
case NativeDefinitions.KEY_NEXTSONG:
case NativeDefinitions.KEY_PLAYPAUSE:
case NativeDefinitions.KEY_PREVIOUSSONG:
case NativeDefinitions.KEY_STOPCD:
case NativeDefinitions.KEY_RECORD:
case NativeDefinitions.KEY_REWIND:
case NativeDefinitions.KEY_PHONE:
case NativeDefinitions.KEY_ISO:
case NativeDefinitions.KEY_CONFIG:
case NativeDefinitions.KEY_HOMEPAGE:
case NativeDefinitions.KEY_REFRESH:
case NativeDefinitions.KEY_EXIT:
case NativeDefinitions.KEY_MOVE:
case NativeDefinitions.KEY_EDIT:
case NativeDefinitions.KEY_SCROLLUP:
case NativeDefinitions.KEY_SCROLLDOWN:
case NativeDefinitions.KEY_KPLEFTPAREN:
case NativeDefinitions.KEY_KPRIGHTPAREN:
case NativeDefinitions.KEY_F13:
case NativeDefinitions.KEY_F14:
case NativeDefinitions.KEY_F15:
case NativeDefinitions.KEY_F16:
case NativeDefinitions.KEY_F17:
case NativeDefinitions.KEY_F18:
case NativeDefinitions.KEY_F19:
case NativeDefinitions.KEY_F20:
case NativeDefinitions.KEY_F21:
case NativeDefinitions.KEY_F22:
case NativeDefinitions.KEY_F23:
case NativeDefinitions.KEY_F24:
case NativeDefinitions.KEY_PLAYCD:
case NativeDefinitions.KEY_PAUSECD:
case NativeDefinitions.KEY_PROG3:
case NativeDefinitions.KEY_PROG4:
case NativeDefinitions.KEY_SUSPEND:
case NativeDefinitions.KEY_CLOSE:
case NativeDefinitions.KEY_PLAY:
case NativeDefinitions.KEY_FASTFORWARD:
case NativeDefinitions.KEY_BASSBOOST:
case NativeDefinitions.KEY_PRINT:
case NativeDefinitions.KEY_HP:
case NativeDefinitions.KEY_CAMERA:
case NativeDefinitions.KEY_SOUND:
case NativeDefinitions.KEY_QUESTION:
case NativeDefinitions.KEY_EMAIL:
case NativeDefinitions.KEY_CHAT:
case NativeDefinitions.KEY_SEARCH:
case NativeDefinitions.KEY_CONNECT:
case NativeDefinitions.KEY_FINANCE:
case NativeDefinitions.KEY_SPORT:
case NativeDefinitions.KEY_SHOP:
case NativeDefinitions.KEY_ALTERASE:
case NativeDefinitions.KEY_CANCEL:
case NativeDefinitions.KEY_BRIGHTNESSDOWN:
case NativeDefinitions.KEY_BRIGHTNESSUP:
case NativeDefinitions.KEY_MEDIA:
case NativeDefinitions.KEY_SWITCHVIDEOMODE:
case NativeDefinitions.KEY_KBDILLUMTOGGLE:
case NativeDefinitions.KEY_KBDILLUMDOWN:
case NativeDefinitions.KEY_KBDILLUMUP:
// case NativeDefinitions.KEY_UNKNOWN:
case NativeDefinitions.KEY_OK:
case NativeDefinitions.KEY_SELECT:
case NativeDefinitions.KEY_GOTO:
case NativeDefinitions.KEY_CLEAR:
case NativeDefinitions.KEY_POWER2:
case NativeDefinitions.KEY_OPTION:
case NativeDefinitions.KEY_INFO:
case NativeDefinitions.KEY_TIME:
case NativeDefinitions.KEY_VENDOR:
case NativeDefinitions.KEY_ARCHIVE:
case NativeDefinitions.KEY_PROGRAM:
case NativeDefinitions.KEY_CHANNEL:
case NativeDefinitions.KEY_FAVORITES:
case NativeDefinitions.KEY_EPG:
case NativeDefinitions.KEY_PVR:
case NativeDefinitions.KEY_MHP:
case NativeDefinitions.KEY_LANGUAGE:
case NativeDefinitions.KEY_TITLE:
case NativeDefinitions.KEY_SUBTITLE:
case NativeDefinitions.KEY_ANGLE:
case NativeDefinitions.KEY_ZOOM:
case NativeDefinitions.KEY_MODE:
case NativeDefinitions.KEY_KEYBOARD:
case NativeDefinitions.KEY_SCREEN:
case NativeDefinitions.KEY_PC:
case NativeDefinitions.KEY_TV:
case NativeDefinitions.KEY_TV2:
case NativeDefinitions.KEY_VCR:
case NativeDefinitions.KEY_VCR2:
case NativeDefinitions.KEY_SAT:
case NativeDefinitions.KEY_SAT2:
case NativeDefinitions.KEY_CD:
case NativeDefinitions.KEY_TAPE:
case NativeDefinitions.KEY_RADIO:
case NativeDefinitions.KEY_TUNER:
case NativeDefinitions.KEY_PLAYER:
case NativeDefinitions.KEY_TEXT:
case NativeDefinitions.KEY_DVD:
case NativeDefinitions.KEY_AUX:
case NativeDefinitions.KEY_MP3:
case NativeDefinitions.KEY_AUDIO:
case NativeDefinitions.KEY_VIDEO:
case NativeDefinitions.KEY_DIRECTORY:
case NativeDefinitions.KEY_LIST:
case NativeDefinitions.KEY_MEMO:
case NativeDefinitions.KEY_CALENDAR:
case NativeDefinitions.KEY_RED:
case NativeDefinitions.KEY_GREEN:
case NativeDefinitions.KEY_YELLOW:
case NativeDefinitions.KEY_BLUE:
case NativeDefinitions.KEY_CHANNELUP:
case NativeDefinitions.KEY_CHANNELDOWN:
case NativeDefinitions.KEY_FIRST:
case NativeDefinitions.KEY_LAST:
case NativeDefinitions.KEY_AB:
case NativeDefinitions.KEY_NEXT:
case NativeDefinitions.KEY_RESTART:
case NativeDefinitions.KEY_SLOW:
case NativeDefinitions.KEY_SHUFFLE:
case NativeDefinitions.KEY_BREAK:
case NativeDefinitions.KEY_PREVIOUS:
case NativeDefinitions.KEY_DIGITS:
case NativeDefinitions.KEY_TEEN:
case NativeDefinitions.KEY_TWEN:
case NativeDefinitions.KEY_DEL_EOL:
case NativeDefinitions.KEY_DEL_EOS:
case NativeDefinitions.KEY_INS_LINE:
case NativeDefinitions.KEY_DEL_LINE:
case NativeDefinitions.KEY_FN:
case NativeDefinitions.KEY_FN_ESC:
case NativeDefinitions.KEY_FN_F1:
case NativeDefinitions.KEY_FN_F2:
case NativeDefinitions.KEY_FN_F3:
case NativeDefinitions.KEY_FN_F4:
case NativeDefinitions.KEY_FN_F5:
case NativeDefinitions.KEY_FN_F6:
case NativeDefinitions.KEY_FN_F7:
case NativeDefinitions.KEY_FN_F8:
case NativeDefinitions.KEY_FN_F9:
case NativeDefinitions.KEY_FN_F10:
case NativeDefinitions.KEY_FN_F11:
case NativeDefinitions.KEY_FN_F12:
case NativeDefinitions.KEY_FN_1:
case NativeDefinitions.KEY_FN_2:
case NativeDefinitions.KEY_FN_D:
case NativeDefinitions.KEY_FN_E:
case NativeDefinitions.KEY_FN_F:
case NativeDefinitions.KEY_FN_S:
case NativeDefinitions.KEY_FN_B:
return Controller.Type.KEYBOARD;
default:
return Controller.Type.UNKNOWN;
}
}
/** Return port type from a native port type int id
* @param nativeid The native port type
* @return The jinput port type
@ -710,45 +746,6 @@ public class LinuxNativeTypesMap {
}
}
/** Returns the name of a native button
* @param nativeID The native button type id
* @return The button name
*/
public static String getButtonName(int nativeID) {
String retval = INSTANCE.keyNames[nativeID];
//if(retval == null){
// retval = "Unknown button id";
// INSTANCE.keyNames[nativeID] = retval;
//}
return retval;
}
/** Retursn the name of the native relative axis
* @param nativeID The axis type ID
* @return The axis name
*/
public static String getRelAxisName(int nativeID) {
String retval = INSTANCE.relAxesNames[nativeID];
if(retval == null) {
retval = "Unknown relative axis id";
INSTANCE.relAxesNames[nativeID] = retval;
}
return retval;
}
/** Retursn the name of the native absolute axis
* @param nativeID The native axis type ID
* @return The name of the axis
*/
public static String getAbsAxisName(int nativeID) {
String retval = INSTANCE.absAxesNames[nativeID];
if(retval == null) {
retval = "Unknown absolute axis id " + nativeID;
INSTANCE.absAxesNames[nativeID] = retval;
}
return retval;
}
/** Gets the identifier for a relative axis
* @param nativeID The axis type ID
* @return The jinput id
@ -793,5 +790,4 @@ public class LinuxNativeTypesMap {
}
return retval;
}
}

View file

@ -0,0 +1,95 @@
/*
* %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.io.IOException;
/** Represents a linux button
* @author elias
* @version 1.0
*/
final class LinuxPOV extends LinuxComponent {
private final LinuxEventComponent component_x;
private final LinuxEventComponent component_y;
private float last_x;
private float last_y;
public LinuxPOV(LinuxEventComponent component_x, LinuxEventComponent component_y) {
super(component_x);
this.component_x = component_x;
this.component_y = component_y;
}
protected final float poll() throws IOException {
last_x = LinuxControllers.poll(component_x);
last_y = LinuxControllers.poll(component_y);
return convertValue(0f, null);
}
public float convertValue(float value, LinuxAxisDescriptor descriptor) {
if (descriptor == component_x.getDescriptor())
last_x = value;
if (descriptor == component_y.getDescriptor())
last_y = value;
if (last_x == -1 && last_y == -1)
return Component.POV.UP_LEFT;
else if (last_x == -1 && last_y == 0)
return Component.POV.LEFT;
else if (last_x == -1 && last_y == 1)
return Component.POV.DOWN_LEFT;
else if (last_x == 0 && last_y == -1)
return Component.POV.UP;
else if (last_x == 0 && last_y == 0)
return Component.POV.OFF;
else if (last_x == 0 && last_y == 1)
return Component.POV.DOWN;
else if (last_x == 1 && last_y == -1)
return Component.POV.UP_RIGHT;
else if (last_x == 1 && last_y == 0)
return Component.POV.RIGHT;
else if (last_x == 1 && last_y == 1)
return Component.POV.DOWN_RIGHT;
else {
ControllerEnvironment.logln("Unknown values x = " + last_x + " | y = " + last_y);
return Component.POV.OFF;
}
}
}

View file

@ -0,0 +1,54 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
package net.java.games.input;
import java.io.IOException;
/**
* @author elias
*/
final class LinuxRumbleFF extends LinuxForceFeedbackEffect {
public LinuxRumbleFF(LinuxEventDevice device) throws IOException {
super(device);
}
protected final int upload(int id, float intensity) throws IOException {
int weak_magnitude;
int strong_magnitude;
if (intensity > 0.666666f) {
strong_magnitude = (int)(0x8000*intensity);
weak_magnitude = (int)(0xc000*intensity);
} else if (intensity > 0.3333333f) {
strong_magnitude = (int)(0x8000*intensity);
weak_magnitude = (int)(0xc000*0);
} else {
strong_magnitude = (int)(0x8000*0);
weak_magnitude = (int)(0xc000*intensity);
}
return getDevice().uploadRumbleEffect(id, 0, 0, 0, -1, 0, strong_magnitude, weak_magnitude);
}
}

View file

@ -4,7 +4,20 @@ package net.java.games.input;
/**
* This file is generated from /usr/include/linux/input.h please do not edit
*/
public class NativeDefinitions {
class NativeDefinitions {
public static final int EV_VERSION = 0x010001;
public static final int EV_SYN = 0x00;
public static final int EV_KEY = 0x01;
public static final int EV_REL = 0x02;
public static final int EV_ABS = 0x03;
public static final int EV_MSC = 0x04;
public static final int EV_LED = 0x11;
public static final int EV_SND = 0x12;
public static final int EV_REP = 0x14;
public static final int EV_FF = 0x15;
public static final int EV_PWR = 0x16;
public static final int EV_FF_STATUS = 0x17;
public static final int EV_MAX = 0x1f;
public static final int KEY_RESERVED = 0;
public static final int KEY_ESC = 1;
public static final int KEY_1 = 2;
@ -89,18 +102,17 @@ public class NativeDefinitions {
public static final int KEY_KP3 = 81;
public static final int KEY_KP0 = 82;
public static final int KEY_KPDOT = 83;
public static final int KEY_103RD = 84;
public static final int KEY_F13 = 85;
public static final int KEY_ZENKAKUHANKAKU = 85;
public static final int KEY_102ND = 86;
public static final int KEY_F11 = 87;
public static final int KEY_F12 = 88;
public static final int KEY_F14 = 89;
public static final int KEY_F15 = 90;
public static final int KEY_F16 = 91;
public static final int KEY_F17 = 92;
public static final int KEY_F18 = 93;
public static final int KEY_F19 = 94;
public static final int KEY_F20 = 95;
public static final int KEY_RO = 89;
public static final int KEY_KATAKANA = 90;
public static final int KEY_HIRAGANA = 91;
public static final int KEY_HENKAN = 92;
public static final int KEY_KATAKANAHIRAGANA = 93;
public static final int KEY_MUHENKAN = 94;
public static final int KEY_KPJPCOMMA = 95;
public static final int KEY_KPENTER = 96;
public static final int KEY_RIGHTCTRL = 97;
public static final int KEY_KPSLASH = 98;
@ -125,11 +137,10 @@ public class NativeDefinitions {
public static final int KEY_KPEQUAL = 117;
public static final int KEY_KPPLUSMINUS = 118;
public static final int KEY_PAUSE = 119;
public static final int KEY_F21 = 120;
public static final int KEY_F22 = 121;
public static final int KEY_F23 = 122;
public static final int KEY_F24 = 123;
public static final int KEY_KPCOMMA = 124;
public static final int KEY_KPCOMMA = 121;
public static final int KEY_HANGUEL = 122;
public static final int KEY_HANJA = 123;
public static final int KEY_YEN = 124;
public static final int KEY_LEFTMETA = 125;
public static final int KEY_RIGHTMETA = 126;
public static final int KEY_COMPOSE = 127;
@ -186,24 +197,18 @@ public class NativeDefinitions {
public static final int KEY_SCROLLDOWN = 178;
public static final int KEY_KPLEFTPAREN = 179;
public static final int KEY_KPRIGHTPAREN = 180;
public static final int KEY_INTL1 = 181;
public static final int KEY_INTL2 = 182;
public static final int KEY_INTL3 = 183;
public static final int KEY_INTL4 = 184;
public static final int KEY_INTL5 = 185;
public static final int KEY_INTL6 = 186;
public static final int KEY_INTL7 = 187;
public static final int KEY_INTL8 = 188;
public static final int KEY_INTL9 = 189;
public static final int KEY_LANG1 = 190;
public static final int KEY_LANG2 = 191;
public static final int KEY_LANG3 = 192;
public static final int KEY_LANG4 = 193;
public static final int KEY_LANG5 = 194;
public static final int KEY_LANG6 = 195;
public static final int KEY_LANG7 = 196;
public static final int KEY_LANG8 = 197;
public static final int KEY_LANG9 = 198;
public static final int KEY_F13 = 183;
public static final int KEY_F14 = 184;
public static final int KEY_F15 = 185;
public static final int KEY_F16 = 186;
public static final int KEY_F17 = 187;
public static final int KEY_F18 = 188;
public static final int KEY_F19 = 189;
public static final int KEY_F20 = 190;
public static final int KEY_F21 = 191;
public static final int KEY_F22 = 192;
public static final int KEY_F23 = 193;
public static final int KEY_F24 = 194;
public static final int KEY_PLAYCD = 200;
public static final int KEY_PAUSECD = 201;
public static final int KEY_PROG3 = 202;
@ -230,6 +235,10 @@ public class NativeDefinitions {
public static final int KEY_BRIGHTNESSDOWN = 224;
public static final int KEY_BRIGHTNESSUP = 225;
public static final int KEY_MEDIA = 226;
public static final int KEY_SWITCHVIDEOMODE = 227;
public static final int KEY_KBDILLUMTOGGLE = 228;
public static final int KEY_KBDILLUMDOWN = 229;
public static final int KEY_KBDILLUMUP = 230;
public static final int KEY_UNKNOWN = 240;
public static final int BTN_MISC = 0x100;
public static final int BTN_0 = 0x100;
@ -366,10 +375,34 @@ public class NativeDefinitions {
public static final int KEY_DEL_EOS = 0x1c1;
public static final int KEY_INS_LINE = 0x1c2;
public static final int KEY_DEL_LINE = 0x1c3;
public static final int KEY_FN = 0x1d0;
public static final int KEY_FN_ESC = 0x1d1;
public static final int KEY_FN_F1 = 0x1d2;
public static final int KEY_FN_F2 = 0x1d3;
public static final int KEY_FN_F3 = 0x1d4;
public static final int KEY_FN_F4 = 0x1d5;
public static final int KEY_FN_F5 = 0x1d6;
public static final int KEY_FN_F6 = 0x1d7;
public static final int KEY_FN_F7 = 0x1d8;
public static final int KEY_FN_F8 = 0x1d9;
public static final int KEY_FN_F9 = 0x1da;
public static final int KEY_FN_F10 = 0x1db;
public static final int KEY_FN_F11 = 0x1dc;
public static final int KEY_FN_F12 = 0x1dd;
public static final int KEY_FN_1 = 0x1de;
public static final int KEY_FN_2 = 0x1df;
public static final int KEY_FN_D = 0x1e0;
public static final int KEY_FN_E = 0x1e1;
public static final int KEY_FN_F = 0x1e2;
public static final int KEY_FN_S = 0x1e3;
public static final int KEY_FN_B = 0x1e4;
public static final int KEY_MAX = 0x1ff;
public static final int REL_X = 0x00;
public static final int REL_Y = 0x01;
public static final int REL_Z = 0x02;
public static final int REL_RX = 0x03;
public static final int REL_RY = 0x04;
public static final int REL_RZ = 0x05;
public static final int REL_HWHEEL = 0x06;
public static final int REL_DIAL = 0x07;
public static final int REL_WHEEL = 0x08;
@ -402,10 +435,16 @@ public class NativeDefinitions {
public static final int ABS_VOLUME = 0x20;
public static final int ABS_MISC = 0x28;
public static final int ABS_MAX = 0x3f;
public static final int USAGE_MOUSE = 0x00;
public static final int USAGE_JOYSTICK = 0x01;
public static final int USAGE_GAMEPAD = 0x02;
public static final int USAGE_KEYBOARD = 0x03;
public static final int USAGE_MAX = 0x0f;
public static final int BUS_PCI = 0x01;
public static final int BUS_ISAPNP = 0x02;
public static final int BUS_USB = 0x03;
public static final int BUS_HIL = 0x04;
public static final int BUS_BLUETOOTH = 0x05;
public static final int BUS_ISA = 0x10;
public static final int BUS_I8042 = 0x11;
public static final int BUS_XTKBD = 0x12;
@ -416,4 +455,24 @@ public class NativeDefinitions {
public static final int BUS_ADB = 0x17;
public static final int BUS_I2C = 0x18;
public static final int BUS_HOST = 0x19;
public static final int FF_STATUS_STOPPED = 0x00;
public static final int FF_STATUS_PLAYING = 0x01;
public static final int FF_STATUS_MAX = 0x01;
public static final int FF_RUMBLE = 0x50;
public static final int FF_PERIODIC = 0x51;
public static final int FF_CONSTANT = 0x52;
public static final int FF_SPRING = 0x53;
public static final int FF_FRICTION = 0x54;
public static final int FF_DAMPER = 0x55;
public static final int FF_INERTIA = 0x56;
public static final int FF_RAMP = 0x57;
public static final int FF_SQUARE = 0x58;
public static final int FF_TRIANGLE = 0x59;
public static final int FF_SINE = 0x5a;
public static final int FF_SAW_UP = 0x5b;
public static final int FF_SAW_DOWN = 0x5c;
public static final int FF_CUSTOM = 0x5d;
public static final int FF_GAIN = 0x60;
public static final int FF_AUTOCENTER = 0x61;
public static final int FF_MAX = 0x7f;
}

View file

@ -1,72 +0,0 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
#if !defined(eventInterface_Device_h)
#define eventInterface_Device_h
/**
* Simple abstract device class
*
* @author Jeremy Booth (jeremy@newdawnsoftware.com)
*/
class Device {
private:
public:
/** Maximum name length for a device */
const static int MAX_NAME_LENGTH = 256;
/** Return the number of relative axes for this device */
virtual int getNumberRelAxes() = 0;
/** Return the number ofr absolute axes for this device */
virtual int getNumberAbsAxes() = 0;
/** Return the number of buttons for this device */
virtual int getNumberButtons() = 0;
/** Get the name of this device */
virtual const char *getName() = 0;
/** get teh bus type */
virtual int getBusType() = 0;
virtual int getVendorID() = 0;
virtual int getProductID() = 0;
virtual int getVersion() = 0;
/** Get the supported axes/button maps */
virtual void getSupportedRelAxes(int supportedAxis[]) = 0;
virtual void getSupportedAbsAxes(int supportedAxis[]) = 0;
virtual void getSupportedButtons(int supportedButtons[]) = 0;
/** poll it */
virtual int poll() = 0;
/** get the data */
virtual void getPolledData(int relAxesData[], int absAxesData[], int buttonData[]) = 0;
/** Get axis details */
virtual int getAbsAxisMinimum(int axisNumber) = 0;
virtual int getAbsAxisMaximum(int axisNumber) = 0;
virtual int getAbsAxisFuzz(int axisNumber) = 0;
virtual bool getFFEnabled() = 0;
virtual void rumble(float force) = 0;
virtual void cleanup() = 0;
};
#endif //eventInterface_Device_h

View file

@ -1,481 +0,0 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
#include "eventInterfaceTypes.h"
#include "EventDevice.h"
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <linux/input.h>
#include <malloc.h>
#include <errno.h>
#include "logger.h"
EventDevice::EventDevice(char *deviceFileName) {
char tempName[Device::MAX_NAME_LENGTH-1] = "Unknown";
int i;
fd = open(deviceFileName, O_RDWR | O_NONBLOCK);
if(fd<0) {
char errorMessage[512];
sprintf(errorMessage, "Error opening device %s read/write, Force Feedback disabled for this device\n", deviceFileName);
perror(errorMessage);
fd = open(deviceFileName, O_RDONLY | O_NONBLOCK);
if(fd<0) {
/*char errorMessage[512];
sprintf(errorMessage, "Error opening device %s\n", deviceFileName);
perror(errorMessage);*/
inited = 0;
return;
}
} else {
if(ioctl(fd, EVIOCGBIT(EV_FF, sizeof(uint8_t) * 16), ff_bitmask) < 0) {
char errorMessage[512];
sprintf(errorMessage, "Error reading device %s\n", deviceFileName);
perror(errorMessage);
}
if(getBit(FF_RUMBLE, ff_bitmask)==1) {
ffSupported = 1;
//LOG_TRACE("Force feedback supported for %s\n", deviceFileName);
int n_effects = 0;
if (ioctl(fd, EVIOCGEFFECTS, &n_effects) == -1) {
char errorMessage[512];
sprintf(errorMessage, "Failed to get number of effects for device %s\n", deviceFileName);
perror(errorMessage);
}
LOG_TRACE("Device %s supports %d simultanious effects\n", deviceFileName, n_effects);
effect_playing = false;
effect.type=FF_RUMBLE;
effect.id=-1;
effect.u.rumble.strong_magnitude = (int)(0x8000);
effect.u.rumble.weak_magnitude = (int)(0xc000);
effect.replay.length = 5000;
effect.replay.delay = 0;
LOG_TRACE("Uploading effect %d\n", effect.id);
if (ioctl(fd, EVIOCSFF, &effect) == -1) {
perror("Upload effect");
}
LOG_TRACE("Uploaded effect %d\n", effect.id);
} else {
ffSupported = 0;
LOG_TRACE("Force feedback not supported for %s %d\n", deviceFileName, getBit(FF_RUMBLE, ff_bitmask));
}
}
if(ioctl(fd, EVIOCGNAME(sizeof(tempName)), tempName) < 0) {
char errorMessage[512];
sprintf(errorMessage, "Error reading device %s\n", deviceFileName);
perror(errorMessage);
}
int namelength=strlen(tempName);
name = (char *)malloc(namelength+1);
strncpy(name,tempName, namelength+1);
LOG_TRACE("Device name for device file %s is %s\n", deviceFileName, name);
uint8_t evtype_bitmask[EV_MAX/8 + 1];
memset(evtype_bitmask, 0, sizeof(evtype_bitmask));
if(ioctl(fd, EVIOCGBIT(0, EV_MAX), evtype_bitmask) < 0) {
char errorMessage[512];
sprintf(errorMessage, "Error reading device %s\n", deviceFileName);
perror(errorMessage);
}
struct input_devinfo deviceInfo;
if(ioctl(fd, EVIOCGID, &deviceInfo) < 0) {
char errorMessage[512];
sprintf(errorMessage, "Error reading device %s\n", deviceFileName);
perror(errorMessage);
}
bustype = deviceInfo.bustype;
vendor = deviceInfo.vendor;
product = deviceInfo.product;
version = deviceInfo.version;
numButtons = -1;
numAbsAxes = -1;
numRelAxes = -1;
if(!(getBit(EV_KEY, evtype_bitmask))) {
numButtons = 0;
}
if(!(getBit(EV_REL, evtype_bitmask))) {
numRelAxes = 0;
}
if(!(getBit(EV_ABS, evtype_bitmask))) {
numAbsAxes = 0;
}
if(!getBit(EV_FF, evtype_bitmask)) {
ffSupported = 0;
}
if(numButtons < 0) {
// This device supports keys, deal with it.
if(ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask) < 0) {
char errorMessage[512];
sprintf(errorMessage, "Error reading device %s\n", deviceFileName);
perror(errorMessage);
}
for(i=0;i<KEY_MAX;i++) {
buttonLookup[i]=-1;
}
short tempSupportedButtons[KEY_MAX];
numButtons = 0;
for(i=0;i<KEY_MAX;i++) {
if(getBit(i,key_bitmask)) {
tempSupportedButtons[numButtons] = i;
numButtons++;
}
}
supportedButtons = (short *)malloc(numButtons * sizeof(short));
buttonData = (uint8_t *)malloc(numButtons * sizeof(uint8_t));
for(i=0;i<numButtons;i++) {
buttonData[i] = 0;
supportedButtons[i] = tempSupportedButtons[i];
buttonLookup[supportedButtons[i]] = i;
}
}
if(numRelAxes < 0) {
// This device supports axes, deal with it.
if(ioctl(fd, EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask) < 0) {
char errorMessage[512];
sprintf(errorMessage, "Error reading device %s\n", deviceFileName);
perror(errorMessage);
}
for(i=0;i<REL_MAX;i++) {
relAxisLookup[i]=-1;
}
short tempSupportedAxes[REL_MAX];
numRelAxes=0;
for(i=0;i<REL_MAX;i++) {
if(getBit(i,rel_bitmask)) {
tempSupportedAxes[numRelAxes] = i;
numRelAxes++;
}
}
relAxesData = (int *)malloc(numRelAxes * sizeof(int));
supportedRelAxes = (short *)malloc(numRelAxes * sizeof(short));
for(i=0;i<numRelAxes;i++) {
relAxesData[i]=0;
supportedRelAxes[i] = tempSupportedAxes[i];
relAxisLookup[supportedRelAxes[i]] = i;
}
}
if(numAbsAxes < 0) {
if(ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask) < 0) {
char errorMessage[512];
sprintf(errorMessage, "Error reading device %s\n", deviceFileName);
perror(errorMessage);
}
for(i=0;i<ABS_MAX;i++) {
absAxisLookup[i] = -1;
}
short tempSupportedAxes[ABS_MAX];
numAbsAxes=0;
for(i=0;i<ABS_MAX;i++) {
if(getBit(i,abs_bitmask)) {
tempSupportedAxes[numAbsAxes] = i;
numAbsAxes++;
}
}
absAxesData = (int *)malloc(numAbsAxes * sizeof(int));
supportedAbsAxes = (short *)malloc(numAbsAxes * sizeof(short));
for(i=0;i<numAbsAxes;i++) {
supportedAbsAxes[i] = tempSupportedAxes[i];
absAxisLookup[supportedAbsAxes[i]] = i;
}
abs_features = (struct input_absinfo *)malloc(numAbsAxes * sizeof(struct input_absinfo));
for(i=0;i<numAbsAxes;i++) {
if(ioctl(fd, EVIOCGABS(supportedAbsAxes[i]), &(abs_features[i]))) {
char errorMessage[512];
sprintf(errorMessage, "Error reading device %s\n", deviceFileName);
perror(errorMessage);
}
absAxesData[i] = abs_features[i].value;
}
}
inited = 1;
}
int EventDevice::isValidDevice() {
return inited;
}
int EventDevice::getNumberRelAxes(){
if(inited!=1) return -1;
return numRelAxes;
}
int EventDevice::getNumberAbsAxes(){
if(inited!=1) return -1;
return numAbsAxes;
}
int EventDevice::getNumberButtons(){
if(inited!=1) return -1;
return numButtons;
}
const char *EventDevice::getName(){
LOG_TRACE("EventDevice::getName()\n");
return name;
}
int EventDevice::getBusType(){
if(inited!=1) return -1;
return bustype;
}
int EventDevice::getVendorID(){
if(inited!=1) return -1;
return vendor;
}
int EventDevice::getProductID(){
if(inited!=1) return -1;
return product;
}
int EventDevice::getVersion(){
if(inited!=1) return -1;
return version;
}
void EventDevice::getSupportedRelAxes(int supportedAxis[]){
int i;
if(inited!=1) return;
for(i=0;i<numRelAxes; i++) {
(supportedAxis)[i] = supportedRelAxes[i];
}
}
void EventDevice::getSupportedAbsAxes(int supportedAxis[]){
int i;
if(inited!=1) return;
for(i=0;i<numAbsAxes; i++) {
(supportedAxis)[i] = supportedAbsAxes[i];
}
}
void EventDevice::getSupportedButtons(int supportedButtons[]){
int i;
if(inited!=1) return;
for(i=0;i<numButtons; i++) {
(supportedButtons)[i] = this->supportedButtons[i];
}
}
/**
* A return value of -1 means error, 0 means ok, but no change
* a return of >0 means the data for this device has changed
*/
int EventDevice::poll(){
size_t read_bytes;
struct input_event events[64];
int dataChanged=0;
if(inited!=1) return -1;
// first thing to do is reset all relative axis as mice never seem to do it
int i;
for(i=0;i<numRelAxes;i++){
if(relAxesData[i]!=0) {
dataChanged=1;
relAxesData[i]=0;
}
}
read_bytes = read(fd, events, sizeof(struct input_event) * 64);
if(read_bytes == 0) {
// no sweat, just return;
return 0;
}
if(read_bytes == -1) {
if(errno == EAGAIN) {
// No worries, we are in non blocking and noting is ready
return 0;
} else {
perror("Error reading events: ");
return -1;
}
}
if (read_bytes < (int) sizeof(struct input_event)) {
perror("Error reading events: ");
return -1;
}
int numEventsRead = (int) (read_bytes / sizeof(struct input_event));
for(i=0;i<numEventsRead;i++) {
switch(events[i].type) {
case EV_SYN:
case EV_MSC:
// not sure what to do with it, ignore for now -- JPK
break;
case EV_KEY: {
dataChanged = 1;
int buttonIndex = buttonLookup[events[i].code];
buttonData[buttonIndex] = events[i].value;
//printf("button %d translates to button %d on this device\n", events[i].code, buttonIndex);
break;
}
case EV_REL: {
dataChanged = 1;
int axisIndex = relAxisLookup[events[i].code];
relAxesData[axisIndex] += events[i].value;
//printf("rel axis %d translates to rel axis %d on this device\n", events[i].code, axisIndex);
break;
}
case EV_ABS: {
dataChanged = 1;
int axisIndex = absAxisLookup[events[i].code];
absAxesData[axisIndex] = events[i].value;
//printf("abs axis %d translates to abs axis %d on this device\n", events[i].code, axisIndex);
break;
}
case EV_LED:
// reveiced for things like numlock led change
break;
default:
fprintf(stderr, "Received event of type 0x%02X from %s, which I wasn't expecting, please report it to jinput forum at www.javagaming.org\n", events[i].type, name);
}
}
return dataChanged;
}
void EventDevice::getPolledData(int relAxesData[], int absAxesData[], int buttonData[]){
int i;
if(inited!=1) return;
for(i=0;i<numRelAxes;i++) {
(relAxesData)[i] = this->relAxesData[i];
}
for(i=0;i<numAbsAxes;i++) {
(absAxesData)[i] = this->absAxesData[i];
}
for(i=0;i<numButtons;i++) {
(buttonData)[i] = this->buttonData[i];
}
}
int EventDevice::getAbsAxisMinimum(int axisNumber) {
return abs_features[axisNumber].minimum;
}
int EventDevice::getAbsAxisMaximum(int axisNumber) {
return abs_features[axisNumber].maximum;
}
int EventDevice::getAbsAxisFuzz(int axisNumber) {
return abs_features[axisNumber].fuzz;
}
bool EventDevice::getFFEnabled() {
if(ffSupported==1) {
//LOG_TRACE("FF is supported for %s\n", getName());
return true;
}
//LOG_TRACE("FF is not supported for %s\n", getName());
return false;
}
void EventDevice::rumble(float force) {
if(force>1) force=1;
if(force<-1) force=-1;
//LOG_TRACE("Rumbling at %d%%, (shh, pretend)\n", (int)(force*100));
if(effect_playing==true) {
stop.type=EV_FF;
stop.code = effect.id;
stop.value=0;
LOG_TRACE("Stopping effect %d\n", stop.code);
if (write(fd, (const void*) &stop, sizeof(stop)) == -1) {
perror("Failed to stop effect");
} else {
effect_playing=false;
}
}
if(force>0.666666) {
effect.u.rumble.strong_magnitude = (int)(0x8000*force);
effect.u.rumble.weak_magnitude = (int)(0xc000*force);
} else if(force>0.3333333) {
effect.u.rumble.strong_magnitude = (int)(0x8000*force);
effect.u.rumble.weak_magnitude = (int)(0xc000*0);
} else {
effect.u.rumble.strong_magnitude = (int)(0x8000*0);
effect.u.rumble.weak_magnitude = (int)(0xc000*force);
}
LOG_TRACE("Uploading effect %d\n", effect.id);
if (ioctl(fd, EVIOCSFF, &effect) == -1) {
perror("Upload effect");
}
LOG_TRACE("Uploaded effect %d\n", effect.id);
if(effect_playing==false && force!=0) {
play.type = EV_FF;
play.code=effect.id;
play.value=1;
LOG_TRACE("Playing effect %d\n", play.code);
if (write(fd, (const void*) &play, sizeof(play)) == -1) {
perror("Failed to play effect");
} else {
effect_playing=true;
}
}
}
void EventDevice::cleanup() {
char message[512];
sprintf(message, "Closing device %s\n", name);
LOG_TRACE(message);
close(fd);
}

View file

@ -1,92 +0,0 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
#if !defined(eventInterface_eventDevice_h)
#define eventInterface_eventDevice_h
#include <stdint.h>
#include <linux/input.h>
#include "eventInterfaceTypes.h"
#include "Device.h"
class EventDevice : public Device {
private:
int fd;
int inited;
char *name;
int numButtons;
uint16_t bustype;
uint16_t vendor;
uint16_t product;
uint16_t version;
short *supportedRelAxes;
short *supportedAbsAxes;
short *supportedButtons;
int *relAxesData;
int *absAxesData;
uint8_t *buttonData;
int ffSupported;
int numRelAxes;
int numAbsAxes;
uint8_t evtype_bitmask[EV_MAX/8 + 1];
uint8_t key_bitmask[KEY_MAX/8 + 1];
uint8_t rel_bitmask[REL_MAX/8 + 1];
uint8_t abs_bitmask[ABS_MAX/8 + 1];
uint8_t ff_bitmask[16];
struct input_absinfo *abs_features;
int absAxisLookup[ABS_MAX];
int relAxisLookup[REL_MAX];
int buttonLookup[KEY_MAX];
struct ff_effect effect;
struct input_event play, stop;
bool effect_playing;
public:
EventDevice(char *deviceFilename);
int getNumberRelAxes();
int getNumberAbsAxes();
int getNumberButtons();
const char *getName();
int getBusType();
int getVendorID();
int getProductID();
int getVersion();
void getSupportedRelAxes(int supportedAxis[]);
void getSupportedAbsAxes(int supportedAxis[]);
void getSupportedButtons(int supportedButtons[]);
int poll();
void getPolledData(int relAxesData[], int absAxesData[], int buttonData[]);
int getAbsAxisMinimum(int axisNumber);
int getAbsAxisMaximum(int axisNumber);
int getAbsAxisFuzz(int axisNumber);
int isValidDevice();
bool getFFEnabled();
void rumble(float force);
void cleanup();
};
#endif //eventInterface_eventDevice_h

View file

@ -1,200 +0,0 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
#include "eventInterfaceTypes.h"
#include "JoystickDevice.h"
#include <stdio.h>
#include <linux/input.h>
#include <linux/joystick.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <malloc.h>
#include <errno.h>
#include "logger.h"
JoystickDevice::JoystickDevice(char *deviceFileName) {
char tempName[Device::MAX_NAME_LENGTH-1] = "Unknown";
int i;
LOG_TRACE("Trying to open %s\n", deviceFileName);
fd = open(deviceFileName, O_RDONLY | O_NONBLOCK);
/*if(fd<0) {
char errorMessage[512];
sprintf(errorMessage, "Error opening device %s\n", deviceFileName);
perror(errorMessage);
}*/
if(fd>0){
LOG_TRACE("Opened %s, trying to get device name\n", deviceFileName);
if(ioctl(fd, JSIOCGNAME(sizeof(tempName)), tempName) < 0) {
LOG_TRACE("Failed to get device name for %s\n", deviceFileName);
char errorMessage[512];
sprintf(errorMessage, "Error reading device %s\n", deviceFileName);
perror(errorMessage);
}
int namelength=strlen(tempName);
name = (char *)malloc(namelength+1);
strncpy(name,tempName, namelength+1);
char tempNumButtons;
char tempNumAxes;
LOG_TRACE("Getting button and axes information for %s\n", deviceFileName);
ioctl (fd, JSIOCGBUTTONS, &tempNumButtons);
ioctl (fd, JSIOCGAXES, &tempNumAxes);
numButtons = tempNumButtons;
numAbsAxes = tempNumAxes;
//fprintf(stderr, "Got joystick %s with %d buttons and %d axes\n", tempName, numButtons, numAbsAxes);
//buttonData = (uint8_t *)malloc(numButtons * sizeof(uint8_t));
buttonData = new uint8_t[numButtons];
//absAxesData = (int *)malloc(numAbsAxes * sizeof(int));
absAxesData = new int[numAbsAxes];
LOG_TRACE("Initialisation of %s completed\n", deviceFileName);
inited = 1;
} else {
LOG_TRACE("Failed to open device %s\n", deviceFileName);
inited = 0;
}
}
int JoystickDevice::isValidDevice() {
return inited;
}
int JoystickDevice::getNumberRelAxes(){
if(inited!=1) return -1;
return 0;
}
int JoystickDevice::getNumberAbsAxes(){
if(inited!=1) return -1;
return numAbsAxes;
}
int JoystickDevice::getNumberButtons(){
if(inited!=1) return -1;
return numButtons;
}
const char *JoystickDevice::getName(){
return name;
}
int JoystickDevice::getBusType(){
if(inited!=1) return -1;
return 0;
}
int JoystickDevice::getVendorID(){
if(inited!=1) return -1;
return 0;
}
int JoystickDevice::getProductID(){
if(inited!=1) return -1;
return 0;
}
int JoystickDevice::getVersion(){
if(inited!=1) return -1;
return 0;
}
void JoystickDevice::getSupportedRelAxes(int supportedAxis[]){
}
void JoystickDevice::getSupportedAbsAxes(int supportedAxis[]){
}
void JoystickDevice::getSupportedButtons(int supportedButtons[]){
}
/**
* A return value of -1 means error, 0 means ok, but no change
* a return of >0 means the data for this device has changed
*/
int JoystickDevice::poll(){
struct js_event event;
int numEvents = 0;
while(read(fd, &event, sizeof event) > 0) {
numEvents++;
event.type &= ~JS_EVENT_INIT;
if(event.type == JS_EVENT_BUTTON) {
buttonData[event.number] = event.value;
} else if(event.type == JS_EVENT_AXIS) {
absAxesData[event.number] = event.value;
}
}
// EAGAIN is returned when the queue is empty
if(errno != EAGAIN) {
printf("Something went wrong getting an event\n");
}
return numEvents;
}
void JoystickDevice::getPolledData(int relAxesData[], int absAxesData[], int buttonData[]){
int i;
if(inited!=1) return;
for(i=0;i<numAbsAxes;i++) {
(absAxesData)[i] = this->absAxesData[i];
}
for(i=0;i<numButtons;i++) {
(buttonData)[i] = this->buttonData[i];
}
}
int JoystickDevice::getAbsAxisMinimum(int axisNumber) {
return -32767;
}
int JoystickDevice::getAbsAxisMaximum(int axisNumber) {
return 32767;
}
int JoystickDevice::getAbsAxisFuzz(int axisNumber) {
return 0;
}
bool JoystickDevice::getFFEnabled() {
return false;
}
void JoystickDevice::rumble(float force) {
return;
}
void JoystickDevice::cleanup() {
close(fd);
}

View file

@ -1,134 +0,0 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
#include "eventInterfaceTypes.h"
#include "JoystickDevice.h"
#include "MixedDevice.h"
#include <stdio.h>
#include <linux/input.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <malloc.h>
#include <errno.h>
MixedDevice::MixedDevice(JoystickDevice *jsDevice, EventDevice *evDevice) {
joystickDevice = jsDevice;
eventDevice = evDevice;
}
int MixedDevice::getNumberRelAxes(){
eventDevice->getNumberRelAxes();
}
int MixedDevice::getNumberAbsAxes(){
return eventDevice->getNumberAbsAxes();
}
int MixedDevice::getNumberButtons(){
return eventDevice->getNumberButtons();
}
const char *MixedDevice::getName(){
return eventDevice->getName();
}
int MixedDevice::getBusType(){
return eventDevice->getBusType();
}
int MixedDevice::getVendorID(){
return eventDevice->getVendorID();
}
int MixedDevice::getProductID(){
return eventDevice->getProductID();
}
int MixedDevice::getVersion(){
return eventDevice->getVersion();
}
void MixedDevice::getSupportedRelAxes(int supportedAxis[]){
return eventDevice->getSupportedRelAxes(supportedAxis);
}
void MixedDevice::getSupportedAbsAxes(int supportedAxis[]){
return eventDevice->getSupportedAbsAxes(supportedAxis);
}
void MixedDevice::getSupportedButtons(int supportedButtons[]){
return eventDevice->getSupportedButtons(supportedButtons);
}
/**
* A return value of -1 means error, 0 means ok, but no change
* a return of >0 means the data for this device has changed
*/
int MixedDevice::poll(){
eventDevice->poll();
return joystickDevice->poll();
}
void MixedDevice::getPolledData(int relAxesData[], int absAxesData[], int buttonData[]){
int i;
joystickDevice->getPolledData(new int[joystickDevice->getNumberRelAxes()], absAxesData, new int[joystickDevice->getNumberButtons()]);
eventDevice->getPolledData(relAxesData, new int[eventDevice->getNumberAbsAxes()], buttonData);
}
int MixedDevice::getAbsAxisMinimum(int axisNumber) {
return joystickDevice->getAbsAxisMinimum(axisNumber);
}
int MixedDevice::getAbsAxisMaximum(int axisNumber) {
return joystickDevice->getAbsAxisMaximum(axisNumber);
}
int MixedDevice::getAbsAxisFuzz(int axisNumber) {
return joystickDevice->getAbsAxisFuzz(axisNumber);
}
bool MixedDevice::getFFEnabled() {
return eventDevice->getFFEnabled();
}
void MixedDevice::rumble(float force) {
eventDevice->rumble(force);
}
void MixedDevice::cleanup() {
if(joystickDevice!=0 && eventDevice!=0) {
joystickDevice->cleanup();
eventDevice->cleanup();
free(joystickDevice);
free(eventDevice);
joystickDevice=0;
eventDevice=0;
}
}

View file

@ -6,50 +6,43 @@
<!-- The idea is that both Ant and NetBeans have to know what the package root is -->
<!-- for the classes in your application. -->
<project name="JInput Linux port, Native code" basedir="." default="compileNativeJinputLib">
<!-- Don't worry if you don't know the Ant syntax completely or need help on some tasks! -->
<!-- The standard Ant documentation is bundled. See Help | Help Sets | Ant 1.4.1 Manual. -->
<property name="libname" value="libjinput-linux.so"/>
<target name="init">
<!-- You can set up any variables you want used throughout the script here. -->
<!-- property name="hello" value="world"/-->
<!-- To use e.g. Jikes, uncomment this line. -->
<!-- (Or make the same change in Tools | Options | Ant Settings | Properties.) -->
<!-- <property name="build.compiler" value="jikes"/> -->
<!-- You might like to set up some overridable paths, etc.: -->
<!-- <property name="mylib" value="../lib/mylib.jar"/> -->
<mkdir dir="build"/>
<mkdir dir="apidoc"/>
</target>
<target name="createNativeDefinitions.java" depends="init">
<exec dir="." executable="./getDefinitions" os="Linux" output="../java/net/java/games/input/NativeDefinitions.java">
<arg line="/usr/include/linux/input.h"/>
</exec>
</target>
</target>
<target name="createJNIHeaders" depends="init">
<javah>
<classpath>
<pathelement path="."/>
<pathelement location="jinput.jar"/>
</classpath>
<class name="net.java.games.input.LinuxDevice"/>
<class name="net.java.games.input.LinuxEnvironmentPlugin"/>
<class name="net.java.games.input.LinuxKeyboard"/>
</javah>
</target>
<target name="compileNativeEventLib" depends="init">
<exec dir="." executable="g++" os="Linux">
<arg line="--shared -DLOGTRACE -o libeventInterface.so eventInterface.cpp EventDevice.cpp"/>
</exec>
</target>
<target depends="init" name="createNativeDefinitions.java">
<exec dir="." executable="gawk" os="Linux" output="../java/net/java/games/input/NativeDefinitions.java">
<arg line="-f"/>
<arg line="getDefinitions"/>
<arg line="/usr/include/linux/input.h"/>
</exec>
</target>
<target name="clean">
<delete>
<fileset dir="." includes="*.o"/>
<fileset file="${libname}"/>
</delete>
</target>
<target name="compileNativeJinputLib" depends="init">
<exec dir="." executable="g++" os="Linux">
<arg line="-I${java.home}/include -I${java.home}/include/linux -I${java.home}/../include -I${java.home}/../include/linux --shared -DLOGTRACE -o libjinput-linux.so jinput.cpp eventInterface.cpp EventDevice.cpp joystickInterface.cpp JoystickDevice.cpp MixedDevice.cpp"/>
</exec>
<apply dir="." executable="cc" os="Linux" dest="." skipemptyfilesets="true" failonerror="true">
<arg line="-O2 -Wall -c -fPIC"/>
<arg value="-I${java.home}/include"/>
<arg value="-I${java.home}/include/linux"/>
<arg value="-I../../../common/src/native"/>
<mapper type="glob" from="*.c" to="*.o"/>
<fileset dir="." includes="*.c"/>
<fileset dir="../../../common/src/native" includes="*.c"/>
</apply>
<apply dir="." parallel="true" executable="cc" os="Linux" failonerror="true">
<arg line="-shared -O2 -Wall -o ${libname}"/>
<fileset dir="." includes="*.o"/>
</apply>
<apply dir="." parallel="true" executable="strip" os="Linux" failonerror="true">
<fileset file="${libname}"/>
</apply>
</target>
</project>

View file

@ -1,147 +0,0 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
#include <sys/dir.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/input.h>
#include <string.h>
#include <malloc.h>
#include <unistd.h>
#include "Device.h"
#include "EventDevice.h"
#include "logger.h"
int evNumDevices;
int eventInterfaceVersion;
Device **evDeviceList;
int evInited = 0;
int evFileFilter(const struct direct *entry) {
if (strncmp(entry->d_name, "event", 5) == 0) {
return 1;
}
return 0;
}
int evGetDeviceFiles(char ***filenames) {
struct direct **files;
int num_files, i;
char dirName[] = {"/dev/input"};
num_files = scandir(dirName, &files, &evFileFilter, alphasort);
*filenames = (char **)malloc(num_files * sizeof(char *));
for(i=0;i<num_files;i++) {
char *filename = files[i]->d_name;
char *fullFileName;
fullFileName = (char *)malloc((strlen(dirName) + 1 + strlen(filename) + 1));
sprintf(fullFileName, "%s/%s", dirName, filename);
(*filenames)[i] = fullFileName;
}
return num_files;
}
int evInit() {
int fd=-1;
int i;
char **deviceFileNames;
int numDeviceFiles;
numDeviceFiles = evGetDeviceFiles(&deviceFileNames);
if(numDeviceFiles<0) {
return -1;
}
if ((fd = open(deviceFileNames[0], O_RDONLY)) <0) {
evNumDevices=0;
evInited=1;
return 0;
}
if (ioctl(fd, EVIOCGVERSION, &eventInterfaceVersion)) {
close(fd);
evNumDevices=0;
evInited=1;
return 0;
}
if(fd>=0) {close(fd);}
Device *tempDeviceList[numDeviceFiles];
evNumDevices = 0;
for(i=0;i<numDeviceFiles;i++) {
EventDevice *tempDevice = new EventDevice(deviceFileNames[i]);
if(tempDevice->isValidDevice()==1) {
tempDeviceList[i] = tempDevice;
evNumDevices++;
} else {
tempDeviceList[i] = NULL;
}
}
int highDeviceCountNumber = i;
int evTempDeviceCount = 0;
// Now we know for certain which devices are open, we can take notes
evDeviceList = (Device **)malloc(evNumDevices * sizeof(Device *));
for(i=0;i<evNumDevices;i++) {
while(tempDeviceList[evTempDeviceCount] == NULL) {
evTempDeviceCount++;
}
evDeviceList[i] = tempDeviceList[evTempDeviceCount];
LOG_TRACE("Copied temp event device %d to event device %d\n", evTempDeviceCount, i);
evTempDeviceCount++;
}
evInited=1;
return 0;
}
int evGetEventInterfaceVersionNumber() {
return eventInterfaceVersion;
}
int evGetNumberDevices() {
if(evInited) {
return evNumDevices;
}
return -1;
}
void evGetDevices(Device **theirDeviceList) {
int i;
for(i=0;i<evNumDevices;i++) {
theirDeviceList[i] = evDeviceList[i];
}
}

View file

@ -1,27 +0,0 @@
#if !defined(eventInterfaceTypes_h)
#define eventInterfaceTypes_h
#include <linux/input.h>
#include <stdint.h>
#define getBit(bit, bitField) (bitField[bit/8] & (1 << (bit%8)))
struct input_devinfo {
uint16_t bustype;
uint16_t vendor;
uint16_t product;
uint16_t version;
};
/** removed for compatability with input.h --JPK
struct input_absinfo {
int value;
int minimum;
int maximum;
int fuzz;
int flat;
};
*/
#endif //eventInterfaceTypes_h

View file

@ -29,7 +29,7 @@ NR == 1 {
printf("package net.java.games.input;\n\n")
printf("\n");
printf("/**\n * This file is generated from %s please do not edit\n */\n", FILENAME);
printf("public class NativeDefinitions {\n")
printf("class NativeDefinitions {\n")
}
/#define ABS_/ {
printf(" public static final int %s = %s;\n", $2, $3)
@ -46,6 +46,15 @@ NR == 1 {
/#define BUS_/ {
printf(" public static final int %s = %s;\n", $2, $3)
}
/#define EV_/ {
printf(" public static final int %s = %s;\n", $2, $3)
}
/#define FF_/ {
printf(" public static final int %s = %s;\n", $2, $3)
}
/#define USAGE_/ {
printf(" public static final int %s = %s;\n", $2, $3)
}
END {
printf("}\n");
}

View file

@ -1,357 +0,0 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include "net_java_games_input_JInputLibrary.h"
#include "Device.h"
#include "EventDevice.h"
#include "JoystickDevice.h"
#include "MixedDevice.h"
#include "eventInterface.h"
#include "joystickInterface.h"
#include "logger.h"
Device **jinputDeviceList;
int jinputNumDevices;
/*
* Class: net_java_games_input_JInputLibrary
* Method: nativeInit
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_nativeInit
(JNIEnv *, jclass) {
LOG_TRACE("Initing event interface\n");
if(evInit()!=0) {
fprintf(stderr, "Could not find any working event devices\n");
// return -1;
}
LOG_TRACE("Initing joystick interface\n");
if(jsInit()!=0) {
fprintf(stderr, "Could not find any working joystick devices\n");
// return -1;
}
LOG_TRACE("Getting the number of event devices\n");
int numEventDevices = evGetNumberDevices();
EventDevice *eventDevices[numEventDevices];
LOG_TRACE("Getting %d event devices\n", numEventDevices);
evGetDevices((Device **)eventDevices);
LOG_TRACE("Getting the number of joystick devices\n");
int numJoysticks = jsGetNumberDevices();
JoystickDevice *jsDevices[numJoysticks];
LOG_TRACE("Getting %d joystick devices\n", numJoysticks);
jsGetDevices((Device **)jsDevices);
int i;
int j;
int joystickPtr = 0;
jinputDeviceList = (Device **)malloc((numEventDevices + numJoysticks) * sizeof(Device *));
for(i=0;i<numEventDevices;i++) {
EventDevice *eventDevice = eventDevices[i];
int deviceCountCache = jinputNumDevices;
for(j=joystickPtr;j<numJoysticks;j++) {
JoystickDevice *jsDevice = jsDevices[j];
LOG_TRACE("Getting device information for event device %d and joystick %d\n", i, j);
if((jsDevice->getNumberButtons() == eventDevice->getNumberButtons()) && (jsDevice->getNumberAbsAxes() == (eventDevice->getNumberAbsAxes() + eventDevice->getNumberRelAxes()))) {
const char *jsName = jsDevice->getName();
const char *eventDeviceName = eventDevice->getName();
if(strcmp(jsName, eventDeviceName) == 0) {
// The current event device is the curre joystick device too
LOG_TRACE("Creating a mixed device with id %d, combining event device %d and joystick device %d\n", jinputNumDevices, i, j);
jinputDeviceList[jinputNumDevices] = new MixedDevice(jsDevice, eventDevice);
jsDevices[j] = NULL;
j++;
jinputNumDevices++;
joystickPtr = j;
j = numJoysticks;
}
}
/*if(jinputNumDevices == deviceCountCache) {
fprintf(stderr, "event device \"%s\" doesn't match js \"%s\"\n", eventDevice->getName(), jsDevice->getName());
fprintf(stderr, "event device has %d rel axes, %d abs axis and %d buttons\n", eventDevice->getNumberRelAxes(), eventDevice->getNumberAbsAxes(), eventDevice->getNumberButtons());
fprintf(stderr, "js device has %d axes and %d buttons\n", jsDevice->getNumberAbsAxes(), jsDevice->getNumberButtons());
} else {
fprintf(stderr, "event device %s did match js %s\n", eventDevice->getName(), jsDevice->getName());
}*/
}
if(jinputNumDevices == deviceCountCache) {
jinputDeviceList[jinputNumDevices] = eventDevice;
jinputNumDevices++;
}
}
for(i=0;i<numJoysticks;i++) {
if(jsDevices[i]!=NULL) {
LOG_TRACE("Copying joystick device %d to jinput device list %d\n", i, jinputNumDevices);
jinputDeviceList[jinputNumDevices] = jsDevices[i];
jinputNumDevices++;
}
}
return(0);
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: getDeviceName
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_net_java_games_input_JInputLibrary_getDeviceName
(JNIEnv *env, jclass, jint deviceID) {
LOG_TRACE("Gettign device name for jinput device %d.\n", deviceID);
LOG_TRACE("jinput device %d is %d\n", deviceID, jinputDeviceList[deviceID]);
LOG_TRACE("Gettign device name for jinput device %d, (%s)\n", deviceID, jinputDeviceList[deviceID]->getName());
return env->NewStringUTF(jinputDeviceList[deviceID]->getName());
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: getNumAbsAxes
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNumAbsAxes
(JNIEnv *env, jclass, jint deviceID) {
LOG_TRACE("Gettign number of absolute axes for jinput device %d (%d)\n", deviceID, jinputDeviceList[deviceID]->getNumberAbsAxes());
return jinputDeviceList[deviceID]->getNumberAbsAxes();
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: getNumRelAxes
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNumRelAxes
(JNIEnv *env, jclass, jint deviceID) {
LOG_TRACE("Gettign number of relative axes for jinput device %d (%d)\n", deviceID, jinputDeviceList[deviceID]->getNumberRelAxes());
return jinputDeviceList[deviceID]->getNumberRelAxes();
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: getNumButtons
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNumButtons
(JNIEnv *, jclass, jint deviceID) {
LOG_TRACE("Gettign number of buttons for jinput device %d (%d)\n", deviceID, jinputDeviceList[deviceID]->getNumberButtons());
return jinputDeviceList[deviceID]->getNumberButtons();
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: getNumberOfDevices
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNumberOfDevices
(JNIEnv *, jclass) {
return jinputNumDevices;
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: getSupportedAbsAxes
* Signature: (I[I)V
*/
JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_getSupportedAbsAxes
(JNIEnv *env, jclass, jint deviceID, jintArray axesData) {
jint *axisReturns = env->GetIntArrayElements(axesData, 0);
LOG_TRACE("Getting suported absolute axes for jinput device %d\n", deviceID);
jinputDeviceList[deviceID]->getSupportedAbsAxes(axisReturns);
env->ReleaseIntArrayElements(axesData, axisReturns, 0);
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: getSupportedRelAxes
* Signature: (I[I)V
*/
JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_getSupportedRelAxes
(JNIEnv *env, jclass, jint deviceID, jintArray axesData) {
jint *axisReturns = env->GetIntArrayElements(axesData, 0);
LOG_TRACE("Getting suported relative axes for jinput device %d\n", deviceID);
jinputDeviceList[deviceID]->getSupportedRelAxes(axisReturns);
env->ReleaseIntArrayElements(axesData, axisReturns, 0);
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: getSupportedButtons
* Signature: (I[I)V
*/
JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_getSupportedButtons
(JNIEnv *env, jclass, jint deviceID, jintArray buttonData) {
jint *buttonDataElements = env->GetIntArrayElements(buttonData, 0);
LOG_TRACE("Getting supported buttons for jinput device %d\n", deviceID);
jinputDeviceList[deviceID]->getSupportedButtons(buttonDataElements);
env->ReleaseIntArrayElements(buttonData, buttonDataElements, 0);
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: poll
* Signature: (I[I[I[I)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_poll
(JNIEnv *env, jclass, jint deviceID, jintArray buttons, jintArray relAxes, jintArray absAxes) {
jint *buttonElements = env->GetIntArrayElements(buttons, 0);
jint *relAxesElements = env->GetIntArrayElements(relAxes, 0);
jint *absAxesElements = env->GetIntArrayElements(absAxes, 0);
LOG_POLL_TRACE("Polling jinput device %d\n", deviceID);
int retval = jinputDeviceList[deviceID]->poll();
LOG_POLL_TRACE("Getting polled data for device %d\n", deviceID);
jinputDeviceList[deviceID]->getPolledData(relAxesElements, absAxesElements, buttonElements);
env->ReleaseIntArrayElements(buttons, buttonElements, 0);
env->ReleaseIntArrayElements(relAxes, relAxesElements, 0);
env->ReleaseIntArrayElements(absAxes, absAxesElements, 0);
return retval;
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: getAbsAxisFuzz
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getAbsAxisFuzz
(JNIEnv *, jclass, jint deviceID, jint axisID) {
LOG_TRACE("Getting fuzz data for axis %d on device %d\n", axisID, deviceID);
return jinputDeviceList[deviceID]->getAbsAxisFuzz(axisID);
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: getAbsAxisMaximum
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getAbsAxisMaximum
(JNIEnv *, jclass, jint deviceID, jint axisID) {
LOG_TRACE("Getting absolute axes maximum value data for axis %d on device %d\n", axisID, deviceID);
return jinputDeviceList[deviceID]->getAbsAxisMaximum(axisID);
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: getAbsAxisMinimum
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getAbsAxisMinimum
(JNIEnv *, jclass, jint deviceID, jint axisID) {
LOG_TRACE("Getting absolute axes minimum value data for axis %d on device %d\n", axisID, deviceID);
return jinputDeviceList[deviceID]->getAbsAxisMinimum(axisID);
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: getNativePortType
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNativePortType
(JNIEnv *, jclass, jint deviceID) {
LOG_TRACE("Getting bus type for device %d\n", deviceID);
return jinputDeviceList[deviceID]->getBusType();
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: getFFEnabled
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL Java_net_java_games_input_JInputLibrary_getFFEnabled
(JNIEnv *, jclass, jint deviceID) {
LOG_TRACE("Getting FFEnabled status for device %d\n", deviceID);
if(jinputDeviceList[deviceID]->getFFEnabled()) {
//LOG_TRACE("jinput lib thinks device %d is ff enabled\n", deviceID);
return JNI_TRUE;
}
//LOG_TRACE("jinput lib thinks device %d is ff disabled\n", deviceID);
return JNI_FALSE;
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: nativeRumble
* Signature: (IF)V
*/
JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_nativeRumble
(JNIEnv *, jclass, jint deviceID, jfloat force) {
if(jinputDeviceList[deviceID]!=0) {
LOG_TRACE("Setting rumble on device %d to %d\n", deviceID, force);
jinputDeviceList[deviceID]->rumble(force);
}
}
/*
* Class: net_java_games_input_JInputLibrary
* Method: nativeCleanup
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_nativeCleanup
(JNIEnv *, jclass, jint deviceID) {
if(jinputDeviceList[deviceID]!=0) {
LOG_TRACE("Cleaning up device %d\n", deviceID);
jinputDeviceList[deviceID]->cleanup();
free(jinputDeviceList[deviceID]);
jinputDeviceList[deviceID]=0;
}
}

View file

@ -1,160 +0,0 @@
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
#include <sys/dir.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/joystick.h>
#include <string.h>
#include <malloc.h>
#include <unistd.h>
#include "Device.h"
#include "JoystickDevice.h"
int jsNumDevices;
int joystickInterfaceVersion;
Device **jsDeviceList;
int jsInited = 0;
int jsFileFilter(const struct direct *entry) {
if (strncmp(entry->d_name, "js", 2) == 0) {
return 1;
}
return 0;
}
int jsGetDeviceFiles(char ***filenames) {
struct direct **files;
int num_files, i;
char dirName[12];
sprintf(dirName, "/dev/input");
num_files = scandir(dirName, &files, &jsFileFilter, alphasort);
if(num_files==0) {
sprintf(dirName, "/dev");
num_files = scandir(dirName, &files, &jsFileFilter, alphasort);
}
*filenames = (char **)malloc(num_files * sizeof(char *));
for(i=0;i<num_files;i++) {
char *filename = files[i]->d_name;
char *fullFileName;
fullFileName = (char *)malloc((strlen(dirName) + 1 + strlen(filename) + 1));
sprintf(fullFileName, "%s/%s", dirName, filename);
(*filenames)[i] = fullFileName;
}
return num_files;
}
int jsInit() {
int fd=-1;
int i;
char **deviceFileNames;
int numDeviceFiles;
numDeviceFiles = jsGetDeviceFiles(&deviceFileNames);
if(numDeviceFiles<0) {
return -1;
}
if(numDeviceFiles==0) {
jsNumDevices = 0;
jsInited=1;
return 0;
}
if ((fd = open(deviceFileNames[0], O_RDONLY)) <0) {
jsNumDevices = 0;
jsInited=1;
return 0;
}
if (ioctl(fd, JSIOCGVERSION, &joystickInterfaceVersion)) {
close(fd);
jsNumDevices = 0;
jsInited=1;
return 0;
}
if(fd>=0) {close(fd);}
Device *tempDeviceList[numDeviceFiles];
jsNumDevices = 0;
for(i=0;i<numDeviceFiles;i++) {
JoystickDevice *tempDevice = new JoystickDevice(deviceFileNames[i]);
// The device has a copy of the name, free the memory
free(deviceFileNames[i]);
if(tempDevice->isValidDevice()==1) {
tempDeviceList[i] = tempDevice;
jsNumDevices++;
}
}
int jsTempDeviceCount = 0;
// Now we know for certain which devices are open, we can take notes
jsDeviceList = (Device **)malloc(jsNumDevices * sizeof(Device *));
for(i=0;i<jsNumDevices;i++) {
while(tempDeviceList[jsTempDeviceCount] == NULL) {
jsTempDeviceCount++;
}
jsDeviceList[i] = tempDeviceList[jsTempDeviceCount];
//printf("Copied joystick %d to %d\n", jsTempDeviceCount, i);
jsTempDeviceCount++;
}
// Free the file names array, which should now be free anyway.
free(deviceFileNames);
jsInited=1;
return 0;
}
int jsGetJoystickInterfaceVersionNumber() {
return joystickInterfaceVersion;
}
int jsGetNumberDevices() {
if(jsInited) {
return jsNumDevices;
}
return -1;
}
void jsGetDevices(Device **theirDeviceList) {
int i;
for(i=0;i<jsNumDevices;i++) {
theirDeviceList[i] = jsDeviceList[i];
}
}

View file

@ -1,11 +0,0 @@
#ifdef LOGTRACE
#define LOG_TRACE(args...) printf(args)
#else
#define LOG_TRACE(args...)
#endif
#ifdef LOGPOLLTRACE
#define LOG_POLL_TRACE(args...) LOG_TRACE(args...)
#else
#define LOG_POLL_TRACE(args...)
#endif

View file

@ -1,156 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class net_java_games_input_JInputLibrary */
#ifndef _Included_net_java_games_input_JInputLibrary
#define _Included_net_java_games_input_JInputLibrary
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: inited */
/* Inaccessible static: workerThreadMonitor */
/* Inaccessible static: shutdown */
/* Inaccessible static: shutdownThreadMonitor */
/* Inaccessible static: cleanupDone */
/* Inaccessible static: rumbler */
/* Inaccessible static: force */
/*
* Class: net_java_games_input_JInputLibrary
* Method: getDeviceName
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_net_java_games_input_JInputLibrary_getDeviceName
(JNIEnv *, jclass, jint);
/*
* Class: net_java_games_input_JInputLibrary
* Method: getNumAbsAxes
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNumAbsAxes
(JNIEnv *, jclass, jint);
/*
* Class: net_java_games_input_JInputLibrary
* Method: getNumRelAxes
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNumRelAxes
(JNIEnv *, jclass, jint);
/*
* Class: net_java_games_input_JInputLibrary
* Method: getNumButtons
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNumButtons
(JNIEnv *, jclass, jint);
/*
* Class: net_java_games_input_JInputLibrary
* Method: nativeInit
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_nativeInit
(JNIEnv *, jclass);
/*
* Class: net_java_games_input_JInputLibrary
* Method: getNumberOfDevices
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNumberOfDevices
(JNIEnv *, jclass);
/*
* Class: net_java_games_input_JInputLibrary
* Method: getSupportedAbsAxes
* Signature: (I[I)V
*/
JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_getSupportedAbsAxes
(JNIEnv *, jclass, jint, jintArray);
/*
* Class: net_java_games_input_JInputLibrary
* Method: getSupportedRelAxes
* Signature: (I[I)V
*/
JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_getSupportedRelAxes
(JNIEnv *, jclass, jint, jintArray);
/*
* Class: net_java_games_input_JInputLibrary
* Method: getSupportedButtons
* Signature: (I[I)V
*/
JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_getSupportedButtons
(JNIEnv *, jclass, jint, jintArray);
/*
* Class: net_java_games_input_JInputLibrary
* Method: poll
* Signature: (I[I[I[I)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_poll
(JNIEnv *, jclass, jint, jintArray, jintArray, jintArray);
/*
* Class: net_java_games_input_JInputLibrary
* Method: getAbsAxisFuzz
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getAbsAxisFuzz
(JNIEnv *, jclass, jint, jint);
/*
* Class: net_java_games_input_JInputLibrary
* Method: getAbsAxisMaximum
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getAbsAxisMaximum
(JNIEnv *, jclass, jint, jint);
/*
* Class: net_java_games_input_JInputLibrary
* Method: getAbsAxisMinimum
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getAbsAxisMinimum
(JNIEnv *, jclass, jint, jint);
/*
* Class: net_java_games_input_JInputLibrary
* Method: getNativePortType
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNativePortType
(JNIEnv *, jclass, jint);
/*
* Class: net_java_games_input_JInputLibrary
* Method: getFFEnabled
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL Java_net_java_games_input_JInputLibrary_getFFEnabled
(JNIEnv *, jclass, jint);
/*
* Class: net_java_games_input_JInputLibrary
* Method: nativeRumble
* Signature: (IF)V
*/
JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_nativeRumble
(JNIEnv *, jclass, jint, jfloat);
/*
* Class: net_java_games_input_JInputLibrary
* Method: nativeCleanup
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_nativeCleanup
(JNIEnv *, jclass, jint);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,257 @@
/*
* %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
*
*****************************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <linux/input.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "util.h"
#include "net_java_games_input_LinuxEventDevice.h"
JNIEXPORT jlong JNICALL Java_net_java_games_input_LinuxEventDevice_nOpen(JNIEnv *env, jclass unused, jstring path, jboolean rw_flag) {
const char *path_str = (*env)->GetStringUTFChars(env, path, NULL);
if (path_str == NULL)
return -1;
int flags = rw_flag == JNI_TRUE ? O_RDWR : O_RDONLY;
flags = flags | O_NONBLOCK;
int fd = open(path_str, flags);
if (fd == -1)
throwIOException(env, "Failed to open device %s (%d)\n", path_str, errno);
(*env)->ReleaseStringUTFChars(env, path, path_str);
return fd;
}
JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nClose(JNIEnv *env, jclass unused, jlong fd_address) {
int fd = (int)fd_address;
int result = close(fd);
if (result == -1)
throwIOException(env, "Failed to close device (%d)\n", errno);
}
JNIEXPORT jstring JNICALL Java_net_java_games_input_LinuxEventDevice_nGetName(JNIEnv *env, jclass unused, jlong fd_address) {
#define BUFFER_SIZE 1024
int fd = (int)fd_address;
char device_name[BUFFER_SIZE];
if (ioctl(fd, EVIOCGNAME(BUFFER_SIZE), device_name) == -1) {
throwIOException(env, "Failed to get device name (%d)\n", errno);
return NULL;
}
jstring jstr = (*env)->NewStringUTF(env, device_name);
return jstr;
}
JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nGetKeyStates(JNIEnv *env, jclass unused, jlong fd_address, jbyteArray bits_array) {
int fd = (int)fd_address;
jsize len = (*env)->GetArrayLength(env, bits_array);
jbyte *bits = (*env)->GetByteArrayElements(env, bits_array, NULL);
if (bits == NULL)
return;
int res = ioctl(fd, EVIOCGKEY(len), bits);
(*env)->ReleaseByteArrayElements(env, bits_array, bits, 0);
if (res == -1)
throwIOException(env, "Failed to get device key states (%d)\n", errno);
}
JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nGetVersion(JNIEnv *env, jclass unused, jlong fd_address) {
int fd = (int)fd_address;
int version;
if (ioctl(fd, EVIOCGVERSION, &version) == -1) {
throwIOException(env, "Failed to get device version (%d)\n", errno);
return -1;
}
return version;
}
JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nGetNumEffects(JNIEnv *env, jclass unused, jlong fd_address) {
int fd = (int)fd_address;
int num_effects;
if (ioctl(fd, EVIOCGEFFECTS, &num_effects) == -1) {
throwIOException(env, "Failed to get number of device effects (%d)\n", errno);
return -1;
}
return num_effects;
}
JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nGetDeviceUsageBits(JNIEnv *env, jclass unused, jlong fd_address, jbyteArray usages_array) {
#if EV_VERSION >= 0x010001
int fd = (int)fd_address;
jsize len = (*env)->GetArrayLength(env, usages_array);
jbyte *usages = (*env)->GetByteArrayElements(env, usages_array, NULL);
if (usages == NULL)
return;
int res = ioctl(fd, EVIOCGUSAGE(len), usages);
(*env)->ReleaseByteArrayElements(env, usages_array, usages, 0);
if (res == -1)
throwIOException(env, "Failed to get device usages (%d)\n", errno);
#endif
}
JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nGetBits(JNIEnv *env, jclass unused, jlong fd_address, jint evtype, jbyteArray bits_array) {
int fd = (int)fd_address;
jsize len = (*env)->GetArrayLength(env, bits_array);
jbyte *bits = (*env)->GetByteArrayElements(env, bits_array, NULL);
if (bits == NULL)
return;
int res = ioctl(fd, EVIOCGBIT(evtype, len), bits);
(*env)->ReleaseByteArrayElements(env, bits_array, bits, 0);
if (res == -1)
throwIOException(env, "Failed to get device bits (%d)\n", errno);
}
JNIEXPORT jobject JNICALL Java_net_java_games_input_LinuxEventDevice_nGetInputID(JNIEnv *env, jclass unused, jlong fd_address) {
int fd = (int)fd_address;
jclass input_id_class = (*env)->FindClass(env, "net/java/games/input/LinuxInputID");
if (input_id_class == NULL)
return NULL;
jmethodID input_id_constructor = (*env)->GetMethodID(env, input_id_class, "<init>", "(IIII)V");
if (input_id_constructor == NULL)
return NULL;
struct input_id id;
int result = ioctl(fd, EVIOCGID, &id);
if (result == -1) {
throwIOException(env, "Failed to get input id for device (%d)\n", errno);
return NULL;
}
return (*env)->NewObject(env, input_id_class, input_id_constructor, (jint)id.bustype, (jint)id.vendor, (jint)id.product, (jint)id.version);
}
JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nGetAbsInfo(JNIEnv *env, jclass unused, jlong fd_address, jint abs_axis, jobject abs_info_return) {
int fd = (int)fd_address;
jclass abs_info_class = (*env)->GetObjectClass(env, abs_info_return);
if (abs_info_class == NULL)
return;
jmethodID abs_info_set = (*env)->GetMethodID(env, abs_info_class, "set", "(IIIII)V");
if (abs_info_set == NULL)
return;
struct input_absinfo abs_info;
int result = ioctl(fd, EVIOCGABS(abs_axis), &abs_info);
if (result == -1) {
throwIOException(env, "Failed to get abs info for axis (%d)\n", errno);
return;
}
(*env)->CallVoidMethod(env, abs_info_return, abs_info_set, (jint)abs_info.value, (jint)abs_info.minimum, (jint)abs_info.maximum, (jint)abs_info.fuzz, (jint)abs_info.flat);
}
JNIEXPORT jboolean JNICALL Java_net_java_games_input_LinuxEventDevice_nGetNextEvent(JNIEnv *env, jclass unused, jlong fd_address, jobject linux_event_return) {
int fd = (int)fd_address;
jclass linux_event_class = (*env)->GetObjectClass(env, linux_event_return);
if (linux_event_class == NULL)
return JNI_FALSE;
jmethodID linux_event_set = (*env)->GetMethodID(env, linux_event_class, "set", "(JJIII)V");
if (linux_event_set == NULL)
return JNI_FALSE;
struct input_event event;
if (read(fd, &event, sizeof(struct input_event)) == -1) {
if (errno == EAGAIN)
return JNI_FALSE;
throwIOException(env, "Failed to read next device event (%d)\n", errno);
return JNI_FALSE;
}
(*env)->CallVoidMethod(env, linux_event_return, linux_event_set, (jlong)event.time.tv_sec, (jlong)event.time.tv_usec, (jint)event.type, (jint)event.code, (jint)event.value);
return JNI_TRUE;
}
JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nUploadRumbleEffect(JNIEnv *env, jclass unused, jlong fd_address, jint id, jint direction, jint trigger_button, jint trigger_interval, jint replay_length, jint replay_delay, jint strong_magnitude, jint weak_magnitude) {
int fd = (int)fd_address;
struct ff_effect effect;
effect.type = FF_RUMBLE;
effect.id = id;
effect.trigger.button = trigger_button;
effect.trigger.interval = trigger_interval;
effect.replay.length = replay_length;
effect.replay.delay = replay_delay;
effect.direction = direction;
effect.u.rumble.strong_magnitude = strong_magnitude;
effect.u.rumble.weak_magnitude = weak_magnitude;
if (ioctl(fd, EVIOCSFF, &effect) == -1) {
throwIOException(env, "Failed to upload effect (%d)\n", errno);
return -1;
}
return effect.id;
}
JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nUploadConstantEffect(JNIEnv *env, jclass unused, jlong fd_address, jint id, jint direction, jint trigger_button, jint trigger_interval, jint replay_length, jint replay_delay, jint constant_level, jint constant_env_attack_length, jint constant_env_attack_level, jint constant_env_fade_length, jint constant_env_fade_level) {
int fd = (int)fd_address;
struct ff_effect effect;
effect.type = FF_CONSTANT;
effect.id = id;
effect.trigger.button = trigger_button;
effect.trigger.interval = trigger_interval;
effect.replay.length = replay_length;
effect.replay.delay = replay_delay;
effect.direction = direction;
effect.u.constant.level = constant_level;
effect.u.constant.envelope.attack_length = constant_env_attack_length;
effect.u.constant.envelope.attack_level = constant_env_attack_level;
effect.u.constant.envelope.fade_length = constant_env_fade_length;
effect.u.constant.envelope.fade_level = constant_env_fade_level;
if (ioctl(fd, EVIOCSFF, &effect) == -1) {
throwIOException(env, "Failed to upload effect (%d)\n", errno);
return -1;
}
return effect.id;
}
JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nWriteEvent(JNIEnv *env, jclass unused, jlong fd_address, jint type, jint code, jint value) {
int fd = (int)fd_address;
struct input_event event;
event.type = type;
event.code = code;
event.value = value;
if (write(fd, &event, sizeof(event)) == -1) {
throwIOException(env, "Failed to write to device (%d)\n", errno);
}
}
JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nEraseEffect(JNIEnv *env, jclass unused, jlong fd_address, jint ff_id) {
int fd = (int)fd_address;
int ff_id_int = ff_id;
if (ioctl(fd, EVIOCRMFF, &ff_id_int) == -1)
throwIOException(env, "Failed to erase effect (%d)\n", errno);
}

View file

@ -0,0 +1,128 @@
/*
* %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
*
*****************************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/joystick.h>
#include "util.h"
#include "net_java_games_input_LinuxJoystickDevice.h"
JNIEXPORT jlong JNICALL Java_net_java_games_input_LinuxJoystickDevice_nOpen(JNIEnv *env, jclass unused, jstring path) {
const char *path_str = (*env)->GetStringUTFChars(env, path, NULL);
if (path_str == NULL)
return -1;
int fd = open(path_str, O_RDONLY | O_NONBLOCK);
if (fd == -1)
throwIOException(env, "Failed to open device %s (%d)\n", path_str, errno);
(*env)->ReleaseStringUTFChars(env, path, path_str);
return fd;
}
JNIEXPORT void JNICALL Java_net_java_games_input_LinuxJoystickDevice_nClose(JNIEnv *env, jclass unused, jlong fd_address) {
int fd = (int)fd_address;
int result = close(fd);
if (result == -1)
throwIOException(env, "Failed to close device (%d)\n", errno);
}
JNIEXPORT jstring JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetName(JNIEnv *env, jclass unused, jlong fd_address) {
#define BUFFER_SIZE 1024
int fd = (int)fd_address;
char device_name[BUFFER_SIZE];
if (ioctl(fd, JSIOCGNAME(BUFFER_SIZE), device_name) == -1) {
throwIOException(env, "Failed to get device name (%d)\n", errno);
return NULL;
}
jstring jstr = (*env)->NewStringUTF(env, device_name);
return jstr;
}
JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetVersion(JNIEnv *env, jclass unused, jlong fd_address) {
int fd = (int)fd_address;
__u32 version;
if (ioctl(fd, JSIOCGVERSION, &version) == -1) {
throwIOException(env, "Failed to get device version (%d)\n", errno);
return -1;
}
return version;
}
JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetNumButtons(JNIEnv *env, jclass unused, jlong fd_address) {
int fd = (int)fd_address;
__u8 num_buttons;
if (ioctl(fd, JSIOCGBUTTONS, &num_buttons) == -1) {
throwIOException(env, "Failed to get number of buttons (%d)\n", errno);
return -1;
}
return num_buttons;
}
JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetNumAxes(JNIEnv *env, jclass unused, jlong fd_address) {
int fd = (int)fd_address;
__u8 num_axes;
if (ioctl(fd, JSIOCGAXES, &num_axes) == -1) {
throwIOException(env, "Failed to get number of buttons (%d)\n", errno);
return -1;
}
return num_axes;
}
JNIEXPORT jboolean JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetNextEvent(JNIEnv *env, jclass unused, jlong fd_address, jobject event_return) {
int fd = (int)fd_address;
jclass event_class = (*env)->GetObjectClass(env, event_return);
if (event_class == NULL)
return JNI_FALSE;
jmethodID event_set = (*env)->GetMethodID(env, event_class, "set", "(JIII)V");
if (event_set == NULL)
return JNI_FALSE;
struct js_event event;
if (read(fd, &event, sizeof(event)) == -1) {
if (errno == EAGAIN)
return JNI_FALSE;
throwIOException(env, "Failed to read next device event (%d)\n", errno);
return JNI_FALSE;
}
(*env)->CallVoidMethod(env, event_return, event_set, (jlong)event.time, (jint)event.value, (jint)event.type, (jint)event.number);
return JNI_TRUE;
}