Last active
June 8, 2025 05:39
-
-
Save El-Wumbus/7734fa2c09a472bb7b09ba848ad2da34 to your computer and use it in GitHub Desktop.
Continuously vibrate a controller using SDL3 in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "rumble" | |
version = "0.1.0" | |
edition = "2024" | |
[dependencies] | |
sdl3 = "0.14" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use sdl3::{self as sdl, event::Event}; | |
fn main() { | |
let ctx = sdl::init().unwrap(); | |
let mut event_pump = ctx.event_pump().unwrap(); | |
let gamepad_sub = ctx.gamepad().unwrap(); | |
let mut gamepad = gamepad_sub | |
.open(gamepad_sub.gamepads().unwrap()[0]) | |
.unwrap(); | |
println!("Using gamepad: {:?}", gamepad.name()); | |
let duration_ms: u32 = 1000; | |
'outer: loop { | |
for event in event_pump.poll_iter() { | |
match event { | |
Event::Quit { .. } => break 'outer, // Handle Ctrl+C | |
_ => {} | |
} | |
} | |
let _ = gamepad.set_rumble(0xFFFF, 0xFFFF, duration_ms); | |
let _ = gamepad.set_rumble_triggers(0xFFFF, 0xFFFF, duration_ms); | |
std::thread::sleep(std::time::Duration::from_millis(duration_ms as u64 + 10)); | |
} | |
println!("Stopped rumbling"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment