Refactor
This commit is contained in:
@@ -11,6 +11,7 @@ const FPS: u32 = 50;
|
||||
enum MCUResponse {
|
||||
Sync,
|
||||
Ack,
|
||||
#[allow(dead_code)]
|
||||
Info { num_pkts: u32 },
|
||||
}
|
||||
|
||||
@@ -38,15 +39,13 @@ fn poll_response(ser: &mut dyn SerialPort) -> Result<MCUResponse> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn controller_thread(running: Arc<Mutex<bool>>, brightness: Arc<Mutex<f32>>) -> Result<()> {
|
||||
pub fn controller_thread(running: Arc<Mutex<bool>>, movingheads: Arc<Mutex<[MovingHead; 4]>>) -> Result<()> {
|
||||
let frame_time = Duration::from_secs_f64(1.0 / FPS as f64);
|
||||
|
||||
let hsl_cycle = 12 * FPS;
|
||||
|
||||
let mut dmx_buffer = [0u8; 512];
|
||||
|
||||
let mut movinghead = MovingHead::new(1);
|
||||
|
||||
let mut ser = serialport::new("/dev/ttyUSB0", 500_000)
|
||||
.timeout(Duration::from_millis(10))
|
||||
.open()?;
|
||||
@@ -72,18 +71,12 @@ pub fn controller_thread(running: Arc<Mutex<bool>>, brightness: Arc<Mutex<f32>>)
|
||||
|
||||
let loop_start = Instant::now();
|
||||
|
||||
let hsl: Srgb = Hsl::new(360.0 * (t as f32 / hsl_cycle as f32), 1.0, 0.5).into_color();
|
||||
|
||||
let [r, g, b]: [u8; 3] = hsl.into_format().into_raw();
|
||||
movinghead.rgbw = (r, g, b, 0);
|
||||
|
||||
movinghead.dimmer = {
|
||||
let brightness = brightness.lock().unwrap();
|
||||
|
||||
0.2 + 0.8 * *brightness
|
||||
};
|
||||
|
||||
movinghead.render(&mut dmx_buffer);
|
||||
{
|
||||
let movingheads = movingheads.lock().unwrap();
|
||||
for head in movingheads.iter() {
|
||||
head.render(&mut dmx_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
t += 1;
|
||||
t %= hsl_cycle;
|
||||
|
||||
Reference in New Issue
Block a user