From 832e7197c5cba33845d43b664ad182e5bf9afe54 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 5 Jun 2019 22:26:06 -0700 Subject: [PATCH] Delay a bit before reporting USB devices to allow the old InputDevice to go away --- .../input/driver/AbstractXboxController.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/limelight/binding/input/driver/AbstractXboxController.java b/app/src/main/java/com/limelight/binding/input/driver/AbstractXboxController.java index 1ca9467a..f3187fc8 100644 --- a/app/src/main/java/com/limelight/binding/input/driver/AbstractXboxController.java +++ b/app/src/main/java/com/limelight/binding/input/driver/AbstractXboxController.java @@ -30,6 +30,18 @@ public abstract class AbstractXboxController extends AbstractController { private Thread createInputThread() { return new Thread() { public void run() { + try { + // Delay for a moment before reporting the new gamepad and + // accepting new input. This allows time for the old InputDevice + // to go away before we reclaim its spot. If the old device is still + // around when we call notifyDeviceAdded(), we won't be able to claim + // the controller number used by the original InputDevice. + Thread.sleep(1000); + } catch (InterruptedException e) {} + + // Report that we're added _before_ reporting input + notifyDeviceAdded(); + while (!isInterrupted() && !stopped) { byte[] buffer = new byte[64]; @@ -114,9 +126,6 @@ public abstract class AbstractXboxController extends AbstractController { return false; } - // Report that we're added _before_ starting the input thread - notifyDeviceAdded(); - // Start listening for controller input inputThread = createInputThread(); inputThread.start();