cant compile
parent
4cd8ac47c8
commit
10cc6a9233
|
|
@ -36,13 +36,12 @@ pub fn build_input_engine_device_gilrs(cfg: &Engine) -> Result<Box<dyn InputEngi
|
|||
}
|
||||
|
||||
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);
|
||||
let active_gamepad = Some(id);
|
||||
|
||||
println!("inspecting event");
|
||||
// You can also use cached gamepad state
|
||||
|
|
@ -54,6 +53,7 @@ pub fn build_input_engine_device_gilrs(cfg: &Engine) -> Result<Box<dyn InputEngi
|
|||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(15));
|
||||
break;
|
||||
}
|
||||
|
||||
return Err("do what".to_string());
|
||||
|
|
@ -101,12 +101,14 @@ impl InputEngine for InputEngineDevice {
|
|||
}
|
||||
|
||||
struct InputEngineUDP {
|
||||
last_socket: Option<std::net::UdpSocket>,
|
||||
port: i32,
|
||||
}
|
||||
|
||||
pub fn build_input_engine_udp(cfg: &Engine) -> Result<Box<dyn InputEngine>, String> {
|
||||
let udp_cfg = cfg.udp.as_ref().unwrap();
|
||||
return Ok(Box::new(InputEngineUDP{
|
||||
last_socket: None,
|
||||
port: udp_cfg.port,
|
||||
}));
|
||||
}
|
||||
|
|
@ -115,11 +117,27 @@ impl InputEngine for InputEngineUDP {
|
|||
fn get(&mut self) -> Vec<char> {
|
||||
let addr = "0.0.0.0:".to_string() + &self.port.to_string();
|
||||
println!("$ echo -n 'hello world' | nc -4u -w0 localhost {}", &self.port.to_string());
|
||||
let socket = std::net::UdpSocket::bind(addr).unwrap();
|
||||
if self.last_socket.is_none() {
|
||||
self.last_socket = Some(std::net::UdpSocket::bind(addr).unwrap());
|
||||
}
|
||||
|
||||
let result = self._get();
|
||||
|
||||
if result.is_err() {
|
||||
self.last_socket = None;
|
||||
return Vec::<char>::new();
|
||||
}
|
||||
return result.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl InputEngineUDP {
|
||||
fn _get(&mut self) -> Result<Vec<char>, std::io::Error> {
|
||||
let mut buf = [0; 128];
|
||||
let (amt, src) = socket.recv_from(&mut buf).unwrap();
|
||||
let socket = self.last_socket.ok_or(std::io::Error::new(std::io::ErrorKind::Other, "no socket"))?;
|
||||
let (amt, _) = socket.recv_from(&mut buf)?;
|
||||
let buf = &mut buf[..amt];
|
||||
return std::str::from_utf8(buf).unwrap().chars().collect();
|
||||
return Ok(std::str::from_utf8(buf).unwrap().chars().collect());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ fn main() {
|
|||
println!("{:?} => {}", cfg.streams.input.engine.name, input_engine.is_ok());
|
||||
println!("{:?} => {}", cfg.streams.output.engine.name, output_engine.is_ok());
|
||||
let mut input_engine = input_engine.unwrap();
|
||||
let mut output_engine = output_engine.unwrap();
|
||||
let output_engine = output_engine.unwrap();
|
||||
loop {
|
||||
output_engine.put(input_engine.get());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue