aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java10
-rw-r--r--plugins/linux/src/java/net/java/games/input/LinuxJoystickDevice.java22
-rw-r--r--plugins/linux/src/native/net_java_games_input_LinuxJoystickDevice.c35
3 files changed, 62 insertions, 5 deletions
diff --git a/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java b/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java
index 7b90cab..ebfc0f0 100644
--- a/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java
+++ b/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java
@@ -312,8 +312,10 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
private final static Controller createJoystickFromJoystickDevice(LinuxJoystickDevice device) {
List components = new ArrayList();
+ byte[] axisMap = device.getAxisMap();
+ char[] buttonMap = device.getButtonMap();
for (int i = 0; i < device.getNumButtons(); i++) {
- Component.Identifier.Button button_id = getButtonIdentifier(i);
+ Component.Identifier.Button button_id = (Component.Identifier.Button)LinuxNativeTypesMap.getButtonID(buttonMap[i]);
if (button_id != null) {
LinuxJoystickButton button = new LinuxJoystickButton(button_id);
device.registerButton(i, button);
@@ -322,14 +324,12 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
}
for (int i = 0; i < device.getNumAxes(); i++) {
Component.Identifier.Axis axis_id;
- if ((i % 2) == 0)
- axis_id = Component.Identifier.Axis.X;
- else
- axis_id = Component.Identifier.Axis.Y;
+ axis_id = (Component.Identifier.Axis) LinuxNativeTypesMap.getAbsAxisID(axisMap[i]);
LinuxJoystickAxis axis = new LinuxJoystickAxis(axis_id);
device.registerAxis(i, axis);
components.add(axis);
}
+
return new LinuxJoystickAbstractController(device, (Component[])components.toArray(new Component[]{}), new Controller[]{}, new Rumbler[]{});
}
diff --git a/plugins/linux/src/java/net/java/games/input/LinuxJoystickDevice.java b/plugins/linux/src/java/net/java/games/input/LinuxJoystickDevice.java
index 2d72027..bc37e7b 100644
--- a/plugins/linux/src/java/net/java/games/input/LinuxJoystickDevice.java
+++ b/plugins/linux/src/java/net/java/games/input/LinuxJoystickDevice.java
@@ -48,6 +48,8 @@ final class LinuxJoystickDevice implements LinuxDevice {
private final Event event = new Event();
private final LinuxJoystickButton[] buttons;
private final LinuxJoystickAxis[] axes;
+ private final byte[] axisMap;
+ private final char[] buttonMap;
private EventQueue event_queue;
@@ -63,6 +65,8 @@ final class LinuxJoystickDevice implements LinuxDevice {
setBufferSize(AbstractController.EVENT_QUEUE_DEPTH);
buttons = new LinuxJoystickButton[getNumDeviceButtons()];
axes = new LinuxJoystickAxis[getNumDeviceAxes()];
+ axisMap = getDeviceAxisMap();
+ buttonMap = getDeviceButtonMap();
} catch (IOException e) {
close();
throw e;
@@ -141,6 +145,14 @@ final class LinuxJoystickDevice implements LinuxDevice {
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);
@@ -151,6 +163,16 @@ final class LinuxJoystickDevice implements LinuxDevice {
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);
diff --git a/plugins/linux/src/native/net_java_games_input_LinuxJoystickDevice.c b/plugins/linux/src/native/net_java_games_input_LinuxJoystickDevice.c
index f82023b..92da2a6 100644
--- a/plugins/linux/src/native/net_java_games_input_LinuxJoystickDevice.c
+++ b/plugins/linux/src/native/net_java_games_input_LinuxJoystickDevice.c
@@ -108,6 +108,41 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetNumAxes
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;
+ int i=0;
+ __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;
+ }
+
+ for(i=0;i<10;i++) {
+ printf("Button %d maps to %d\n", i, button_map[i]);
+ }
+
+ 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), (jbyte *)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);