Step 1. Get the Mac (and python) to read gamepad input
I connected the generic USB gamepad to my mac but not much happened. So I tried connecting a PS3 sixaxis controller. This showed a visible connection, in the list of bluetooth devices. Ok, now python. Some googling gave me three options for libraries: jaraco.input, PyGame, Py-SDL2. There were some more but I couldn't get them to install. Turned out that jaraco.input only worked on linux and windows. PyGame took a very long time to compile, and in the meantime I tried SDL2. Installing SDL2 via homebrew was really fast and the coding examples worked right away. It turns out I could read both the cheap generic USB controller and the nice PS3 sixaxis controller. Sweet!
When you can get it to install with homebrew and pip, it's as simple as this:
Step 2. Send motor commands to the NXT via bluetooth
For sending motor commands I had already found the jaraco.nxt library. I used that one for sending bluetooth messages in the Sumo project. It saw that it contained motor commands too. As it turned, sending the motor commands wasn't as easy as I thought. Jaraco comes with pretty meager documentation and examples, so I had to do some digging in the source code. It turned out that you have to explicitly turn motor regulation on, otherwise the motors only seem to run at half power. Turning that on was an undocumented feature.
So here's the code for sending a simple motor command, turning the motor on with a certain speed.
So here's the code for sending a simple motor command, turning the motor on with a certain speed.