39 lines
1.4 KiB
Rust
39 lines
1.4 KiB
Rust
#![allow(non_camel_case_types)]
|
|
use std::{io::Read, sync::mpsc::{self, Receiver, Sender}, thread, time::Duration};
|
|
use crate::{input::Input, parser};
|
|
|
|
impl Input {
|
|
pub fn stdin(tx: Sender<Vec<[f32; 4]>>) {
|
|
let (stdintx, stdinrx): (Sender<Vec<u8>>, Receiver<Vec<u8>>) = mpsc::channel();
|
|
thread::spawn(move || {
|
|
let mut buf = [0; 1500];
|
|
let mut e = std::io::stdin().lock();
|
|
loop {
|
|
let amt = e.read(&mut buf).unwrap();
|
|
if buf[..amt].to_vec().len() > 0 {
|
|
let _ = stdintx.send(buf[..amt].to_vec());
|
|
}
|
|
}
|
|
});
|
|
thread::spawn(move || {
|
|
loop {
|
|
// let amt = e.read(&mut buf).unwrap();
|
|
match stdinrx.recv_timeout(Duration::from_millis(500)) {
|
|
Ok(d) => {
|
|
let r: Vec<[f32; 4]> = parser::parseleds(
|
|
d,
|
|
parser::ParserOptions::default()
|
|
.mirror(true)
|
|
.double(true)
|
|
.offset(15),
|
|
);
|
|
let _ = tx.send(r);
|
|
}
|
|
Err(_) => {
|
|
std::process::exit(0);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
}
|
|
}
|