Added deadzone for left/right sticks

This commit is contained in:
admiralmachado
2014-03-11 21:22:44 +01:00
committed by Iwan Timmer
parent 161175b866
commit 06fb196b6a
2 changed files with 14 additions and 4 deletions

View File

@@ -157,13 +157,13 @@ public class EvdevHandler implements Runnable {
conn.sendMouseMove((short) 0, (short) value);
} else if (type==EvdevConstants.EV_ABS) {
if (code==mapping.abs_x)
leftStickX = absLX.getShort(value);
leftStickX = accountForDeadzone(absLX.getShort(value));
else if (code==mapping.abs_y)
leftStickY = absLY.getShort(value);
leftStickY = accountForDeadzone(absLY.getShort(value));
else if (code==mapping.abs_rx)
rightStickX = absRX.getShort(value);
rightStickX = accountForDeadzone(absRX.getShort(value));
else if (code==mapping.abs_ry)
rightStickY = absRY.getShort(value);
rightStickY = accountForDeadzone(absRY.getShort(value));
else if (code==mapping.abs_throttle)
leftTrigger = absLT.getByte(value);
else if (code==mapping.abs_rudder)
@@ -198,6 +198,14 @@ public class EvdevHandler implements Runnable {
}
}
private short accountForDeadzone(short value) {
if (Math.abs(value) > mapping.abs_deadzone) {
return value;
} else {
return 0;
}
}
@Override
public void run() {
try {

View File

@@ -18,6 +18,8 @@ public class GamepadMapping {
public short abs_rx = EvdevConstants.ABS_RX;
public short abs_ry = EvdevConstants.ABS_RY;
public short abs_deadzone = 0;
public short abs_dpad_y = -1;
public short abs_dpad_x = -1;