mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 19:42:45 +00:00
Add Moga controller support.
This commit is contained in:
parent
aa4e07ea2f
commit
ae65bbe3ca
@ -333,76 +333,90 @@ public class Game extends Activity implements OnGenericMotionListener, OnTouchLi
|
|||||||
@Override
|
@Override
|
||||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||||
InputDevice dev = event.getDevice();
|
InputDevice dev = event.getDevice();
|
||||||
|
|
||||||
if (dev == null) {
|
if (dev == null) {
|
||||||
System.err.println("Unknown device");
|
System.err.println("Unknown device");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
|
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
|
||||||
float LS_X = event.getAxisValue(MotionEvent.AXIS_X);
|
float LS_X = event.getAxisValue(MotionEvent.AXIS_X);
|
||||||
float LS_Y = event.getAxisValue(MotionEvent.AXIS_Y);
|
float LS_Y = event.getAxisValue(MotionEvent.AXIS_Y);
|
||||||
|
|
||||||
float RS_X, RS_Y, L2, R2;
|
float RS_X, RS_Y, L2, R2;
|
||||||
|
|
||||||
InputDevice.MotionRange l2Range = dev.getMotionRange(MotionEvent.AXIS_LTRIGGER);
|
InputDevice.MotionRange leftTriggerRange = dev.getMotionRange(MotionEvent.AXIS_LTRIGGER);
|
||||||
InputDevice.MotionRange r2Range = dev.getMotionRange(MotionEvent.AXIS_RTRIGGER);
|
InputDevice.MotionRange rightTriggerRange = dev.getMotionRange(MotionEvent.AXIS_RTRIGGER);
|
||||||
if (l2Range != null && r2Range != null)
|
if (leftTriggerRange != null && rightTriggerRange != null)
|
||||||
{
|
{
|
||||||
// Ouya controller
|
// Ouya controller
|
||||||
RS_X = event.getAxisValue(MotionEvent.AXIS_Z);
|
L2 = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
|
||||||
RS_Y = event.getAxisValue(MotionEvent.AXIS_RZ);
|
R2 = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
|
||||||
L2 = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
|
RS_X = event.getAxisValue(MotionEvent.AXIS_Z);
|
||||||
R2 = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
|
RS_Y = event.getAxisValue(MotionEvent.AXIS_RZ);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Xbox controller
|
InputDevice.MotionRange brakeRange = dev.getMotionRange(MotionEvent.AXIS_BRAKE);
|
||||||
RS_X = event.getAxisValue(MotionEvent.AXIS_RX);
|
InputDevice.MotionRange gasRange = dev.getMotionRange(MotionEvent.AXIS_GAS);
|
||||||
RS_Y = event.getAxisValue(MotionEvent.AXIS_RY);
|
if (brakeRange != null && gasRange != null)
|
||||||
L2 = (event.getAxisValue(MotionEvent.AXIS_Z) + 1) / 2;
|
{
|
||||||
R2 = (event.getAxisValue(MotionEvent.AXIS_RZ) + 1) / 2;
|
// Moga controller
|
||||||
}
|
RS_X = event.getAxisValue(MotionEvent.AXIS_Z);
|
||||||
|
RS_Y = event.getAxisValue(MotionEvent.AXIS_RZ);
|
||||||
InputDevice.MotionRange hatXRange = dev.getMotionRange(MotionEvent.AXIS_HAT_X);
|
L2 = event.getAxisValue(MotionEvent.AXIS_BRAKE);
|
||||||
InputDevice.MotionRange hatYRange = dev.getMotionRange(MotionEvent.AXIS_HAT_Y);
|
R2 = event.getAxisValue(MotionEvent.AXIS_GAS);
|
||||||
if (hatXRange != null && hatYRange != null)
|
}
|
||||||
{
|
else
|
||||||
// Xbox controller D-pad
|
{
|
||||||
float hatX, hatY;
|
// Xbox controller
|
||||||
|
RS_X = event.getAxisValue(MotionEvent.AXIS_RX);
|
||||||
hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
|
RS_Y = event.getAxisValue(MotionEvent.AXIS_RY);
|
||||||
hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
|
L2 = (event.getAxisValue(MotionEvent.AXIS_Z) + 1) / 2;
|
||||||
|
R2 = (event.getAxisValue(MotionEvent.AXIS_RZ) + 1) / 2;
|
||||||
inputMap &= ~(NvControllerPacket.LEFT_FLAG | NvControllerPacket.RIGHT_FLAG);
|
}
|
||||||
inputMap &= ~(NvControllerPacket.UP_FLAG | NvControllerPacket.DOWN_FLAG);
|
}
|
||||||
if (hatX < -0.5) {
|
|
||||||
inputMap |= NvControllerPacket.LEFT_FLAG;
|
|
||||||
}
|
InputDevice.MotionRange hatXRange = dev.getMotionRange(MotionEvent.AXIS_HAT_X);
|
||||||
if (hatX > 0.5) {
|
InputDevice.MotionRange hatYRange = dev.getMotionRange(MotionEvent.AXIS_HAT_Y);
|
||||||
inputMap |= NvControllerPacket.RIGHT_FLAG;
|
if (hatXRange != null && hatYRange != null)
|
||||||
}
|
{
|
||||||
if (hatY < -0.5) {
|
// Xbox controller D-pad
|
||||||
inputMap |= NvControllerPacket.UP_FLAG;
|
float hatX, hatY;
|
||||||
}
|
|
||||||
if (hatY > 0.5) {
|
hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
|
||||||
inputMap |= NvControllerPacket.DOWN_FLAG;
|
hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
|
||||||
}
|
|
||||||
}
|
inputMap &= ~(NvControllerPacket.LEFT_FLAG | NvControllerPacket.RIGHT_FLAG);
|
||||||
|
inputMap &= ~(NvControllerPacket.UP_FLAG | NvControllerPacket.DOWN_FLAG);
|
||||||
leftStickX = (short)Math.round(LS_X * 0x7FFF);
|
if (hatX < -0.5) {
|
||||||
leftStickY = (short)Math.round(-LS_Y * 0x7FFF);
|
inputMap |= NvControllerPacket.LEFT_FLAG;
|
||||||
|
}
|
||||||
rightStickX = (short)Math.round(RS_X * 0x7FFF);
|
if (hatX > 0.5) {
|
||||||
rightStickY = (short)Math.round(-RS_Y * 0x7FFF);
|
inputMap |= NvControllerPacket.RIGHT_FLAG;
|
||||||
|
}
|
||||||
leftTrigger = (byte)Math.round(L2 * 0xFF);
|
if (hatY < -0.5) {
|
||||||
rightTrigger = (byte)Math.round(R2 * 0xFF);
|
inputMap |= NvControllerPacket.UP_FLAG;
|
||||||
|
}
|
||||||
sendControllerInputPacket();
|
if (hatY > 0.5) {
|
||||||
return true;
|
inputMap |= NvControllerPacket.DOWN_FLAG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
leftStickX = (short)Math.round(LS_X * 0x7FFF);
|
||||||
|
leftStickY = (short)Math.round(-LS_Y * 0x7FFF);
|
||||||
|
|
||||||
|
rightStickX = (short)Math.round(RS_X * 0x7FFF);
|
||||||
|
rightStickY = (short)Math.round(-RS_Y * 0x7FFF);
|
||||||
|
|
||||||
|
leftTrigger = (byte)Math.round(L2 * 0xFF);
|
||||||
|
rightTrigger = (byte)Math.round(R2 * 0xFF);
|
||||||
|
|
||||||
|
sendControllerInputPacket();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0)
|
else if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0)
|
||||||
{
|
{
|
||||||
// Send a mouse move update (if neccessary)
|
// Send a mouse move update (if neccessary)
|
||||||
updateMousePosition((int)event.getX(), (int)event.getY());
|
updateMousePosition((int)event.getX(), (int)event.getY());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user