robreuss / VirtualGameController

Software-based game controllers for iOS, tvOS, OS X and watchOS in Swift 4.2.
MIT License
462 stars 44 forks source link

hi, is it possible to use a generic USB gamepad to control an iOS device using some bridge on a Mac ? #35

Closed rafikb closed 5 years ago

robreuss commented 6 years ago

It would only be possible if the USB gamepad is MFi compliant. VGC taps into the GCGameController framework to do it's magic. It sounds like the gamepad you're talking about uses custom drivers, yes?

rafikb commented 6 years ago

Thanks for the lightening fast reply! You're absolutely right, I'm talking about a non MFi compliant controller. It's a generic USB controller and it works natively with apps like OpenEmu. Not sure if there's some sort of drivers for macOS.

I was thinking maybe I could make a custom "Peripheral" app on macOS that acts like a converter of some sort... That said, not sure how things work under the hood so I thought I might ask if that's even possible.

robreuss commented 6 years ago

I thought about trying to support OpenEmu at some point but didn't see the market for it. I do support iCade but I doubt anyone ever even put that to use.

If you wanted to roll something on your own, you would create your own driver for the controller and then talk to the VGC framework as if you had created a virtual peripheral, and then you could utilize the bridge functionality on the Mac to talk to the iOS device. I could help you get it going, but I would wonder about your use case for putting into the effort.

rafikb commented 6 years ago

My motivation is purely experimental. I have some controllers laying around so I thought why not ? But it sounds like a lot of work and effort to put for such a small use cases.

I'll get back to you if I decide to dive into it. Thank you very much ! Much appreciated :)

JoeMatt commented 6 years ago

This is an interest in the Provenance EMU project that I work on. MFi mappings are really terrible for some systems like N64 and Genesis.

I have two things in early dev,

1. Using a Raspberry Pi Zero to connect to bluetooth controllers and running the board's USB in client mode. Using the Camera Connection Kit, you can connect and power the board on lightening devices and it shows up as a class complient USB MIDI device. I then convert the gamepad button presses on the bluetooth input (just /dev/joy# using python gamebad library), and output MIDI messages over USB to the iPhone. MIDI channel 1 to 16 to support up to 16 controllers.

I intend to use VGC to listen to MIDI devices and create GCGameController instances out of them. Right now my code is hardcoded for a single controller and skips makingn it look like a GCGameControler so it's specific to Provenance, but it's early testing. I'll use MIDI sysex messages for two way communication to identify controller data, number of controllers, disconnect and enable pairing mode to connect new controllers. Low power and compact, can be built into a small dongle for on the go use.

Since this requires a lightening / USB connection, it's not for tvOS though.

2. Do the same as 1, but use a Teensy 3.6 Arduino board, which has two USB controllers. This could do the same as 1, but connect USB gamepads and convert them to USB MIDI on the other port. Again, using VGC to wrap it up nicely in a framework for MIDI to GCGameController inputs.

3. Do the same as 1, but connect to the iOS devive via Bluetooh, either as a custom Bluetooh LE device, or Bluetooh LE MIDI which is built into iOS standard bluetooth stack (one of the few device types that works out of the box). Then use the USB port on the Raspberry pi for USB controllers. RPI only support 1 USB chipset at a time, so you can't do USB to USB conversion. This is basically just the inverse of 1. EAsier to write for rPI though since it's a linux system, not embedded like Arduino (though arduino isn't hard to cod with their large library of plugins).

Down side is since it's not wired into the iOS device, you need another 3.3v power source, like a portable battery pack or USB wall wart. Less 'on the go' friendly.

This MIGHT work on tvOS. tvOS doesn't support Bluetooh MIDI, but you can write Bluetooth LE communication with bespoke hardware. I haven't dug much into the stack though so not sure what's possible or not. Again, would use VGC to handle the abstraction to any app that supports GCGameControllers

4. Basically the idea that's mentioned in the title of this ticket.

Write a small app using the VGC OS X host code to connect to generic USB gamepads on desktop and use VGC's network features to talk to the iOS device. This would be best for Apple TVs where they are always on network to be of any use, and it's not a far stretch to assume that people have a Mac laptop they can use as a bridge in their living rooms.

5. Use a combo of 1 & 4. Use my USB to MIDI adapter board to an iPhone or iPad and have an iOS app forward controls to tvOS over network.

Wouldn't require a Mac hardware, and most ppl who have an Apple TV probably have an iPad or iPhone too. This is basically wireless control too minus the cable from the gamepad to the mobile device, but no wires need to run to a desktop somewhere far away if no Mac laptop is available for idea 4.


So far i've only done 1 in some prototype capacity. Im' able to play games that use a GCGameController with my PS3 dualshock controllers via Bluetooh, and no latency that I can detect, at least not any more than any bluetooth controller would have natively.

I'm working on the Arduino part, but I have to get a breakout board for my Teensy 3.6 to start building it. Probably won't have time for a couple months.

If i write the hardware side, I could use some help when the time comes to code the VGC side of things. I only dabbled with it for a bit, but we plan on using it in Provenane anyway soon to replace our custom and limited iCade translation.

If there's any interest in what I've done so far, I can provide the files for a Raspberry Pi Zero to be the go between. So far it's limited to just PS3 controllers, I'm looking for a better solution than the Python lib I found to handle the Linux Gamepad side of things. I kind of hate Python.