i want a gui
This commit is contained in:
@@ -2,6 +2,7 @@ use crate::config::Engine;
|
||||
|
||||
use hidapi::HidApi;
|
||||
use rusb::UsbContext;
|
||||
use gilrs::{Gilrs, Button, Event};
|
||||
|
||||
pub trait InputEngine {
|
||||
fn get(&mut self) -> Vec<char>;
|
||||
@@ -20,13 +21,50 @@ struct InputEngineDevice {
|
||||
}
|
||||
|
||||
pub fn build_input_engine_device(cfg: &Engine) -> Result<Box<dyn InputEngine>, String> {
|
||||
return build_input_engine_device_gilrs(cfg)
|
||||
}
|
||||
|
||||
pub fn build_input_engine_device_gilrs(cfg: &Engine) -> Result<Box<dyn InputEngine>, String> {
|
||||
let _device_cfg = cfg.device.as_ref().unwrap();
|
||||
|
||||
let mut gilrs = Gilrs::new().unwrap();
|
||||
|
||||
println!("printing gamepads");
|
||||
for (_id, gamepad) in gilrs.gamepads() {
|
||||
println!("{} is {:?}", gamepad.name(), gamepad.power_info());
|
||||
}
|
||||
|
||||
println!("printing gamepads events");
|
||||
let mut active_gamepad = None;
|
||||
loop {
|
||||
// println!("reading gamepads events");
|
||||
// Examine new events
|
||||
while let Some(Event { id, event, time }) = gilrs.next_event() {
|
||||
println!("{:?} New event from {}: {:?}", time, id, event);
|
||||
active_gamepad = Some(id);
|
||||
|
||||
println!("inspecting event");
|
||||
// You can also use cached gamepad state
|
||||
if let Some(gamepad) = active_gamepad.map(|id| gilrs.gamepad(id)) {
|
||||
if gamepad.is_pressed(Button::South) {
|
||||
println!("Button South is pressed (XBox - A, PS - X)");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(15));
|
||||
}
|
||||
|
||||
return Err("do what".to_string());
|
||||
}
|
||||
|
||||
pub fn build_input_engine_device_hidapi(cfg: &Engine) -> Result<Box<dyn InputEngine>, String> {
|
||||
let _device_cfg = cfg.device.as_ref().unwrap();
|
||||
|
||||
match HidApi::new() {
|
||||
Ok(api) => {
|
||||
for device in api.devices() {
|
||||
println!("{:#?}", device.product_string);
|
||||
println!("{:#?}", device);
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
|
||||
Reference in New Issue
Block a user