ELApse/src/input/piston.rs
2025-09-24 16:05:23 +02:00

29 lines
975 B
Rust

use std::{net::UdpSocket, sync::mpsc::Sender, thread};
use crate::input::Input;
impl Input {
pub fn piston(tx: Sender<Vec<[f32; 4]>>) {
thread::spawn(move || {
let socket = UdpSocket::bind("127.0.0.1:45052").unwrap();
let mut buf = [0; 1500];
loop {
let mut leds: Vec<[f32; 4]> = Vec::new();
let (amt, _src) = socket.recv_from(&mut buf).unwrap();
let bytes = buf[..amt].to_vec();
// let _ = tx.send();
for byte in bytes {
for i in 0..8 {
let bit = (byte >> i) & 1;
if bit == 1 {
leds.push([1.0,1.0,1.0,1.0])
} else {
leds.push([0.02,0.02,0.02,1.0])
};
}
}
let _ = tx.send(leds.clone());
}
});
}
}