mirror of
https://github.com/shadowfacts/jinput-arm64.git
synced 2026-04-06 23:14:20 +00:00
Linux building under maven
This commit is contained in:
parent
294629a312
commit
b2fd759065
78 changed files with 418 additions and 297 deletions
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* 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 LinuxAbsInfo {
|
||||
private int value;
|
||||
private int minimum;
|
||||
private int maximum;
|
||||
private int fuzz;
|
||||
private int flat;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return "AbsInfo: value = " + value + " | min = " + minimum + " | max = " + maximum + " | fuzz = " + fuzz + " | flat = " + flat;
|
||||
}
|
||||
|
||||
public final int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
final int getMax() {
|
||||
return maximum;
|
||||
}
|
||||
|
||||
final int getMin() {
|
||||
return minimum;
|
||||
}
|
||||
|
||||
final int getFlat() {
|
||||
return flat;
|
||||
}
|
||||
|
||||
final int getFuzz() {
|
||||
return fuzz;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* @author elias
|
||||
*/
|
||||
final class LinuxAxisDescriptor {
|
||||
private int type;
|
||||
private int code;
|
||||
|
||||
public final void set(int type, int code) {
|
||||
this.type = type;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public final int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public final int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public final int hashCode() {
|
||||
return type ^ code;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package net.java.games.input;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class LinuxCombinedController extends AbstractController {
|
||||
|
||||
private LinuxAbstractController eventController;
|
||||
private LinuxJoystickAbstractController joystickController;
|
||||
|
||||
LinuxCombinedController(LinuxAbstractController eventController, LinuxJoystickAbstractController joystickController) {
|
||||
super(eventController.getName(), joystickController.getComponents(), eventController.getControllers(), eventController.getRumblers());
|
||||
this.eventController = eventController;
|
||||
this.joystickController = joystickController;
|
||||
}
|
||||
|
||||
protected boolean getNextDeviceEvent(Event event) throws IOException {
|
||||
return joystickController.getNextDeviceEvent(event);
|
||||
}
|
||||
|
||||
public final PortType getPortType() {
|
||||
return eventController.getPortType();
|
||||
}
|
||||
|
||||
public final void pollDevice() throws IOException {
|
||||
eventController.pollDevice();
|
||||
joystickController.pollDevice();
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return eventController.getType();
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* 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 LinuxConstantFF extends LinuxForceFeedbackEffect {
|
||||
public LinuxConstantFF(LinuxEventDevice device) throws IOException {
|
||||
super(device);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
interface LinuxDevice {
|
||||
void close() throws IOException;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,499 @@
|
|||
/**
|
||||
* 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.util.plugins.Plugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
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 final class LinuxEnvironmentPlugin extends ControllerEnvironment implements Plugin {
|
||||
private final static String LIBNAME = "jinput-linux";
|
||||
private final static String POSTFIX64BIT = "64";
|
||||
private static boolean supported = false;
|
||||
|
||||
private final Controller[] controllers;
|
||||
private final List devices = new ArrayList();
|
||||
private final static LinuxDeviceThread device_thread = new LinuxDeviceThread();
|
||||
|
||||
/**
|
||||
* Static utility method for loading native libraries.
|
||||
* It will try to load from either the path given by
|
||||
* the net.java.games.input.librarypath property
|
||||
* or through System.loadLibrary().
|
||||
*
|
||||
*/
|
||||
static void loadLibrary(final String lib_name) {
|
||||
AccessController.doPrivileged(
|
||||
new PrivilegedAction() {
|
||||
public final Object run() {
|
||||
String lib_path = System.getProperty("net.java.games.input.librarypath");
|
||||
try {
|
||||
if (lib_path != null)
|
||||
System.load(lib_path + File.separator + System.mapLibraryName(lib_name));
|
||||
else
|
||||
System.loadLibrary(lib_name);
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
logln("Failed to load library: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
supported = false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static String getPrivilegedProperty(final String property) {
|
||||
return (String)AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return System.getProperty(property);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
static String getPrivilegedProperty(final String property, final String default_value) {
|
||||
return (String)AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return System.getProperty(property, default_value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static {
|
||||
String osName = getPrivilegedProperty("os.name", "").trim();
|
||||
if(osName.equals("Linux")) {
|
||||
supported = true;
|
||||
if("i386".equals(getPrivilegedProperty("os.arch"))) {
|
||||
loadLibrary(LIBNAME);
|
||||
} else {
|
||||
loadLibrary(LIBNAME + POSTFIX64BIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final static Object execute(LinuxDeviceTask task) throws IOException {
|
||||
return device_thread.execute(task);
|
||||
}
|
||||
|
||||
public LinuxEnvironmentPlugin() {
|
||||
if(isSupported()) {
|
||||
this.controllers = enumerateControllers();
|
||||
logln("Linux plugin claims to have found " + controllers.length + " controllers");
|
||||
AccessController.doPrivileged(
|
||||
new PrivilegedAction() {
|
||||
public final Object run() {
|
||||
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
controllers = new Controller[0];
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns a list of all controllers available to this environment,
|
||||
* or an empty array if there are no controllers in this environment.
|
||||
* @return Returns a list of all controllers available to this environment,
|
||||
* or an empty array if there are no controllers in this environment.
|
||||
*/
|
||||
public final Controller[] getControllers() {
|
||||
return controllers;
|
||||
}
|
||||
|
||||
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:
|
||||
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.getPrimaryButton() != 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();
|
||||
List eventControllers = new ArrayList();
|
||||
List jsControllers = new ArrayList();
|
||||
enumerateEventControllers(eventControllers);
|
||||
enumerateJoystickControllers(jsControllers);
|
||||
|
||||
for(int i=0;i<eventControllers.size();i++) {
|
||||
for(int j=0;j<jsControllers.size();j++) {
|
||||
Controller evController = (Controller) eventControllers.get(i);
|
||||
Controller jsController = (Controller) jsControllers.get(j);
|
||||
|
||||
// compare
|
||||
// Check if the nodes have the same name
|
||||
if(evController.getName().equals(jsController.getName())) {
|
||||
// Check they have the same component count
|
||||
Component[] evComponents = evController.getComponents();
|
||||
Component[] jsComponents = jsController.getComponents();
|
||||
if(evComponents.length==jsComponents.length) {
|
||||
boolean foundADifference = false;
|
||||
// check the component pairs are of the same type
|
||||
for(int k=0;k<evComponents.length;k++) {
|
||||
// Check the type of the component is the same
|
||||
if(!(evComponents[k].getIdentifier() == jsComponents[k].getIdentifier())) {
|
||||
foundADifference = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundADifference) {
|
||||
controllers.add(new LinuxCombinedController((LinuxAbstractController)eventControllers.remove(i), (LinuxJoystickAbstractController)jsControllers.remove(j)));
|
||||
i--;
|
||||
j--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
controllers.addAll(eventControllers);
|
||||
controllers.addAll(jsControllers);
|
||||
|
||||
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();
|
||||
byte[] axisMap = device.getAxisMap();
|
||||
char[] buttonMap = device.getButtonMap();
|
||||
LinuxJoystickAxis[] hatBits = new LinuxJoystickAxis[6];
|
||||
|
||||
for (int i = 0; i < device.getNumButtons(); i++) {
|
||||
Component.Identifier button_id = (Component.Identifier)LinuxNativeTypesMap.getButtonID(buttonMap[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;
|
||||
axis_id = (Component.Identifier.Axis) LinuxNativeTypesMap.getAbsAxisID(axisMap[i]);
|
||||
LinuxJoystickAxis axis = new LinuxJoystickAxis(axis_id);
|
||||
|
||||
device.registerAxis(i, axis);
|
||||
|
||||
if(axisMap[i]==NativeDefinitions.ABS_HAT0X) {
|
||||
hatBits[0] = axis;
|
||||
} else if(axisMap[i]==NativeDefinitions.ABS_HAT0Y) {
|
||||
hatBits[1] = axis;
|
||||
axis = new LinuxJoystickPOV(Component.Identifier.Axis.POV, hatBits[0], hatBits[1]);
|
||||
device.registerPOV((LinuxJoystickPOV)axis);
|
||||
components.add(axis);
|
||||
} else if(axisMap[i]==NativeDefinitions.ABS_HAT1X) {
|
||||
hatBits[2] = axis;
|
||||
} else if(axisMap[i]==NativeDefinitions.ABS_HAT1Y) {
|
||||
hatBits[3] = axis;
|
||||
axis = new LinuxJoystickPOV(Component.Identifier.Axis.POV, hatBits[2], hatBits[3]);
|
||||
device.registerPOV((LinuxJoystickPOV)axis);
|
||||
components.add(axis);
|
||||
} else if(axisMap[i]==NativeDefinitions.ABS_HAT2X) {
|
||||
hatBits[4] = axis;
|
||||
} else if(axisMap[i]==NativeDefinitions.ABS_HAT2Y) {
|
||||
hatBits[5] = axis;
|
||||
axis = new LinuxJoystickPOV(Component.Identifier.Axis.POV, hatBits[4], hatBits[5]);
|
||||
device.registerPOV((LinuxJoystickPOV)axis);
|
||||
components.add(axis);
|
||||
} else {
|
||||
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 {
|
||||
String path = getAbsolutePathPrivileged(event_file);
|
||||
LinuxJoystickDevice device = new LinuxJoystickDevice(path);
|
||||
Controller controller = createJoystickFromJoystickDevice(device);
|
||||
if (controller != null) {
|
||||
controllers.add(controller);
|
||||
devices.add(device);
|
||||
} else
|
||||
device.close();
|
||||
} catch (IOException e) {
|
||||
logln("Failed to open device (" + event_file + "): " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final static File[] enumerateJoystickDeviceFiles(final String dev_path) {
|
||||
final File dev = new File(dev_path);
|
||||
return listFilesPrivileged(dev, new FilenameFilter() {
|
||||
public final boolean accept(File dir, String name) {
|
||||
return name.startsWith("js");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static String getAbsolutePathPrivileged(final File file) {
|
||||
return (String)AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static File[] listFilesPrivileged(final File dir, final FilenameFilter filter) {
|
||||
return (File[])AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
File[] files = dir.listFiles(filter);
|
||||
Arrays.sort(files, new Comparator(){
|
||||
public int compare(Object f1, Object f2) {
|
||||
return ((File)f1).getName().compareTo(((File)f2).getName());
|
||||
}
|
||||
});
|
||||
return files;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private final void enumerateEventControllers(List controllers) {
|
||||
final File dev = new File("/dev/input");
|
||||
File[] event_device_files = listFilesPrivileged(dev, 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 {
|
||||
String path = getAbsolutePathPrivileged(event_file);
|
||||
LinuxEventDevice device = new LinuxEventDevice(path);
|
||||
try {
|
||||
Controller controller = createControllerFromDevice(device);
|
||||
if (controller != null) {
|
||||
controllers.add(controller);
|
||||
devices.add(device);
|
||||
} else
|
||||
device.close();
|
||||
} catch (IOException e) {
|
||||
logln("Failed to create Controller: " + e.getMessage());
|
||||
device.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logln("Failed to open device (" + event_file + "): " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
logln("Failed to close device: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSupported() {
|
||||
return supported;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,366 @@
|
|||
/**
|
||||
* 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 to 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;
|
||||
boolean detect_rumblers = true;
|
||||
try {
|
||||
fd = nOpen(filename, true);
|
||||
} catch (IOException e) {
|
||||
fd = nOpen(filename, false);
|
||||
detect_rumblers = false;
|
||||
}
|
||||
this.fd = fd;
|
||||
try {
|
||||
this.name = getDeviceName();
|
||||
this.input_id = getDeviceInputID();
|
||||
this.components = getDeviceComponents();
|
||||
if (detect_rumblers)
|
||||
this.rumblers = enumerateRumblers();
|
||||
else
|
||||
this.rumblers = new Rumbler[]{};
|
||||
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 {
|
||||
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) {
|
||||
LinuxEnvironmentPlugin.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;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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) {
|
||||
LinuxEnvironmentPlugin.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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 device.getNextEvent(event);
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return Controller.Type.STICK;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* %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;
|
||||
private boolean analog;
|
||||
|
||||
public LinuxJoystickAxis(Component.Identifier.Axis axis_id) {
|
||||
this(axis_id, true);
|
||||
}
|
||||
|
||||
public LinuxJoystickAxis(Component.Identifier.Axis axis_id, boolean analog) {
|
||||
super(axis_id.getName(), axis_id);
|
||||
this.analog = analog;
|
||||
}
|
||||
|
||||
public final boolean isRelative() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean isAnalog() {
|
||||
return analog;
|
||||
}
|
||||
|
||||
final void setValue(float value) {
|
||||
this.value = value;
|
||||
resetHasPolled();
|
||||
}
|
||||
|
||||
protected final float poll() throws IOException {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
@ -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_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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,239 @@
|
|||
/**
|
||||
* 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 final Map povXs = new HashMap();
|
||||
private final Map povYs = new HashMap();
|
||||
private final byte[] axisMap;
|
||||
private final char[] buttonMap;
|
||||
|
||||
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()];
|
||||
axisMap = getDeviceAxisMap();
|
||||
buttonMap = getDeviceButtonMap();
|
||||
} 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);
|
||||
if(povXs.containsKey(new Integer(index))) {
|
||||
LinuxJoystickPOV pov = (LinuxJoystickPOV)(povXs.get(new Integer(index)));
|
||||
pov.updateValue();
|
||||
event.set(pov, pov.getPollData(), joystick_event.getNanos());
|
||||
} else if(povYs.containsKey(new Integer(index))) {
|
||||
LinuxJoystickPOV pov = (LinuxJoystickPOV)(povYs.get(new Integer(index)));
|
||||
pov.updateValue();
|
||||
event.set(pov, pov.getPollData(), joystick_event.getNanos());
|
||||
} else {
|
||||
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 void registerPOV(LinuxJoystickPOV pov) {
|
||||
// The x and y on a joystick device are not the same as on an event device
|
||||
LinuxJoystickAxis xAxis = pov.getYAxis();
|
||||
LinuxJoystickAxis yAxis = pov.getXAxis();
|
||||
int xIndex;
|
||||
int yIndex;
|
||||
for(xIndex=0;xIndex<axes.length;xIndex++) {
|
||||
if(axes[xIndex]==xAxis) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(yIndex=0;yIndex<axes.length;yIndex++) {
|
||||
if(axes[yIndex]==yAxis) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
povXs.put(new Integer(xIndex),pov);
|
||||
povYs.put(new Integer(yIndex),pov);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public final byte[] getAxisMap() {
|
||||
return axisMap;
|
||||
}
|
||||
|
||||
public final char[] getButtonMap() {
|
||||
return buttonMap;
|
||||
}
|
||||
|
||||
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 byte[] getDeviceAxisMap() throws IOException {
|
||||
return nGetAxisMap(fd);
|
||||
}
|
||||
private final static native byte[] nGetAxisMap(long fd) throws IOException;
|
||||
|
||||
private final char[] getDeviceButtonMap() throws IOException {
|
||||
return nGetButtonMap(fd);
|
||||
}
|
||||
private final static native char[] nGetButtonMap(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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* 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 LinuxJoystickEvent {
|
||||
private long nanos;
|
||||
private int value;
|
||||
private int type;
|
||||
private int number;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public final int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public final int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public final int getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public final long getNanos() {
|
||||
return nanos;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package net.java.games.input;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class LinuxJoystickPOV extends LinuxJoystickAxis {
|
||||
|
||||
private LinuxJoystickAxis hatX;
|
||||
private LinuxJoystickAxis hatY;
|
||||
|
||||
LinuxJoystickPOV(Component.Identifier.Axis id, LinuxJoystickAxis hatX, LinuxJoystickAxis hatY) {
|
||||
super(id, false);
|
||||
this.hatX = hatX;
|
||||
this.hatY = hatY;
|
||||
}
|
||||
|
||||
protected LinuxJoystickAxis getXAxis() {
|
||||
return hatX;
|
||||
}
|
||||
|
||||
protected LinuxJoystickAxis getYAxis() {
|
||||
return hatY;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void updateValue() {
|
||||
float last_x = hatX.getPollData();
|
||||
float last_y = hatY.getPollData();
|
||||
|
||||
resetHasPolled();
|
||||
if (last_x == -1 && last_y == -1)
|
||||
setValue(Component.POV.UP_LEFT);
|
||||
else if (last_x == -1 && last_y == 0)
|
||||
setValue(Component.POV.LEFT);
|
||||
else if (last_x == -1 && last_y == 1)
|
||||
setValue(Component.POV.DOWN_LEFT);
|
||||
else if (last_x == 0 && last_y == -1)
|
||||
setValue(Component.POV.UP);
|
||||
else if (last_x == 0 && last_y == 0)
|
||||
setValue(Component.POV.OFF);
|
||||
else if (last_x == 0 && last_y == 1)
|
||||
setValue(Component.POV.DOWN);
|
||||
else if (last_x == 1 && last_y == -1)
|
||||
setValue(Component.POV.UP_RIGHT);
|
||||
else if (last_x == 1 && last_y == 0)
|
||||
setValue(Component.POV.RIGHT);
|
||||
else if (last_x == 1 && last_y == 1)
|
||||
setValue(Component.POV.DOWN_RIGHT);
|
||||
else {
|
||||
LinuxEnvironmentPlugin.logln("Unknown values x = " + last_x + " | y = " + last_y);
|
||||
setValue(Component.POV.OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* %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 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* %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 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,848 @@
|
|||
/**
|
||||
* 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.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Mapping utility class between native type ints and string names or
|
||||
* Key.Identifiers
|
||||
* @author Jeremy Booth (jeremy@newdawnsoftware.com)
|
||||
*/
|
||||
class LinuxNativeTypesMap {
|
||||
private static LinuxNativeTypesMap INSTANCE = new LinuxNativeTypesMap();
|
||||
private static Logger log = Logger.getLogger(LinuxNativeTypesMap.class.getName());
|
||||
|
||||
private final Component.Identifier relAxesIDs[];
|
||||
private final Component.Identifier absAxesIDs[];
|
||||
private final Component.Identifier buttonIDs[];
|
||||
|
||||
/** create an empty, uninitialsed map
|
||||
*/
|
||||
private LinuxNativeTypesMap() {
|
||||
buttonIDs = new Component.Identifier[NativeDefinitions.KEY_MAX];
|
||||
relAxesIDs = new Component.Identifier[NativeDefinitions.REL_MAX];
|
||||
absAxesIDs = new Component.Identifier[NativeDefinitions.ABS_MAX];
|
||||
reInit();
|
||||
}
|
||||
|
||||
/** Do the work.
|
||||
*/
|
||||
private void reInit() {
|
||||
buttonIDs[NativeDefinitions.KEY_ESC] = Component.Identifier.Key.ESCAPE;
|
||||
buttonIDs[NativeDefinitions.KEY_1] = Component.Identifier.Key._1;
|
||||
buttonIDs[NativeDefinitions.KEY_2] = Component.Identifier.Key._2;
|
||||
buttonIDs[NativeDefinitions.KEY_3] = Component.Identifier.Key._3;
|
||||
buttonIDs[NativeDefinitions.KEY_4] = Component.Identifier.Key._4;
|
||||
buttonIDs[NativeDefinitions.KEY_5] = Component.Identifier.Key._5;
|
||||
buttonIDs[NativeDefinitions.KEY_6] = Component.Identifier.Key._6;
|
||||
buttonIDs[NativeDefinitions.KEY_7] = Component.Identifier.Key._7;
|
||||
buttonIDs[NativeDefinitions.KEY_8] = Component.Identifier.Key._8;
|
||||
buttonIDs[NativeDefinitions.KEY_9] = Component.Identifier.Key._9;
|
||||
buttonIDs[NativeDefinitions.KEY_0] = Component.Identifier.Key._0;
|
||||
buttonIDs[NativeDefinitions.KEY_MINUS] = Component.Identifier.Key.MINUS;
|
||||
buttonIDs[NativeDefinitions.KEY_EQUAL] = Component.Identifier.Key.EQUALS;
|
||||
buttonIDs[NativeDefinitions.KEY_BACKSPACE] = Component.Identifier.Key.BACK;
|
||||
buttonIDs[NativeDefinitions.KEY_TAB] = Component.Identifier.Key.TAB;
|
||||
buttonIDs[NativeDefinitions.KEY_Q] = Component.Identifier.Key.Q;
|
||||
buttonIDs[NativeDefinitions.KEY_W] = Component.Identifier.Key.W;
|
||||
buttonIDs[NativeDefinitions.KEY_E] = Component.Identifier.Key.E;
|
||||
buttonIDs[NativeDefinitions.KEY_R] = Component.Identifier.Key.R;
|
||||
buttonIDs[NativeDefinitions.KEY_T] = Component.Identifier.Key.T;
|
||||
buttonIDs[NativeDefinitions.KEY_Y] = Component.Identifier.Key.Y;
|
||||
buttonIDs[NativeDefinitions.KEY_U] = Component.Identifier.Key.U;
|
||||
buttonIDs[NativeDefinitions.KEY_I] = Component.Identifier.Key.I;
|
||||
buttonIDs[NativeDefinitions.KEY_O] = Component.Identifier.Key.O;
|
||||
buttonIDs[NativeDefinitions.KEY_P] = Component.Identifier.Key.P;
|
||||
buttonIDs[NativeDefinitions.KEY_LEFTBRACE] = Component.Identifier.Key.LBRACKET;
|
||||
buttonIDs[NativeDefinitions.KEY_RIGHTBRACE] = Component.Identifier.Key.RBRACKET;
|
||||
buttonIDs[NativeDefinitions.KEY_ENTER] = Component.Identifier.Key.RETURN;
|
||||
buttonIDs[NativeDefinitions.KEY_LEFTCTRL] = Component.Identifier.Key.LCONTROL;
|
||||
buttonIDs[NativeDefinitions.KEY_A] = Component.Identifier.Key.A;
|
||||
buttonIDs[NativeDefinitions.KEY_S] = Component.Identifier.Key.S;
|
||||
buttonIDs[NativeDefinitions.KEY_D] = Component.Identifier.Key.D;
|
||||
buttonIDs[NativeDefinitions.KEY_F] = Component.Identifier.Key.F;
|
||||
buttonIDs[NativeDefinitions.KEY_G] = Component.Identifier.Key.G;
|
||||
buttonIDs[NativeDefinitions.KEY_H] = Component.Identifier.Key.H;
|
||||
buttonIDs[NativeDefinitions.KEY_J] = Component.Identifier.Key.J;
|
||||
buttonIDs[NativeDefinitions.KEY_K] = Component.Identifier.Key.K;
|
||||
buttonIDs[NativeDefinitions.KEY_L] = Component.Identifier.Key.L;
|
||||
buttonIDs[NativeDefinitions.KEY_SEMICOLON] = Component.Identifier.Key.SEMICOLON;
|
||||
buttonIDs[NativeDefinitions.KEY_APOSTROPHE] = Component.Identifier.Key.APOSTROPHE;
|
||||
buttonIDs[NativeDefinitions.KEY_GRAVE] = Component.Identifier.Key.GRAVE;
|
||||
buttonIDs[NativeDefinitions.KEY_LEFTSHIFT] = Component.Identifier.Key.LSHIFT;
|
||||
buttonIDs[NativeDefinitions.KEY_BACKSLASH] = Component.Identifier.Key.BACKSLASH;
|
||||
buttonIDs[NativeDefinitions.KEY_Z] = Component.Identifier.Key.Z;
|
||||
buttonIDs[NativeDefinitions.KEY_X] = Component.Identifier.Key.X;
|
||||
buttonIDs[NativeDefinitions.KEY_C] = Component.Identifier.Key.C;
|
||||
buttonIDs[NativeDefinitions.KEY_V] = Component.Identifier.Key.V;
|
||||
buttonIDs[NativeDefinitions.KEY_B] = Component.Identifier.Key.B;
|
||||
buttonIDs[NativeDefinitions.KEY_N] = Component.Identifier.Key.N;
|
||||
buttonIDs[NativeDefinitions.KEY_M] = Component.Identifier.Key.M;
|
||||
buttonIDs[NativeDefinitions.KEY_COMMA] = Component.Identifier.Key.COMMA;
|
||||
buttonIDs[NativeDefinitions.KEY_DOT] = Component.Identifier.Key.PERIOD;
|
||||
buttonIDs[NativeDefinitions.KEY_SLASH] = Component.Identifier.Key.SLASH;
|
||||
buttonIDs[NativeDefinitions.KEY_RIGHTSHIFT] = Component.Identifier.Key.RSHIFT;
|
||||
buttonIDs[NativeDefinitions.KEY_KPASTERISK] = Component.Identifier.Key.MULTIPLY;
|
||||
buttonIDs[NativeDefinitions.KEY_LEFTALT] = Component.Identifier.Key.LALT;
|
||||
buttonIDs[NativeDefinitions.KEY_SPACE] = Component.Identifier.Key.SPACE;
|
||||
buttonIDs[NativeDefinitions.KEY_CAPSLOCK] = Component.Identifier.Key.CAPITAL;
|
||||
buttonIDs[NativeDefinitions.KEY_F1] = Component.Identifier.Key.F1;
|
||||
buttonIDs[NativeDefinitions.KEY_F2] = Component.Identifier.Key.F2;
|
||||
buttonIDs[NativeDefinitions.KEY_F3] = Component.Identifier.Key.F3;
|
||||
buttonIDs[NativeDefinitions.KEY_F4] = Component.Identifier.Key.F4;
|
||||
buttonIDs[NativeDefinitions.KEY_F5] = Component.Identifier.Key.F5;
|
||||
buttonIDs[NativeDefinitions.KEY_F6] = Component.Identifier.Key.F6;
|
||||
buttonIDs[NativeDefinitions.KEY_F7] = Component.Identifier.Key.F7;
|
||||
buttonIDs[NativeDefinitions.KEY_F8] = Component.Identifier.Key.F8;
|
||||
buttonIDs[NativeDefinitions.KEY_F9] = Component.Identifier.Key.F9;
|
||||
buttonIDs[NativeDefinitions.KEY_F10] = Component.Identifier.Key.F10;
|
||||
buttonIDs[NativeDefinitions.KEY_NUMLOCK] = Component.Identifier.Key.NUMLOCK;
|
||||
buttonIDs[NativeDefinitions.KEY_SCROLLLOCK] = Component.Identifier.Key.SCROLL;
|
||||
buttonIDs[NativeDefinitions.KEY_KP7] = Component.Identifier.Key.NUMPAD7;
|
||||
buttonIDs[NativeDefinitions.KEY_KP8] = Component.Identifier.Key.NUMPAD8;
|
||||
buttonIDs[NativeDefinitions.KEY_KP9] = Component.Identifier.Key.NUMPAD9;
|
||||
buttonIDs[NativeDefinitions.KEY_KPMINUS] = Component.Identifier.Key.SUBTRACT;
|
||||
buttonIDs[NativeDefinitions.KEY_KP4] = Component.Identifier.Key.NUMPAD4;
|
||||
buttonIDs[NativeDefinitions.KEY_KP5] = Component.Identifier.Key.NUMPAD5;
|
||||
buttonIDs[NativeDefinitions.KEY_KP6] = Component.Identifier.Key.NUMPAD6;
|
||||
buttonIDs[NativeDefinitions.KEY_KPPLUS] = Component.Identifier.Key.ADD;
|
||||
buttonIDs[NativeDefinitions.KEY_KP1] = Component.Identifier.Key.NUMPAD1;
|
||||
buttonIDs[NativeDefinitions.KEY_KP2] = Component.Identifier.Key.NUMPAD2;
|
||||
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_F13] = Component.Identifier.Key.F13;
|
||||
buttonIDs[NativeDefinitions.KEY_102ND] = null;
|
||||
buttonIDs[NativeDefinitions.KEY_F11] = Component.Identifier.Key.F11;
|
||||
buttonIDs[NativeDefinitions.KEY_F12] = Component.Identifier.Key.F12;
|
||||
buttonIDs[NativeDefinitions.KEY_F14] = Component.Identifier.Key.F14;
|
||||
buttonIDs[NativeDefinitions.KEY_F15] = Component.Identifier.Key.F15;
|
||||
buttonIDs[NativeDefinitions.KEY_F16] = null;
|
||||
buttonIDs[NativeDefinitions.KEY_F17] = null;
|
||||
buttonIDs[NativeDefinitions.KEY_F18] = null;
|
||||
buttonIDs[NativeDefinitions.KEY_F19] = null;
|
||||
buttonIDs[NativeDefinitions.KEY_F20] = null;
|
||||
buttonIDs[NativeDefinitions.KEY_KPENTER] = Component.Identifier.Key.NUMPADENTER;
|
||||
buttonIDs[NativeDefinitions.KEY_RIGHTCTRL] = Component.Identifier.Key.RCONTROL;
|
||||
buttonIDs[NativeDefinitions.KEY_KPSLASH] = Component.Identifier.Key.DIVIDE;
|
||||
buttonIDs[NativeDefinitions.KEY_SYSRQ] = Component.Identifier.Key.SYSRQ;
|
||||
buttonIDs[NativeDefinitions.KEY_RIGHTALT] = Component.Identifier.Key.RALT;
|
||||
buttonIDs[NativeDefinitions.KEY_LINEFEED] = null;
|
||||
buttonIDs[NativeDefinitions.KEY_HOME] = Component.Identifier.Key.HOME;
|
||||
buttonIDs[NativeDefinitions.KEY_UP] = Component.Identifier.Key.UP;
|
||||
buttonIDs[NativeDefinitions.KEY_PAGEUP] = Component.Identifier.Key.PAGEUP;
|
||||
buttonIDs[NativeDefinitions.KEY_LEFT] = Component.Identifier.Key.LEFT;
|
||||
buttonIDs[NativeDefinitions.KEY_RIGHT] = Component.Identifier.Key.RIGHT;
|
||||
buttonIDs[NativeDefinitions.KEY_END] = Component.Identifier.Key.END;
|
||||
buttonIDs[NativeDefinitions.KEY_DOWN] = Component.Identifier.Key.DOWN;
|
||||
buttonIDs[NativeDefinitions.KEY_PAGEDOWN] = Component.Identifier.Key.PAGEDOWN;
|
||||
buttonIDs[NativeDefinitions.KEY_INSERT] = Component.Identifier.Key.INSERT;
|
||||
buttonIDs[NativeDefinitions.KEY_DELETE] = Component.Identifier.Key.DELETE;
|
||||
buttonIDs[NativeDefinitions.KEY_PAUSE] = Component.Identifier.Key.PAUSE;
|
||||
/* buttonIDs[NativeDefinitions.KEY_MACRO] = "Macro";
|
||||
buttonIDs[NativeDefinitions.KEY_MUTE] = "Mute";
|
||||
buttonIDs[NativeDefinitions.KEY_VOLUMEDOWN] = "Volume Down";
|
||||
buttonIDs[NativeDefinitions.KEY_VOLUMEUP] = "Volume Up";
|
||||
buttonIDs[NativeDefinitions.KEY_POWER] = "Power";*/
|
||||
buttonIDs[NativeDefinitions.KEY_KPEQUAL] = Component.Identifier.Key.NUMPADEQUAL;
|
||||
//buttonIDs[NativeDefinitions.KEY_KPPLUSMINUS] = "KeyPad +/-";
|
||||
/* buttonIDs[NativeDefinitions.KEY_F21] = "F21";
|
||||
buttonIDs[NativeDefinitions.KEY_F22] = "F22";
|
||||
buttonIDs[NativeDefinitions.KEY_F23] = "F23";
|
||||
buttonIDs[NativeDefinitions.KEY_F24] = "F24";
|
||||
buttonIDs[NativeDefinitions.KEY_KPCOMMA] = "KeyPad comma";
|
||||
buttonIDs[NativeDefinitions.KEY_LEFTMETA] = "LH Meta";
|
||||
buttonIDs[NativeDefinitions.KEY_RIGHTMETA] = "RH Meta";
|
||||
buttonIDs[NativeDefinitions.KEY_COMPOSE] = "Compose";
|
||||
buttonIDs[NativeDefinitions.KEY_STOP] = "Stop";
|
||||
buttonIDs[NativeDefinitions.KEY_AGAIN] = "Again";
|
||||
buttonIDs[NativeDefinitions.KEY_PROPS] = "Properties";
|
||||
buttonIDs[NativeDefinitions.KEY_UNDO] = "Undo";
|
||||
buttonIDs[NativeDefinitions.KEY_FRONT] = "Front";
|
||||
buttonIDs[NativeDefinitions.KEY_COPY] = "Copy";
|
||||
buttonIDs[NativeDefinitions.KEY_OPEN] = "Open";
|
||||
buttonIDs[NativeDefinitions.KEY_PASTE] = "Paste";
|
||||
buttonIDs[NativeDefinitions.KEY_FIND] = "Find";
|
||||
buttonIDs[NativeDefinitions.KEY_CUT] = "Cut";
|
||||
buttonIDs[NativeDefinitions.KEY_HELP] = "Help";
|
||||
buttonIDs[NativeDefinitions.KEY_MENU] = "Menu";
|
||||
buttonIDs[NativeDefinitions.KEY_CALC] = "Calculator";
|
||||
buttonIDs[NativeDefinitions.KEY_SETUP] = "Setup";*/
|
||||
buttonIDs[NativeDefinitions.KEY_SLEEP] = Component.Identifier.Key.SLEEP;
|
||||
/*buttonIDs[NativeDefinitions.KEY_WAKEUP] = "Wakeup";
|
||||
buttonIDs[NativeDefinitions.KEY_FILE] = "File";
|
||||
buttonIDs[NativeDefinitions.KEY_SENDFILE] = "Send File";
|
||||
buttonIDs[NativeDefinitions.KEY_DELETEFILE] = "Delete File";
|
||||
buttonIDs[NativeDefinitions.KEY_XFER] = "Transfer";
|
||||
buttonIDs[NativeDefinitions.KEY_PROG1] = "Program 1";
|
||||
buttonIDs[NativeDefinitions.KEY_PROG2] = "Program 2";
|
||||
buttonIDs[NativeDefinitions.KEY_WWW] = "Web Browser";
|
||||
buttonIDs[NativeDefinitions.KEY_MSDOS] = "DOS mode";
|
||||
buttonIDs[NativeDefinitions.KEY_COFFEE] = "Coffee";
|
||||
buttonIDs[NativeDefinitions.KEY_DIRECTION] = "Direction";
|
||||
buttonIDs[NativeDefinitions.KEY_CYCLEWINDOWS] = "Window cycle";
|
||||
buttonIDs[NativeDefinitions.KEY_MAIL] = "Mail";
|
||||
buttonIDs[NativeDefinitions.KEY_BOOKMARKS] = "Book Marks";
|
||||
buttonIDs[NativeDefinitions.KEY_COMPUTER] = "Computer";
|
||||
buttonIDs[NativeDefinitions.KEY_BACK] = "Back";
|
||||
buttonIDs[NativeDefinitions.KEY_FORWARD] = "Forward";
|
||||
buttonIDs[NativeDefinitions.KEY_CLOSECD] = "Close CD";
|
||||
buttonIDs[NativeDefinitions.KEY_EJECTCD] = "Eject CD";
|
||||
buttonIDs[NativeDefinitions.KEY_EJECTCLOSECD] = "Eject / Close CD";
|
||||
buttonIDs[NativeDefinitions.KEY_NEXTSONG] = "Next Song";
|
||||
buttonIDs[NativeDefinitions.KEY_PLAYPAUSE] = "Play and Pause";
|
||||
buttonIDs[NativeDefinitions.KEY_PREVIOUSSONG] = "Previous Song";
|
||||
buttonIDs[NativeDefinitions.KEY_STOPCD] = "Stop CD";
|
||||
buttonIDs[NativeDefinitions.KEY_RECORD] = "Record";
|
||||
buttonIDs[NativeDefinitions.KEY_REWIND] = "Rewind";
|
||||
buttonIDs[NativeDefinitions.KEY_PHONE] = "Phone";
|
||||
buttonIDs[NativeDefinitions.KEY_ISO] = "ISO";
|
||||
buttonIDs[NativeDefinitions.KEY_CONFIG] = "Config";
|
||||
buttonIDs[NativeDefinitions.KEY_HOMEPAGE] = "Home";
|
||||
buttonIDs[NativeDefinitions.KEY_REFRESH] = "Refresh";
|
||||
buttonIDs[NativeDefinitions.KEY_EXIT] = "Exit";
|
||||
buttonIDs[NativeDefinitions.KEY_MOVE] = "Move";
|
||||
buttonIDs[NativeDefinitions.KEY_EDIT] = "Edit";
|
||||
buttonIDs[NativeDefinitions.KEY_SCROLLUP] = "Scroll Up";
|
||||
buttonIDs[NativeDefinitions.KEY_SCROLLDOWN] = "Scroll Down";
|
||||
buttonIDs[NativeDefinitions.KEY_KPLEFTPAREN] = "KeyPad LH parenthesis";
|
||||
buttonIDs[NativeDefinitions.KEY_KPRIGHTPAREN] = "KeyPad RH parenthesis";
|
||||
buttonIDs[NativeDefinitions.KEY_INTL1] = "Intl 1";
|
||||
buttonIDs[NativeDefinitions.KEY_INTL2] = "Intl 2";
|
||||
buttonIDs[NativeDefinitions.KEY_INTL3] = "Intl 3";
|
||||
buttonIDs[NativeDefinitions.KEY_INTL4] = "Intl 4";
|
||||
buttonIDs[NativeDefinitions.KEY_INTL5] = "Intl 5";
|
||||
buttonIDs[NativeDefinitions.KEY_INTL6] = "Intl 6";
|
||||
buttonIDs[NativeDefinitions.KEY_INTL7] = "Intl 7";
|
||||
buttonIDs[NativeDefinitions.KEY_INTL8] = "Intl 8";
|
||||
buttonIDs[NativeDefinitions.KEY_INTL9] = "Intl 9";
|
||||
buttonIDs[NativeDefinitions.KEY_LANG1] = "Language 1";
|
||||
buttonIDs[NativeDefinitions.KEY_LANG2] = "Language 2";
|
||||
buttonIDs[NativeDefinitions.KEY_LANG3] = "Language 3";
|
||||
buttonIDs[NativeDefinitions.KEY_LANG4] = "Language 4";
|
||||
buttonIDs[NativeDefinitions.KEY_LANG5] = "Language 5";
|
||||
buttonIDs[NativeDefinitions.KEY_LANG6] = "Language 6";
|
||||
buttonIDs[NativeDefinitions.KEY_LANG7] = "Language 7";
|
||||
buttonIDs[NativeDefinitions.KEY_LANG8] = "Language 8";
|
||||
buttonIDs[NativeDefinitions.KEY_LANG9] = "Language 9";
|
||||
buttonIDs[NativeDefinitions.KEY_PLAYCD] = "Play CD";
|
||||
buttonIDs[NativeDefinitions.KEY_PAUSECD] = "Pause CD";
|
||||
buttonIDs[NativeDefinitions.KEY_PROG3] = "Program 3";
|
||||
buttonIDs[NativeDefinitions.KEY_PROG4] = "Program 4";
|
||||
buttonIDs[NativeDefinitions.KEY_SUSPEND] = "Suspend";
|
||||
buttonIDs[NativeDefinitions.KEY_CLOSE] = "Close";*/
|
||||
buttonIDs[NativeDefinitions.KEY_UNKNOWN] = Component.Identifier.Key.UNLABELED;
|
||||
/*buttonIDs[NativeDefinitions.KEY_BRIGHTNESSDOWN] = "Brightness Down";
|
||||
buttonIDs[NativeDefinitions.KEY_BRIGHTNESSUP] = "Brightness Up";*/
|
||||
|
||||
//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;
|
||||
buttonIDs[NativeDefinitions.BTN_3] = Component.Identifier.Button._3;
|
||||
buttonIDs[NativeDefinitions.BTN_4] = Component.Identifier.Button._4;
|
||||
buttonIDs[NativeDefinitions.BTN_5] = Component.Identifier.Button._5;
|
||||
buttonIDs[NativeDefinitions.BTN_6] = Component.Identifier.Button._6;
|
||||
buttonIDs[NativeDefinitions.BTN_7] = Component.Identifier.Button._7;
|
||||
buttonIDs[NativeDefinitions.BTN_8] = Component.Identifier.Button._8;
|
||||
buttonIDs[NativeDefinitions.BTN_9] = Component.Identifier.Button._9;
|
||||
|
||||
// Mouse
|
||||
buttonIDs[NativeDefinitions.BTN_LEFT] = Component.Identifier.Button.LEFT;
|
||||
buttonIDs[NativeDefinitions.BTN_RIGHT] = Component.Identifier.Button.RIGHT;
|
||||
buttonIDs[NativeDefinitions.BTN_MIDDLE] = Component.Identifier.Button.MIDDLE;
|
||||
buttonIDs[NativeDefinitions.BTN_SIDE] = Component.Identifier.Button.SIDE;
|
||||
buttonIDs[NativeDefinitions.BTN_EXTRA] = Component.Identifier.Button.EXTRA;
|
||||
buttonIDs[NativeDefinitions.BTN_FORWARD] = Component.Identifier.Button.FORWARD;
|
||||
buttonIDs[NativeDefinitions.BTN_BACK] = Component.Identifier.Button.BACK;
|
||||
|
||||
// Joystick
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER] = Component.Identifier.Button.TRIGGER;
|
||||
buttonIDs[NativeDefinitions.BTN_THUMB] = Component.Identifier.Button.THUMB;
|
||||
buttonIDs[NativeDefinitions.BTN_THUMB2] = Component.Identifier.Button.THUMB2;
|
||||
buttonIDs[NativeDefinitions.BTN_TOP] = Component.Identifier.Button.TOP;
|
||||
buttonIDs[NativeDefinitions.BTN_TOP2] = Component.Identifier.Button.TOP2;
|
||||
buttonIDs[NativeDefinitions.BTN_PINKIE] = Component.Identifier.Button.PINKIE;
|
||||
buttonIDs[NativeDefinitions.BTN_BASE] = Component.Identifier.Button.BASE;
|
||||
buttonIDs[NativeDefinitions.BTN_BASE2] = Component.Identifier.Button.BASE2;
|
||||
buttonIDs[NativeDefinitions.BTN_BASE3] = Component.Identifier.Button.BASE3;
|
||||
buttonIDs[NativeDefinitions.BTN_BASE4] = Component.Identifier.Button.BASE4;
|
||||
buttonIDs[NativeDefinitions.BTN_BASE5] = Component.Identifier.Button.BASE5;
|
||||
buttonIDs[NativeDefinitions.BTN_BASE6] = Component.Identifier.Button.BASE6;
|
||||
buttonIDs[NativeDefinitions.BTN_DEAD] = Component.Identifier.Button.DEAD;
|
||||
|
||||
// Gamepad
|
||||
buttonIDs[NativeDefinitions.BTN_A] = Component.Identifier.Button.A;
|
||||
buttonIDs[NativeDefinitions.BTN_B] = Component.Identifier.Button.B;
|
||||
buttonIDs[NativeDefinitions.BTN_C] = Component.Identifier.Button.C;
|
||||
buttonIDs[NativeDefinitions.BTN_X] = Component.Identifier.Button.X;
|
||||
buttonIDs[NativeDefinitions.BTN_Y] = Component.Identifier.Button.Y;
|
||||
buttonIDs[NativeDefinitions.BTN_Z] = Component.Identifier.Button.Z;
|
||||
buttonIDs[NativeDefinitions.BTN_TL] = Component.Identifier.Button.LEFT_THUMB;
|
||||
buttonIDs[NativeDefinitions.BTN_TR] = Component.Identifier.Button.RIGHT_THUMB;
|
||||
buttonIDs[NativeDefinitions.BTN_TL2] = Component.Identifier.Button.LEFT_THUMB2;
|
||||
buttonIDs[NativeDefinitions.BTN_TR2] = Component.Identifier.Button.RIGHT_THUMB2;
|
||||
buttonIDs[NativeDefinitions.BTN_SELECT] = Component.Identifier.Button.SELECT;
|
||||
buttonIDs[NativeDefinitions.BTN_START] = Component.Identifier.Button.START;
|
||||
buttonIDs[NativeDefinitions.BTN_MODE] = Component.Identifier.Button.MODE;
|
||||
buttonIDs[NativeDefinitions.BTN_THUMBL] = Component.Identifier.Button.LEFT_THUMB3;
|
||||
buttonIDs[NativeDefinitions.BTN_THUMBR] = Component.Identifier.Button.RIGHT_THUMB3;
|
||||
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY1] = Component.Identifier.Button.EXTRA_1;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY2] = Component.Identifier.Button.EXTRA_2;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY3] = Component.Identifier.Button.EXTRA_3;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY4] = Component.Identifier.Button.EXTRA_4;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY5] = Component.Identifier.Button.EXTRA_5;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY6] = Component.Identifier.Button.EXTRA_6;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY7] = Component.Identifier.Button.EXTRA_7;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY8] = Component.Identifier.Button.EXTRA_8;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY9] = Component.Identifier.Button.EXTRA_9;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY10] = Component.Identifier.Button.EXTRA_10;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY11] = Component.Identifier.Button.EXTRA_11;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY12] = Component.Identifier.Button.EXTRA_12;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY13] = Component.Identifier.Button.EXTRA_13;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY14] = Component.Identifier.Button.EXTRA_14;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY15] = Component.Identifier.Button.EXTRA_15;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY16] = Component.Identifier.Button.EXTRA_16;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY17] = Component.Identifier.Button.EXTRA_17;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY18] = Component.Identifier.Button.EXTRA_18;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY19] = Component.Identifier.Button.EXTRA_19;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY20] = Component.Identifier.Button.EXTRA_20;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY21] = Component.Identifier.Button.EXTRA_21;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY22] = Component.Identifier.Button.EXTRA_22;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY23] = Component.Identifier.Button.EXTRA_23;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY24] = Component.Identifier.Button.EXTRA_24;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY25] = Component.Identifier.Button.EXTRA_25;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY26] = Component.Identifier.Button.EXTRA_26;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY27] = Component.Identifier.Button.EXTRA_27;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY28] = Component.Identifier.Button.EXTRA_28;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY29] = Component.Identifier.Button.EXTRA_29;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY30] = Component.Identifier.Button.EXTRA_30;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY31] = Component.Identifier.Button.EXTRA_31;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY32] = Component.Identifier.Button.EXTRA_32;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY33] = Component.Identifier.Button.EXTRA_33;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY34] = Component.Identifier.Button.EXTRA_34;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY35] = Component.Identifier.Button.EXTRA_35;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY36] = Component.Identifier.Button.EXTRA_36;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY37] = Component.Identifier.Button.EXTRA_37;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY38] = Component.Identifier.Button.EXTRA_38;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY39] = Component.Identifier.Button.EXTRA_39;
|
||||
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY40] = Component.Identifier.Button.EXTRA_40;
|
||||
|
||||
// Digitiser
|
||||
buttonIDs[NativeDefinitions.BTN_TOOL_PEN] = Component.Identifier.Button.TOOL_PEN;
|
||||
buttonIDs[NativeDefinitions.BTN_TOOL_RUBBER] = Component.Identifier.Button.TOOL_RUBBER;
|
||||
buttonIDs[NativeDefinitions.BTN_TOOL_BRUSH] = Component.Identifier.Button.TOOL_BRUSH;
|
||||
buttonIDs[NativeDefinitions.BTN_TOOL_PENCIL] = Component.Identifier.Button.TOOL_PENCIL;
|
||||
buttonIDs[NativeDefinitions.BTN_TOOL_AIRBRUSH] = Component.Identifier.Button.TOOL_AIRBRUSH;
|
||||
buttonIDs[NativeDefinitions.BTN_TOOL_FINGER] = Component.Identifier.Button.TOOL_FINGER;
|
||||
buttonIDs[NativeDefinitions.BTN_TOOL_MOUSE] = Component.Identifier.Button.TOOL_MOUSE;
|
||||
buttonIDs[NativeDefinitions.BTN_TOOL_LENS] = Component.Identifier.Button.TOOL_LENS;
|
||||
buttonIDs[NativeDefinitions.BTN_TOUCH] = Component.Identifier.Button.TOUCH;
|
||||
buttonIDs[NativeDefinitions.BTN_STYLUS] = Component.Identifier.Button.STYLUS;
|
||||
buttonIDs[NativeDefinitions.BTN_STYLUS2] = Component.Identifier.Button.STYLUS2;
|
||||
|
||||
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.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;
|
||||
|
||||
absAxesIDs[NativeDefinitions.ABS_X] = Component.Identifier.Axis.X;
|
||||
absAxesIDs[NativeDefinitions.ABS_Y] = Component.Identifier.Axis.Y;
|
||||
absAxesIDs[NativeDefinitions.ABS_Z] = Component.Identifier.Axis.Z;
|
||||
absAxesIDs[NativeDefinitions.ABS_RX] = Component.Identifier.Axis.RX;
|
||||
absAxesIDs[NativeDefinitions.ABS_RY] = Component.Identifier.Axis.RY;
|
||||
absAxesIDs[NativeDefinitions.ABS_RZ] = Component.Identifier.Axis.RZ;
|
||||
absAxesIDs[NativeDefinitions.ABS_THROTTLE] = Component.Identifier.Axis.SLIDER;
|
||||
absAxesIDs[NativeDefinitions.ABS_RUDDER] = Component.Identifier.Axis.RZ;
|
||||
absAxesIDs[NativeDefinitions.ABS_WHEEL] = Component.Identifier.Axis.Y;
|
||||
absAxesIDs[NativeDefinitions.ABS_GAS] = Component.Identifier.Axis.SLIDER;
|
||||
absAxesIDs[NativeDefinitions.ABS_BRAKE] = Component.Identifier.Axis.SLIDER;
|
||||
// Hats are done this way as they are mapped from two axis down to one
|
||||
absAxesIDs[NativeDefinitions.ABS_HAT0X] = Component.Identifier.Axis.POV;
|
||||
absAxesIDs[NativeDefinitions.ABS_HAT0Y] = Component.Identifier.Axis.POV;
|
||||
absAxesIDs[NativeDefinitions.ABS_HAT1X] = Component.Identifier.Axis.POV;
|
||||
absAxesIDs[NativeDefinitions.ABS_HAT1Y] = Component.Identifier.Axis.POV;
|
||||
absAxesIDs[NativeDefinitions.ABS_HAT2X] = Component.Identifier.Axis.POV;
|
||||
absAxesIDs[NativeDefinitions.ABS_HAT2Y] = Component.Identifier.Axis.POV;
|
||||
absAxesIDs[NativeDefinitions.ABS_HAT3X] = Component.Identifier.Axis.POV;
|
||||
absAxesIDs[NativeDefinitions.ABS_HAT3Y] = Component.Identifier.Axis.POV;
|
||||
// erm, yeah
|
||||
absAxesIDs[NativeDefinitions.ABS_PRESSURE] = null;
|
||||
absAxesIDs[NativeDefinitions.ABS_DISTANCE] = null;
|
||||
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_START :
|
||||
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
|
||||
*/
|
||||
public static Controller.PortType getPortType(int nativeid) {
|
||||
// Have to do this one this way as there is no BUS_MAX
|
||||
switch (nativeid) {
|
||||
case NativeDefinitions.BUS_GAMEPORT :
|
||||
return Controller.PortType.GAME;
|
||||
case NativeDefinitions.BUS_I8042 :
|
||||
return Controller.PortType.I8042;
|
||||
case NativeDefinitions.BUS_PARPORT :
|
||||
return Controller.PortType.PARALLEL;
|
||||
case NativeDefinitions.BUS_RS232 :
|
||||
return Controller.PortType.SERIAL;
|
||||
case NativeDefinitions.BUS_USB :
|
||||
return Controller.PortType.USB;
|
||||
default:
|
||||
return Controller.PortType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the identifier for a relative axis
|
||||
* @param nativeID The axis type ID
|
||||
* @return The jinput id
|
||||
*/
|
||||
public static Component.Identifier getRelAxisID(int nativeID) {
|
||||
Component.Identifier retval = null;
|
||||
try {
|
||||
retval = INSTANCE.relAxesIDs[nativeID];
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
log.warning("INSTANCE.relAxesIDis only " + INSTANCE.relAxesIDs.length + " long, so " + nativeID + " not contained");
|
||||
//ignore, pretend it was null
|
||||
}
|
||||
if(retval == null) {
|
||||
retval = Component.Identifier.Axis.SLIDER_VELOCITY;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** Gets the identifier for a absolute axis
|
||||
* @param nativeID The native axis type id
|
||||
* @return The jinput id
|
||||
*/
|
||||
public static Component.Identifier getAbsAxisID(int nativeID) {
|
||||
Component.Identifier retval = null;
|
||||
try {
|
||||
retval = INSTANCE.absAxesIDs[nativeID];
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
log.warning("INSTANCE.absAxesIDs is only " + INSTANCE.absAxesIDs.length + " long, so " + nativeID + " not contained");
|
||||
//ignore, pretend it was null
|
||||
}
|
||||
if(retval == null) {
|
||||
retval = Component.Identifier.Axis.SLIDER;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** Gets the identifier for a button
|
||||
* @param nativeID The native button type id
|
||||
* @return The jinput id
|
||||
*/
|
||||
public static Component.Identifier getButtonID(int nativeID) {
|
||||
Component.Identifier retval = null;
|
||||
try {
|
||||
retval = INSTANCE.buttonIDs[nativeID];
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
log.warning("INSTANCE.buttonIDs is only " + INSTANCE.buttonIDs.length + " long, so " + nativeID + " not contained");
|
||||
//ignore, pretend it was null
|
||||
}
|
||||
if(retval == null) {
|
||||
retval = Component.Identifier.Button.UNKNOWN;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
|
@ -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 {
|
||||
LinuxEnvironmentPlugin.logln("Unknown values x = " + last_x + " | y = " + last_y);
|
||||
return Component.POV.OFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,634 @@
|
|||
package net.java.games.input;
|
||||
|
||||
|
||||
/**
|
||||
* This file is generated from /usr/src/linux-headers-3.2.0-38-generic/include/linux/input.h please do not edit
|
||||
*/
|
||||
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_SW = 0x05;
|
||||
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 EV_CNT = (EV_MAX+1);
|
||||
public static final int KEY_RESERVED = 0;
|
||||
public static final int KEY_ESC = 1;
|
||||
public static final int KEY_1 = 2;
|
||||
public static final int KEY_2 = 3;
|
||||
public static final int KEY_3 = 4;
|
||||
public static final int KEY_4 = 5;
|
||||
public static final int KEY_5 = 6;
|
||||
public static final int KEY_6 = 7;
|
||||
public static final int KEY_7 = 8;
|
||||
public static final int KEY_8 = 9;
|
||||
public static final int KEY_9 = 10;
|
||||
public static final int KEY_0 = 11;
|
||||
public static final int KEY_MINUS = 12;
|
||||
public static final int KEY_EQUAL = 13;
|
||||
public static final int KEY_BACKSPACE = 14;
|
||||
public static final int KEY_TAB = 15;
|
||||
public static final int KEY_Q = 16;
|
||||
public static final int KEY_W = 17;
|
||||
public static final int KEY_E = 18;
|
||||
public static final int KEY_R = 19;
|
||||
public static final int KEY_T = 20;
|
||||
public static final int KEY_Y = 21;
|
||||
public static final int KEY_U = 22;
|
||||
public static final int KEY_I = 23;
|
||||
public static final int KEY_O = 24;
|
||||
public static final int KEY_P = 25;
|
||||
public static final int KEY_LEFTBRACE = 26;
|
||||
public static final int KEY_RIGHTBRACE = 27;
|
||||
public static final int KEY_ENTER = 28;
|
||||
public static final int KEY_LEFTCTRL = 29;
|
||||
public static final int KEY_A = 30;
|
||||
public static final int KEY_S = 31;
|
||||
public static final int KEY_D = 32;
|
||||
public static final int KEY_F = 33;
|
||||
public static final int KEY_G = 34;
|
||||
public static final int KEY_H = 35;
|
||||
public static final int KEY_J = 36;
|
||||
public static final int KEY_K = 37;
|
||||
public static final int KEY_L = 38;
|
||||
public static final int KEY_SEMICOLON = 39;
|
||||
public static final int KEY_APOSTROPHE = 40;
|
||||
public static final int KEY_GRAVE = 41;
|
||||
public static final int KEY_LEFTSHIFT = 42;
|
||||
public static final int KEY_BACKSLASH = 43;
|
||||
public static final int KEY_Z = 44;
|
||||
public static final int KEY_X = 45;
|
||||
public static final int KEY_C = 46;
|
||||
public static final int KEY_V = 47;
|
||||
public static final int KEY_B = 48;
|
||||
public static final int KEY_N = 49;
|
||||
public static final int KEY_M = 50;
|
||||
public static final int KEY_COMMA = 51;
|
||||
public static final int KEY_DOT = 52;
|
||||
public static final int KEY_SLASH = 53;
|
||||
public static final int KEY_RIGHTSHIFT = 54;
|
||||
public static final int KEY_KPASTERISK = 55;
|
||||
public static final int KEY_LEFTALT = 56;
|
||||
public static final int KEY_SPACE = 57;
|
||||
public static final int KEY_CAPSLOCK = 58;
|
||||
public static final int KEY_F1 = 59;
|
||||
public static final int KEY_F2 = 60;
|
||||
public static final int KEY_F3 = 61;
|
||||
public static final int KEY_F4 = 62;
|
||||
public static final int KEY_F5 = 63;
|
||||
public static final int KEY_F6 = 64;
|
||||
public static final int KEY_F7 = 65;
|
||||
public static final int KEY_F8 = 66;
|
||||
public static final int KEY_F9 = 67;
|
||||
public static final int KEY_F10 = 68;
|
||||
public static final int KEY_NUMLOCK = 69;
|
||||
public static final int KEY_SCROLLLOCK = 70;
|
||||
public static final int KEY_KP7 = 71;
|
||||
public static final int KEY_KP8 = 72;
|
||||
public static final int KEY_KP9 = 73;
|
||||
public static final int KEY_KPMINUS = 74;
|
||||
public static final int KEY_KP4 = 75;
|
||||
public static final int KEY_KP5 = 76;
|
||||
public static final int KEY_KP6 = 77;
|
||||
public static final int KEY_KPPLUS = 78;
|
||||
public static final int KEY_KP1 = 79;
|
||||
public static final int KEY_KP2 = 80;
|
||||
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_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_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;
|
||||
public static final int KEY_SYSRQ = 99;
|
||||
public static final int KEY_RIGHTALT = 100;
|
||||
public static final int KEY_LINEFEED = 101;
|
||||
public static final int KEY_HOME = 102;
|
||||
public static final int KEY_UP = 103;
|
||||
public static final int KEY_PAGEUP = 104;
|
||||
public static final int KEY_LEFT = 105;
|
||||
public static final int KEY_RIGHT = 106;
|
||||
public static final int KEY_END = 107;
|
||||
public static final int KEY_DOWN = 108;
|
||||
public static final int KEY_PAGEDOWN = 109;
|
||||
public static final int KEY_INSERT = 110;
|
||||
public static final int KEY_DELETE = 111;
|
||||
public static final int KEY_MACRO = 112;
|
||||
public static final int KEY_MUTE = 113;
|
||||
public static final int KEY_VOLUMEDOWN = 114;
|
||||
public static final int KEY_VOLUMEUP = 115;
|
||||
public static final int KEY_POWER = 116;
|
||||
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_SCALE = 120;
|
||||
public static final int KEY_KPCOMMA = 121;
|
||||
public static final int KEY_HANGEUL = 122;
|
||||
public static final int KEY_HANGUEL = KEY_HANGEUL;
|
||||
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;
|
||||
public static final int KEY_STOP = 128;
|
||||
public static final int KEY_AGAIN = 129;
|
||||
public static final int KEY_PROPS = 130;
|
||||
public static final int KEY_UNDO = 131;
|
||||
public static final int KEY_FRONT = 132;
|
||||
public static final int KEY_COPY = 133;
|
||||
public static final int KEY_OPEN = 134;
|
||||
public static final int KEY_PASTE = 135;
|
||||
public static final int KEY_FIND = 136;
|
||||
public static final int KEY_CUT = 137;
|
||||
public static final int KEY_HELP = 138;
|
||||
public static final int KEY_MENU = 139;
|
||||
public static final int KEY_CALC = 140;
|
||||
public static final int KEY_SETUP = 141;
|
||||
public static final int KEY_SLEEP = 142;
|
||||
public static final int KEY_WAKEUP = 143;
|
||||
public static final int KEY_FILE = 144;
|
||||
public static final int KEY_SENDFILE = 145;
|
||||
public static final int KEY_DELETEFILE = 146;
|
||||
public static final int KEY_XFER = 147;
|
||||
public static final int KEY_PROG1 = 148;
|
||||
public static final int KEY_PROG2 = 149;
|
||||
public static final int KEY_WWW = 150;
|
||||
public static final int KEY_MSDOS = 151;
|
||||
public static final int KEY_COFFEE = 152;
|
||||
public static final int KEY_SCREENLOCK = KEY_COFFEE;
|
||||
public static final int KEY_DIRECTION = 153;
|
||||
public static final int KEY_CYCLEWINDOWS = 154;
|
||||
public static final int KEY_MAIL = 155;
|
||||
public static final int KEY_BOOKMARKS = 156;
|
||||
public static final int KEY_COMPUTER = 157;
|
||||
public static final int KEY_BACK = 158;
|
||||
public static final int KEY_FORWARD = 159;
|
||||
public static final int KEY_CLOSECD = 160;
|
||||
public static final int KEY_EJECTCD = 161;
|
||||
public static final int KEY_EJECTCLOSECD = 162;
|
||||
public static final int KEY_NEXTSONG = 163;
|
||||
public static final int KEY_PLAYPAUSE = 164;
|
||||
public static final int KEY_PREVIOUSSONG = 165;
|
||||
public static final int KEY_STOPCD = 166;
|
||||
public static final int KEY_RECORD = 167;
|
||||
public static final int KEY_REWIND = 168;
|
||||
public static final int KEY_PHONE = 169;
|
||||
public static final int KEY_ISO = 170;
|
||||
public static final int KEY_CONFIG = 171;
|
||||
public static final int KEY_HOMEPAGE = 172;
|
||||
public static final int KEY_REFRESH = 173;
|
||||
public static final int KEY_EXIT = 174;
|
||||
public static final int KEY_MOVE = 175;
|
||||
public static final int KEY_EDIT = 176;
|
||||
public static final int KEY_SCROLLUP = 177;
|
||||
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_NEW = 181;
|
||||
public static final int KEY_REDO = 182;
|
||||
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;
|
||||
public static final int KEY_PROG4 = 203;
|
||||
public static final int KEY_DASHBOARD = 204;
|
||||
public static final int KEY_SUSPEND = 205;
|
||||
public static final int KEY_CLOSE = 206;
|
||||
public static final int KEY_PLAY = 207;
|
||||
public static final int KEY_FASTFORWARD = 208;
|
||||
public static final int KEY_BASSBOOST = 209;
|
||||
public static final int KEY_PRINT = 210;
|
||||
public static final int KEY_HP = 211;
|
||||
public static final int KEY_CAMERA = 212;
|
||||
public static final int KEY_SOUND = 213;
|
||||
public static final int KEY_QUESTION = 214;
|
||||
public static final int KEY_EMAIL = 215;
|
||||
public static final int KEY_CHAT = 216;
|
||||
public static final int KEY_SEARCH = 217;
|
||||
public static final int KEY_CONNECT = 218;
|
||||
public static final int KEY_FINANCE = 219;
|
||||
public static final int KEY_SPORT = 220;
|
||||
public static final int KEY_SHOP = 221;
|
||||
public static final int KEY_ALTERASE = 222;
|
||||
public static final int KEY_CANCEL = 223;
|
||||
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_SEND = 231;
|
||||
public static final int KEY_REPLY = 232;
|
||||
public static final int KEY_FORWARDMAIL = 233;
|
||||
public static final int KEY_SAVE = 234;
|
||||
public static final int KEY_DOCUMENTS = 235;
|
||||
public static final int KEY_BATTERY = 236;
|
||||
public static final int KEY_BLUETOOTH = 237;
|
||||
public static final int KEY_WLAN = 238;
|
||||
public static final int KEY_UWB = 239;
|
||||
public static final int KEY_UNKNOWN = 240;
|
||||
public static final int KEY_VIDEO_NEXT = 241;
|
||||
public static final int KEY_VIDEO_PREV = 242;
|
||||
public static final int KEY_BRIGHTNESS_CYCLE = 243;
|
||||
public static final int KEY_BRIGHTNESS_ZERO = 244;
|
||||
public static final int KEY_DISPLAY_OFF = 245;
|
||||
public static final int KEY_WIMAX = 246;
|
||||
public static final int KEY_RFKILL = 247;
|
||||
public static final int KEY_MICMUTE = 248;
|
||||
public static final int BTN_MISC = 0x100;
|
||||
public static final int BTN_0 = 0x100;
|
||||
public static final int BTN_1 = 0x101;
|
||||
public static final int BTN_2 = 0x102;
|
||||
public static final int BTN_3 = 0x103;
|
||||
public static final int BTN_4 = 0x104;
|
||||
public static final int BTN_5 = 0x105;
|
||||
public static final int BTN_6 = 0x106;
|
||||
public static final int BTN_7 = 0x107;
|
||||
public static final int BTN_8 = 0x108;
|
||||
public static final int BTN_9 = 0x109;
|
||||
public static final int BTN_MOUSE = 0x110;
|
||||
public static final int BTN_LEFT = 0x110;
|
||||
public static final int BTN_RIGHT = 0x111;
|
||||
public static final int BTN_MIDDLE = 0x112;
|
||||
public static final int BTN_SIDE = 0x113;
|
||||
public static final int BTN_EXTRA = 0x114;
|
||||
public static final int BTN_FORWARD = 0x115;
|
||||
public static final int BTN_BACK = 0x116;
|
||||
public static final int BTN_TASK = 0x117;
|
||||
public static final int BTN_JOYSTICK = 0x120;
|
||||
public static final int BTN_TRIGGER = 0x120;
|
||||
public static final int BTN_THUMB = 0x121;
|
||||
public static final int BTN_THUMB2 = 0x122;
|
||||
public static final int BTN_TOP = 0x123;
|
||||
public static final int BTN_TOP2 = 0x124;
|
||||
public static final int BTN_PINKIE = 0x125;
|
||||
public static final int BTN_BASE = 0x126;
|
||||
public static final int BTN_BASE2 = 0x127;
|
||||
public static final int BTN_BASE3 = 0x128;
|
||||
public static final int BTN_BASE4 = 0x129;
|
||||
public static final int BTN_BASE5 = 0x12a;
|
||||
public static final int BTN_BASE6 = 0x12b;
|
||||
public static final int BTN_DEAD = 0x12f;
|
||||
public static final int BTN_GAMEPAD = 0x130;
|
||||
public static final int BTN_A = 0x130;
|
||||
public static final int BTN_B = 0x131;
|
||||
public static final int BTN_C = 0x132;
|
||||
public static final int BTN_X = 0x133;
|
||||
public static final int BTN_Y = 0x134;
|
||||
public static final int BTN_Z = 0x135;
|
||||
public static final int BTN_TL = 0x136;
|
||||
public static final int BTN_TR = 0x137;
|
||||
public static final int BTN_TL2 = 0x138;
|
||||
public static final int BTN_TR2 = 0x139;
|
||||
public static final int BTN_SELECT = 0x13a;
|
||||
public static final int BTN_START = 0x13b;
|
||||
public static final int BTN_MODE = 0x13c;
|
||||
public static final int BTN_THUMBL = 0x13d;
|
||||
public static final int BTN_THUMBR = 0x13e;
|
||||
public static final int BTN_DIGI = 0x140;
|
||||
public static final int BTN_TOOL_PEN = 0x140;
|
||||
public static final int BTN_TOOL_RUBBER = 0x141;
|
||||
public static final int BTN_TOOL_BRUSH = 0x142;
|
||||
public static final int BTN_TOOL_PENCIL = 0x143;
|
||||
public static final int BTN_TOOL_AIRBRUSH = 0x144;
|
||||
public static final int BTN_TOOL_FINGER = 0x145;
|
||||
public static final int BTN_TOOL_MOUSE = 0x146;
|
||||
public static final int BTN_TOOL_LENS = 0x147;
|
||||
public static final int BTN_TOOL_QUINTTAP = 0x148;
|
||||
public static final int BTN_TOUCH = 0x14a;
|
||||
public static final int BTN_STYLUS = 0x14b;
|
||||
public static final int BTN_STYLUS2 = 0x14c;
|
||||
public static final int BTN_TOOL_DOUBLETAP = 0x14d;
|
||||
public static final int BTN_TOOL_TRIPLETAP = 0x14e;
|
||||
public static final int BTN_TOOL_QUADTAP = 0x14f;
|
||||
public static final int BTN_WHEEL = 0x150;
|
||||
public static final int BTN_GEAR_DOWN = 0x150;
|
||||
public static final int BTN_GEAR_UP = 0x151;
|
||||
public static final int KEY_OK = 0x160;
|
||||
public static final int KEY_SELECT = 0x161;
|
||||
public static final int KEY_GOTO = 0x162;
|
||||
public static final int KEY_CLEAR = 0x163;
|
||||
public static final int KEY_POWER2 = 0x164;
|
||||
public static final int KEY_OPTION = 0x165;
|
||||
public static final int KEY_INFO = 0x166;
|
||||
public static final int KEY_TIME = 0x167;
|
||||
public static final int KEY_VENDOR = 0x168;
|
||||
public static final int KEY_ARCHIVE = 0x169;
|
||||
public static final int KEY_PROGRAM = 0x16a;
|
||||
public static final int KEY_CHANNEL = 0x16b;
|
||||
public static final int KEY_FAVORITES = 0x16c;
|
||||
public static final int KEY_EPG = 0x16d;
|
||||
public static final int KEY_PVR = 0x16e;
|
||||
public static final int KEY_MHP = 0x16f;
|
||||
public static final int KEY_LANGUAGE = 0x170;
|
||||
public static final int KEY_TITLE = 0x171;
|
||||
public static final int KEY_SUBTITLE = 0x172;
|
||||
public static final int KEY_ANGLE = 0x173;
|
||||
public static final int KEY_ZOOM = 0x174;
|
||||
public static final int KEY_MODE = 0x175;
|
||||
public static final int KEY_KEYBOARD = 0x176;
|
||||
public static final int KEY_SCREEN = 0x177;
|
||||
public static final int KEY_PC = 0x178;
|
||||
public static final int KEY_TV = 0x179;
|
||||
public static final int KEY_TV2 = 0x17a;
|
||||
public static final int KEY_VCR = 0x17b;
|
||||
public static final int KEY_VCR2 = 0x17c;
|
||||
public static final int KEY_SAT = 0x17d;
|
||||
public static final int KEY_SAT2 = 0x17e;
|
||||
public static final int KEY_CD = 0x17f;
|
||||
public static final int KEY_TAPE = 0x180;
|
||||
public static final int KEY_RADIO = 0x181;
|
||||
public static final int KEY_TUNER = 0x182;
|
||||
public static final int KEY_PLAYER = 0x183;
|
||||
public static final int KEY_TEXT = 0x184;
|
||||
public static final int KEY_DVD = 0x185;
|
||||
public static final int KEY_AUX = 0x186;
|
||||
public static final int KEY_MP3 = 0x187;
|
||||
public static final int KEY_AUDIO = 0x188;
|
||||
public static final int KEY_VIDEO = 0x189;
|
||||
public static final int KEY_DIRECTORY = 0x18a;
|
||||
public static final int KEY_LIST = 0x18b;
|
||||
public static final int KEY_MEMO = 0x18c;
|
||||
public static final int KEY_CALENDAR = 0x18d;
|
||||
public static final int KEY_RED = 0x18e;
|
||||
public static final int KEY_GREEN = 0x18f;
|
||||
public static final int KEY_YELLOW = 0x190;
|
||||
public static final int KEY_BLUE = 0x191;
|
||||
public static final int KEY_CHANNELUP = 0x192;
|
||||
public static final int KEY_CHANNELDOWN = 0x193;
|
||||
public static final int KEY_FIRST = 0x194;
|
||||
public static final int KEY_LAST = 0x195;
|
||||
public static final int KEY_AB = 0x196;
|
||||
public static final int KEY_NEXT = 0x197;
|
||||
public static final int KEY_RESTART = 0x198;
|
||||
public static final int KEY_SLOW = 0x199;
|
||||
public static final int KEY_SHUFFLE = 0x19a;
|
||||
public static final int KEY_BREAK = 0x19b;
|
||||
public static final int KEY_PREVIOUS = 0x19c;
|
||||
public static final int KEY_DIGITS = 0x19d;
|
||||
public static final int KEY_TEEN = 0x19e;
|
||||
public static final int KEY_TWEN = 0x19f;
|
||||
public static final int KEY_VIDEOPHONE = 0x1a0;
|
||||
public static final int KEY_GAMES = 0x1a1;
|
||||
public static final int KEY_ZOOMIN = 0x1a2;
|
||||
public static final int KEY_ZOOMOUT = 0x1a3;
|
||||
public static final int KEY_ZOOMRESET = 0x1a4;
|
||||
public static final int KEY_WORDPROCESSOR = 0x1a5;
|
||||
public static final int KEY_EDITOR = 0x1a6;
|
||||
public static final int KEY_SPREADSHEET = 0x1a7;
|
||||
public static final int KEY_GRAPHICSEDITOR = 0x1a8;
|
||||
public static final int KEY_PRESENTATION = 0x1a9;
|
||||
public static final int KEY_DATABASE = 0x1aa;
|
||||
public static final int KEY_NEWS = 0x1ab;
|
||||
public static final int KEY_VOICEMAIL = 0x1ac;
|
||||
public static final int KEY_ADDRESSBOOK = 0x1ad;
|
||||
public static final int KEY_MESSENGER = 0x1ae;
|
||||
public static final int KEY_DISPLAYTOGGLE = 0x1af;
|
||||
public static final int KEY_SPELLCHECK = 0x1b0;
|
||||
public static final int KEY_LOGOFF = 0x1b1;
|
||||
public static final int KEY_DOLLAR = 0x1b2;
|
||||
public static final int KEY_EURO = 0x1b3;
|
||||
public static final int KEY_FRAMEBACK = 0x1b4;
|
||||
public static final int KEY_FRAMEFORWARD = 0x1b5;
|
||||
public static final int KEY_CONTEXT_MENU = 0x1b6;
|
||||
public static final int KEY_MEDIA_REPEAT = 0x1b7;
|
||||
public static final int KEY_10CHANNELSUP = 0x1b8;
|
||||
public static final int KEY_10CHANNELSDOWN = 0x1b9;
|
||||
public static final int KEY_IMAGES = 0x1ba;
|
||||
public static final int KEY_DEL_EOL = 0x1c0;
|
||||
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_BRL_DOT1 = 0x1f1;
|
||||
public static final int KEY_BRL_DOT2 = 0x1f2;
|
||||
public static final int KEY_BRL_DOT3 = 0x1f3;
|
||||
public static final int KEY_BRL_DOT4 = 0x1f4;
|
||||
public static final int KEY_BRL_DOT5 = 0x1f5;
|
||||
public static final int KEY_BRL_DOT6 = 0x1f6;
|
||||
public static final int KEY_BRL_DOT7 = 0x1f7;
|
||||
public static final int KEY_BRL_DOT8 = 0x1f8;
|
||||
public static final int KEY_BRL_DOT9 = 0x1f9;
|
||||
public static final int KEY_BRL_DOT10 = 0x1fa;
|
||||
public static final int KEY_NUMERIC_0 = 0x200;
|
||||
public static final int KEY_NUMERIC_1 = 0x201;
|
||||
public static final int KEY_NUMERIC_2 = 0x202;
|
||||
public static final int KEY_NUMERIC_3 = 0x203;
|
||||
public static final int KEY_NUMERIC_4 = 0x204;
|
||||
public static final int KEY_NUMERIC_5 = 0x205;
|
||||
public static final int KEY_NUMERIC_6 = 0x206;
|
||||
public static final int KEY_NUMERIC_7 = 0x207;
|
||||
public static final int KEY_NUMERIC_8 = 0x208;
|
||||
public static final int KEY_NUMERIC_9 = 0x209;
|
||||
public static final int KEY_NUMERIC_STAR = 0x20a;
|
||||
public static final int KEY_NUMERIC_POUND = 0x20b;
|
||||
public static final int KEY_CAMERA_FOCUS = 0x210;
|
||||
public static final int KEY_WPS_BUTTON = 0x211;
|
||||
public static final int KEY_TOUCHPAD_TOGGLE = 0x212;
|
||||
public static final int KEY_TOUCHPAD_ON = 0x213;
|
||||
public static final int KEY_TOUCHPAD_OFF = 0x214;
|
||||
public static final int KEY_CAMERA_ZOOMIN = 0x215;
|
||||
public static final int KEY_CAMERA_ZOOMOUT = 0x216;
|
||||
public static final int KEY_CAMERA_UP = 0x217;
|
||||
public static final int KEY_CAMERA_DOWN = 0x218;
|
||||
public static final int KEY_CAMERA_LEFT = 0x219;
|
||||
public static final int KEY_CAMERA_RIGHT = 0x21a;
|
||||
public static final int BTN_TRIGGER_HAPPY = 0x2c0;
|
||||
public static final int BTN_TRIGGER_HAPPY1 = 0x2c0;
|
||||
public static final int BTN_TRIGGER_HAPPY2 = 0x2c1;
|
||||
public static final int BTN_TRIGGER_HAPPY3 = 0x2c2;
|
||||
public static final int BTN_TRIGGER_HAPPY4 = 0x2c3;
|
||||
public static final int BTN_TRIGGER_HAPPY5 = 0x2c4;
|
||||
public static final int BTN_TRIGGER_HAPPY6 = 0x2c5;
|
||||
public static final int BTN_TRIGGER_HAPPY7 = 0x2c6;
|
||||
public static final int BTN_TRIGGER_HAPPY8 = 0x2c7;
|
||||
public static final int BTN_TRIGGER_HAPPY9 = 0x2c8;
|
||||
public static final int BTN_TRIGGER_HAPPY10 = 0x2c9;
|
||||
public static final int BTN_TRIGGER_HAPPY11 = 0x2ca;
|
||||
public static final int BTN_TRIGGER_HAPPY12 = 0x2cb;
|
||||
public static final int BTN_TRIGGER_HAPPY13 = 0x2cc;
|
||||
public static final int BTN_TRIGGER_HAPPY14 = 0x2cd;
|
||||
public static final int BTN_TRIGGER_HAPPY15 = 0x2ce;
|
||||
public static final int BTN_TRIGGER_HAPPY16 = 0x2cf;
|
||||
public static final int BTN_TRIGGER_HAPPY17 = 0x2d0;
|
||||
public static final int BTN_TRIGGER_HAPPY18 = 0x2d1;
|
||||
public static final int BTN_TRIGGER_HAPPY19 = 0x2d2;
|
||||
public static final int BTN_TRIGGER_HAPPY20 = 0x2d3;
|
||||
public static final int BTN_TRIGGER_HAPPY21 = 0x2d4;
|
||||
public static final int BTN_TRIGGER_HAPPY22 = 0x2d5;
|
||||
public static final int BTN_TRIGGER_HAPPY23 = 0x2d6;
|
||||
public static final int BTN_TRIGGER_HAPPY24 = 0x2d7;
|
||||
public static final int BTN_TRIGGER_HAPPY25 = 0x2d8;
|
||||
public static final int BTN_TRIGGER_HAPPY26 = 0x2d9;
|
||||
public static final int BTN_TRIGGER_HAPPY27 = 0x2da;
|
||||
public static final int BTN_TRIGGER_HAPPY28 = 0x2db;
|
||||
public static final int BTN_TRIGGER_HAPPY29 = 0x2dc;
|
||||
public static final int BTN_TRIGGER_HAPPY30 = 0x2dd;
|
||||
public static final int BTN_TRIGGER_HAPPY31 = 0x2de;
|
||||
public static final int BTN_TRIGGER_HAPPY32 = 0x2df;
|
||||
public static final int BTN_TRIGGER_HAPPY33 = 0x2e0;
|
||||
public static final int BTN_TRIGGER_HAPPY34 = 0x2e1;
|
||||
public static final int BTN_TRIGGER_HAPPY35 = 0x2e2;
|
||||
public static final int BTN_TRIGGER_HAPPY36 = 0x2e3;
|
||||
public static final int BTN_TRIGGER_HAPPY37 = 0x2e4;
|
||||
public static final int BTN_TRIGGER_HAPPY38 = 0x2e5;
|
||||
public static final int BTN_TRIGGER_HAPPY39 = 0x2e6;
|
||||
public static final int BTN_TRIGGER_HAPPY40 = 0x2e7;
|
||||
public static final int KEY_MIN_INTERESTING = KEY_MUTE;
|
||||
public static final int KEY_MAX = 0x2ff;
|
||||
public static final int KEY_CNT = (KEY_MAX+1);
|
||||
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;
|
||||
public static final int REL_MISC = 0x09;
|
||||
public static final int REL_MAX = 0x0f;
|
||||
public static final int REL_CNT = (REL_MAX+1);
|
||||
public static final int ABS_X = 0x00;
|
||||
public static final int ABS_Y = 0x01;
|
||||
public static final int ABS_Z = 0x02;
|
||||
public static final int ABS_RX = 0x03;
|
||||
public static final int ABS_RY = 0x04;
|
||||
public static final int ABS_RZ = 0x05;
|
||||
public static final int ABS_THROTTLE = 0x06;
|
||||
public static final int ABS_RUDDER = 0x07;
|
||||
public static final int ABS_WHEEL = 0x08;
|
||||
public static final int ABS_GAS = 0x09;
|
||||
public static final int ABS_BRAKE = 0x0a;
|
||||
public static final int ABS_HAT0X = 0x10;
|
||||
public static final int ABS_HAT0Y = 0x11;
|
||||
public static final int ABS_HAT1X = 0x12;
|
||||
public static final int ABS_HAT1Y = 0x13;
|
||||
public static final int ABS_HAT2X = 0x14;
|
||||
public static final int ABS_HAT2Y = 0x15;
|
||||
public static final int ABS_HAT3X = 0x16;
|
||||
public static final int ABS_HAT3Y = 0x17;
|
||||
public static final int ABS_PRESSURE = 0x18;
|
||||
public static final int ABS_DISTANCE = 0x19;
|
||||
public static final int ABS_TILT_X = 0x1a;
|
||||
public static final int ABS_TILT_Y = 0x1b;
|
||||
public static final int ABS_TOOL_WIDTH = 0x1c;
|
||||
public static final int ABS_VOLUME = 0x20;
|
||||
public static final int ABS_MISC = 0x28;
|
||||
public static final int ABS_MT_SLOT = 0x2f;
|
||||
public static final int ABS_MT_TOUCH_MAJOR = 0x30;
|
||||
public static final int ABS_MT_TOUCH_MINOR = 0x31;
|
||||
public static final int ABS_MT_WIDTH_MAJOR = 0x32;
|
||||
public static final int ABS_MT_WIDTH_MINOR = 0x33;
|
||||
public static final int ABS_MT_ORIENTATION = 0x34;
|
||||
public static final int ABS_MT_POSITION_X = 0x35;
|
||||
public static final int ABS_MT_POSITION_Y = 0x36;
|
||||
public static final int ABS_MT_TOOL_TYPE = 0x37;
|
||||
public static final int ABS_MT_BLOB_ID = 0x38;
|
||||
public static final int ABS_MT_TRACKING_ID = 0x39;
|
||||
public static final int ABS_MT_PRESSURE = 0x3a;
|
||||
public static final int ABS_MT_DISTANCE = 0x3b;
|
||||
public static final int ABS_MT_FIRST = ABS_MT_TOUCH_MAJOR;
|
||||
public static final int ABS_MT_LAST = ABS_MT_DISTANCE;
|
||||
public static final int ABS_MAX = 0x3f;
|
||||
public static final int ABS_CNT = (ABS_MAX+1);
|
||||
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_VIRTUAL = 0x06;
|
||||
public static final int BUS_ISA = 0x10;
|
||||
public static final int BUS_I8042 = 0x11;
|
||||
public static final int BUS_XTKBD = 0x12;
|
||||
public static final int BUS_RS232 = 0x13;
|
||||
public static final int BUS_GAMEPORT = 0x14;
|
||||
public static final int BUS_PARPORT = 0x15;
|
||||
public static final int BUS_AMIGA = 0x16;
|
||||
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 BUS_GSC = 0x1A;
|
||||
public static final int BUS_ATARI = 0x1B;
|
||||
public static final int BUS_SPI = 0x1C;
|
||||
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_EFFECT_MIN = FF_RUMBLE;
|
||||
public static final int FF_EFFECT_MAX = FF_RAMP;
|
||||
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_WAVEFORM_MIN = FF_SQUARE;
|
||||
public static final int FF_WAVEFORM_MAX = FF_CUSTOM;
|
||||
public static final int FF_GAIN = 0x60;
|
||||
public static final int FF_AUTOCENTER = 0x61;
|
||||
public static final int FF_MAX = 0x7f;
|
||||
public static final int FF_CNT = (FF_MAX+1);
|
||||
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;
|
||||
}
|
||||
60
plugins/linux/src/main/native/getDefinitions
Normal file
60
plugins/linux/src/main/native/getDefinitions
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#!/bin/gawk -f
|
||||
|
||||
# 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
|
||||
|
||||
NR == 1 {
|
||||
FILENAME == ARGV[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("class NativeDefinitions {\n")
|
||||
}
|
||||
/#define ABS_/ {
|
||||
printf(" public static final int %s = %s;\n", $2, $3)
|
||||
}
|
||||
/#define REL_/ {
|
||||
printf(" public static final int %s = %s;\n", $2, $3)
|
||||
}
|
||||
/#define BTN_/ {
|
||||
printf(" public static final int %s = %s;\n", $2, $3)
|
||||
}
|
||||
/#define KEY_/ {
|
||||
printf(" public static final int %s = %s;\n", $2, $3)
|
||||
}
|
||||
/#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");
|
||||
}
|
||||
|
|
@ -0,0 +1,243 @@
|
|||
/*
|
||||
* %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_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);
|
||||
}
|
||||
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* %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 jbyteArray JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetAxisMap(JNIEnv *env, jclass unused, jlong fd_address) {
|
||||
int fd = (int)fd_address;
|
||||
__u8 axis_map[ABS_MAX + 1];
|
||||
if (ioctl(fd, JSIOCGAXMAP, axis_map) == -1) {
|
||||
throwIOException(env, "Failed to get axis map (%d)\n", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jbyteArray axis_map_array = (*env)->NewByteArray(env, (ABS_MAX + 1));
|
||||
if (axis_map_array == NULL)
|
||||
return NULL;
|
||||
(*env)->SetByteArrayRegion(env, axis_map_array, 0, (ABS_MAX + 1), (jbyte *)axis_map);
|
||||
return axis_map_array;
|
||||
}
|
||||
|
||||
JNIEXPORT jcharArray JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetButtonMap(JNIEnv *env, jclass unused, jlong fd_address) {
|
||||
int fd = (int)fd_address;
|
||||
__u16 button_map[KEY_MAX - BTN_MISC + 1];
|
||||
if (ioctl(fd, JSIOCGBTNMAP, button_map) == -1) {
|
||||
throwIOException(env, "Failed to get button map (%d)\n", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jcharArray button_map_array = (*env)->NewCharArray(env, (KEY_MAX - BTN_MISC + 1));
|
||||
if (button_map_array == NULL)
|
||||
return NULL;
|
||||
(*env)->SetCharArrayRegion(env, button_map_array, 0, (KEY_MAX - BTN_MISC + 1), (jchar *)button_map);
|
||||
return button_map_array;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue