26 lines
849 B
Rust
26 lines
849 B
Rust
#![allow(non_camel_case_types)]
|
|
use std::{net::UdpSocket, sync::mpsc::Receiver};
|
|
|
|
use crate::output::Output;
|
|
|
|
impl Output {
|
|
pub fn realtimeudp(rx: Receiver<Vec<[f32; 4]>>, addr: String) {
|
|
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
|
loop {
|
|
let leds = rx.recv().unwrap();
|
|
let mut packet: Vec<u8> = vec![2, 2];
|
|
for led in leds {
|
|
packet.push((led[0] * 255.0) as u8);
|
|
packet.push((led[1] * 255.0) as u8);
|
|
packet.push((led[2] * 255.0) as u8);
|
|
}
|
|
match socket.send_to(&packet, &addr) {
|
|
Ok(_) => (),
|
|
Err(err) => {
|
|
println!("Error while sending trying to send data: {}", err);
|
|
std::process::exit(1);
|
|
}
|
|
};
|
|
}
|
|
}
|
|
}
|