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

PS3 gamepads do not work with macOS 12 #4923

Closed
vit9696 opened this issue Nov 8, 2021 · 36 comments
Closed

PS3 gamepads do not work with macOS 12 #4923

vit9696 opened this issue Nov 8, 2021 · 36 comments
Assignees
Milestone

Comments

@vit9696
Copy link

vit9696 commented Nov 8, 2021

As of macOS 12.0.1 HID controllers are recognised but fail to provide any input to macOS. In particular, IOHIDDeviceRegisterInputValueCallback/IOHIDDeviceRegisterInputReportCallback apparently never call callbacks with e.g. Sony DualShock 3, but likely others.

This was originally reported as hrydgard/ppsspp#15112 and sent as FB9745903 to Apple. The simplest project I was able to reproduce it is https://github.com/armadillu/MacJoystickHIDTest.

@slouken slouken self-assigned this Nov 8, 2021
@slouken slouken added this to the 2.0.18 milestone Nov 8, 2021
@slouken slouken added the Apple Apple is tracking this bug internally label Nov 8, 2021
@slouken slouken removed this from the 2.0.18 milestone Nov 8, 2021
@vit9696
Copy link
Author

vit9696 commented Nov 8, 2021

@slouken any comment on this besides the label changes :)? I think implementing direct DS3 HID packet handling on macOS through libusb will likely work, but am unsure whether it is worth the effort.

For rumble purposes it is nice, in the past I did exactly that, but I still left other data like button input to SDL at that time.

@slouken
Copy link
Collaborator

slouken commented Nov 9, 2021

I don't have a macOS 12 system right now, but I did report it to Apple and they're investigating.

BTW, we don't have HIDAPI support for the DS3, but that's certainly something we can add, if you're interested in contributing it.

@vit9696
Copy link
Author

vit9696 commented Nov 12, 2021

@slouken I tried libusb router, and it does not seem to be too easy. IOUSBHostHIDDevice.kext owns the USB interface, so libusb_claim_interface would fail. This can be resolved by ensuring libusb_detach_kernel_driver gets called and succeeded: for this one needs to run the app with root privileges. But even in this case I get timeouts.

On the other side, I did find a workaround for the native macOS HID API by reviewing my old code for DS3 dating back to 10.6 days :-) For some reason macOS driver is no longer sending the initialisation sequence for DS3, which is the reason why the gamepad does nothing. I have a suspect this happened before, because I added exactly this code some while ago, though the intent was to support rumbling.

It was enough for me to run the following code to get DS3 working in all applications until replug:

    {
        uint8_t dataBlob[] = { 0x42, 0x0C, 0x00, 0x00};
        IOHIDDeviceSetReport(device, kIOHIDReportTypeFeature, 0xF4, dataBlob, sizeof(dataBlob));
    }

And the following sequence could be used to activate rumble support and additionally disable LEDs.

    {
        uint8_t dataBlob[] = {
            0x01,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00, // rumble values [0x00, right-timeout, right-force, left-timeout, left-force]
            0x00,
            0x00, // Gyro
            0x00,
            0x00,
            0x00, // 0x02=LED1 .. 0x10=LED4
            /*
             * the total time the led is active (0xff means forever)
             * |     duty_length: how long a cycle is in deciseconds:
             * |     |                              (0 means "blink very fast")
             * |     |     ??? (Maybe a phase shift or duty_length multiplier?)
             * |     |     |     % of duty_length led is off (0xff means 100%)
             * |     |     |     |     % of duty_length led is on (0xff is 100%)
             * |     |     |     |     |
             * 0xff, 0x27, 0x10, 0x00, 0x32,
             */
            0xff,
            0x27,
            0x10,
            0x00,
            0x32, // LED 4
            0xff,
            0x27,
            0x10,
            0x00,
            0x32, // LED 3
            0xff,
            0x27,
            0x10,
            0x00,
            0x32, // LED 2
            0xff,
            0x27,
            0x10,
            0x00,
            0x32, // LED 1
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            // Necessary for Fake DS3
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
        };
        static const size_t RumbleLengthL = 4;
        static const size_t RumblePowerL = 5;
        static const size_t RumbleLengthR = 2;
        static const size_t RumblePowerR = 3;
        dataBlob[RumbleLengthL] = dataBlob[RumbleLengthR] = 80;
        dataBlob[RumblePowerL]                            = 255;
        dataBlob[RumblePowerR]                            = 1;
        IOHIDDeviceSetReport(device, kIOHIDReportTypeOutput, 1, dataBlob, sizeof(dataBlob));
    }

