Add cross-platform gamepad rumble via SDL2#860
Add cross-platform gamepad rumble via SDL2#860chiefautism wants to merge 2 commits intobuttplugio:masterfrom
Conversation
New crate: buttplug_server_hwmgr_sdl_gamepad Adds SDL2-based gamepad haptics as a buttplug device communication manager. Xbox, PlayStation, and Switch controllers appear as XInput-compatible buttplug devices with dual vibration motors (left/right, 65535 steps each). Works on macOS (GCController backend), Windows (XInput/DirectInput), and Linux (evdev) — all from a single SDL2 codebase. Usage: intiface-engine --use-sdl-gamepad --websocket-port 12345 Tested with Xbox Series X controller on macOS via Bluetooth. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Buttplug sends separate write_value calls for each motor (left then right). Without draining, a stop sequence would send rumble(65535, 0, 10000) then rumble(0, 0, 10000) — the first call re-activates vibration before the second can cancel it. Now the SDL worker thread waits 5ms and drains all pending commands before applying, so both motor values arrive as a single set_rumble() call. Also: SDL on macOS requires duration > 0 to override active rumble, so stop now sends rumble(0, 0, 10000) instead of rumble(0, 0, 1). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
|
|
Oh hell yeah. Lemme know what platforms you need tests run on if you don't have them yourself. I've also got xbox/dualsense/pro controllers to test with. |
|
Ok, so, you changed the copyright on this and haven't signed the contributor agreement, so I can't bring this in until those are done. Looking pretty decent otherwise, there's a race condition on discovery and it doesn't seem to detect/emit on devices being disconnected, but I can write those up in a review after the licensing stuff gets done. |
Summary
buttplug_server_hwmgr_sdl_gamepad— cross-platform gamepad haptics via SDL2intiface-engine --use-sdl-gamepadbundledfeature — no system dependency requiredMotivation
buttplug currently supports gamepads only via XInput on Windows. SDL2 provides a single cross-platform API for gamepad rumble that works everywhere, including macOS where XInput is unavailable.
This unlocks game controllers as haptic devices for creative applications — interactive fiction with haptic feedback, biofeedback loops, accessibility tools, and more.
Implementation
SdlGamepadCommunicationManager: scans for controllers via SDL2's GameController API on a dedicated thread (SDL types are !Send)SdlGamepadHardware: wraps a GameController with a worker thread that processes rumble commands, with 5ms drain batching to coalesce per-motor write_value callsTest plan
🤖 Generated with Claude Code