mirror of
https://github.com/shadowfacts/jinput-arm64.git
synced 2026-02-18 05:34:46 +01:00
Make the joystick plugin on linux respect POV Hats
This commit is contained in:
parent
ae8b23e4ba
commit
ea90a2d3b4
|
|
@ -314,6 +314,8 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
|
|||
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 button_id = (Component.Identifier.Button)LinuxNativeTypesMap.getButtonID(buttonMap[i]);
|
||||
if (button_id != null) {
|
||||
|
|
@ -326,8 +328,33 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
|
|||
Component.Identifier.Axis axis_id;
|
||||
axis_id = (Component.Identifier.Axis) LinuxNativeTypesMap.getAbsAxisID(axisMap[i]);
|
||||
LinuxJoystickAxis axis = new LinuxJoystickAxis(axis_id);
|
||||
|
||||
device.registerAxis(i, axis);
|
||||
components.add(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[]{});
|
||||
|
|
|
|||
|
|
@ -46,9 +46,15 @@ import java.io.IOException;
|
|||
*/
|
||||
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() {
|
||||
|
|
@ -56,11 +62,12 @@ class LinuxJoystickAxis extends AbstractComponent {
|
|||
}
|
||||
|
||||
public final boolean isAnalog() {
|
||||
return true;
|
||||
return analog;
|
||||
}
|
||||
|
||||
final void setValue(float value) {
|
||||
this.value = value;
|
||||
resetHasPolled();
|
||||
}
|
||||
|
||||
protected final float poll() throws IOException {
|
||||
|
|
|
|||
|
|
@ -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 Map povXs = new HashMap();
|
||||
private final Map povYs = new HashMap();
|
||||
private final byte[] axisMap;
|
||||
private final char[] buttonMap;
|
||||
|
||||
|
|
@ -100,7 +102,17 @@ final class LinuxJoystickDevice implements LinuxDevice {
|
|||
if (axis != null) {
|
||||
float value = (float)joystick_event.getValue()/AXIS_MAX_VALUE;
|
||||
axis.setValue(value);
|
||||
event.set(axis, value, joystick_event.getNanos());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -121,6 +133,26 @@ final class LinuxJoystickDevice implements LinuxDevice {
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
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() {
|
||||
LinuxEnvironmentPlugin.logln("Updating pov " + hatX.getName() + ", " + hatY.getName());
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue