From e148a1ec5eefa9e7dab03966e39042967961339f Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 20 Jul 2023 21:34:23 +0200 Subject: [PATCH] fix: cleanup for errors --- src/device/etherdream.rs | 19 ++----------------- src/device/helios.rs | 9 +++++++-- src/point.rs | 16 ++-------------- src/redis_ctrl.rs | 2 ++ 4 files changed, 13 insertions(+), 33 deletions(-) diff --git a/src/device/etherdream.rs b/src/device/etherdream.rs index 6d1e626..e4ea6a6 100644 --- a/src/device/etherdream.rs +++ b/src/device/etherdream.rs @@ -9,7 +9,7 @@ use crate::conf::EtherDreamConf; use crate::device::{Device, Status, PlaybackState}; use crate::errors::{LJError, LJResult}; use crate::point::{Color, Point}; -use ether_dream::protocol::{DacBroadcast, DacPoint, DacResponse}; +use ether_dream::protocol::{DacBroadcast, DacResponse}; use log::{debug, info, warn}; #[warn(dead_code)] @@ -155,23 +155,13 @@ impl Device for EtherdreamDevice { let n_points = self.points_capacity(); // let n_points = &line.len(); debug!("Etherdream::device draw Generating {:?} points", n_points); - let frames_per_second = 60.0; - // Lets use the DAC at an eighth the maximum scan rate. - let points_per_second = self.stream.dac().max_point_rate / 32; - // Determine the number of points per frame given our target frame and point rates. - let points_per_frame = (points_per_second as f32 / frames_per_second) as u16; - let mut sine_wave = SineWave { - point: 0, - points_per_frame, - frames_per_second, - }; + match self.stream .queue_commands() .data( line.into_iter() .map(|point| point.into()) - // .take(line.len() as usize) .take(n_points as usize) ) // .data(sine_wave.by_ref().take(n_points as usize)) @@ -245,11 +235,6 @@ impl Device for EtherdreamDevice { } } -// Determine the number of points needed to fill the DAC. -fn points_to_generate(dac: ðer_dream::dac::Dac) -> usize { - dac.buffer_capacity as usize - 1 - dac.status.buffer_fullness as usize -} - // An iterator that endlessly generates a sine wave of DAC points. // // The sine wave oscillates at a rate of once per second. diff --git a/src/device/helios.rs b/src/device/helios.rs index 19a346c..0971aeb 100644 --- a/src/device/helios.rs +++ b/src/device/helios.rs @@ -1,3 +1,4 @@ +use std::time::SystemTime; /// /// Configure udev: /// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md @@ -14,7 +15,7 @@ use crate::conf::HeliosConf; use crate::device::{Device, Status, PlaybackState}; use crate::errors::{LJError, LJResult}; use crate::point::{Color, Point}; -use chrono::Utc; +use chrono::{DateTime, Utc}; pub struct HeliosDevice { pub conf: HeliosConf, @@ -34,13 +35,17 @@ impl HeliosDevice { return Err(Box::new(LJError::HeliosDeviceMissing)); }; let dac = device.open()?; + let now = SystemTime::now(); + let now: DateTime = now.into(); + let last_traced_at = now.to_rfc3339(); + Ok(Self { conf: (*conf).clone(), dac, sent_points: 0, state: PlaybackState::PREPARE, lack: "".to_string(), - last_traced_at: "1985-04-12T23:20:50.52Z".to_string(), + last_traced_at, }) } } diff --git a/src/point.rs b/src/point.rs index 9f88f43..6ce6268 100644 --- a/src/point.rs +++ b/src/point.rs @@ -1,15 +1,4 @@ use ether_dream::protocol::DacPoint; -use log::debug; - -fn clamp(val: f32, min: f32, max: f32) -> f32 { - if val < min { - return min; - } - if val > max { - return max; - } - val -} #[derive(Debug, Clone, Copy, Default, PartialEq)] pub struct Point { @@ -56,13 +45,12 @@ impl From for helios_dac::Point { } impl From for DacPoint { - fn from(pt: Point) -> DacPoint { let control = 0; let (u1, u2) = (0, 0); let i = 255; - let x = clamp(pt.x, -32000 as f32, 32000 as f32); - let y = clamp(pt.y, -32000 as f32, 32000 as f32); + let x = pt.x.clamp(-32000.0, 32000.0); + let y = pt.y.clamp(-32000.0, 32000.0); DacPoint { control, x: x as i16, diff --git a/src/redis_ctrl.rs b/src/redis_ctrl.rs index 4fdcdde..03d7cba 100644 --- a/src/redis_ctrl.rs +++ b/src/redis_ctrl.rs @@ -17,6 +17,7 @@ pub enum Order { Intensity, Kpps, ColorBalance, + PowerOff } impl TryFrom for Order { @@ -39,6 +40,7 @@ impl TryFrom for Order { 6 => Intensity, 7 => Kpps, 8 => ColorBalance, + 9 => PowerOff, _ => unreachable!() }) }