Poll devices for input

This commit is contained in:
Marc Riera 2023-02-28 00:03:28 +01:00
parent 7e640edcc6
commit 382990f596
3 changed files with 29 additions and 28 deletions

View file

@ -11,11 +11,12 @@ use virtual_controller::ControllerModel;
fn main() -> Result<()> {
match physical_controller::init() {
Ok(mut dev) => {
Ok(dev) => {
// Wait 3 seconds and get current state of the controller
println!("Press a button to select the controller model...");
sleep(Duration::from_secs(3));
let mut controller_state = physical_controller::get_state(dev);
let mut controller_state = Default::default();
physical_controller::get_state(&mut controller_state, &dev);
let controller_model = virtual_controller::set_model(&controller_state);
// If no model selected, quit
@ -23,29 +24,18 @@ fn main() -> Result<()> {
return Result::Ok(());
}
// Stop main game
stop_game();
// Vibrate to end selection mode
physical_controller::set_rumble(true);
sleep(Duration::from_millis(500));
physical_controller::set_rumble(false);
// Stop main game
stop_game();
loop {
// Process events from input devices
/*for mut device in [&mut d1, &mut d2] {
let evs = device.fetch_events();
match evs {
Ok(evs) => {
for event in evs {
if event.event_type() == EventType::KEY {
physical_controller::read_input(&mut controller_state, Key(event.code()), event.value());
}
}
},
Err(_e) => (),
}
}*/
// Fetch events from input devices
physical_controller::get_state(&mut controller_state, &dev);
sleep(Duration::from_millis(100));
}
},
Err(_e) => println!("ERROR: Could not read input devices! Exiting."),