fix: cleanup for errors

This commit is contained in:
alban 2023-07-20 21:34:23 +02:00
parent f45b9e5748
commit e148a1ec5e
4 changed files with 13 additions and 33 deletions

View File

@ -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: &ether_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.

View File

@ -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<Utc> = 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,
})
}
}

View File

@ -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<Point> for helios_dac::Point {
}
impl From<Point> 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,

View File

@ -17,6 +17,7 @@ pub enum Order {
Intensity,
Kpps,
ColorBalance,
PowerOff
}
impl TryFrom<u8> for Order {
@ -39,6 +40,7 @@ impl TryFrom<u8> for Order {
6 => Intensity,
7 => Kpps,
8 => ColorBalance,
9 => PowerOff,
_ => unreachable!()
})
}