I’ve been playing around with the HID part of IOKit lately on my Mac with a PS3 controller. I’ve managed to look though the sample code and connect to my controller, receive a stream of data and parse it (Everything, including the accelerometer and gyro).
However, today I decided I wanted to start setting the LEDs on the back of the device and triggering the rumble motors, but I just can’t get it to work!
Controller communicates directly with ESP32 MCU using Arduino libraries PS3 Controller Host, PS4Controller. They provide API to read controller buttons, control leds, vibration, etc. When PS button is pressed, controller tries to connect device with MAC address stored in it's memory. ESP32 presents itself with this address and accepts connection. Now go ahead and connect the controller to the PC using its miniUSB cable. Once plugged in, the application will display the MAC address of the device, which the controller is currently paired with. Enter your Android device's Bluetooth MAC address, the one you just wrote down, and click the Update button. Question or issue on macOS: I’ve been playing around with the HID part of IOKit lately on my Mac with a PS3 controller. I’ve managed to look though the sample code and connect to my controller, receive a stream of data and parse it (Everything, including the accelerometer and gyro). However, today I decided I.
Looking though the sample code Apple provides for IOHID there isn’t much I can see on setting things on the HID device, only receiving data. From looking on the web (for petty much half a day) I’ve got what I think is a working send method which uses IOHIDDeviceSetReport(). However, I can’t work out what data I should be sending.
You can add your device’s MAC address to your account so it doesn’t have to log in like laptops and mobile devices.Feel free to contact us for further help:P.
I’ve found several sites that list data examples:
(I know not all these examples are for between Mac an a PS3 controller)
A lot of people seem to be talking about this and even doing it (I refuse to believe no one has got this working) but I can’t seem to find anything about actually how to do it that works!
I feel like I am missing a simple step here, so if anyone has any ideas, help or a solution please let me know.
Example Code of how I’m trying to send a report (is is returning success):
This is just sending a lot of nothing (literally) but it’s just an example of what I’m using just incase it’s not correct.
Extra: I’ve also just noticed that Apples defenition of IOHIDDeviceSetReport differes from there example given.
There it says report should be “address of report buffer”. But…
There it say *report (being a pointer) is “The report bytes to be sent to the device.”.
there’s an example at: http://www.circuitsathome.com/mcu/ps3-and-wiimote-game-controllers-on-the-arduino-host-shield-part-2
with the code describing the LED and Rumble control at:
It seems that the bytes that you sent as report need to have a certain format:
In the LEDRumble function, these bytes are copied into buf and then buf is overridden to set the LED state and the bytes from buf through buf are used to configure the Rumble. The the bytes are all sent to the controller.
There are some constants defined here: https://github.com/ribbotson/USB-Host/blob/master/ps3/PS3USB/ps3_usb.h#L100
These constants are passed to the LEDRumble function as parameters.
Their example seems fine, as far as I’ve read it. Under these circumstances, either an uint8_t variable or an uint8_t* variable will be both interpreted as a pointer to uint8_t when passed to IOHIDDeviceSetReport.
I’m on a restricted network right now, so I won’t be able to help any further. But I’ll try to read a little bit more about this later at home, as I also have a related project in mind. If I find out anything that can help us on this, I’ll get back here to talk about it.