From f6e64b6e0ba830b751d1712c90e2e73d7f2b4a2a Mon Sep 17 00:00:00 2001 From: "0m.ax" Date: Fri, 17 Jul 2026 16:16:36 +0200 Subject: [PATCH] wip --- flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 29 +++++++++++++++++++++++++++++ src/main.rs | 51 +++++++++++++++++++++++++++++++++++---------------- 3 files changed, 91 insertions(+), 16 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7dac337 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1759733170, + "narHash": "sha256-TXnlsVb5Z8HXZ6mZoeOAIwxmvGHp1g4Dw89eLvIwKVI=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "8913c168d1c56dc49a7718685968f38752171c3b", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..004750b --- /dev/null +++ b/flake.nix @@ -0,0 +1,29 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + }; + + outputs = { self, nixpkgs }: { + devShells.x86_64-linux.default = + let + insecure-package-overlay = final: prev: { + nixpkgs.config.permittedInsecurePackages = [ + # Add the full name and version of the package here + "openssl-1.1.1w" + # "another-insecure-package-2.0" + ]; + }; + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = []; + }; + in + pkgs.mkShell { + buildInputs = [ + pkgs.cargo + ]; + }; + }; +} diff --git a/src/main.rs b/src/main.rs index 8585c0b..ad21f83 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ const QUEUE_LEN: usize = 1000; const MSG_PAYLOAD_SIZE: usize = 7 * 211; const MSGSIZE: usize = 2 + MSG_PAYLOAD_SIZE; -const DISPLAY_HOST: &str = "100.65.0.2"; +const DISPLAY_HOST: &str = "100.65.13.2"; const DISPLAY_PORT: u16 = 5005; const DISPLAY_WIDTH: i32 = 1920; const DISPLAY_HEIGHT: i32 = 1080; @@ -95,7 +95,7 @@ impl BouncingImage { let index = (sy * self.img.width + sx) as usize * 4; let rgba = &self.img.pixels[index..index + 4]; if rgba[3] > 0 { // Check alpha channel - //display.set_pixel((x + sx as i32) as u16, (y + sy as i32) as u16, rgba[0], rgba[1], rgba[2]); + display.set_pixel((x + sx as i32), (y + sy as i32), rgba[0], rgba[1], rgba[2]); } } } @@ -126,13 +126,17 @@ impl Drawable for BouncingImage { struct Circle { x: Arc>, y: Arc>, + set: Arc>, + radius: u32 } impl Circle { - fn new(x:Arc>, y: Arc>) -> Self { + fn new(x:Arc>, y: Arc>, set: Arc>) -> Self { Circle { x, - y + y, + set, + radius:0 } } @@ -190,17 +194,27 @@ impl Drawable for Circle { } /// Helper method to draw the 8 symmetric points for a given (x, y) offset. - fn draw_and_move(&mut self, display: &mut Display,tick:u32) { + fn draw_and_move(&mut self, display: &mut Display,tick:u32){ +// if(*self.set.lock().unwrap()){ + self.radius = 150; + // *self.set.lock().unwrap() = false; + //} + + //if(self.radius != 0){ let hsv_color = color::Hsv { - h: ((tick/200)%360).try_into().unwrap(), + h: ((tick)%360).try_into().unwrap(), s: 1.0, v: 1.0, }; let rgb: color::Rgb = hsv_color.into(); let draw_y =*self.x.lock().unwrap(); let draw_x = *self.y.lock().unwrap(); - let radius = (tick/30) % (300/2); - self.draw_circle(display,draw_y,draw_x,radius.try_into().unwrap(),rgb.r,rgb.g,rgb.b); + //let radius = (tick/30) % (300/2); + let radius = self.radius; + self.radius = self.radius -1; + for i in 0..10 { + self.draw_circle(display,draw_y,draw_x,radius-i,rgb.r,rgb.g,rgb.b); + } } } @@ -311,9 +325,12 @@ fn main() { let y:Arc>= Arc::new(Mutex::new(0)); let y_thread = y.clone(); - let circle = Box::new(Circle::new(x,y)); + let set:Arc> = Arc::new(Mutex::new(false)); + let set_thread = set.clone(); + + let circle = Box::new(Circle::new(x,y,set)); let mut images:Vec> = vec![ -// Box::new(BouncingImage::new("images/unicorn_cc.png", 13, -10, 1, -1, -1)), +// Box::new(BouncingImage::new("images/unicorn_cc.png", 13, -10, 2, -1, -1)), // Box::new(BouncingImage::new("images/windows_logo.png", -8, 3, 2, -1, -1)), // Box::new(BouncingImage::new("images/spade.png", 32, -12, 1, 0, 0)), // Box::new(BouncingImage::new("images/dvdvideo.png", 20, 6, 5, 1000, 800)), @@ -323,12 +340,13 @@ fn main() { let mut display = Display::new(DISPLAY_HOST, DISPLAY_PORT); let mut frame_counter: u32 = 0; + thread::spawn(move || { let bind_address = format!("0.0.0.0:12345"); let socket = Socket::new(Domain::IPV4, Type::DGRAM, None).unwrap(); socket.set_reuse_address(true).unwrap(); //socket.set_nonblocking(true).unwrap(); - socket.join_multicast_v4(&Ipv4Addr::new(239, 1, 1, 1), &Ipv4Addr::new(0, 0, 0, 0)).unwrap(); + //socket.join_multicast_v4(&Ipv4Addr::new(239, 1, 1, 1), &Ipv4Addr::new(0, 0, 0, 0)).unwrap(); socket.bind(&"0.0.0.0:1234".parse::().unwrap().into()).unwrap(); // Bind the UDP socket to the specified address and port. let socket: UdpSocket = socket.into(); @@ -337,7 +355,7 @@ fn main() { // Create a buffer to hold incoming data. 4 bytes for two u16 values. let mut buf = [0u8; 4]; - + loop { // Wait for a packet to arrive. match socket.recv_from(&mut buf) { @@ -349,12 +367,13 @@ fn main() { // Unpack the buffer into coordinates. if let Some((x_rev, y_rev)) = unpack_coordinates(&buf) { - println!("Received Coordinates: X = {}, Y = {}", x_rev, y_rev); let x_32:u32 = x_rev.into(); + println!("Received Coordinates: X = {}, Y = {}", x_rev, y_rev); + let x_32:u32 = x_rev.into(); let y_32:u32 = y_rev.into(); *x_thread.lock().unwrap() = x_32; *y_thread.lock().unwrap() = y_32; - - + *set_thread.lock().unwrap() = true; + } else { // This case should ideally not be reached if number_of_bytes is 4. eprintln!("Error: Failed to unpack coordinate data."); @@ -390,7 +409,7 @@ fn main() { frame_counter += 1; // A small delay to control the frame rate - //std::thread::sleep(Duration::from_millis(16)); + std::thread::sleep(Duration::from_millis(16)); } }