Gamepad API fails on Chrome v73 and later

I have had a strange behavior when I (was forced to) upgrade to Chrome v73, my gamepad interface no longer works. If I go to any gamepad test site the controller does work (https://html5gamepad.com/) but on openrov it does not. So I suspect that there is something iffy in the openrov code using the gamepad API that is no longer acceptable to Chrome. It doesn’t seem to matter which gamepad I use (XBOX 360, XBOX, etc.) the outcome is the same. I noticed that the call to navigator.getGamepads() returns null on v73 and later but returns the gamepads on earlier versions.

Any ideas?

Hi neil2,

I have the same issues with recent chrome.
I do a quick fix on the gamepad.js file.
You could look at my github fork of openrov-cockpit into the v31.0.0-rc branch.
Copy this files https://github.com/eyoz/openrov-cockpit/blob/v31.0.0-rc/src/static/js/libs/gamepad.js to your rov.

Excellent. I will try this out

You could try too the release I do 31.0.0-rc7, you will find the ref here New Release Candidate Image ready with 31.0.0 RC.

This image is based on the v31 version with imu and gamepad fix.
This image is attended to be run from the sdcard and don’t touch the bbb memory.

So in the end it was better but not perfect. I had to make one additional change for an XBOX 360 gamepad to work.

In the Gamepad.prototype._update function where you made modifications I needed one more

      for (controlName in this.gamepads[i].libmapping.axes) {
        mapping = this.gamepads[i].libmapping.axes[controlName];
        if (typeof mapping === 'function') {
             // I added the change below
            value = mapping(navigator.getGamepads()[i], this);
            // value = mapping(this.gamepads[i], this);
        } else {
          value = this._applyDeadzoneMaximize(navigator.getGamepads()[i].axes[mapping]);
          // value = this._applyDeadzoneMaximize(this.gamepads[i].axes[mapping]);
        }
        this.gamepads[i].state[controlName] = value;
        if (value !== this.gamepads[i].lastState[controlName]) {
          this._fire(Gamepad.Event.AXIS_CHANGED, {
            gamepad: this.gamepads[i],
            mapping: mapping,
            axis: controlName,
            value: value
          });
        }

Now the game controller works without issue. On the surface this fix doesn’t make a lot of sense to me. But it works.