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

Controller support request for Xiaomi Gamepad #40

Closed
ricardoesppinozag opened this issue Aug 31, 2020 · 46 comments
Closed

Controller support request for Xiaomi Gamepad #40

ricardoesppinozag opened this issue Aug 31, 2020 · 46 comments
Labels
feature request New feature or request

Comments

@ricardoesppinozag
Copy link

Controller support for Xiaomi Gamepad would ve aprecciated, awsome work, contrats and thankyou.

Website link: https://xiaomi-mi.com/accessories-for-tv/xiaomi-mi-bluetooth-gamepad/

@ricardoesppinozag
Copy link
Author

ricardoesppinozag commented Aug 31, 2020

the control connects and appears as pro controller in mission control app but does not work and does not appear in the config controls menu.

@ndeadly
Copy link
Owner

ndeadly commented Aug 31, 2020

Can you post the output of the app so I can see what it's using for a hardware ID? Might just be a simple matter of whitelisting that. Do you know anything about the input format it uses?

@ricardoesppinozag
Copy link
Author

Sorry for te closed, i hope the photo can help, thank you.

@ricardoesppinozag
Copy link
Author

WhatsApp Image 2020-08-31 at 12 52 46 PM

@ndeadly
Copy link
Owner

ndeadly commented Aug 31, 2020

Thanks. Looks like it uses a unique ID, so there shouldn't be any issues identifying the controller. I think it might use the same format as an Xbox 360 controller though so I'll need to make a new handler for it. I'll probably need you to test a build for it in the next day or two when I get a chance to work on it.

@ricardoesppinozag
Copy link
Author

Okay, I can test whatever is needed to see compatibility, thanks for your work

@ndeadly ndeadly added the feature request New feature or request label Sep 1, 2020
@ndeadly
Copy link
Owner

ndeadly commented Sep 2, 2020

Here's a build with initial support for the xiaomi. It should now appear to connect to the console but not respond to button presses just yet.
MissionControl-0.1.0-xiaomi.zip

Could you install that and then run this tool to view the raw HID reports? It's a bit crappy and lags by about 1sec but will show how the data changes when you use the controls. If this makes sense to you, you could try to figure out which bits/bytes are affected by which buttons. Otherwise, a screenshot of the output would be a good start for me to find further info online.

Note this app steals the HID controller events from the system, so you will need to use the home button on the joycon to exit.

hid_report_tool.zip

@ricardoesppinozag
Copy link
Author

Look, it didnt appear connected at console menu but in hid repport there somo information. These photos are from there:

No button in use:
No button pressed
Right stick pressed:
Right stick pressed
Left stick pressed:
Left stick pressed

Im sorry i dont know about the bites/bytes affected but i can try anything you need, Let me know if i can help in something else. Thanks.

@ndeadly
Copy link
Owner

ndeadly commented Sep 2, 2020

Hmm, not sure why it wouldn't have showed up as connected. Maybe I got the ID wrong.

If you want to speed things up you could try and note down the numbers that change when you press each button or push the stick to an extreme position in x or y. If this flies over your head feel free to ignore and I'll figure it out eventually or find someone else with the same controller to test.

To understand what we're doing here:
If you look at those screenshots you've sent me, you'll see that the third number in white changes with each different state you showed
hid_report

If you punch these numbers into a programming calculator in hex mode, you'll see that they correspond to a binary number with (usually) exactly one bit set to 1. These ones correspond to the button being pressed.
calc

0x20 -> 00100000
0x40 -> 01000000

You could write these down something like the below, or simply copy down all the numbers as shown in your screen captures

left stick pressed:
byte[3] = 0x20

right stick pressed:
byte[3] = 0x40

@puked79
Copy link

puked79 commented Sep 3, 2020

