diff --git a/examples/wled-demo.rs b/examples/wled-demo.rs index b671ce9..ecf138f 100644 --- a/examples/wled-demo.rs +++ b/examples/wled-demo.rs @@ -1,34 +1,30 @@ #![allow(unused_variables)] use anyhow::Result; -use palette::{Hsl, Srgb}; +use palette::Hsl; use photonic::attr::AsFixedAttr; use photonic::Scene; -use photonic_effects::nodes::{Brightness, Raindrops}; -use photonic_output_null::Null; +use photonic_effects::nodes::Raindrops; +use photonic_output_net::wled; #[tokio::main] async fn main() -> Result<()> { let mut scene = Scene::new(); - let base = scene.node("raindrops", Raindrops { + let raindrops = scene.node("raindrops", Raindrops { rate: 0.3.fixed(), decay: (0.96, 0.98).fixed(), - color: (Hsl::new(187.5, 0.25, 0.5), Hsl::new(223.92, 0.5, 0.5)).fixed(), + color: (Hsl::new(27.5, 0.25, 0.5), Hsl::new(79.0, 0.5, 0.5)).fixed(), })?; - let brightness = scene.node("brightness", Brightness { - value: 1.0.fixed(), - source: base, - range: None, - })?; - - // let (scene, introspection) = scene.run(brightness, Terminal { - // waterfall: true, - // })?; + let output = wled::WledSender { + mode: Default::default(), + size: 50, + target: "192.168.0.29:21324".parse()?, + }; - let scene = scene.run(brightness, Null::::default()).await?; + let scene = scene.run(raindrops, output).await?; return scene.run(60).await; } diff --git a/output-net/src/wled.rs b/output-net/src/wled.rs index 5f4a480..49d2112 100644 --- a/output-net/src/wled.rs +++ b/output-net/src/wled.rs @@ -1,6 +1,7 @@ -use byteorder::{BigEndian, WriteBytesExt}; +use std::net::SocketAddr; use anyhow::Result; +use byteorder::{BigEndian, WriteBytesExt}; use palette::rgb::Rgb; use photonic::{BufferReader, Output, OutputDecl, WhiteMode}; @@ -32,15 +33,18 @@ impl Mode { } } -#[derive(Default)] pub struct WledSender { pub mode: Mode, pub size: usize, + + pub target: SocketAddr, } pub struct WledSenderOutput { mode: Mode, size: usize, + + socket: tokio::net::UdpSocket, } impl OutputDecl for WledSender { @@ -50,9 +54,13 @@ impl OutputDecl for WledSender { async fn materialize(self) -> Result where Self::Output: Sized { + let socket = tokio::net::UdpSocket::bind("[::]:0").await?; + socket.connect(self.target).await?; + return Ok(Self::Output { mode: self.mode, size: self.size, + socket, }); } } @@ -110,6 +118,8 @@ impl Output for WledSenderOutput { } } + self.socket.send(&buffer).await?; + return Ok(()); }