Question is, should we integrate it into SDL? This simple set of sequences does not cover everything but is necessary to activate DS3 support on macOS 12.0.1. I attached a small program that can be run once after connecting the gamepad as a workaround…

ds3activate.zip

@kode54
Copy link

kode54 commented Jan 2, 2022

I'm having trouble making an Xbox Wireless Controller work. Could this be related?

@AlexNelsonMusic
Copy link

Thank you for this! I actually prefer it to the old method, it used to be super finicky to connect.

@slouken slouken changed the title HID gamepads do not work with macOS 12 PS3 gamepads do not work with macOS 12 Mar 19, 2022
@crishs2001
Copy link

I tried running the script OP provided, but the D-Pad is not working, and both triggers appear as permanently pressed. Any ideas on how to tackle that?

@cortozld
Copy link

I tried running the script OP provided, but the D-Pad is not working, and both triggers appear as permanently pressed. Any ideas on how to tackle that?

I have the same issue. A fix would be awesome

@andrekandore
Copy link

andrekandore commented Apr 17, 2022

both triggers appear as permanently pressed

same issue as well...

@maciekish
Copy link

I got my Dualshock 3 working using the provided binary, however PCSX2 doesnt seem to support the pressure sensitivity. Don't know if it uses SDL to be honest, anyone know more about this? Tried MGS 2 & 3, cant lower weapons without firing and grabbing an enemy in MGS3 while pressing lightly kills them instead of starting an interrogation.

@brroges
Copy link

brroges commented May 5, 2022

can anyone guide me into using ps3 controller on my MacBook? for use with nividia geforce

@yeetyeah59
Copy link

This makes my DualShock 3 controller usable but it won't stop vibrating. Any workaround for this particular issue?

@MilGreat2010
Copy link

MilGreat2010 commented Jun 16, 2022

can anyone guide me into using ps3 controller on my MacBook? for use with nividia geforce

@brroges

look above for ds3activate.zip , connect your ps3 controller to your mac (wired), right click the ds3activate file and select open, if it worked, the controller should vibrate, and now it should work!

@andrew1-1
Copy link

andrew1-1 commented Jul 23, 2022

can anyone guide me into using ps3 controller on my MacBook? for use with nividia geforce

@brroges

look above for ds3activate.zip , connect your ps3 controller to your mac (wired), right click the ds3activate file and select open, if it worked, the controller should vibrate, and now it should work!

@vit9696 @danielholmes

Is it normal that it won't stop vibrating?

@ShadowBullet25
Copy link

I tried running the script OP provided, but the D-Pad is not working, and both triggers appear as permanently pressed. Any ideas on how to tackle that?

i have the exact same problem, except that its my two bumpers instead of the triggers. does anyone know how to fix this?

@EzeZucchiatti
Copy link

I've tried the script but my controller doesn't stop vibrating, need to unplug and plug on my cellphone and open octopus to stop. Any idea?

@icculus
Copy link
Collaborator

icculus commented Aug 23, 2022

Okay, we can't really do tech support on the script, so let's bring this back to an SDL thing:

  • I assume this still isn't supported out of the box on macOS; @slouken mentioned Apple was investigating, but that was a long time ago and as much as I love my PS3 controller, I wouldn't be surprised if they decided it's not worth adding support now that we're two generations of the PlayStation past it.
  • Do we want to add this to SDL's HIDAPI code? I'm totally ignorant of HIDAPI details; doesn't this controller already work with HIDAPI on other platforms, or have we just been relying on the OS to make it work all this time?

@slouken
Copy link
Collaborator

slouken commented Aug 23, 2022

Sony no longer supports the PS3 controller on PS Now, which is where most people were getting their driver. I looked into adding support to HIDAPI, but I wasn't actually able to read the controller on Windows or macOS for some reason, and Linux drivers are already working fine.

@slouken
Copy link
Collaborator

slouken commented Aug 23, 2022

I'll take another quick stab at this and see what I can come up with.

@slouken slouken removed the Apple Apple is tracking this bug internally label Aug 24, 2022
@slouken
Copy link
Collaborator

slouken commented Aug 24, 2022

So, good news, the latest SDL code supports wired PS3 controllers on macOS, thanks @vit9696!

@icculus
Copy link
Collaborator

icculus commented Aug 24, 2022

So we can close this issue?

@slouken
Copy link
Collaborator