2020090312400200-DB1426D1DFD034027CECDE9C2DD914B8
2020090312412700-DB1426D1DFD034027CECDE9C2DD914B8
2020090312413900-DB1426D1DFD034027CECDE9C2DD914B8
2020090312414900-DB1426D1DFD034027CECDE9C2DD914B8
2020090312415300-DB1426D1DFD034027CECDE9C2DD914B8
2020090312420100-DB1426D1DFD034027CECDE9C2DD914B8
2020090312420500-DB1426D1DFD034027CECDE9C2DD914B8
2020090312421000-DB1426D1DFD034027CECDE9C2DD914B8
2020090312421400-DB1426D1DFD034027CECDE9C2DD914B8
2020090312422400-DB1426D1DFD034027CECDE9C2DD914B8
2020090312423300-DB1426D1DFD034027CECDE9C2DD914B8
2020090312423500-DB1426D1DFD034027CECDE9C2DD914B8
2020090312423700-DB1426D1DFD034027CECDE9C2DD914B8
2020090312423900-DB1426D1DFD034027CECDE9C2DD914B8
2020090312424100-DB1426D1DFD034027CECDE9C2DD914B8
2020090312424300-DB1426D1DFD034027CECDE9C2DD914B8
2020090312424500-DB1426D1DFD034027CECDE9C2DD914B8
2020090312425900-DB1426D1DFD034027CECDE9C2DD914B8
2020090312430500-DB1426D1DFD034027CECDE9C2DD914B8
2020090312431400-DB1426D1DFD034027CECDE9C2DD914B8
2020090312432600-DB1426D1DFD034027CECDE9C2DD914B8
2020090312433300-DB1426D1DFD034027CECDE9C2DD914B8
2020090312434200-DB1426D1DFD034027CECDE9C2DD914B8
2020090312434700-DB1426D1DFD034027CECDE9C2DD914B8
2020090312440700-DB1426D1DFD034027CECDE9C2DD914B8
2020090312441100-DB1426D1DFD034027CECDE9C2DD914B8
2020090312441400-DB1426D1DFD034027CECDE9C2DD914B8
2020090312441700-DB1426D1DFD034027CECDE9C2DD914B8
2020090312443800-DB1426D1DFD034027CECDE9C2DD914B8
2020090312444600-DB1426D1DFD034027CECDE9C2DD914B8

@ndeadly
Copy link
Owner

ndeadly commented Sep 3, 2020

@puked79 Thanks mate, I'll get to adding the button mappings.

@puked79
Copy link

puked79 commented Sep 3, 2020

youre welcome ;) Seems like "home button" works, too - but its only registered for the fraction of a second - to fast for my eyes...

and thanks again for this great project! I love it!

@ndeadly
Copy link
Owner

ndeadly commented Sep 3, 2020

