Mac OS Bluetooth Gamepad

234 views
Skip to first unread message

Zellyn

unread,
Mar 26, 2018, 10:19:24 PM3/26/18
to golang-nuts
Inspired by a Wired article mentioning XBox One gamepads for $34, I finally got a game controller.

Naturally, now I'm wondering how to read it from Go :-)

It connects to Mac OS over Bluetooth. Various games seem to vary in whether they recognize or even notice it, but it works flawlessly in Chrome using http://html5gamepad.com/

So, if there's anyone here who even begins to know how gamepads work… am I about to wade into an ocean of pain? I'd like to avoid linking to sdl as gobot seems to do for joysticks: it would be lovely to have something in pure Go. Is that unlikely?

How are games (and Chrome) even finding the controller? Do they have to interrogate the Bluetooth stack, and then speak both Bluetooth and the XBox controller protocol?

Any help appreciated.

Zellyn

Egon

unread,
Mar 27, 2018, 8:02:10 AM3/27/18
to golang-nuts
Usually controllers don't speak directly to your application nor browser.

Usually there is a driver that the controller has, this talks with the appropriate protocol to the device. The driver itself provides some common HID api that the OS has specified.

The reading and writing the input is effectively about communicating with the OS.


You can do those calls using syscall package, e.g. one for Windows


and a quick search on godoc.org revealed this:

Of course since it's OS specific, you need to implement for all of them. Where each might their own quirks.

SDL and GLFW are both thoroughly tested. I'm not sure about the existing package, but it shouldn't be difficult to switch when you do encounter problems with the pure Go libs.

+ Egon

Egon

unread,
Mar 27, 2018, 8:31:23 AM3/27/18
to golang-nuts
Ah, just noticed the Mac part...


Also Chromium source for the Gamepad implementation:


Unfortunately I didn't notice a Go gamepad implementation for Mac... however there might be one.

Zellyn

unread,
Mar 27, 2018, 9:07:16 AM3/27/18
to golang-nuts
Thanks for the pointers. I spent some time last night finding the gamepad code in the Chromium sources, although I haven't had a chance to really read it properly.

It makes sense that you'd read against some kind of OS-specific abstraction, but I was curious what it was because I don't see any gamepad config or listing in the Mac OS Settings panels.

Sounds like I'm going to be reading some source code… :-)

Thanks again,

Zellyn

Egon

unread,
Mar 27, 2018, 9:50:04 AM3/27/18
to golang-nuts

Fino

unread,
Mar 27, 2018, 8:56:05 PM3/27/18
to golang-nuts
it's all about each OS' API; 
for  Windows, u need to find the Win32 API which can read the hardware's data out. 
Go can call the API via syscall, or load the DLL in your app.

BR fino 
Reply all
Reply to author
Forward
0 new messages