i want a gui

This commit is contained in:
bel
2023-03-20 18:43:22 -06:00
parent a51e0ef802
commit ae0925bc7c
4 changed files with 250 additions and 1 deletions

View File

@@ -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) => {