MFi Game Controller Support
I bought a SteelSeries Stratus XL game controller for my new Apple TV today. I thought it would be fun to connect to it with Pythonista, but I ran into problems very quickly.
The whole thing seemed pretty straight forward. The objc_util package is fantastic, it is the first time I read the documentation. The GCController class should very easy to work with, especially since it should work well with only polling (I want to stay away from callbacks, handlers and blocks, at least at first): https://developer.apple.com/library/ios/documentation/GameController/Reference/GameController_RefColl/index.html
So here we go!
from objc_util import * GCController = ObjCClass('GCController') controllers = GCController.controllers() print controllers
I expected to see an empty list when the controller was turned off, and a list with one element when the controller was on. Instead I got an error:
ValueError: no Objective-C class named 'GCController' found
I checked what classes are available. (This takes some time if anyone plans to run this code.)
from objc_util import * classes = ObjCClass.get_names() print classes
There are no classes starting with GC in the list. It would have been between 'FontSizeSliderCell' and 'GEOABExperimentAssignment'. I assume that is due to the fact that the "Game Controller Framework" is not linked into the Pythonista binary.
What a pity! I was kind of looking forward to building something to play with proper buttons. That would have been great fun.
So I assume we cannot use a controller unless @omz decides to add the "Game Controller Framework" to Pythonista. Or am I missing something?
I seem to be stuck again. I only get an empty list from GCController.controllers(), even though a controller is paired and connected.
It'll be some time, but next I'll try to do this in XCode and see what I get from the call. Unless someone else can figure out what's going on before that of course.
@Oscar I can't take credit, It was posted in the past by someone else and I kept the snippet stashed away.
I can't help you with the rest of it as I have never dealt with GCController before and don't have a controller to play with.
I would be very interested in how you go with it though.
Are you able to test that the controller works in other iOS applications?
Also try reading through the apple documentation https://developer.apple.com/library/ios/documentation/GameController/Reference/GameController_RefColl/index.html
You need to call
And then stop the search after you have your controller.
@Cethric, I am pretty certain that you do not have to handle controller discovery in the app unless you want to.
"Although support for pairing is normally provided by the operating system (typically in the Preferences or Settings, you can use the Game Controller framework to pair devices inside your game. "
"Normally, discovery occurs outside your game—that is, a player usually pairs the controller before launching your game. However, you can let a player discover new controllers from within your game."
Still I tried using startWirelessControllerDiscoveryWithCompletionHandler, but that didn't make a difference. I might have made a mistake though, because the completion handler block was never called, not even after a call to stopWirelessControllerDiscovery.
I do not have a controller to test this with. How ever the controller should be showing up in system preferences (if it is a wireless controller, don't know about wired (lightening) controllers, but I would assume they should as well)
Have you tryed testing the controller in another application/game?
Also isn't there a tag that needs to go in the Application's plist file to say that it is allowed to connect to MFI Controllers? (I can't check this at the moment cause I am not at my computer)
@Cethric Yes, I made sure that the Controller was listed as connected in Settings, and that I could use it in another app.
I've looked around to find out if Game Controller support needs to be declared in the app plist. It seems to be true for tvOS apps, but I can't find anything about that for iOS. It would explain the behavior though.
I've run into the very same problem, unfortunately.
Now I can be sure that it's not my fault that it doesnt work :P
I have a suspicion that MFi controllers require that the app is actually linked against the GameController framework – could be an optimization to turn off controller communication while an app is running that doesn't support them or something like that... I don't have a controller to test this unfortunately, though controller support is something that I find potentially interesting as an addition to the scene module. I might buy one for testing at some point.