Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gamepad axis mapping #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

z3db0y
Copy link

@z3db0y z3db0y commented Sep 17, 2022

This issue has been bothering me for a long time and I have decided to open a PR to fix it:
The mapping on our team's controllers in the dashboard was off - left stick axes were mapped correctly but right_stick_x was mapped to the controller's right_stick_y and right_stick_y wasn't being mapped at all. Taking a look at the code, it was simply 2 typos.

@rbrott
Copy link
Member

rbrott commented Sep 20, 2022

Thanks for the patch. I'm not sure those two indices are actually typos, and it's impossible for me to test. I don't want to change the general case if possible, but I'm happy to add a new case for you. Can you give me the full name of the gamepad as reported by this site as well as your browser and OS? For context, I'm hoping to fill out this info for all gamepad changes going forward.

@z3db0y
Copy link
Author

z3db0y commented Oct 1, 2022

Sorry, for the late reply, but here is the test:

image

Controller Used: official Xbox One Controller:

image

@Windwoes
Copy link

One possible way to fix this would be to use WebHID to manually interpret the data reports for the FTC legal gamepad types.

@NoahBres
Copy link
Contributor

:(
CleanShot 2022-11-20 at 22 44 36@2x

@rbrott
Copy link
Member

rbrott commented Nov 21, 2022

To be clear: Chrome-only support for gamepads is reasonable. Doubly so if the implementation actually works without constant fiddling.

@qwertychouskie
Copy link

Chrome-only would be a big bummer for our team. Ideally there would at least be the old code path as a fallback, preferably with a config option in the dashboard to allow users to change their axis mappings.

@NoahBres
Copy link
Contributor

NoahBres commented Nov 26, 2022

@qwertychouskie Do the other browsers still work with gamepads as of now?

@Glaferg
Copy link

Glaferg commented Dec 10, 2022

Well... I don't know. A quick search at-Comp yielded this Firefox library. for controller support, and Safari's apparently works, as detailed here. Incredibly eager to see one of the most helpful libs in FTC grow!!

@qwertychouskie
Copy link

I will also mention I am able to use https://gamepad-tester.com/ just fine on Firefox+Linux.

@NoahBres
Copy link
Contributor

This isn't a problem with the gamepad API not working. The problem is that the gamepad API doesn't work in non-secure contexts. Local dash isn't HTTPS, thus not a secure context. More details on my investigation can be found here: #67

Those sites should work fine because they are served over HTTPS. The problem is that dash is not served over HTTPS.

@z3db0y
Copy link
Author

z3db0y commented Mar 4, 2023

Lol you guys over-thought the issue, the API you're using is fine and well-supported, it's just that xbox controllers get mapped wrong. I asked another team about their dashboard sticks and they told me their right stick is also wrongly mapped. If a member of the repo has an xbox controller, I suggest testing it- here's proof of concept:

2023-03-04.22-27-09.mp4

Cannot get axes[4] of a 4 element array xd

@z3db0y
Copy link
Author

z3db0y commented Dec 19, 2023

// ==UserScript==
// @name         FTC Dashboard Gamepad Fix
// @namespace    https://z3db0y.com
// @version      1.0
// @description  Fixes improper axes mapping on Xbox controllers in FTC dashboard.
// @author       z3db0y
// @match        http://192.168.43.1:8080/dash
// @match        http://192.168.49.1:8080/dash
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    let map = {};

    let observer = new MutationObserver(m => {
       for(let mut of m) {
           for(let node of mut.addedNodes || []) {
               if(node.nodeName !== 'SCRIPT' || !node.src || !/\/index\..*\.js$/.test(node.src)) continue;
               node.remove();

               let xhr = new XMLHttpRequest();
               xhr.open('GET', node.src, false);
               xhr.send();

               let n = document.createElement('script');
               n.textContent = xhr.response
                   .replace(/case (.+)\.XBOX_360:return{left_stick_x:(.+)\((.+)\.axes\[0]\),left_stick_y:(?:.+)\((?:.+)\.axes\[1]\),right_stick_x:(?:.+)\((?:.+)\.axes\[3]\),right_stick_y:(?:.+)\((?:.+)\.axes\[4]\)/g, 'case $1.XBOX_360:return{left_stick_x:$2($3.axes[0]),left_stick_y:$2($3.axes[1]),right_stick_x:$2($3.axes[2]),right_stick_y:$2($3.axes[3])');
               console.log(n.textContent);
               window.onload = () => document.head.appendChild(n);
           }
       }
    });
    observer.observe(document.documentElement, { childList: true, subtree: true })
})();

For those still having this issue, here's a makeshift fix. (tampermonkey)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants