mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-10 18:06:32 +00:00
Suport for Dpads which use absolute values in evdev
This commit is contained in:
@@ -9,6 +9,8 @@ import java.nio.ByteOrder;
|
||||
*/
|
||||
public class EvdevAbsolute {
|
||||
|
||||
public final static int UP = 1, DOWN = -1, NONE = 0;
|
||||
|
||||
private final static int ABS_OFFSET = 0x40;
|
||||
private final static int READ_ONLY = 2;
|
||||
private final static char EVDEV_TYPE = 'E';
|
||||
@@ -52,4 +54,18 @@ public class EvdevAbsolute {
|
||||
return (byte) ((value-avg) * range / Byte.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert input value to direction
|
||||
* @param value received input
|
||||
* @return input value as direction
|
||||
*/
|
||||
public byte getDirection(int value) {
|
||||
if (value>(avg+range/4))
|
||||
return UP;
|
||||
else if (value<(avg-range/4))
|
||||
return DOWN;
|
||||
else
|
||||
return NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class EvdevHandler implements Runnable {
|
||||
private byte leftTrigger, rightTrigger;
|
||||
private short leftStickX, leftStickY, rightStickX, rightStickY;
|
||||
|
||||
private EvdevAbsolute absLX, absLY, absRX, absRY, absLT, absRT;
|
||||
private EvdevAbsolute absLX, absLY, absRX, absRY, absLT, absRT, absDX, absDY;
|
||||
|
||||
private NvConnection conn;
|
||||
private FileChannel deviceInput;
|
||||
@@ -56,6 +56,8 @@ public class EvdevHandler implements Runnable {
|
||||
absRY = new EvdevAbsolute(device, mapping.abs_ry);
|
||||
absLT = new EvdevAbsolute(device, mapping.abs_rudder);
|
||||
absRT = new EvdevAbsolute(device, mapping.abs_throttle);
|
||||
absDX = new EvdevAbsolute(device, mapping.abs_dpad_x);
|
||||
absDY = new EvdevAbsolute(device, mapping.abs_dpad_y);
|
||||
|
||||
translator = new KeyboardTranslator(conn);
|
||||
}
|
||||
@@ -160,6 +162,31 @@ public class EvdevHandler implements Runnable {
|
||||
leftTrigger = absLT.getByte(value);
|
||||
else if (code==mapping.abs_rudder)
|
||||
rightTrigger = absRT.getByte(value);
|
||||
else if (code==mapping.abs_dpad_x) {
|
||||
int dir = absRT.getDirection(value);
|
||||
if (dir==EvdevAbsolute.UP) {
|
||||
buttonFlags |= ControllerPacket.RIGHT_FLAG;
|
||||
buttonFlags &= ~ControllerPacket.LEFT_FLAG;
|
||||
} else if (dir==EvdevAbsolute.NONE) {
|
||||
buttonFlags &= ~ControllerPacket.LEFT_FLAG;
|
||||
buttonFlags &= ~ControllerPacket.RIGHT_FLAG;
|
||||
} else if (dir==EvdevAbsolute.DOWN) {
|
||||
buttonFlags |= ControllerPacket.LEFT_FLAG;
|
||||
buttonFlags &= ~ControllerPacket.RIGHT_FLAG;
|
||||
}
|
||||
} else if (code==mapping.abs_dpad_y) {
|
||||
int dir = absRT.getDirection(value);
|
||||
if (dir==EvdevAbsolute.UP) {
|
||||
buttonFlags |= ControllerPacket.UP_FLAG;
|
||||
buttonFlags &= ~ControllerPacket.DOWN_FLAG;
|
||||
} else if (dir==EvdevAbsolute.NONE) {
|
||||
buttonFlags &= ~ControllerPacket.DOWN_FLAG;
|
||||
buttonFlags &= ~ControllerPacket.UP_FLAG;
|
||||
} else if (dir==EvdevAbsolute.DOWN) {
|
||||
buttonFlags |= ControllerPacket.DOWN_FLAG;
|
||||
buttonFlags &= ~ControllerPacket.UP_FLAG;
|
||||
}
|
||||
}
|
||||
|
||||
conn.sendControllerInput(buttonFlags, leftTrigger, rightTrigger, leftStickX, leftStickY, rightStickX, rightStickY);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ public class GamepadMapping {
|
||||
public short abs_rx = EvdevConstants.ABS_RX;
|
||||
public short abs_ry = EvdevConstants.ABS_RY;
|
||||
|
||||
public short abs_dpad_y = -1;
|
||||
public short abs_dpad_x = -1;
|
||||
|
||||
public short abs_throttle = EvdevConstants.ABS_THROTTLE;
|
||||
public short abs_rudder = EvdevConstants.ABS_RUDDER;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user