From 4b135ce283e919febd28f3d9174f0d08d514cc72 Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 8 Jun 2023 20:18:28 +0200 Subject: [PATCH 1/6] fix: rework device --- src/{device/mod.rs => device.rs} | 2 +- src/device/helios.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) rename src/{device/mod.rs => device.rs} (98%) diff --git a/src/device/mod.rs b/src/device.rs similarity index 98% rename from src/device/mod.rs rename to src/device.rs index 70a3916..e231299 100644 --- a/src/device/mod.rs +++ b/src/device.rs @@ -29,7 +29,7 @@ pub struct Status { pub trait Device { fn status( &self ) -> Status; fn draw( - &self, + &mut self, frame: Vec, speed: u32, ) -> LJResult<()> ; diff --git a/src/device/helios.rs b/src/device/helios.rs index a090209..518a45a 100644 --- a/src/device/helios.rs +++ b/src/device/helios.rs @@ -30,7 +30,8 @@ impl HeliosDevice { }; let dac = device.open()?; Ok(Self { - conf: (*conf).clone(), dac, + conf: (*conf).clone(), + dac, }) } } @@ -44,7 +45,7 @@ impl Device for HeliosDevice { }; } - fn draw(&self, + fn draw(&mut self, line: Vec, speed: u32, ) -> LJResult<()> { @@ -52,6 +53,11 @@ impl Device for HeliosDevice { let points: Vec = line.into_iter().map(|p| p.into()).collect(); let frame = Frame::new(speed, points); + + while let Ok(DeviceStatus::NotReady) = self.dac.status() { + self.dac.write_frame(frame.clone())?; + } + Ok(()) } From 6e97b1c4411ed9f56f5322aa7a3415d01aba0ce4 Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 8 Jun 2023 20:21:51 +0200 Subject: [PATCH 2/6] fix: rename settings template --- copyme.Settings.toml => copyme.settings.toml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename copyme.Settings.toml => copyme.settings.toml (100%) diff --git a/copyme.Settings.toml b/copyme.settings.toml similarity index 100% rename from copyme.Settings.toml rename to copyme.settings.toml From 560b3be71b0647e7143112fe445ea2b5b5b041c9 Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 8 Jun 2023 20:22:36 +0200 Subject: [PATCH 3/6] fix: rename settings.toml --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0e205d4..de3276d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Configuration file -Settings.* +settings.* # Generated by Cargo # will have compiled files and executables From d9b96f609080b964d361a3b7007f7ab7cb705827 Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Thu, 8 Jun 2023 21:06:33 +0200 Subject: [PATCH 4/6] fix draw loop --- src/device/helios.rs | 9 +++------ src/main.rs | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/device/helios.rs b/src/device/helios.rs index 9e0cd81..f607bb8 100644 --- a/src/device/helios.rs +++ b/src/device/helios.rs @@ -46,15 +46,12 @@ impl Device for HeliosDevice { line: Vec, speed: u32, ) -> LJResult<()> { - while let Ok(DeviceStatus::NotReady) = self.dac.status() {} + while let Ok(DeviceStatus::NotReady) = self.dac.status() { + } let points: Vec = line.into_iter().map(|p| p.into()).collect(); let frame = Frame::new(speed, points); - - while let Ok(DeviceStatus::NotReady) = self.dac.status() { - self.dac.write_frame(frame.clone())?; - } - + self.dac.write_frame(frame.clone())?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index cb05855..e52ef28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -109,6 +109,6 @@ fn get_next_frame( line = transformer.apply(&line); } - info!("Line: {:?}", line); + //info!("Line: {:?}", line); Ok(line) } From 177f08e461eebc3067ff45b5ee2046a144074a89 Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Thu, 8 Jun 2023 22:23:01 +0200 Subject: [PATCH 5/6] fancy example --- examples/simple_client.rs | 35 ++++++++++++++++++++++++++--------- src/main.rs | 3 +-- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/examples/simple_client.rs b/examples/simple_client.rs index a62c4cc..3bc42cc 100644 --- a/examples/simple_client.rs +++ b/examples/simple_client.rs @@ -5,19 +5,36 @@ use redis::{ Connection, }; +use std::time::Instant; + fn do_something() -> redis::RedisResult<()> { let client = Client::open("redis://127.0.0.1/")?; let mut con: Connection = client.get_connection()?; - - /* do something here */ - //let val : String = con.get("/pl/0/0")?; - let _ = con.set("/pl/0/0", "[(150.0, 230.0, 65280), \ - (170.0, 170.0, 65280), \ - (230.0, 170.0, 65280), \ - (210.0, 230.0, 65280), \ - (150.0, 230.0, 65280)]")?; + let start = Instant::now(); - Ok(()) + loop { + let elapsed = start.elapsed(); + let time = 60.0 * elapsed.as_millis() as f32 / 1000.0; + + let mut v : Vec<(f32,f32,u32)> = vec![]; + + for i in 0..128 { + let a = (time + i as f32) / 128.0 * std::f32::consts::PI * 2.0; + let r = 1200.0 + (a*5.0).cos() * (500.0 * (time/5.0).cos()); + + let x = a.cos() * r; + let y = a.sin() * r; + let col = if i % 8 < 4 { + 0x000000ff + } else { + 0x00ff0000 + }; + v.push((x,y,col)); + } + // println!("{:?}", v); + let _ = con.set("/pl/0/0", format!("{:?}", v))?; + } + // Ok(()) } fn main() { diff --git a/src/main.rs b/src/main.rs index e52ef28..669642c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,9 +72,8 @@ fn run_all() -> LJResult<()> { let frame = get_next_frame(&config, &transformers, &mut rs, order == Order::Black)?; - // For now, draw all the time - tracer.draw(frame, 1000)?; + tracer.draw(frame, 10_000)?; } info!("Exiting, stoping device."); From 015ef9871c15b3d3c4592e17e4294f90710bb765 Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Thu, 8 Jun 2023 22:33:05 +0200 Subject: [PATCH 6/6] add command line --- examples/simple_client.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/simple_client.rs b/examples/simple_client.rs index 3bc42cc..c5fc083 100644 --- a/examples/simple_client.rs +++ b/examples/simple_client.rs @@ -1,3 +1,7 @@ +/// +/// $ cargo run --example simple_client +/// + use redis::{ //RedisResult, Client,