Skip to content

Commit

Permalink
Update haptic example to use joystick index
Browse files Browse the repository at this point in the history
  • Loading branch information
ticky committed Oct 10, 2017
1 parent 6b3b0b9 commit 5809b73
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions examples/haptic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,26 @@ fn main() {

println!("{} joysticks available", available);

let mut joystick = None;
let mut joystick_index = None;

// Iterate over all available joysticks and stop once we manage to
// open one.
for id in 0..available {
match joystick_subsystem.open(id) {
Ok(c) => {
println!("Success: opened \"{}\"", c.name());
joystick = Some(c);
joystick_index = Some(id);
break;
},
Err(e) => println!("failed: {:?}", e),
}
}

if joystick.is_none() {
if joystick_index.is_none() {
panic!("Couldn't open any joystick");
};

let joystick = joystick.unwrap();

let mut haptic = haptic_subsystem.open_from_joystick_id(joystick.instance_id()).unwrap();
let mut haptic = haptic_subsystem.open_from_joystick_id(joystick_index.unwrap()).unwrap();

for event in sdl_context.event_pump().unwrap().wait_iter() {
use sdl2::event::Event;
Expand Down

0 comments on commit 5809b73

Please sign in to comment.