Compare commits
No commits in common. "a2d7bb321191aaa79c53ebcb6185e7ffde10532e" and "2dedc086367609916a7fd3593bb29d62404fd2ad" have entirely different histories.
a2d7bb3211
...
2dedc08636
@ -1,108 +0,0 @@
|
|||||||
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 anyhow::{anyhow, Result};
|
||||||
use palette::{Hsl, IntoColor, Srgb};
|
use palette::{FromColor, Hsl, Pixel, Srgb};
|
||||||
use serialport::SerialPort;
|
use serialport::SerialPort;
|
||||||
|
|
||||||
mod fixtures;
|
const TEST_VALUE: [u8; 9] = [0, 0, 134, 0, 0, 0, 0, 0, 0];
|
||||||
|
|
||||||
const FPS: u32 = 50;
|
const FPS: u32 = 50;
|
||||||
|
|
||||||
@ -45,21 +45,14 @@ fn main() -> Result<()> {
|
|||||||
let frame_time = Duration::from_secs_f64(1.0 / FPS as f64);
|
let frame_time = Duration::from_secs_f64(1.0 / FPS as f64);
|
||||||
|
|
||||||
let mut dmx_buffer = [0u8; 512];
|
let mut dmx_buffer = [0u8; 512];
|
||||||
|
let start_addr = 10;
|
||||||
|
|
||||||
let mut movingheads = [
|
dmx_buffer[(start_addr - 1)..(start_addr - 1 + TEST_VALUE.len())].copy_from_slice(&TEST_VALUE);
|
||||||
fixtures::MovingHead14CH::new(1),
|
|
||||||
fixtures::MovingHead14CH::new(15),
|
|
||||||
fixtures::MovingHead14CH::new(29),
|
|
||||||
fixtures::MovingHead14CH::new(43),
|
|
||||||
];
|
|
||||||
|
|
||||||
for movinghead in movingheads.iter_mut() {
|
|
||||||
movinghead.dimmer = 134;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut ser = serialport::new("/dev/ttyUSB0", 500_000)
|
let mut ser = serialport::new("/dev/ttyUSB0", 500_000)
|
||||||
.timeout(Duration::from_millis(10))
|
.timeout(Duration::from_millis(10))
|
||||||
.open()?;
|
.open()?;
|
||||||
|
|
||||||
println!("open");
|
println!("open");
|
||||||
|
|
||||||
// wait for initial sync
|
// wait for initial sync
|
||||||
@ -77,18 +70,13 @@ fn main() -> Result<()> {
|
|||||||
'main: loop {
|
'main: loop {
|
||||||
let loop_start = Instant::now();
|
let loop_start = Instant::now();
|
||||||
|
|
||||||
let dist = FPS as f32 / movingheads.len() as f32;
|
// 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();
|
||||||
|
|
||||||
for (i, movinghead) in movingheads.iter_mut().enumerate() {
|
let offset = start_addr + 2;
|
||||||
let hsl_color = Hsl::new(
|
dmx_buffer[offset..offset + 3].copy_from_slice(&rgb);
|
||||||
360.0 * ((t % FPS) as f32 / FPS as f32) + i as f32 * dist,
|
|
||||||
1.0,
|
|
||||||
0.5,
|
|
||||||
);
|
|
||||||
movinghead.rgb = hsl_color.into_color();
|
|
||||||
|
|
||||||
movinghead.render(&mut dmx_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write DMX data
|
// write DMX data
|
||||||
let write_result = ser.write(&dmx_buffer);
|
let write_result = ser.write(&dmx_buffer);
|
||||||
@ -122,7 +110,7 @@ fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t += 1;
|
t = (t + 1) % FPS;
|
||||||
|
|
||||||
let loop_time = loop_start.elapsed();
|
let loop_time = loop_start.elapsed();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user