Issue number: 35

Read the axis and button maps from the joystick nodes.
This commit is contained in:
endolf 2007-08-12 15:47:51 +00:00
parent 940c48b558
commit 8699a0c8b1
3 changed files with 62 additions and 5 deletions

View file

@ -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[]{});
}

View file

@ -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);