The Gilrs (game input library) crate allows the user to connect to a gamepad.
use gilrs::Gil;
let gilrs = Gil::new().unwrap();
Cargo compiles this and runs successfully. However, I’ve tried both my Xbox Series controllers yet gilrs.gamepads()
is empty.
I’ve made sure the controller is connected through numerous ways:
- The issue doesn’t persist when I test with FireFox’s devtools: running
navigator.getGamepads()
returns my controller. - The bluetooth menu for my Macbook shows that the controller is connected.
- Running
system_profiler SPBluetoothDataType
in zsh returns my controller:
Connected:
Xbox Wireless Controller:
Address: 98:7A:14:BC:BA:F2
Vendor ID: 0x045E
Product ID: 0x0B13
Battery Level: 100%
Firmware Version: 5.9.2709.0
Minor Type: Gamepad
Services: 0x400000 < BLE >
- With the controller plugged to my Macbook using USB-C, running
system_profiler SPUSBDataType
in zsh returns this:
USB 3.1 Bus:
Host Controller Driver: AppleT8112USBXHCI
Controller:
Product ID: 0x0b12
Vendor ID: 0x045e (Microsoft Corporation)
Version: 5.09
Serial Number: 3039565831363736393234303336
Speed: Up to 12 Mb/s
Manufacturer: Microsoft
Location ID: 0x00100000 / 1
Current Available (mA): 500
Current Required (mA): 500
Extra Operating Current (mA): 0
However, even though everything else shows that my controller is connected, gilrs.gamepads()
is an empty iterator upon running Cargo.
Question
- Why does this behavior occur? What can I do to fix this?
- How are controllers/gamepads detected anyway?
- Is there a way I can do this without any hardware abstraction libraries as a last resort?
note: I’m running on an M2 Macbook Air.