diff --git a/src/controller.rs b/src/controller.rs index 2af419f..9a8efb1 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -6,7 +6,9 @@ use { pub struct Controller { pub tbegin: Instant, pub transition_begin: Instant, - pub last_tap: Instant + pub last_tap: Instant, + + pub ctrl: bool } impl Controller { @@ -14,7 +16,8 @@ impl Controller { Controller { tbegin: Instant::now(), transition_begin: Instant::now(), - last_tap: Instant::now() + last_tap: Instant::now(), + ctrl: false } } @@ -22,11 +25,68 @@ impl Controller { &mut self, event: winit::event::KeyEvent, inputs: &mut crate::inputs::Inputs, - ) { + setup: &mut crate::setup::LightingSetup + ) { + if event.state == winit::event::ElementState::Released { + match event.logical_key { + winit::keyboard::Key::Named( + winit::keyboard::NamedKey::Control + ) => { + eprintln!("released control"); + self.ctrl = false; + } + _ => {} + } + } else if event.state == winit::event::ElementState::Pressed { match event.logical_key { - winit::keyboard::Key::Character(c) => { - eprintln!("pressed {}", c); + winit::keyboard::Key::Named( + winit::keyboard::NamedKey::Control + ) => { + eprintln!("pressed control"); + self.ctrl = true; + } + winit::keyboard::Key::Character(c) => { + eprintln!("pressed {}", c); + + if self.ctrl { + if c.is_ascii() { + match &c[0..1] { + "0" => { + if let Some(f) = setup.fixtures.get_mut(0) { + eprintln!("toggle mirror_y of fixture 0"); + f.mirror_y = !f.mirror_y; + } + } + "1" => { + if let Some(f) = setup.fixtures.get_mut(1) { + eprintln!("toggle mirror_y of fixture 1"); + f.mirror_y = !f.mirror_y; + } + } + "2" => { + if let Some(f) = setup.fixtures.get_mut(2) { + eprintln!("toggle mirror_y of fixture 2"); + f.mirror_y = !f.mirror_y; + } + } + "3" => { + if let Some(f) = setup.fixtures.get_mut(3) { + eprintln!("toggle mirror_y of fixture 3"); + f.mirror_y = !f.mirror_y; + } + } + "4" => { + if let Some(f) = setup.fixtures.get_mut(4) { + eprintln!("toggle mirror_y of fixture 4"); + f.mirror_y = !f.mirror_y; + } + } + _ => {} + } + } + } else { + if c.is_ascii() { match &c[0..1] { "x" => { @@ -79,6 +139,7 @@ impl Controller { _=>{} } + } eprintln!("--------------"); eprintln!("updated inputs:\n {:?}", inputs); diff --git a/src/fixture.rs b/src/fixture.rs index f430c1d..e8f83c5 100644 --- a/src/fixture.rs +++ b/src/fixture.rs @@ -15,19 +15,21 @@ pub struct Fixture { pub position: Vector2, pub rotation: f32, pub scale: f32, + pub mirror_y: bool, pub brightness: f32, pub buffer: Vec< Rgb >, pub driver: Option> } impl Fixture { - pub fn new_stripe() -> Self { + pub fn new_stripe(mirror_y: bool) -> Self { let mut fixture = Fixture { resolution: Vector2::new(1, 72), position: Vector2::new(0.0, 0.0), rotation: 0.0, scale: 0.015, brightness: 0.8, + mirror_y, buffer: Vec::new(), driver: None }; @@ -43,6 +45,7 @@ impl Fixture { position: Vector2::new(0.0, 0.0), rotation: 0.0, scale: 0.03, + mirror_y: false, brightness: 0.8, buffer: Vec::new(), driver: None @@ -76,6 +79,11 @@ impl Fixture { let gpos = self.get_global_pos(&Vector2::new(xi, yi)); let col = view.get(&gpos); + let yi = if self.mirror_y { + self.resolution.y - 1 - yi + } else { + yi + }; let index = xi + yi * self.resolution.x; self.buffer[index as usize] = Rgb::new( (col.red() * 255.0 * self.brightness) as u8, diff --git a/src/main.rs b/src/main.rs index 55d9aba..51fa0fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,20 +58,20 @@ async fn main() { Fixture::new_matrix(), // .with_driver( Box::new(MatrixTcpDriver::new("ip:port")) ), - Fixture::new_stripe() - .with_driver( Box::new(StripeDriver::new("192.168.0.111:4210", socket.clone())) ) + Fixture::new_stripe(false) + .with_driver( Box::new(StripeDriver::new("192.168.0.114:4210", socket.clone())) ) .offset(Vector2::new(-0.5, 0.0)), - Fixture::new_stripe() - .with_driver( Box::new(StripeDriver::new("192.168.0.112:4210", socket.clone())) ) + Fixture::new_stripe(true) + .with_driver( Box::new(StripeDriver::new("192.168.0.113:4210", socket.clone())) ) .offset(Vector2::new(-0.4, 0.0)), - Fixture::new_stripe() - .with_driver( Box::new(StripeDriver::new("192.168.0.113:4210", socket.clone())) ) + Fixture::new_stripe(false) + .with_driver( Box::new(StripeDriver::new("192.168.0.112:4210", socket.clone())) ) .offset(Vector2::new(0.4, 0.0)), - Fixture::new_stripe() - .with_driver( Box::new(StripeDriver::new("192.168.0.114:4210", socket.clone()))) + Fixture::new_stripe(true) + .with_driver( Box::new(StripeDriver::new("192.168.0.111:4210", socket.clone()))) .offset(Vector2::new(0.5, 0.0)) ], @@ -159,7 +159,7 @@ async fn main() { event: winit::event::WindowEvent::KeyboardInput{ device_id, event, is_synthetic } } => { controller.handle_key( - event, &mut inputs + event, &mut inputs, &mut lighting_setup ); } diff --git a/src/setup.rs b/src/setup.rs index d00cddc..d455036 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -10,7 +10,7 @@ use { }; pub struct LightingSetup { - fixtures: Vec, + pub fixtures: Vec, t: Arc>, animation: Box