Use IDs to track controllers instead of descriptors. Fixes #64

This commit is contained in:
Cameron Gutman 2015-05-05 20:08:58 -04:00
parent f1230d46f3
commit 9878902a89

View File

@ -1,10 +1,10 @@
package com.limelight.binding.input; package com.limelight.binding.input;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import android.hardware.input.InputManager; import android.hardware.input.InputManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.SparseArray;
import android.view.InputDevice; import android.view.InputDevice;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -31,7 +31,7 @@ public class ControllerHandler implements InputManager.InputDeviceListener {
private final Vector2d inputVector = new Vector2d(); private final Vector2d inputVector = new Vector2d();
private final HashMap<String, ControllerContext> contexts = new HashMap<String, ControllerContext>(); private final SparseArray<ControllerContext> contexts = new SparseArray<ControllerContext>();
private final NvConnection conn; private final NvConnection conn;
private final double stickDeadzone; private final double stickDeadzone;
@ -104,13 +104,11 @@ public class ControllerHandler implements InputManager.InputDeviceListener {
@Override @Override
public void onInputDeviceRemoved(int deviceId) { public void onInputDeviceRemoved(int deviceId) {
for (Map.Entry<String, ControllerContext> device : contexts.entrySet()) { ControllerContext context = contexts.get(deviceId);
if (device.getValue().id == deviceId) { if (context != null) {
LimeLog.info("Removed controller: "+device.getValue().name); LimeLog.info("Removed controller: "+context.name+" ("+deviceId+")");
releaseControllerNumber(device.getValue()); releaseControllerNumber(context);
contexts.remove(device.getKey()); contexts.remove(deviceId);
return;
}
} }
} }
@ -135,7 +133,7 @@ public class ControllerHandler implements InputManager.InputDeviceListener {
return; return;
} }
LimeLog.info(context.name+" needs a controller number assigned"); LimeLog.info(context.name+" ("+context.id+") needs a controller number assigned");
if (context.name != null && context.name.contains("gpio-keys")) { if (context.name != null && context.name.contains("gpio-keys")) {
// This is the back button on Shield portable consoles // This is the back button on Shield portable consoles
LimeLog.info("Built-in buttons hardcoded as controller 0"); LimeLog.info("Built-in buttons hardcoded as controller 0");
@ -322,17 +320,15 @@ public class ControllerHandler implements InputManager.InputDeviceListener {
return defaultContext; return defaultContext;
} }
String descriptor = dev.getDescriptor();
// Return the existing context if it exists // Return the existing context if it exists
ControllerContext context = contexts.get(descriptor); ControllerContext context = contexts.get(dev.getId());
if (context != null) { if (context != null) {
return context; return context;
} }
// Otherwise create a new context // Otherwise create a new context
context = createContextForDevice(dev); context = createContextForDevice(dev);
contexts.put(descriptor, context); contexts.put(dev.getId(), context);
return context; return context;
} }