slouken commented Aug 24, 2022

I want to leave it open for bug reports and the hope that someone can figure out why the controller initialization code doesn't work on Windows.

@slouken
Copy link
Collaborator

slouken commented Aug 24, 2022

If nothing pops up we can close this before 2.26 release.

@icculus icculus added this to the 2.26.0 milestone Aug 24, 2022
@slouken
Copy link
Collaborator

slouken commented Aug 24, 2022

It's been confirmed that you can't talk to PS3 controllers using stock Windows drivers. This is documented in 1fc7f68.

@slouken
Copy link
Collaborator

slouken commented Sep 1, 2022

Confirmed, this works well on macOS for wired PS3 controllers.

@slouken slouken closed this as completed Sep 1, 2022
@ballo
Copy link

ballo commented Oct 19, 2022

@slouken I tried libusb router, and it does not seem to be too easy. IOUSBHostHIDDevice.kext owns the USB interface, so libusb_claim_interface would fail. This can be resolved by ensuring libusb_detach_kernel_driver gets called and succeeded: for this one needs to run the app with root privileges. But even in this case I get timeouts.

On the other side, I did find a workaround for the native macOS HID API by reviewing my old code for DS3 dating back to 10.6 days :-) For some reason macOS driver is no longer sending the initialisation sequence for DS3, which is the reason why the gamepad does nothing. I have a suspect this happened before, because I added exactly this code some while ago, though the intent was to support rumbling.

[Snip]

ds3activate.zip

I compiled the source and ran it (m1 MacBook). The controller rumbled but it's not working in Dolphin?
cc -framework CoreFoundation -framework IOKit ds3activate.c -o ds3activate

Edit: My arm64 compiled version worked fine playing an SNES game via OpenEMU. I think I got Dolphin to work but I had to remap everything!

@PirateGuy147
Copy link

PirateGuy147 commented Oct 19, 2022

I connected the controller and turned on ds3activate.zip, and it vibrated. But it doesn't do anything. it says its connected but nothing works and the light is off

Edit: I found out that it works but only if I hold down the ps button

@LeWolfYT
Copy link

LeWolfYT commented Dec 4, 2022

ds3activate.zip
How do i stop the rumbling?

@MattiaFenzi
Copy link

This works great! But L2 and R2 are treated like normal buttons so i cannot modulate the pressure, can it be fixed?

@slouken
Copy link
Collaborator

slouken commented Apr 19, 2023

It looks like L2 and R2 aren't pressure sensitive in the DS3 controller:
https://en.wikipedia.org/wiki/DualShock#DualShock_3

@MattiaFenzi
Copy link

Well they are analog, in fact on PS3 and Windows they can be modulated

@slouken
Copy link
Collaborator

slouken commented Apr 19, 2023

Sorry, I was thinking of L3 and R3. Yes, L2 and R2 are analog triggers, and are reported as axes 4 and 5. I just tested them on macOS and they work correctly.

@rosariogueli
Copy link

If anyone is still experiencing a never ending rumble / vibration, i've sorted it by removing line 91. ie
IOHIDDeviceSetReport(device, kIOHIDReportTypeOutput, 1, rumbleBlob, sizeof(rumbleBlob));
I then re-compiled using the following terminal command:
cc -framework CoreFoundation -framework IOKit ds3activate.c -o ds3activate
Once done, double click on the executable ds3activate and it will work without vibration. This was done on MacBook Pro M2 Max. Cheers!

@RobertoB8
Copy link

RobertoB8 commented Dec 25, 2023

I tried running the script OP provided, but the D-Pad is not working, and both triggers appear as permanently pressed. Any ideas on how to tackle that?

same problem, have you found any solutions? thank you very much !!!

@Batibaran
Copy link

I tried running the script OP provided, but the D-Pad is not working, and both triggers appear as permanently pressed. Any ideas on how to tackle that?

Same issue. Dpad and L2 R2 appear to be constantly pressed. Has anyone found the solution

@drzeissler
Copy link

drzeissler commented May 25, 2024

ps3activate does work on my m1 macmini with wired ps3 controller, but it breaks sleep mode on the os. can this be fixed? thx!
(I am using 14.5 sonoma)

@poof86
Copy link

poof86 commented Jul 8, 2024

Seems to work on Sonoma 14.5, but the L2 and R2 are not recognised? They are greyed out in the https://hardwaretester.com/gamepad and don't respond in games.

Solution would be very much appreciated 🙇

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

No branches or pull requests