Change speed scale, Implement reset
This commit is contained in:
@@ -23,7 +23,9 @@ pub struct MovingHead {
|
||||
pub tilt: f64, // -pi/2 to pi/2
|
||||
pub brightness: Brightness,
|
||||
pub rgbw: (u8, u8, u8, u8), // RGBW
|
||||
pub speed: u8, // reversed
|
||||
pub speed: f64, // 0 to 1, mapping to (255 to 0)
|
||||
|
||||
pub reset: bool,
|
||||
}
|
||||
|
||||
pub trait DMXFixture {
|
||||
@@ -32,6 +34,8 @@ pub trait DMXFixture {
|
||||
|
||||
impl DMXFixture for MovingHead {
|
||||
fn render(&self, dst: &mut [u8]) {
|
||||
// TODO use pan_fine and tilt_fine for more accuracy
|
||||
|
||||
let pan = rescale(self.pan, (-1.5 * PI, 1.5 * PI), (255.0, 0.0)) as u8;
|
||||
let pan_fine = 0;
|
||||
|
||||
@@ -47,10 +51,14 @@ impl DMXFixture for MovingHead {
|
||||
|
||||
let (r, g, b, w) = self.rgbw;
|
||||
|
||||
let speed = rescale(self.speed, (0.0, 1.0), (255.0, 0.0)) as u8;
|
||||
|
||||
let reset = if self.reset { 175 } else { 0 };
|
||||
|
||||
let offset = self.start_address - 1;
|
||||
|
||||
let channels = [
|
||||
pan, pan_fine, tilt, tilt_fine, self.speed, dimmer, r, g, b, w, 0, 0, 0, 0,
|
||||
pan, pan_fine, tilt, tilt_fine, speed, dimmer, r, g, b, w, 0, 0, 0, reset,
|
||||
];
|
||||
|
||||
dst[offset..offset + channels.len()].copy_from_slice(&channels);
|
||||
|
||||
@@ -139,7 +139,12 @@ fn set_output(mut cx: FunctionContext) -> JsResult<JsObject> {
|
||||
speed: head
|
||||
.get(&mut cx, "speed")?
|
||||
.downcast_or_throw::<JsNumber, _>(&mut cx)?
|
||||
.value(&mut cx) as u8,
|
||||
.value(&mut cx),
|
||||
|
||||
reset: head
|
||||
.get(&mut cx, "reset")?
|
||||
.downcast_or_throw::<JsBoolean, _>(&mut cx)?
|
||||
.value(&mut cx),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user