OpenROV / openrov-software

Meta project for all of the OpenROV Software projects
http://openrov.com
Other
423 stars 189 forks source link

System no longer wires up a gamepad that is connected after cockpit has started #626

Closed BrianAdams closed 7 years ago

BrianAdams commented 7 years ago

Start cockpit Plugin gamepad

Expected: full control Actually: no control from gamepad

gilborty commented 7 years ago

The Gamepad API we have been using has been deprecated. The maintainer suggests just using the provided Web APIs

gilborty commented 7 years ago

As per your steps for recreating the bug, I am having difficulty recreating it in MOCK mode on my machine. The PS4 controller always comes up when I start cockpit and plug in the gamepad. Am I missing something?

I do realize that these steps produce a bug:

Expected: Full control Actually: No control

BrianAdams commented 7 years ago

I suspect this might fix it:

diff --git a/src/static/js/libs/gamepad.js b/src/static/js/libs/gamepad.js
index 5dc89de..9225f0a 100644
--- a/src/static/js/libs/gamepad.js
+++ b/src/static/js/libs/gamepad.js
@@ -582,7 +582,13 @@
       console.log('Not supposed to go here!');
       return;  // should not happen
     }
-    if (gamepads.length !== this.gamepads.length) {
+    gamepads.nonNulllength = 0;
+    for (i = 0; i < gamepads.length; i++) {
+      if (gamepads[i]!==null){
+        gamepads.nonNulllength++;
+      }
+    }
+    if (gamepads.nonNulllength !== this.gamepads.length) {
       var gamepad, i;
       for (i = 0; i < gamepads.length; i++) {
         gamepad = gamepads[i];

Trying to find a gamepad to test with