Move fixture definition to module
This commit is contained in:
parent
2dedc08636
commit
07ba32f0ee
108
backend/src/fixtures.rs
Normal file
108
backend/src/fixtures.rs
Normal file
@ -0,0 +1,108 @@
|
||||
use palette::{Pixel, Srgb};
|
||||
|
||||
// 9 Channel mode
|
||||
|
||||
pub struct MovingHead9CH {
|
||||
start_addr: usize,
|
||||
|
||||
pub pan: u8,
|
||||
pub tilt: u8,
|
||||
pub dimmer: u8, // 0-7 off, 8-134 dim, 135-239 strobe, 240-255 "switch"?
|
||||
pub rgb: Srgb,
|
||||
pub w: u8,
|
||||
pub speed: u8, // reversed
|
||||
pub rst: u8, // 150-200
|
||||
}
|
||||
|
||||
impl MovingHead9CH {
|
||||
pub fn new(start_addr: usize) -> Self {
|
||||
Self {
|
||||
start_addr,
|
||||
pan: 0,
|
||||
tilt: 0,
|
||||
dimmer: 0,
|
||||
rgb: Srgb::new(0.0, 0.0, 0.0),
|
||||
w: 0,
|
||||
speed: 0,
|
||||
rst: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&self, destination: &mut [u8]) {
|
||||
let [r, g, b]: [u8; 3] = self.rgb.into_format().into_raw();
|
||||
|
||||
destination[self.start_addr - 1..self.start_addr - 1 + 9].copy_from_slice(&[
|
||||
self.pan,
|
||||
self.tilt,
|
||||
self.dimmer,
|
||||
r,
|
||||
g,
|
||||
b,
|
||||
self.w,
|
||||
self.speed,
|
||||
self.rst,
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
// 14 Channel mode
|
||||
|
||||
pub struct MovingHead14CH {
|
||||
start_addr: usize,
|
||||
|
||||
pub pan: u8,
|
||||
pub pan_fine: u8,
|
||||
pub tilt: u8,
|
||||
pub tilt_fine: u8,
|
||||
pub speed: u8,
|
||||
pub dimmer: u8,
|
||||
pub rgb: Srgb,
|
||||
pub w: u8,
|
||||
pub color_mode: u8,
|
||||
pub color_auto_jump_speed: u8,
|
||||
pub control_mode: u8,
|
||||
pub rst: u8,
|
||||
}
|
||||
|
||||
impl MovingHead14CH {
|
||||
pub fn new(start_addr: usize) -> Self {
|
||||
Self {
|
||||
start_addr,
|
||||
|
||||
pan: 0,
|
||||
pan_fine: 0,
|
||||
tilt: 0,
|
||||
tilt_fine: 0,
|
||||
speed: 0,
|
||||
dimmer: 0, // 0-7 off, 8-134 dim, 135-239 strobe, 240-255 "switch"?
|
||||
rgb: Srgb::new(0.0, 0.0, 0.0),
|
||||
w: 0,
|
||||
color_mode: 0, // 0-7 "select color" -> dmx?, 8-231 "built in"?, 232-255 "seven colors jumping"
|
||||
color_auto_jump_speed: 0, // speed for "seven colors jumping" mode
|
||||
control_mode: 0, /* 0-7 "custom control" -> dmx?, 8-63 "working in fast", 64-127 "working in slow"
|
||||
128-191 "Sound1Active", 192-255 "Sound2Active" */
|
||||
rst: 0, // 150-200
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&self, destination: &mut [u8]) {
|
||||
let [r, g, b]: [u8; 3] = self.rgb.into_format().into_raw();
|
||||
|
||||
destination[self.start_addr - 1..self.start_addr - 1 + 14].copy_from_slice(&[
|
||||
self.pan,
|
||||
self.pan_fine,
|
||||
self.tilt,
|
||||
self.tilt_fine,
|
||||
self.speed,
|
||||
self.dimmer,
|
||||
r,
|
||||
g,
|
||||
b,
|
||||
self.w,
|
||||
self.color_mode,
|
||||
self.color_auto_jump_speed,
|
||||
self.control_mode,
|
||||
self.rst,
|
||||
]);
|
||||
}
|
||||
}
|
@ -4,10 +4,10 @@ use std::{
|
||||
};
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use palette::{FromColor, Hsl, Pixel, Srgb};
|
||||
use palette::{Hsl, IntoColor, Srgb};
|
||||
use serialport::SerialPort;
|
||||
|
||||
const TEST_VALUE: [u8; 9] = [0, 0, 134, 0, 0, 0, 0, 0, 0];
|
||||
mod fixtures;
|
||||
|
||||
const FPS: u32 = 50;
|
||||
|
||||
@ -45,14 +45,13 @@ fn main() -> Result<()> {
|
||||
let frame_time = Duration::from_secs_f64(1.0 / FPS as f64);
|
||||
|
||||
let mut dmx_buffer = [0u8; 512];
|
||||
let start_addr = 10;
|
||||
|
||||
dmx_buffer[(start_addr - 1)..(start_addr - 1 + TEST_VALUE.len())].copy_from_slice(&TEST_VALUE);
|
||||
let mut movinghead = fixtures::MovingHead14CH::new(1);
|
||||
movinghead.dimmer = 134;
|
||||
|
||||
let mut ser = serialport::new("/dev/ttyUSB0", 500_000)
|
||||
.timeout(Duration::from_millis(10))
|
||||
.open()?;
|
||||
|
||||
println!("open");
|
||||
|
||||
// wait for initial sync
|
||||
@ -70,13 +69,10 @@ fn main() -> Result<()> {
|
||||
'main: loop {
|
||||
let loop_start = Instant::now();
|
||||
|
||||
// calculate color
|
||||
let hsl_color = Hsl::new(360.0 * (t as f64 / FPS as f64), 1.0, 0.5);
|
||||
let rgb_color = Srgb::from_color(hsl_color);
|
||||
let rgb: [u8; 3] = rgb_color.into_format().into_raw();
|
||||
let hsl_color = Hsl::new(360.0 * ((t % FPS) as f32 / FPS as f32), 1.0, 0.5);
|
||||
movinghead.rgb = hsl_color.into_color();
|
||||
|
||||
let offset = start_addr + 2;
|
||||
dmx_buffer[offset..offset + 3].copy_from_slice(&rgb);
|
||||
movinghead.render(&mut dmx_buffer);
|
||||
|
||||
// write DMX data
|
||||
let write_result = ser.write(&dmx_buffer);
|
||||
@ -110,7 +106,7 @@ fn main() -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
t = (t + 1) % FPS;
|
||||
t += 1;
|
||||
|
||||
let loop_time = loop_start.elapsed();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user