Ah yeah, the old firmware on the xbox controller puts the home button on a separate report too. It flashes up because it gets quickly overwritten with the usual button/stick data report. Try this version where I've filtered out the normal button packets from the xiaomi. It's also worth noting whether you see any other reports come up. One of these may contain battery level info (though it could also be that 0x3c value in the screenshots you posted. Maybe you could see if that or any other values change depending on the battery level or whether the controller is charging via cable.
hid_report_tool-xiaomi.zip

Anyway, here's a new build with the controls mapped according to the images you posted. Let me know if anything is not as it should be.
MissionControl-0.1.0-xiaomi-experimental.zip

You can use this tool I made to help test the mappings.
ControllerTest.zip

@puked79
Copy link

puked79 commented Sep 3, 2020

that was fast.

tested - unfortunately it does not work.
ControllerTest does not detect any button. The program itself and missioncontrol itself are working - i tested with a wii pro controller .
hid_report_tool blacks out. it does not crash, but shows nothing. When wiimote and the xiaomi gamepad are connected, it flickers and shows only values for the wiimote.

@ndeadly
Copy link
Owner

ndeadly commented Sep 3, 2020

Strange. So no controls work at all (even if incorrect)? Does the controller show up as connected to the system now?

Yeah that's to be expected with the hid_report_tool. I'm filtering out the main button data report from the xiaomi in the hope of catching any others that might be sent. You shouldn't really have two wireless controllers connected when using this as they will interfere with one another (the reason for the flickering). At some point I might refine this tool for general use, but at the moment it's just a bit of a hack I was using for my own purposes.

@puked79
Copy link

puked79 commented Sep 3, 2020

I just wanted to test, if it crashed - that`s why i connected a second controller. It indeed does not flicker, when only the wii controller is connected.

No, it does not show as connected to the system. I guess ControllerTest would only work, if it was?!

@ndeadly
Copy link
Owner

ndeadly commented Sep 3, 2020

Ok, sounds like maybe it's not completing the handshake with the console after connecting. This can mean one of two things. Either the controller ID hasn't been matched and the handler isn't attached, or your switch is sending some commands to the controller that I haven't seen before and therefore don't handle. Start by dumping your controller database with btdb.nro and confirm your controller has the same ID as @ricardoesppinozag 2717:3144. If that all checks out I'll make you a build with logging included so we can log the connection process.

Oh also, what I was mainly interested in with the modified hid_report_tool was whether you see any data send when you press the home button, as this might be sent in a different report. Did you check that?

@puked79
Copy link

puked79 commented Sep 3, 2020

I did on Aug. 27th ;P

edit: I checked, if data is send when home button is pressed. No - there is not. At least nothing shows up in the modified hid_report_tool.

mpwcRlZ
l2VVXGT

@ndeadly
Copy link
Owner

ndeadly commented Sep 3, 2020

Everything looks fine to me. Install this build with logging enabled and get a log of attempting to connect the controller. It will create the log on your SD root at btdrv-mitm.log. Note that the log is wiped every time you reboot.

The logging introduces a fair amount of lag, so it's not recommended to leave this build installed outside of debugging issues like this.

MissionControl-0.1.0-debug-logging-xiaomi.zip

@pabermod
Copy link

pabermod commented Sep 3, 2020

photo_2020-09-03_17-26-53
It seems the first 4 Hex values are the same (last pro controller) And the 8 digits at the end

@pabermod
Copy link

pabermod commented Sep 3, 2020

btdrv-mitm.log
Not working with latest build

@pabermod
Copy link

pabermod commented Sep 3, 2020

Also when I try the hid report tool as soon as a I push one button the screen goes black

@pabermod
Copy link

pabermod commented Sep 3, 2020

I want to note that this gamepad has a gyroscope

@ndeadly
Copy link
Owner

ndeadly commented Sep 3, 2020

@pabermod yeah it's not expected to be working yet. That build simply enables logging.

It looks like maybe this controller is generating an unknown HID event that other controllers don't. See if this build where I drop the event makes any difference (no logs here).
MissionControl-0.1.0-xiaomi-experimental-silence-event.zip

@ndeadly
Copy link
Owner

ndeadly commented Sep 3, 2020

I want to note that this gamepad has a gyroscope

Do you know if anything special has to be done to enable it? I'm guessing that's what those 00s at the end of the data reports might be for, but I'd expect them to be changing.

@pabermod
Copy link

pabermod commented Sep 3, 2020 via email

@puked79
Copy link

puked79 commented Sep 3, 2020

@pabermod yeah it's not expected to be working yet. That build simply enables logging.

It looks like maybe this controller is generating an unknown HID event that other controllers don't. See if this build where I drop the event makes any difference (no logs here).
MissionControl-0.1.0-xiaomi-experimental-silence-event.zip

tested - makes no difference

@ndeadly
Copy link
Owner

ndeadly commented Sep 6, 2020

Try this one. I think I was just stupid and forgot to actually create the controller handler XD.
MissionControl-0.1.0-xiaomi-experimental.zip

@puked79
Copy link

puked79 commented Sep 7, 2020

It works :) - thank you!
a/b and x/y are reversed
hid_report_tool does not show anything at all

@ndeadly
Copy link
Owner

ndeadly commented Sep 7, 2020

Nice. I didn't think those looked right vs other XInput controllers. I just looked at your captures again and I guess you tried to report in terms of how they would map to a Switch Pro controller, rather than the face value of the buttons themselves.
All good. This build should fix it.
MissionControl-0.1.0-xiaomi-experimental.zip

Does this controller have a player led indicator or anything?

@pabermod
Copy link

pabermod commented Sep 7, 2020

Nice. I didn't think those looked right vs other XInput controllers. I just looked at your captures again and I guess you tried to report in terms of how they would map to a Switch Pro controller, rather than the face value of the buttons themselves.
All good. This build should fix it.
MissionControl-0.1.0-xiaomi-experimental.zip

Does this controller have a player led indicator or anything?

It does not have a player indicator. Can you map the "Home" button of the gamepad?

I manage to capture a screenshot of the changed byte when pressing the home button. It changes the last byte from 00 to 01

@ndeadly
Copy link
Owner

ndeadly commented Sep 7, 2020

It does not have a player indicator. Can you map the "Home" button of the gamepad?

Oh, is it not working? Maybe I don't have the mapping quite right. Can you post the screenshot?

@ndeadly
Copy link
Owner

ndeadly commented Sep 7, 2020

Try this one.
MissionControl-0.1.0-xiaomi-experimental.zip

@pabermod
Copy link

pabermod commented Sep 7, 2020

Home button not working with that latest version

photo_2020-09-07_17-32-28

@ndeadly
Copy link
Owner

ndeadly commented Sep 7, 2020

Hmm that looks fine for the current mapping. How are you verifying the buttons are working? Did you try it with ControllerTest.nro?

@pabermod
Copy link

pabermod commented Sep 7, 2020 via email

@ndeadly
Copy link
Owner

ndeadly commented Sep 7, 2020

Yeah I can't see why that wouldn't be working then. If you run hid_report_tool does the value stay as 01 if you hold the home button down or just flash up on the screen? I'm wondering whether maybe it needs to be registered as pressed for multiple reports before it's recognised

@pabermod
Copy link

pabermod commented Sep 7, 2020 via email

@ndeadly
Copy link
Owner

ndeadly commented Sep 7, 2020

Maybe that's the issue. Does it flash up as 01 again when you release maybe? Or just stays 00..

In this build I've swapped the back and home buttons. See if the physical home button shows as a press of the minus button or not.
MissionControl-0.1.0-xiaomi-experimental.zip

@pabermod
Copy link

pabermod commented Sep 7, 2020

Now using the minus button works good as home button... So it seems the "Home" button is sending a strange event

@ndeadly
Copy link
Owner

ndeadly commented Sep 7, 2020

@pabermod that's to be expected, but does the home button work as the minus button (even briefly) when you press it. I want to know whether home presses are maybe handled differently by the system or if my mapping is still somehow wrong.

@pabermod
Copy link

pabermod commented Sep 7, 2020

No, the home button is working as previously, quick flash of the last byte even when holding it

@ndeadly
Copy link
Owner

ndeadly commented Sep 7, 2020

I don't think you're understanding what I'm asking of you. The underlying behaviour of the controller won't change, so looking at hid_report_tool will always show the same thing. I want you to take a look at ControllerTest and see whether pressing the home button (which I've now mapped as the minus button) flashes up as a button press or not.

@pabermod
Copy link

pabermod commented Sep 7, 2020

it doesnt

@ndeadly
Copy link
Owner

ndeadly commented Sep 7, 2020

Hmm, weird. I might have to sleep on this one for now then as I want to try and push out a new release tonight to fix some other issues.

@ndeadly
Copy link
Owner

ndeadly commented Oct 4, 2020

I've reworked the way that controller state is processed in version 0.3.0. See if it makes any difference to your Home button issue. Either way, you can now use the combo MINUS + DPAD_DOWN for Home on any controller.

I'll consider this controller supported now.

@ndeadly ndeadly closed this as completed Oct 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants